Skip to content

Commit df2145e

Browse files
committed
cmake: Parse ZEPHYR_TOOLCHAIN_VARIANT in SDK instead of Zephyr
When ZEPHYR_TOOLCHAIN_VARIANT is of the form toolchain/compiler, it needs to be split into the toolchain (which overwrites ZEPHYR_TOOLCHAIN_VARIANT) and compiler (stored in TOOLCHAIN_VARIANT_COMPILER). Otherwise, when defined, it is left alone. When undefined it is set to "zephyr". Finally, if the value is "zephyr" and no TOOLCHAIN_VARIANT_COMPILER setting is present, then TOOLCHAIN_VARIANT_COMPILER is set to "gnu". This allows existing configurations which set ZEPHYR_TOOLCHAIN_VARIANT to "zephyr" to work with the new SDK and allows Zephyr to easily support both old and new variable settings during the SDK transition period. Finally, write both values into the environment so that Kconfig can use them. Signed-off-by: Keith Packard <[email protected]>
1 parent d0665e2 commit df2145e

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

cmake/Zephyr-sdkConfig.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,26 @@ set(SDK_MAJOR_MINOR_MICRO ${SDK_VERSION})
1212
get_filename_component(ZEPHYR_SDK_INSTALL_DIR ${CMAKE_CURRENT_LIST_DIR}/.. ABSOLUTE)
1313
set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR})
1414

15-
if(NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT)
16-
set(ZEPHYR_TOOLCHAIN_VARIANT "zephyr/gnu")
15+
# Check and see if the user specified a toolchain
16+
if(DEFINED ZEPHYR_TOOLCHAIN_VARIANT)
17+
# Check and see if the specified toolchain includes a compiler
18+
if(ZEPHYR_TOOLCHAIN_VARIANT MATCHES "^([^/])+/([^/]+)$")
19+
# Replace any existing values with the provided components
20+
set(ZEPHYR_TOOLCHAIN_VARIANT "${CMAKE_MATCH_1}" CACHE STRING "toolchain" FORCE)
21+
set(TOOLCHAIN_VARIANT_COMPILER "${CMAKE_MATCH_2}" CACHE STRING "compiler" FORCE)
22+
endif()
23+
else()
24+
set(ZEPHYR_TOOLCHAIN_VARIANT "zephyr")
1725
endif()
1826

27+
# When using the Zephyr SDK, use the gnu compiler by default
28+
if(ZEPHYR_TOOLCHAIN_VARIANT STREQUAL "zephyr" AND NOT DEFINED TOOLCHAIN_VARIANT_COMPILER)
29+
set(TOOLCHAIN_VARIANT_COMPILER "gnu")
30+
endif()
31+
32+
set(ENV{ZEPHYR_TOOLCHAIN_VARIANT} "${ZEPHYR_TOOLCHAIN_VARIANT}")
33+
set(ENV{TOOLCHAIN_VARIANT_COMPILER} "${TOOLCHAIN_VARIANT_COMPILER}")
34+
1935
# Those are CMake package parameters.
2036
set(Zephyr-sdk_FOUND True)
2137
set(Zephyr-sdk_DIR ${ZEPHYR_SDK_INSTALL_DIR})

0 commit comments

Comments
 (0)