Skip to content

Commit ba7abf6

Browse files
nashifkeith-packard
authored andcommitted
cmake: add support enhanced variants with multiple compilers
Retain support for older SDK versions by checking for both paths to GNU toolchains. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent 0b2fbb7 commit ba7abf6

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

cmake/modules/FindHostTools.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ zephyr_file(APPLICATION_ROOT TOOLCHAIN_ROOT)
9595

9696
# Host-tools don't unconditionally set TOOLCHAIN_HOME anymore,
9797
# but in case Zephyr's SDK toolchain is used, set TOOLCHAIN_HOME
98-
if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "zephyr")
98+
if("${ZEPHYR_TOOLCHAIN_VARIANT}" MATCHES "^zephyr/?")
9999
set(TOOLCHAIN_HOME ${HOST_TOOLS_HOME})
100100
endif()
101101

@@ -108,12 +108,11 @@ if("${ZEPHYR_TOOLCHAIN_VARIANT}" MATCHES "^([^/]+)/([^/]+)$")
108108
set(_variant "${CMAKE_MATCH_1}")
109109
set(_compiler "${CMAKE_MATCH_2}")
110110
set(ZEPHYR_TOOLCHAIN_VARIANT "${_variant}")
111-
set(TOOLCHAIN_VARIANT_COMPILER "${_compiler}")
112111
set(TOOLCHAIN_VARIANT_COMPILER ${_compiler} CACHE STRING "compiler used by the toolchain variant" FORCE)
113112
endif()
114113

115114
# Set cached ZEPHYR_TOOLCHAIN_VARIANT.
116-
set(ZEPHYR_TOOLCHAIN_VARIANT ${ZEPHYR_TOOLCHAIN_VARIANT} CACHE STRING "Zephyr toolchain variant")
115+
set(ZEPHYR_TOOLCHAIN_VARIANT ${ZEPHYR_TOOLCHAIN_VARIANT} CACHE STRING "Zephyr toolchain variant" FORCE)
117116

118117
# Configure the toolchain based on what SDK/toolchain is in use.
119118
include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/generic.cmake)

cmake/modules/FindZephyr-sdk.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ endif()
5454
# 1) Zephyr specified as toolchain (ZEPHYR_SDK_INSTALL_DIR still used if defined)
5555
# 2) No toolchain specified == Default to Zephyr toolchain
5656
# Until we completely deprecate it
57-
if(("zephyr" STREQUAL ${ZEPHYR_TOOLCHAIN_VARIANT}) OR
57+
if((${ZEPHYR_TOOLCHAIN_VARIANT} MATCHES "^zephyr/?") OR
5858
(NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT) OR
5959
(DEFINED ZEPHYR_SDK_INSTALL_DIR) OR
6060
(Zephyr-sdk_FIND_REQUIRED))

cmake/toolchain/zephyr/generic.cmake

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/generic.cmake)
3+
if(TOOLCHAIN_VARIANT_COMPILER STREQUAL "gnu" OR
4+
NOT DEFINED TOOLCHAIN_VARIANT_COMPILER)
5+
if(EXISTS ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/gnu/generic.cmake)
6+
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/gnu/generic.cmake)
7+
else()
8+
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/generic.cmake)
9+
endif()
10+
set(TOOLCHAIN_VARIANT_COMPILER "gnu" CACHE STRING "compiler used by the toolchain variant" FORCE)
411

5-
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)
12+
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)
13+
# Zephyr SDK < 0.17.1 does not set TOOLCHAIN_HAS_GLIBCXX
14+
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")
15+
message(STATUS "Found toolchain: zephyr ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")
16+
elseif(TOOLCHAIN_VARIANT_COMPILER STREQUAL "llvm")
17+
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/llvm/generic.cmake)
18+
set(TOOLCHAIN_VARIANT_COMPILER "llvm" CACHE STRING "compiler used by the toolchain variant" FORCE)
619

7-
# Zephyr SDK < 0.17.1 does not set TOOLCHAIN_HAS_GLIBCXX
8-
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")
20+
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)
921

10-
message(STATUS "Found toolchain: zephyr-sdk-gnu ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")
22+
message(STATUS "Found toolchain: zephyr ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")
23+
else()
24+
message(FATAL_ERROR "Unsupported TOOLCHAIN_VARIANT_COMPILER: ${TOOLCHAIN_VARIANT_COMPILER}")
25+
endif()

cmake/toolchain/zephyr/target.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/target.cmake)
3+
if(TOOLCHAIN_VARIANT_COMPILER STREQUAL "gnu" OR
4+
TOOLCHAIN_VARIANT_COMPILER STREQUAL "default")
5+
set(TOOLCHAIN_VARIANT_COMPILER gnu CACHE STRING "Variant compiler being used")
6+
if(EXISTS ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/gnu/target.cmake)
7+
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/gnu/target.cmake)
8+
else()
9+
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/target.cmake)
10+
endif()
11+
elseif (TOOLCHAIN_VARIANT_COMPILER STREQUAL "llvm")
12+
set(TOOLCHAIN_VARIANT_COMPILER llvm CACHE STRING "Variant compiler being used")
13+
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/llvm/target.cmake)
14+
else()
15+
message(FATAL_ERROR "Unsupported TOOLCHAIN_VARIANT_COMPILER: ${TOOLCHAIN_VARIANT_COMPILER}")
16+
endif()

0 commit comments

Comments
 (0)