Skip to content

Commit

Permalink
cmake: toolchain/xcc,xt-clang: env vars for multiple cores
Browse files Browse the repository at this point in the history
To use Xtensa toolchain, various environment variables must be
set so the executables can find necessary files and what core
to compile for. This becomes an annoyance when you have to
test multiple boards with different cores. You have to use
one set of environment variables per core. Twister cannot test
them all in one setting, and it is especially annoying doing
west builds. So enhance the environment variables handling so
that TOOLCHAIN_VER and XTENSA_CORE can be replaced by
TOOLCHAIN_VAR_<board> and XTENSA_CORE_<board> where <board>
is the normalized board target (think <board>.yaml). CMake
will then figure out the core ID for the toolchain to use.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
  • Loading branch information
dcpleung committed Oct 8, 2024
1 parent c44c9fb commit 86874bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion arch/xtensa/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ set(CORE_ISA_DM ${CMAKE_BINARY_DIR}/zephyr/include/generated/zephyr/core-isa-dM.
set(CORE_ISA_IN ${CMAKE_BINARY_DIR}/zephyr/include/generated/core-isa-dM.c)
file(WRITE ${CORE_ISA_IN} "#include <xtensa/config/core-isa.h>\n")
add_custom_command(OUTPUT ${CORE_ISA_DM}
COMMAND ${CMAKE_C_COMPILER} -E -dM -U__XCC__
COMMAND ${CMAKE_C_COMPILER} -E -dM -U__XCC__ ${XTENSA_CORE_LOCAL_C_FLAG}
-I${ZEPHYR_XTENSA_MODULE_DIR}/zephyr/soc/${CONFIG_SOC}
-I${SOC_FULL_DIR}
${CORE_ISA_IN} -o ${CORE_ISA_DM})
Expand Down
4 changes: 2 additions & 2 deletions cmake/compiler/xcc/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ TOOLCHAIN_VER: ${TOOLCHAIN_VER}
endif()

execute_process(
COMMAND ${CMAKE_C_COMPILER} --version
COMMAND ${CMAKE_C_COMPILER} --version ${XTENSA_CORE_LOCAL_C_FLAG}
RESULT_VARIABLE ret
OUTPUT_VARIABLE stdoutput
)
if(ret)
message(FATAL_ERROR "Executing the below command failed. Are permissions set correctly?
${CMAKE_C_COMPILER} --version
${CMAKE_C_COMPILER} --version ${XTENSA_CORE_LOCAL_C_FLAG}
${stdoutput}
"
)
Expand Down
19 changes: 18 additions & 1 deletion cmake/toolchain/xcc/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,24 @@ 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)
if(DEFINED ENV{TOOLCHAIN_VER})
set(XTENSA_TOOLCHAIN_VER $ENV{TOOLCHAIN_VER})
elseif(DEFINED ENV{TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET}})
set(XTENSA_TOOLCHAIN_VER $ENV{TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET}})
else()
message(FATAL "Environment variable TOOLCHAIN_VER must be set")
endif()

if(DEFINED ENV{XTENSA_CORE_${NORMALIZED_BOARD_TARGET}})
set(XTENSA_CORE_LOCAL_C_FLAG "--xtensa-core=$ENV{XTENSA_CORE_${NORMALIZED_BOARD_TARGET}}")
list(APPEND TOOLCHAIN_C_FLAGS "--xtensa-core=$ENV{XTENSA_CORE_${NORMALIZED_BOARD_TARGET}}")
else()
# Not having XTENSA_CORE is not necessarily fatal as
# the toolchain can have a default core configuration to use.
set(XTENSA_CORE_LOCAL_C_FLAG)
endif()

set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/${XTENSA_TOOLCHAIN_VER}/XtensaTools)

set(LINKER ld)
set(BINTOOLS gnu)
Expand Down

0 comments on commit 86874bc

Please sign in to comment.