Skip to content

Commit 527485f

Browse files
BujSetGithub Executorch
authored andcommitted
Testing overloading of arm-eabi-gcc.cmake to use for both zephyr and bare metal
1 parent bafc2e4 commit 527485f

File tree

4 files changed

+125
-6
lines changed

4 files changed

+125
-6
lines changed

.github/workflows/trunk.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ jobs:
241241
cxx_flags="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context -DET_HAVE_PREAD=0"
242242
if [[ ${{ matrix.os}} == "bare_metal" ]]; then
243243
setup_script=.ci/scripts/setup-arm-baremetal-tools.sh
244-
toolchain_prefic=arm-none-eabi-
244+
toolchain_prefix=arm-none-eabi-
245245
threshold="103268" # ~100KiB
246246
elif [[ ${{ matrix.os}} == "zephyr-preset" ]]; then
247247
setup_script=.ci/scripts/setup-arm-zephyr-x86-64-tools.sh
248-
toolchain_prefic=arm-zephyr-eabi-
248+
toolchain_prefix=arm-zephyr-eabi-
249249
threshold="153600" # should be ~138KB, set threashold to 150KB
250250
else
251251
echo "Fail unsupport OS selection ${{ matrix.os }}"
@@ -259,7 +259,7 @@ jobs:
259259
260260
# User toolchain
261261
${toolchain_prefix}c++ --version
262-
toolchain_cmake=examples/arm/ethos-u-setup/${toolchain_prefix}gcc.cmake
262+
toolchain_cmake=examples/arm/ethos-u-setup/arm-eabi-gcc.cmake
263263
toolchain_cmake=$(realpath ${toolchain_cmake})
264264
265265
# Build and test size test
@@ -268,7 +268,7 @@ jobs:
268268
elif [[ ${{ matrix.os}} == "zephyr-preset" ]]; then
269269
CXXFLAGS=${cxx_flags} cmake --preset zephyr -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out .
270270
cmake --build cmake-out -j9 --target install --config Release
271-
CXXFLAGS=${cxx_flags} cmake -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out/test test
271+
CXXFLAGS=${cxx_flags} cmake -DARM_TOOLCHAIN_NAME=zephyr -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out/test test
272272
cmake --build cmake-out/test -j9 --config Release
273273
else
274274
echo "Fail unsupport OS selection ${{ matrix.os }}"

CMakePresets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@
113113
],
114114
"cacheVariables": {
115115
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/zephyr.cmake",
116-
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/examples/arm/ethos-u-setup/arm-zephyr-eabi-gcc.cmake"
116+
"ARM_TOOLCHAIN_NAME": "zephyr",
117+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/examples/arm/ethos-u-setup/arm-eabi-gcc.cmake"
117118
}
118119
}
119120
]
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
#
3+
# Copyright (c) 2020-2022 Arm Limited. All rights reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the License); you may
8+
# not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake And
21+
# modified to align better with cs300 platform
22+
23+
set(TARGET_CPU
24+
"cortex-m55"
25+
CACHE STRING "Target CPU"
26+
)
27+
string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)
28+
29+
if(ARM_TOOLCHAIN_NAME MATCHES "^zephyr")
30+
set(CMAKE_ARM_ARCH_ABI arm-zephyr-eabi)
31+
else()
32+
set(CMAKE_ARM_ARCH_ABI arm-none-eabi)
33+
endif()
34+
35+
set(CMAKE_SYSTEM_NAME Generic)
36+
set(CMAKE_C_COMPILER "${CMAKE_ARM_ARCH_ABI}-gcc")
37+
set(CMAKE_CXX_COMPILER "${CMAKE_ARM_ARCH_ABI}-g++")
38+
set(CMAKE_ASM_COMPILER "${CMAKE_ARM_ARCH_ABI}-gcc")
39+
set(CMAKE_LINKER "${CMAKE_ARM_ARCH_ABI}-ld")
40+
41+
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
42+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
43+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
44+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
45+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
46+
47+
# Select C/C++ version
48+
set(CMAKE_C_STANDARD 11)
49+
set(CMAKE_CXX_STANDARD 17)
50+
51+
set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR})
52+
string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU})
53+
54+
# Compile options
55+
add_compile_options(
56+
-mcpu=${GCC_CPU} -mthumb "$<$<CONFIG:DEBUG>:-gdwarf-3>"
57+
"$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>"
58+
-fdata-sections -ffunction-sections
59+
)
60+
61+
# Compile defines
62+
add_compile_definitions("$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
63+
64+
# Link options
65+
add_link_options(-mcpu=${GCC_CPU} -mthumb)
66+
67+
if(SEMIHOSTING)
68+
add_link_options(--specs=rdimon.specs)
69+
else()
70+
add_link_options(--specs=nosys.specs)
71+
endif()
72+
73+
# Set floating point unit
74+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp")
75+
set(FLOAT hard)
76+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp")
77+
set(FLOAT soft)
78+
elseif(
79+
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)"
80+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)"
81+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)"
82+
)
83+
set(FLOAT hard)
84+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)"
85+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)"
86+
)
87+
set(FLOAT hard)
88+
set(FPU_CONFIG "fpv4-sp-d16")
89+
add_compile_options(-mfpu=${FPU_CONFIG})
90+
add_link_options(-mfpu=${FPU_CONFIG})
91+
else()
92+
set(FLOAT soft)
93+
endif()
94+
95+
if(FLOAT)
96+
add_compile_options(-mfloat-abi=${FLOAT})
97+
add_link_options(-mfloat-abi=${FLOAT})
98+
endif()
99+
100+
add_link_options(LINKER:--nmagic,--gc-sections)
101+
102+
# Compilation warnings
103+
add_compile_options(
104+
# -Wall -Wextra -Wcast-align -Wdouble-promotion -Wformat
105+
# -Wmissing-field-initializers -Wnull-dereference -Wredundant-decls -Wshadow
106+
# -Wswitch -Wswitch-default -Wunused -Wno-redundant-decls
107+
-Wno-error=deprecated-declarations
108+
-Wno-error=shift-count-overflow
109+
-Wno-psabi
110+
)
111+
112+
if (CMAKE_ARM_ARCH_ABI STREQUAL "arm-zephyr-eabi")
113+
add_compile_options(
114+
-Wno-stringop-overread
115+
-Wno-error=format=
116+
-Wno-error=maybe-uninitialized
117+
)
118+
endif()

tools/cmake/preset/zephyr.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8-
set_overridable_option(CMAKE_TOOLCHAIN_FILE "${PROJECT_SOURCE_DIR}/examples/arm/ethos-u-setup/arm-zephyr-eabi-gcc.cmake")
8+
set(ARM_TOOLCHAIN_NAME zephyr)
99
set_overridable_option(EXECUTORCH_BUILD_COREML OFF)
1010
set_overridable_option(EXECUTORCH_ENABLE_EVENT_TRACER OFF)
1111
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM OFF)

0 commit comments

Comments
 (0)