Skip to content

Commit 94202f3

Browse files
daor-otinashif
authored andcommitted
toolchain: cmake: Off-tree toolchains gets other.h included if selected
To ensure that an off-tree toolchain gets the toolchain/other.h header included, such that it can include the correct header for the toolchain via the other.h, the define __TOOLCHAIN_CUSTOM__ will be set when ever the cmake flag TOOLCHAIN_USE_CUSTOM is set. An off-tree toolchain needs to set the set(TOOLCHAIN_USE_CUSTOM 1) in the off-tree generic.cmake and/or target.cmake, in order for the include/other.h to be included. The generic.cmake and target.cmake will be under ${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/ As the TOOLCHAIN_USE_CUSTOM is only set for off-tree toolchains, this has no impact on in-tree toolchains and their functionality. Fixes #36117 Signed-off-by: Danny Oerndrup <[email protected]>
1 parent 51f2022 commit 94202f3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ zephyr_compile_definitions(
9595
__ZEPHYR__=1
9696
)
9797

98+
# Ensure that include/toolchain.h includes toolchain/other.h for all off-tree toolchains
99+
if(TOOLCHAIN_USE_CUSTOM)
100+
zephyr_compile_definitions(__TOOLCHAIN_CUSTOM__)
101+
endif()
102+
98103
# @Intent: Set compiler flags to enable buffer overflow checks in libc functions
99104
# @config in CONFIG_NO_OPTIMIZATIONS optional : Optimizations may affect security
100105
zephyr_compile_definitions($<TARGET_PROPERTY:compiler,security_fortify> )

include/toolchain.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
#define HAS_BUILTIN(x) HAS_BUILTIN_##x
3434
#endif
3535

36-
#if defined(__XCC__)
36+
#if defined(__TOOLCHAIN_CUSTOM__)
37+
/* This include line exists for off-tree definitions of compilers,
38+
* and therefore this header is not meant to exist in-tree
39+
*/
40+
#include <toolchain/other.h>
41+
#elif defined(__XCC__)
3742
#include <toolchain/xcc.h>
3843
#elif defined(__CCAC__)
3944
#include <toolchain/mwdt.h>
@@ -42,10 +47,7 @@
4247
#elif defined(__GNUC__) || (defined(_LINKER) && defined(__GCC_LINKER_CMD__))
4348
#include <toolchain/gcc.h>
4449
#else
45-
/* This include line exists for off-tree definitions of compilers,
46-
* and therefore this header is not meant to exist in-tree
47-
*/
48-
#include <toolchain/other.h>
50+
#error "Invalid/unknown toolchain configuration"
4951
#endif
5052

5153
/*

0 commit comments

Comments
 (0)