Commit 14fe12ac authored by Anas Nashif's avatar Anas Nashif Committed by Stephanos Ioannidis
Browse files

cmake: add support enhanced variants with multiple compilers

parent 24207346
Loading
Loading
Loading
Loading
+2 −3
Changes for cmake/modules/FindHostTools.cmake: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ zephyr_file(APPLICATION_ROOT TOOLCHAIN_ROOT)

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

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

# Set cached ZEPHYR_TOOLCHAIN_VARIANT.
set(ZEPHYR_TOOLCHAIN_VARIANT ${ZEPHYR_TOOLCHAIN_VARIANT} CACHE STRING "Zephyr toolchain variant")
set(ZEPHYR_TOOLCHAIN_VARIANT ${ZEPHYR_TOOLCHAIN_VARIANT} CACHE STRING "Zephyr toolchain variant" FORCE)

# Configure the toolchain based on what SDK/toolchain is in use.
include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/generic.cmake)
+1 −1
Changes for cmake/modules/FindZephyr-sdk.cmake: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ endif()
# 1) Zephyr specified as toolchain (ZEPHYR_SDK_INSTALL_DIR still used if defined)
# 2) No toolchain specified == Default to Zephyr toolchain
# Until we completely deprecate it
if(("zephyr" STREQUAL ${ZEPHYR_TOOLCHAIN_VARIANT}) OR
if((${ZEPHYR_TOOLCHAIN_VARIANT} MATCHES "^zephyr/?") OR
   (NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT) OR
   (DEFINED ZEPHYR_SDK_INSTALL_DIR) OR
   (Zephyr-sdk_FIND_REQUIRED))
+14 −3
Changes for cmake/toolchain/zephyr/generic.cmake: 14 added lines, 3 removed lines.
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/generic.cmake)
if(TOOLCHAIN_VARIANT_COMPILER STREQUAL "gnu" OR
    NOT DEFINED TOOLCHAIN_VARIANT_COMPILER)
  include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/gnu/generic.cmake)
  set(TOOLCHAIN_VARIANT_COMPILER "gnu" CACHE STRING "compiler used by the toolchain variant" FORCE)

  set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)

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

  set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)

message(STATUS "Found toolchain: zephyr-sdk-gnu ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")
  message(STATUS "Found toolchain: zephyr ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")
else()
  message(FATAL_ERROR "Unsupported TOOLCHAIN_VARIANT_COMPILER: ${TOOLCHAIN_VARIANT_COMPILER}")
endif()
+10 −1
Changes for cmake/toolchain/zephyr/target.cmake: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/target.cmake)
if(TOOLCHAIN_VARIANT_COMPILER STREQUAL "gnu" OR
   TOOLCHAIN_VARIANT_COMPILER STREQUAL "default")
  set(TOOLCHAIN_VARIANT_COMPILER gnu CACHE STRING "Variant compiler being used")
  include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/gnu/target.cmake)
elseif (TOOLCHAIN_VARIANT_COMPILER STREQUAL "llvm")
  set(TOOLCHAIN_VARIANT_COMPILER llvm CACHE STRING "Variant compiler being used")
  include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/llvm/target.cmake)
else()
  message(FATAL_ERROR "Unsupported TOOLCHAIN_VARIANT_COMPILER: ${TOOLCHAIN_VARIANT_COMPILER}")
endif()