Enhance sysbuild controlled configurations. The current scheme of passing settings using `-D` on the CMake invocation is vulnerable to quoting and lists. With `zephyr_get()` in place as a uniform way of handling user controlled settings (CMake cache / environment / CMake local variable) we have a mechanism in place for a cleaner handling of sysbuild controlled settings. This improves the robustness of variable passing and add the same cleans up and simplifies the logic in sysbuild. The Kconfig Zephyr CMake module has been updated accordingly so that CONFIG settings are taken from the sysbuild shadow cache when sysbuild is used as higher level build system. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
118 lines
3.8 KiB
CMake
118 lines
3.8 KiB
CMake
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Copyright (c) 2021, Nordic Semiconductor ASA
|
|
|
|
# This CMake module will load all Zephyr CMake modules in correct order for
|
|
# default Zephyr build system.
|
|
#
|
|
# Outcome:
|
|
# See individual CMake module descriptions
|
|
|
|
include_guard(GLOBAL)
|
|
|
|
# The code line below defines the real minimum supported CMake version.
|
|
#
|
|
# Unfortunately CMake requires the toplevel CMakeLists.txt file to define the
|
|
# required version, not even invoking it from a CMake module is sufficient.
|
|
# It is however permitted to have multiple invocations of cmake_minimum_required.
|
|
cmake_minimum_required(VERSION 3.20.0)
|
|
|
|
message(STATUS "Application: ${APPLICATION_SOURCE_DIR}")
|
|
|
|
find_package(ZephyrBuildConfiguration
|
|
QUIET NO_POLICY_SCOPE
|
|
NAMES ZephyrBuild
|
|
PATHS ${ZEPHYR_BASE}/../*
|
|
NO_CMAKE_PATH
|
|
NO_CMAKE_ENVIRONMENT_PATH
|
|
NO_SYSTEM_ENVIRONMENT_PATH
|
|
NO_CMAKE_PACKAGE_REGISTRY
|
|
NO_CMAKE_SYSTEM_PATH
|
|
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
|
|
)
|
|
|
|
# Test and error-out if we are affected by the PyPI CMake 3.22.1 / 3.22.2 bug
|
|
if(${CMAKE_VERSION} VERSION_EQUAL 3.22.1 OR ${CMAKE_VERSION} VERSION_EQUAL 3.22.2)
|
|
# It seems only pip-installed builds are affected so we test to see if we are affected
|
|
cmake_path(GET ZEPHYR_BASE PARENT_PATH test_cmake_path)
|
|
if(ZEPHYR_BASE STREQUAL test_cmake_path)
|
|
message(FATAL_ERROR "The CMake version ${CMAKE_VERSION} installed suffers"
|
|
" the \n 'cmake_path(... PARENT_PATH)' bug, see: \n"
|
|
"https://gitlab.kitware.com/cmake/cmake/-/issues/23187\n"
|
|
"https://github.com/scikit-build/cmake-python-distributions/issues/221\n"
|
|
"Please install another CMake version or use a build of CMake that"
|
|
" does not come from PyPI."
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
# Prepare user cache
|
|
list(APPEND zephyr_cmake_modules python)
|
|
list(APPEND zephyr_cmake_modules user_cache)
|
|
|
|
# Load Zephyr extensions
|
|
list(APPEND zephyr_cmake_modules extensions)
|
|
list(APPEND zephyr_cmake_modules version)
|
|
|
|
# Load basic settings
|
|
list(APPEND zephyr_cmake_modules basic_settings)
|
|
|
|
#
|
|
# Find tools
|
|
#
|
|
|
|
list(APPEND zephyr_cmake_modules west)
|
|
list(APPEND zephyr_cmake_modules ccache)
|
|
|
|
# Load default root settings
|
|
list(APPEND zephyr_cmake_modules root)
|
|
|
|
#
|
|
# Find Zephyr modules.
|
|
# Those may contain additional DTS, BOARD, SOC, ARCH ROOTs.
|
|
# Also create the Kconfig binary dir for generated Kconf files.
|
|
#
|
|
list(APPEND zephyr_cmake_modules zephyr_module)
|
|
|
|
list(APPEND zephyr_cmake_modules boards)
|
|
list(APPEND zephyr_cmake_modules shields)
|
|
list(APPEND zephyr_cmake_modules arch)
|
|
list(APPEND zephyr_cmake_modules configuration_files)
|
|
|
|
# Include board specific device-tree flags before parsing.
|
|
set(pre_dt_board "\${BOARD_DIR}/pre_dt_board.cmake" OPTIONAL)
|
|
list(APPEND zephyr_cmake_modules "\${pre_dt_board}")
|
|
|
|
# DTS should be close to kconfig because CONFIG_ variables from
|
|
# kconfig and dts should be available at the same time.
|
|
list(APPEND zephyr_cmake_modules dts)
|
|
list(APPEND zephyr_cmake_modules kconfig)
|
|
list(APPEND zephyr_cmake_modules soc)
|
|
|
|
foreach(component ${SUB_COMPONENTS})
|
|
if(NOT ${component} IN_LIST zephyr_cmake_modules)
|
|
message(FATAL_ERROR
|
|
"Subcomponent '${component}' not default module for Zephyr CMake build system.\n"
|
|
"Please choose one or more valid components: ${zephyr_cmake_modules}"
|
|
)
|
|
endif()
|
|
endforeach()
|
|
|
|
foreach(module IN LISTS zephyr_cmake_modules)
|
|
# Ensures any module of type `${module}` are properly expanded to list before
|
|
# passed on the `include(${module})`.
|
|
# This is done twice to support cases where the content of `${module}` itself
|
|
# contains a variable, like `${BOARD_DIR}`.
|
|
string(CONFIGURE "${module}" module)
|
|
string(CONFIGURE "${module}" module)
|
|
include(${module})
|
|
|
|
list(REMOVE_ITEM SUB_COMPONENTS ${module})
|
|
if(DEFINED SUB_COMPONENTS AND NOT SUB_COMPONENTS)
|
|
# All requested Zephyr CMake modules have been loaded, so let's return.
|
|
return()
|
|
endif()
|
|
endforeach()
|
|
|
|
include(kernel)
|