cmake: Zephyr sdk package handling
This commit introduces Zephyr SDK CMake config package. This removes the need for setting ZEPHYR_SDK_INSTALL_DIR and ZEPHYR_TOOLCHAIN_VARIANT when using Zephyr SDK in Linux. It also allows to introduces never SDKs without breaking Zephyr. For example, with this PR, the current Zephyr SDK is 0.11.1 but when releasing 0.12 then the current Zephyr will no longer built. This PR moves the Zephyr SDK CMake related code to the SDK and thus allowing to use newer SDKs, as long as they are backwards compatible. It also allows multiple SDK installations, and will automatically select the version closet to the required version. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
6789ecbd5e
commit
299a154fdd
11 changed files with 69 additions and 197 deletions
|
|
@ -50,8 +50,8 @@ endif()
|
|||
set(TOOLCHAIN_ROOT ${TOOLCHAIN_ROOT} CACHE STRING "Zephyr toolchain root")
|
||||
assert(TOOLCHAIN_ROOT "Zephyr toolchain root path invalid: please set the TOOLCHAIN_ROOT-variable")
|
||||
|
||||
# Set cached ZEPHYR_TOOLCHAIN_VARIANT.
|
||||
set(ZEPHYR_TOOLCHAIN_VARIANT ${ZEPHYR_TOOLCHAIN_VARIANT} CACHE STRING "Zephyr toolchain variant")
|
||||
assert(ZEPHYR_TOOLCHAIN_VARIANT "Zephyr toolchain variant invalid: please set the ZEPHYR_TOOLCHAIN_VARIANT-variable")
|
||||
|
||||
# Pick host system's toolchain if we are targeting posix
|
||||
if(${ARCH} STREQUAL "posix")
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set(TOOLCHAIN_HOME ${ZEPHYR_SDK_INSTALL_DIR})
|
||||
|
||||
set(COMPILER gcc)
|
||||
set(LINKER ld)
|
||||
set(BINTOOLS gnu)
|
||||
|
||||
set(CROSS_COMPILE_TARGET i586-${TOOLCHAIN_VENDOR}-elf)
|
||||
set(SYSROOT_TARGET i586-${TOOLCHAIN_VENDOR}-elf)
|
||||
|
||||
set(CROSS_COMPILE ${TOOLCHAIN_HOME}/${CROSS_COMPILE_TARGET}/bin/${CROSS_COMPILE_TARGET}-)
|
||||
set(SYSROOT_DIR ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${SYSROOT_TARGET}/usr)
|
||||
set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib")
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${TOOLCHAIN_ARCH}-pokysdk-linux)
|
||||
|
||||
# Path used for searching by the find_*() functions, with appropriate
|
||||
# suffixes added. Ensures that the SDK's host tools will be found when
|
||||
# we call, e.g. find_program(QEMU qemu-system-x86)
|
||||
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/usr)
|
||||
|
||||
# TODO: Use find_* somehow for these as well?
|
||||
set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/usr/share/qemu)
|
||||
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/usr/share/openocd/scripts)
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set(CROSS_COMPILE_TARGET_arm arm-zephyr-eabi)
|
||||
set(CROSS_COMPILE_TARGET_nios2 nios2-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_riscv riscv64-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_mips mipsel-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_xtensa xtensa-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_arc arc-zephyr-elf)
|
||||
|
||||
if(CONFIG_X86_64)
|
||||
set(CROSS_COMPILE_TARGET_x86 x86_64-zephyr-elf)
|
||||
else()
|
||||
set(CROSS_COMPILE_TARGET_x86 i586-zephyr-elf)
|
||||
endif()
|
||||
|
||||
set(CROSS_COMPILE_TARGET ${CROSS_COMPILE_TARGET_${ARCH}})
|
||||
set(SYSROOT_TARGET ${CROSS_COMPILE_TARGET})
|
||||
|
||||
set(CROSS_COMPILE ${TOOLCHAIN_HOME}/${CROSS_COMPILE_TARGET}/bin/${CROSS_COMPILE_TARGET}-)
|
||||
|
||||
set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET}/${SYSROOT_TARGET})
|
||||
|
||||
if("${ARCH}" STREQUAL "x86")
|
||||
if(CONFIG_X86_64)
|
||||
if(CONFIG_LIB_CPLUSPLUS)
|
||||
# toolchain was built with a few missing bits in
|
||||
# the multilib configuration so we need to specify
|
||||
# where to find the 64-bit libstdc++.
|
||||
LIST(APPEND LIB_INCLUDE_DIR -L${SYSROOT_DIR}/lib64)
|
||||
endif()
|
||||
|
||||
list(APPEND TOOLCHAIN_C_FLAGS -m64)
|
||||
list(APPEND TOOLCHAIN_LD_FLAGS -m64)
|
||||
else()
|
||||
list(APPEND TOOLCHAIN_C_FLAGS -m32)
|
||||
list(APPEND TOOLCHAIN_LD_FLAGS -m32)
|
||||
endif()
|
||||
endif()
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
# Zephyr 0.11 SDK Toolchain
|
||||
|
||||
# Copyright (c) 2020 Linaro Limited.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config TOOLCHAIN_ZEPHYR_0_11
|
||||
def_bool y
|
||||
select HAS_NEWLIB_LIBC_NANO if (ARC || (ARM && !ARM64) || RISCV)
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set(TOOLCHAIN_HOME ${ZEPHYR_SDK_INSTALL_DIR})
|
||||
|
||||
set(COMPILER gcc)
|
||||
set(LINKER ld)
|
||||
set(BINTOOLS gnu)
|
||||
|
||||
# Find some toolchain that is distributed with this particular SDK
|
||||
|
||||
file(GLOB toolchain_paths
|
||||
LIST_DIRECTORIES true
|
||||
${TOOLCHAIN_HOME}/xtensa/*/*-zephyr-elf
|
||||
${TOOLCHAIN_HOME}/*-zephyr-elf
|
||||
${TOOLCHAIN_HOME}/*-zephyr-eabi
|
||||
)
|
||||
|
||||
if(toolchain_paths)
|
||||
list(GET toolchain_paths 0 some_toolchain_path)
|
||||
|
||||
get_filename_component(one_toolchain_root "${some_toolchain_path}" DIRECTORY)
|
||||
get_filename_component(one_toolchain "${some_toolchain_path}" NAME)
|
||||
|
||||
set(CROSS_COMPILE_TARGET ${one_toolchain})
|
||||
set(SYSROOT_TARGET ${one_toolchain})
|
||||
endif()
|
||||
|
||||
if(NOT CROSS_COMPILE_TARGET)
|
||||
message(FATAL_ERROR "Unable to find 'x86_64-zephyr-elf' or any other architecture in ${TOOLCHAIN_HOME}")
|
||||
endif()
|
||||
|
||||
set(CROSS_COMPILE ${one_toolchain_root}/${CROSS_COMPILE_TARGET}/bin/${CROSS_COMPILE_TARGET}-)
|
||||
set(SYSROOT_DIR ${one_toolchain_root}/${SYSROOT_TARGET}/${SYSROOT_TARGET})
|
||||
set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib")
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${TOOLCHAIN_ARCH}-pokysdk-linux)
|
||||
|
||||
# Path used for searching by the find_*() functions, with appropriate
|
||||
# suffixes added. Ensures that the SDK's host tools will be found when
|
||||
# we call, e.g. find_program(QEMU qemu-system-x86)
|
||||
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/usr)
|
||||
|
||||
# TODO: Use find_* somehow for these as well?
|
||||
set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/usr/share/qemu)
|
||||
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/usr/share/openocd/scripts)
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if(CONFIG_ARM64)
|
||||
set(CROSS_COMPILE_TARGET_arm aarch64-zephyr-elf)
|
||||
else()
|
||||
set(CROSS_COMPILE_TARGET_arm arm-zephyr-eabi)
|
||||
endif()
|
||||
set(CROSS_COMPILE_TARGET_nios2 nios2-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_riscv riscv64-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_mips mipsel-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_xtensa xtensa-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_arc arc-zephyr-elf)
|
||||
set(CROSS_COMPILE_TARGET_x86 x86_64-zephyr-elf)
|
||||
|
||||
set(CROSS_COMPILE_TARGET ${CROSS_COMPILE_TARGET_${ARCH}})
|
||||
set(SYSROOT_TARGET ${CROSS_COMPILE_TARGET})
|
||||
|
||||
if("${ARCH}" STREQUAL "xtensa")
|
||||
set(SYSROOT_DIR ${TOOLCHAIN_HOME}/xtensa/${SOC_NAME}/${SYSROOT_TARGET})
|
||||
set(CROSS_COMPILE ${TOOLCHAIN_HOME}/xtensa/${SOC_NAME}/${CROSS_COMPILE_TARGET}/bin/${CROSS_COMPILE_TARGET}-)
|
||||
else()
|
||||
set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET}/${SYSROOT_TARGET})
|
||||
set(CROSS_COMPILE ${TOOLCHAIN_HOME}/${CROSS_COMPILE_TARGET}/bin/${CROSS_COMPILE_TARGET}-)
|
||||
endif()
|
||||
|
||||
if("${ARCH}" STREQUAL "x86")
|
||||
if(CONFIG_X86_64)
|
||||
list(APPEND TOOLCHAIN_C_FLAGS -m64)
|
||||
list(APPEND TOOLCHAIN_LD_FLAGS -m64)
|
||||
else()
|
||||
list(APPEND TOOLCHAIN_C_FLAGS -m32)
|
||||
list(APPEND TOOLCHAIN_LD_FLAGS -m32)
|
||||
endif()
|
||||
endif()
|
||||
|
|
@ -1,11 +1,5 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if (NOT ZEPHYR_SDK_INSTALL_DIR)
|
||||
message(FATAL_ERROR "ZEPHYR_SDK_INSTALL_DIR must be set")
|
||||
endif()
|
||||
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/generic.cmake)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/${SDK_MAJOR_MINOR}/generic.cmake)
|
||||
|
||||
set(TOOLCHAIN_KCONFIG_DIR ${CMAKE_CURRENT_LIST_DIR}/${SDK_MAJOR_MINOR})
|
||||
|
||||
message(STATUS "Found toolchain: zephyr (${ZEPHYR_SDK_INSTALL_DIR})")
|
||||
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)
|
||||
|
|
|
|||
|
|
@ -7,51 +7,81 @@
|
|||
# and currently provided by the Zephyr SDK. Those tools will need to be
|
||||
# provided for different OSes and sepearately from the toolchain.
|
||||
|
||||
set_ifndef(ZEPHYR_SDK_INSTALL_DIR "$ENV{ZEPHYR_SDK_INSTALL_DIR}")
|
||||
set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR} CACHE PATH "Zephyr SDK install directory")
|
||||
# This is the minimum required version which supports CMake package
|
||||
set(MINIMUM_REQUIRED_SDK_VERSION 0.11.3)
|
||||
|
||||
if(NOT ZEPHYR_SDK_INSTALL_DIR)
|
||||
set_ifndef(ZEPHYR_TOOLCHAIN_VARIANT $ENV{ZEPHYR_TOOLCHAIN_VARIANT} "")
|
||||
set_ifndef(ZEPHYR_SDK_INSTALL_DIR $ENV{ZEPHYR_SDK_INSTALL_DIR} "")
|
||||
|
||||
# There are three scenarios where Zephyr SDK should be looked up:
|
||||
# 1) Zephyr specified as toolchain (ZEPHYR_SDK_INSTALL_DIR still used if defined)
|
||||
# 2) No toolchain specified == Default to Zephyr toolchain (Linux only)
|
||||
# 3) Other toolchain specified, but ZEPHYR_SDK_INSTALL_DIR also given.
|
||||
# This means Zephyr SDK toolchain will not be used for compilation,
|
||||
# but other supplementary host tools will be used.
|
||||
if(("zephyr" STREQUAL ${ZEPHYR_TOOLCHAIN_VARIANT}) OR
|
||||
((NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT) AND (${CMAKE_HOST_SYSTEM_NAME} STREQUAL Linux)) OR
|
||||
(DEFINED ZEPHYR_SDK_INSTALL_DIR))
|
||||
|
||||
# No toolchain was specified, so inform user that we will be searching.
|
||||
if (NOT DEFINED ZEPHYR_SDK_INSTALL_DIR AND NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT)
|
||||
message("ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK")
|
||||
endif()
|
||||
|
||||
# This ensure packages are sorted in descending order.
|
||||
SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION_CURRENT ${CMAKE_FIND_PACKAGE_SORT_DIRECTION})
|
||||
SET(CMAKE_FIND_PACKAGE_SORT_ORDER_CURRENT ${CMAKE_FIND_PACKAGE_SORT_ORDER})
|
||||
SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
|
||||
SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
|
||||
|
||||
if(DEFINED ZEPHYR_SDK_INSTALL_DIR)
|
||||
find_package(Zephyr-sdk ${MINIMUM_REQUIRED_SDK_VERSION} QUIET HINTS $ENV{ZEPHYR_SDK_INSTALL_DIR})
|
||||
else()
|
||||
find_package(Zephyr-sdk ${MINIMUM_REQUIRED_SDK_VERSION} QUIET PATHS
|
||||
/usr
|
||||
/usr/local
|
||||
/opt
|
||||
$ENV{HOME}
|
||||
$ENV{HOME}/.local
|
||||
$ENV{HOME}/.local/opt
|
||||
$ENV{HOME}/bin)
|
||||
endif()
|
||||
|
||||
SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION ${CMAKE_FIND_PACKAGE_SORT_DIRECTION_CURRENT})
|
||||
SET(CMAKE_FIND_PACKAGE_SORT_ORDER ${CMAKE_FIND_PACKAGE_SORT_ORDER_CURRENT})
|
||||
else ()
|
||||
# Until https://github.com/zephyrproject-rtos/zephyr/issues/4912 is
|
||||
# resolved we use ZEPHYR_SDK_INSTALL_DIR to determine whether the user
|
||||
# wants to use the Zephyr SDK or not.
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(REQUIRED_SDK_VER 0.11.1)
|
||||
set(TOOLCHAIN_VENDOR zephyr)
|
||||
set(TOOLCHAIN_ARCH x86_64)
|
||||
set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR} CACHE PATH "Zephyr SDK install directory")
|
||||
|
||||
set(sdk_version_path ${ZEPHYR_SDK_INSTALL_DIR}/sdk_version)
|
||||
if(NOT (EXISTS ${sdk_version_path}))
|
||||
message(FATAL_ERROR
|
||||
"The file '${ZEPHYR_SDK_INSTALL_DIR}/sdk_version' was not found. \
|
||||
Is ZEPHYR_SDK_INSTALL_DIR=${ZEPHYR_SDK_INSTALL_DIR} misconfigured?")
|
||||
endif()
|
||||
|
||||
# Read version as published by the SDK
|
||||
file(READ ${sdk_version_path} SDK_VERSION_PRE1)
|
||||
# Remove any pre-release data, for example 0.10.0-beta4 -> 0.10.0
|
||||
string(REGEX REPLACE "-.*" "" SDK_VERSION_PRE2 ${SDK_VERSION_PRE1})
|
||||
# Strip any trailing spaces/newlines from the version string
|
||||
string(STRIP ${SDK_VERSION_PRE2} SDK_VERSION)
|
||||
string(REGEX MATCH "([0-9]*).([0-9]*)" SDK_MAJOR_MINOR ${SDK_VERSION})
|
||||
if(NOT ${Zephyr-sdk_FOUND})
|
||||
# Note: When CMake mimimun version becomes >= 3.17, change this loop into:
|
||||
# foreach(version config IN ZIP_LISTS Zephyr-sdk_CONSIDERED_VERSIONS Zephyr-sdk_CONSIDERED_CONFIGS)
|
||||
set(missing_version "You need SDK version ${MINIMUM_REQUIRED_SDK_VERSION} or newer.")
|
||||
foreach (version ${Zephyr-sdk_CONSIDERED_VERSIONS})
|
||||
if(${version} VERSION_GREATER ${MINIMUM_REQUIRED_SDK_VERSION})
|
||||
set(missing_version "You need SDK version ${MINIMUM_REQUIRED_SDK_VERSION} or compatible version.")
|
||||
endif()
|
||||
list(GET Zephyr-sdk_CONSIDERED_CONFIGS 0 zephyr-sdk-candidate)
|
||||
list(REMOVE_AT Zephyr-sdk_CONSIDERED_CONFIGS 0)
|
||||
get_filename_component(zephyr-sdk-path ${zephyr-sdk-candidate}/../.. ABSOLUTE)
|
||||
string(APPEND version_path " ${version} (${zephyr-sdk-path})\n")
|
||||
endforeach()
|
||||
|
||||
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" SDK_MAJOR_MINOR_MICRO ${SDK_VERSION})
|
||||
|
||||
#at least 0.0.0
|
||||
if(NOT SDK_MAJOR_MINOR_MICRO)
|
||||
message(FATAL_ERROR "sdk version: ${SDK_MAJOR_MINOR_MICRO} improper format.
|
||||
Expected format: x.y.z
|
||||
Check whether the Zephyr SDK was installed correctly.
|
||||
")
|
||||
|
||||
elseif(${REQUIRED_SDK_VER} VERSION_GREATER ${SDK_VERSION})
|
||||
message(FATAL_ERROR "The SDK version you are using is too old, please update your SDK.
|
||||
You need at least SDK version ${REQUIRED_SDK_VER}.
|
||||
You have version ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR}).
|
||||
The new version of the SDK can be downloaded from:
|
||||
https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${REQUIRED_SDK_VER}/zephyr-sdk-${REQUIRED_SDK_VER}-setup.run
|
||||
message(FATAL_ERROR "The SDK version you are using is not supported, please update your SDK.
|
||||
${missing_version}
|
||||
You have version(s):
|
||||
${version_path}
|
||||
The SDK can be downloaded from:
|
||||
https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${MINIMUM_REQUIRED_SDK_VERSION}/zephyr-sdk-${MINIMUM_REQUIRED_SDK_VERSION}-setup.run
|
||||
")
|
||||
endif()
|
||||
|
||||
include(${ZEPHYR_BASE}/cmake/toolchain/zephyr/${SDK_MAJOR_MINOR}/host-tools.cmake)
|
||||
message(STATUS "Found toolchain: zephyr (${ZEPHYR_SDK_INSTALL_DIR})")
|
||||
|
||||
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/host-tools.cmake)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
include(${ZEPHYR_BASE}/cmake/toolchain/zephyr/${SDK_MAJOR_MINOR}/target.cmake)
|
||||
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/target.cmake)
|
||||
|
|
|
|||
Loading…
Reference in a new issue