cmake: Zephyr sdk backward compatibility with 0.11.1 and 0.11.2

This commit introduces backward compatibility with Zephyr SDK 0.11.1
and 0.11.2 so that users having one of those versions installed can
continue to use that version.

This remove the need to force users to update their SDK.

This is kept in independent commit to ensure it can easily be reverted
when minimum required Zephyr SDK is bumped to version 0.12.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-04-28 23:20:15 +02:00 committed by Carles Cufí
parent 299a154fdd
commit b557bd90a6
7 changed files with 153 additions and 5 deletions

View file

@ -0,0 +1,8 @@
# 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)

View file

@ -0,0 +1,34 @@
# 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")

View file

@ -0,0 +1,12 @@
# 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)

View file

@ -0,0 +1,34 @@
# 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()

View file

@ -1,5 +1,13 @@
# SPDX-License-Identifier: Apache-2.0
if(${SDK_VERSION} VERSION_LESS_EQUAL 0.11.2)
# For backward compatibility with 0.11.1 and 0.11.2
# we need to source files from Zephyr repo
include(${CMAKE_CURRENT_LIST_DIR}/${SDK_MAJOR_MINOR}/generic.cmake)
set(TOOLCHAIN_KCONFIG_DIR ${CMAKE_CURRENT_LIST_DIR}/${SDK_MAJOR_MINOR})
else()
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/generic.cmake)
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)
endif()

View file

@ -10,6 +10,10 @@
# This is the minimum required version which supports CMake package
set(MINIMUM_REQUIRED_SDK_VERSION 0.11.3)
# This is the minimum required version for Zephyr to work (Old style)
set(REQUIRED_SDK_VER 0.11.1)
set(TOOLCHAIN_ARCH x86_64)
set_ifndef(ZEPHYR_TOOLCHAIN_VARIANT $ENV{ZEPHYR_TOOLCHAIN_VARIANT} "")
set_ifndef(ZEPHYR_SDK_INSTALL_DIR $ENV{ZEPHYR_SDK_INSTALL_DIR} "")
@ -58,11 +62,42 @@ endif()
set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR} CACHE PATH "Zephyr SDK install directory")
if(NOT ${Zephyr-sdk_FOUND})
if(ZEPHYR_TOOLCHAIN_VARIANT AND ZEPHYR_SDK_INSTALL_DIR)
# Manual detection for Zephyr SDK 0.11.1 and 0.11.2 for backward compatibility.
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})
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(${SDK_VERSION} VERSION_GREATER_EQUAL ${REQUIRED_SDK_VER})
set(Zephyr-sdk_FOUND TRUE)
endif()
endif()
endif()
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.")
set(missing_version "You need SDK version ${REQUIRED_SDK_VER} 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.")
@ -73,15 +108,26 @@ if(NOT ${Zephyr-sdk_FOUND})
string(APPEND version_path " ${version} (${zephyr-sdk-path})\n")
endforeach()
if(NOT ZEPHYR_TOOLCHAIN_VARIANT AND NOT ZEPHYR_SDK_INSTALL_DIR)
set(error_note "Note: If you are using SDK 0.11.1 or 0.11.2, remember to set ZEPHYR_SDK_INSTALL_DIR and ZEPHYR_TOOLCHAIN_VARIANT")
endif()
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
${error_note}
")
endif()
message(STATUS "Found toolchain: zephyr (${ZEPHYR_SDK_INSTALL_DIR})")
if(${SDK_VERSION} VERSION_LESS_EQUAL 0.11.2)
# For backward compatibility with 0.11.1 and 0.11.2
# we need to source files from Zephyr repo
include(${CMAKE_CURRENT_LIST_DIR}/${SDK_MAJOR_MINOR}/host-tools.cmake)
else()
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/host-tools.cmake)
endif()

View file

@ -1,3 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
if(${SDK_VERSION} VERSION_LESS_EQUAL 0.11.2)
# For backward compatibility with 0.11.1 and 0.11.2
# we need to source files from Zephyr repo
include(${CMAKE_CURRENT_LIST_DIR}/${SDK_MAJOR_MINOR}/target.cmake)
else()
include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/target.cmake)
endif()