zephyr/share/sysbuild/images/CMakeLists.txt

37 lines
1.5 KiB
CMake
Raw Normal View History

sysbuild: Make the image processing order well-defined Adjust the order in which image-specific `sysbuild.cmake` files are iteratively included by sysbuild. This is motivated by the introduction of `sysbuild_add_dependencies()`. In the following example: sysbuild_add_dependencies(CONFIGURE my_sample sample_a sample_b) the `my_sample` image is expected to be added before this function is called. Success depends not only on the placement of the call, but on the order in which new images are added, which itself is influenced by the order in which `sysbuild.cmake` files are included. This last order can be tweaked to make the "dependencies" feature more user-friendly. This is done by rewriting the internal `sysbuild.cmake` processing loop into a new, general purpose function - `sysbuild_add_subdirectory()` - which is a wrapper for `add_subdirectory(<source_dir>)` that recursively includes `sysbuild.cmake` files for all images found in `<source_dir>`. With the new function, all images that are expected to be found in a given `<source_dir>` are guaranteed to be added around the same time. This wasn't the case with the old processing loop, because the image- specific `sysbuild.cmake` files (where "sub-images" could be defined) were left to be processed at the very end. Below is the initial order in which sysbuild will add all images. Note: the order of Zephyr modules (from 1 to n) is well-defined. 1. Main application (aka DEFAULT_IMAGE) 2. MCUboot (optional) 3. All images added via these directories: 3.1. <module-1>.sysbuild-cmake 3.2. <module-2>.sysbuild-cmake ... 3.n. <module-n>.sysbuild-cmake 4. All images added via these files: 4.1. ${BOARD_DIR}/sysbuild.cmake 4.2. ${APP_DIR}/sysbuild.cmake (aka sub-images of DEFAULT_IMAGE) These images are intended to be sorted for the users' convenience, from most to least important in the build system, or least to most dependent on other images for configuration (potentially). Finally, the use of `sysbuild_add_subdirectory()` requires updating the directory structure in sysbuild: ./images - All images should belong here. The `DEFAULT_IMAGE` should be the first and only image at the top level, so that it gets added first and its sub-images get added last. ./images/bootloader - Moved from ./bootloader. ./images/boards - Adds images from the board-specific `sysbuild.cmake` file. Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-08-25 18:45:14 +08:00
# Copyright (c) 2021-2023 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0
# The primary application is the first image to be added to the build, so that
# it is available while processing the remaining images.
ExternalZephyrProject_Add(
APPLICATION ${DEFAULT_IMAGE}
SOURCE_DIR ${APP_DIR}
APP_TYPE MAIN
)
# This allows for MCUboot to be included.
sysbuild_add_subdirectory(bootloader)
# Include zephyr modules generated sysbuild CMake file.
foreach(SYSBUILD_CURRENT_MODULE_NAME ${SYSBUILD_MODULE_NAMES})
# Note the second, binary_dir parameter requires the added
# subdirectory to have its own, local cmake target(s). If not then
# this binary_dir is created but stays empty. Object files land in
# the main binary dir instead.
# https://cmake.org/pipermail/cmake/2019-June/069547.html
zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${SYSBUILD_CURRENT_MODULE_NAME})
if(NOT ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "")
set(SYSBUILD_CURRENT_MODULE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_MODULE_DIR})
set(SYSBUILD_CURRENT_CMAKE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR})
sysbuild_add_subdirectory(${SYSBUILD_CURRENT_CMAKE_DIR}
${CMAKE_BINARY_DIR}/modules/${SYSBUILD_CURRENT_MODULE_NAME})
endif()
endforeach()
# Done processing modules, clear SYSBUILD_CURRENT_MODULE_DIR and SYSBUILD_CURRENT_CMAKE_DIR.
set(SYSBUILD_CURRENT_MODULE_DIR)
set(SYSBUILD_CURRENT_CMAKE_DIR)
# This allows for board specific images to be included.
sysbuild_add_subdirectory(boards)