diff --git a/cmake/compiler/xcc-clang/compiler_flags.cmake b/cmake/compiler/xcc-clang/compiler_flags.cmake new file mode 100644 index 00000000000..8b0a29a0533 --- /dev/null +++ b/cmake/compiler/xcc-clang/compiler_flags.cmake @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake) + +# Clear "nostdinc" +set_compiler_property(PROPERTY nostdinc) +set_compiler_property(PROPERTY nostdinc_include) + +if($ENV{XCC_NO_G_FLAG}) + # Older xcc/clang cannot use "-g" due to this bug: + # https://bugs.llvm.org/show_bug.cgi?id=11740. + # Clear the related flag(s) here so it won't cause issues. + set_compiler_property(PROPERTY debug) +endif() diff --git a/cmake/compiler/xcc-clang/generic.cmake b/cmake/compiler/xcc-clang/generic.cmake new file mode 100644 index 00000000000..4b48733b188 --- /dev/null +++ b/cmake/compiler/xcc-clang/generic.cmake @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/cmake/compiler/xcc/generic.cmake) diff --git a/cmake/compiler/xcc-clang/target.cmake b/cmake/compiler/xcc-clang/target.cmake new file mode 100644 index 00000000000..33b3be758da --- /dev/null +++ b/cmake/compiler/xcc-clang/target.cmake @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/cmake/compiler/xcc/target.cmake) diff --git a/cmake/compiler/xcc/compiler_flags.cmake b/cmake/compiler/xcc/compiler_flags.cmake index fa830d92692..f6e14aacc63 100644 --- a/cmake/compiler/xcc/compiler_flags.cmake +++ b/cmake/compiler/xcc/compiler_flags.cmake @@ -1,23 +1,11 @@ -# No special flags are needed for xcc. -# Only select whether gcc or clang flags should be inherited. -if(CC STREQUAL "clang") - include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake) +# SPDX-License-Identifier: Apache-2.0 - # Now, let's overwrite the flags that are different in xcc/clang. - if($ENV{XCC_NO_G_FLAG}) - # Older xcc/clang cannot use "-g" due to this bug: - # https://bugs.llvm.org/show_bug.cgi?id=11740. - # Clear the related flag(s) here so it won't cause issues. - set_compiler_property(PROPERTY debug) - endif() -else() - include(${ZEPHYR_BASE}/cmake/compiler/gcc/compiler_flags.cmake) +include(${ZEPHYR_BASE}/cmake/compiler/gcc/compiler_flags.cmake) - # XCC is based on GCC 4.2 which has a somewhat pedantic take on the - # fact that linkage semantics differed between C99 and GNU at the - # time. Suppress the warning, it's the best we can do given that - # it's a legacy compiler. - set_compiler_property(APPEND PROPERTY warning_base "-fgnu89-inline") +# XCC is based on GCC 4.2 which has a somewhat pedantic take on the +# fact that linkage semantics differed between C99 and GNU at the +# time. Suppress the warning, it's the best we can do given that +# it's a legacy compiler. +set_compiler_property(APPEND PROPERTY warning_base "-fgnu89-inline") - set_compiler_property(PROPERTY warning_error_misra_sane) -endif() +set_compiler_property(PROPERTY warning_error_misra_sane) diff --git a/cmake/modules/verify-toolchain.cmake b/cmake/modules/verify-toolchain.cmake index 06a01b7abb2..114c7dd94ee 100644 --- a/cmake/modules/verify-toolchain.cmake +++ b/cmake/modules/verify-toolchain.cmake @@ -37,6 +37,13 @@ if("${ARCH}" STREQUAL "posix") return() endif() +# Keep XCC_USE_CLANG behaviour for a while. +if ("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "xcc" + AND "$ENV{XCC_USE_CLANG}" STREQUAL "1") + set(ZEPHYR_TOOLCHAIN_VARIANT xcc-clang) + message(STATUS "XCC_USE_CLANG is deprecated. Please set ZEPHYR_TOOLCHAIN_VARIANT to 'xcc-clang'") +endif() + if(NOT ZEPHYR_TOOLCHAIN_VARIANT AND (CROSS_COMPILE OR (DEFINED ENV{CROSS_COMPILE}))) set(ZEPHYR_TOOLCHAIN_VARIANT cross-compile) diff --git a/cmake/toolchain/xcc-clang/generic.cmake b/cmake/toolchain/xcc-clang/generic.cmake new file mode 100644 index 00000000000..a8c8685ccbc --- /dev/null +++ b/cmake/toolchain/xcc-clang/generic.cmake @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/cmake/toolchain/xcc/common.cmake) + +set(COMPILER xcc-clang) +set(CC clang) +set(C++ clang++) + +message(STATUS "Found toolchain: xcc-clang (${XTENSA_TOOLCHAIN_PATH})") diff --git a/cmake/toolchain/xcc-clang/target.cmake b/cmake/toolchain/xcc-clang/target.cmake new file mode 100644 index 00000000000..b970dc3e7d8 --- /dev/null +++ b/cmake/toolchain/xcc-clang/target.cmake @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Intentionally left blank. diff --git a/cmake/toolchain/xcc/common.cmake b/cmake/toolchain/xcc/common.cmake new file mode 100644 index 00000000000..756c1cf3df9 --- /dev/null +++ b/cmake/toolchain/xcc/common.cmake @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: Apache-2.0 + +set_ifndef(XTENSA_TOOLCHAIN_PATH "$ENV{XTENSA_TOOLCHAIN_PATH}") +set( XTENSA_TOOLCHAIN_PATH ${XTENSA_TOOLCHAIN_PATH} CACHE PATH "xtensa tools install directory") +assert( XTENSA_TOOLCHAIN_PATH "XTENSA_TOOLCHAIN_PATH is not set") + +if(NOT EXISTS ${XTENSA_TOOLCHAIN_PATH}) + message(FATAL_ERROR "Nothing found at XTENSA_TOOLCHAIN_PATH: '${XTENSA_TOOLCHAIN_PATH}'") +endif() + +set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/$ENV{TOOLCHAIN_VER}/XtensaTools) + +set(LINKER ld) +set(BINTOOLS gnu) + +set(CROSS_COMPILE_TARGET xt) +set(SYSROOT_TARGET xtensa-elf) + +set(CROSS_COMPILE ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-) +set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET}) + +set(NOSYSDEF_CFLAG "") + +list(APPEND TOOLCHAIN_C_FLAGS -fms-extensions) + +set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") diff --git a/cmake/toolchain/xcc/generic.cmake b/cmake/toolchain/xcc/generic.cmake index fd9515fa72b..26b1a3868e4 100644 --- a/cmake/toolchain/xcc/generic.cmake +++ b/cmake/toolchain/xcc/generic.cmake @@ -1,54 +1,24 @@ # SPDX-License-Identifier: Apache-2.0 -set_ifndef(XTENSA_TOOLCHAIN_PATH "$ENV{XTENSA_TOOLCHAIN_PATH}") -set( XTENSA_TOOLCHAIN_PATH ${XTENSA_TOOLCHAIN_PATH} CACHE PATH "xtensa tools install directory") -assert( XTENSA_TOOLCHAIN_PATH "XTENSA_TOOLCHAIN_PATH is not set") - -if(NOT EXISTS ${XTENSA_TOOLCHAIN_PATH}) - message(FATAL_ERROR "Nothing found at XTENSA_TOOLCHAIN_PATH: '${XTENSA_TOOLCHAIN_PATH}'") -endif() - -set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/$ENV{TOOLCHAIN_VER}/XtensaTools) +include(${ZEPHYR_BASE}/cmake/toolchain/xcc/common.cmake) set(COMPILER xcc) -set(LINKER ld) -set(BINTOOLS gnu) - -set(CROSS_COMPILE_TARGET xt) -set(SYSROOT_TARGET xtensa-elf) - -set(CROSS_COMPILE ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-) -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($ENV{XCC_USE_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 + ) - list(APPEND TOOLCHAIN_C_FLAGS - -imacros${ZEPHYR_BASE}/include/toolchain/xcc_missing_defs.h - ) - - # GCC-based XCC uses GNU Assembler (xt-as). - # However, CMake doesn't recognize it when invoking through xt-xcc. - # This results in CMake going through all possible combinations of - # command line arguments while invoking xt-xcc to determine - # assembler vendor. This multiple invocation of xt-xcc unnecessarily - # lengthens the CMake phase of build, especially when XCC needs to - # obtain license information from remote licensing servers. So here - # forces the assembler ID to be GNU to speed things up a bit. - set(CMAKE_ASM_COMPILER_ID "GNU") -endif() - -set(NOSYSDEF_CFLAG "") - -list(APPEND TOOLCHAIN_C_FLAGS -fms-extensions) - -set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") +# GCC-based XCC uses GNU Assembler (xt-as). +# However, CMake doesn't recognize it when invoking through xt-xcc. +# This results in CMake going through all possible combinations of +# command line arguments while invoking xt-xcc to determine +# assembler vendor. This multiple invocation of xt-xcc unnecessarily +# lengthens the CMake phase of build, especially when XCC needs to +# obtain license information from remote licensing servers. So here +# forces the assembler ID to be GNU to speed things up a bit. +set(CMAKE_ASM_COMPILER_ID "GNU") message(STATUS "Found toolchain: xcc (${XTENSA_TOOLCHAIN_PATH})") diff --git a/doc/getting_started/toolchain_3rd_party_x_compilers.rst b/doc/getting_started/toolchain_3rd_party_x_compilers.rst index a433ed89e09..a196319bd1a 100644 --- a/doc/getting_started/toolchain_3rd_party_x_compilers.rst +++ b/doc/getting_started/toolchain_3rd_party_x_compilers.rst @@ -233,14 +233,12 @@ Cadence Tensilica Xtensa C/C++ Compiler (XCC) * Clang-based compiler: ``xt-clang`` and its friends. - * By default, Zephyr would use GCC-based ``xt-xcc``. - #. Make sure you have obtained a license to use the SDK, or has access to a remote licensing server. #. :ref:`Set these environment variables `: - * Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to ``xcc``. + * Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to ``xcc`` or ``xcc-clang``. * Set :envvar:`XTENSA_TOOLCHAIN_PATH` to the toolchain installation directory. * Set :envvar:`XTENSA_CORE` to the SoC ID where application is being @@ -261,14 +259,7 @@ Cadence Tensilica Xtensa C/C++ Compiler (XCC) #. To use Clang-based compiler: - * Set :envvar:`XCC_USE_CLANG` to ``1``. - - * For example: - - .. code-block:: console - - # Linux - export XCC_USE_CLANG=1 + * Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to ``xcc-clang``. * Note that the Clang-based compiler may contain an old LLVM bug which results in the following error: @@ -288,6 +279,10 @@ Cadence Tensilica Xtensa C/C++ Compiler (XCC) # Linux export XCC_NO_G_FLAG=1 + * Also note that setting :envvar:`XCC_USE_CLANG` to ``1`` and + :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to ``xcc`` is deprecated. + Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to ``xcc-clang`` instead. + .. _GNU Arm Embedded: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm .. _crosstool-ng site: http://crosstool-ng.org .. _Arm Compiler 6: https://developer.arm.com/tools-and-software/embedded/arm-compiler/downloads/version-6