diff --git a/cmake/compiler/xcc/target.cmake b/cmake/compiler/xcc/target.cmake index 329d35bf72c..a0d1d4693f1 100644 --- a/cmake/compiler/xcc/target.cmake +++ b/cmake/compiler/xcc/target.cmake @@ -73,6 +73,11 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_optimizations.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake) -include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_warnings.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_base.cmake) + +if(CC STREQUAL "clang") + include(${ZEPHYR_BASE}/cmake/compiler/clang/target_warnings.cmake) +else() + include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_warnings.cmake) +endif() diff --git a/cmake/toolchain/xcc/generic.cmake b/cmake/toolchain/xcc/generic.cmake index 37e3c2994ef..9104886ba11 100644 --- a/cmake/toolchain/xcc/generic.cmake +++ b/cmake/toolchain/xcc/generic.cmake @@ -23,15 +23,20 @@ set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET}) # xt-xcc does not support -Og, so make it -O0 set(OPTIMIZE_FOR_DEBUG_FLAG "-O0") -set(CC xcc) -set(C++ xc++) +if(EXISTS ${CROSS_COMPILE}clang) + set(CC clang) + set(C++ clang++) +else() + set(CC xcc) + set(C++ xc++) + + list(APPEND TOOLCHAIN_C_FLAGS + -imacros${ZEPHYR_BASE}/include/toolchain/xcc_missing_defs.h + ) +endif() set(NOSYSDEF_CFLAG "") list(APPEND TOOLCHAIN_C_FLAGS -fms-extensions) -list(APPEND TOOLCHAIN_C_FLAGS - -imacros${ZEPHYR_BASE}/include/toolchain/xcc_missing_defs.h - ) - set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") diff --git a/include/toolchain/xcc.h b/include/toolchain/xcc.h index ed4030efd0f..4803227dae3 100644 --- a/include/toolchain/xcc.h +++ b/include/toolchain/xcc.h @@ -11,10 +11,18 @@ * there. However, __BYTE_ORDER__ is actually being defined later in * this file. So define __BYTE_ORDER__ to skip the check in gcc.h * and undefine after including gcc.h. + * + * Clang has it defined so there is no need to work around. */ +#ifndef __clang__ #define __BYTE_ORDER__ +#endif + #include + +#ifndef __clang__ #undef __BYTE_ORDER__ +#endif #include @@ -22,8 +30,12 @@ #define UINT32_C(x) x ## U #endif -/* XCC doesn't support __COUNTER__ but this should be good enough */ +#ifndef __COUNTER__ +/* XCC (GCC-based compiler) doesn't support __COUNTER__ + * but this should be good enough + */ #define __COUNTER__ __LINE__ +#endif #undef __in_section_unique #define __in_section_unique(seg) \ diff --git a/soc/xtensa/intel_s1000/xcc/CMakeLists.txt b/soc/xtensa/intel_s1000/xcc/CMakeLists.txt index 009b3882e93..090721d7500 100644 --- a/soc/xtensa/intel_s1000/xcc/CMakeLists.txt +++ b/soc/xtensa/intel_s1000/xcc/CMakeLists.txt @@ -2,5 +2,10 @@ zephyr_library_sources_ifdef(CONFIG_CPLUSPLUS cpp_fixes.c) zephyr_library_sources_ifdef(CONFIG_NEWLIB_LIBC newlib_fixes.c) + +if(NOT (CC STREQUAL "clang")) +# These two are due to IS_ENABLED() not being parsed correctly +# in old GCC 4.2 based XCC. Clang is not affected. zephyr_library_sources_ifdef(CONFIG_LOG_MINIMAL log_minimal_fixes.c) zephyr_library_sources_ifdef(CONFIG_TEST ztest_fixes.c) +endif()