zephyr/share/sysbuild/cmake/domains.cmake

20 lines
832 B
CMake
Raw Normal View History

# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0
sysbuild: Support relative ordering of images Fixes #53650 The existing solution for image ordering involves the `IMAGES` variable, which sysbuild originally provided to let users manually add a new image in a desired order. This isn't very flexible for the following reasons: * The order in which `IMAGES` is updated across multiple modules and `sysbuild.cmake` files is not well defined. * Having a single variable means that the same order is used for both configuration and flashing. Usually, there is no reason for the flashing order to be the same as the configuration order. Introduce the `sysbuild_add_dependencies()` function for more fine-tuned ordering of images. It makes one image depend on other images in either configuration or flashing order. Its usage is similar to the standard CMake function `add_dependencies()`, but with an extra parameter to distinguish between two types of dependencies: sysbuild_add_dependencies(CONFIGURE my_sample sample_a sample_b) sysbuild_add_dependencies(FLASH my_sample sample_c sample_d) CONFIGURE dependencies determine the order in which sysbuild configures (runs CMake for) the individual images. This is useful if there is some information from one application's build which needs to be available to another application. FLASH dependencies control the sequence of images used by `west flash`. This could be used if a specific flashing order is required by an SoC, a runner, or something else. Note that these dependencies are not valid for images specified as `BUILD_ONLY`. The internal `sysbuild_images_order()` function is responsible for assembling two sorted lists of images based on the added dependencies, with the help of `topological_sort()`. Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-05-15 17:19:47 +08:00
sysbuild_images_order(IMAGES_FLASHING_ORDER FLASH IMAGES ${IMAGES})
set(domains_yaml "default: ${DEFAULT_IMAGE}")
set(domains_yaml "${domains_yaml}\nbuild_dir: ${CMAKE_BINARY_DIR}")
set(domains_yaml "${domains_yaml}\ndomains:")
foreach(image ${IMAGES})
set(domains_yaml "${domains_yaml}\n - name: ${image}")
set(domains_yaml "${domains_yaml}\n build_dir: $<TARGET_PROPERTY:${image},_EP_BINARY_DIR>")
endforeach()
set(domains_yaml "${domains_yaml}\nflash_order:")
foreach(image ${IMAGES_FLASHING_ORDER})
set(flash_cond "$<NOT:$<BOOL:$<TARGET_PROPERTY:${image},BUILD_ONLY>>>")
set(domains_yaml "${domains_yaml}$<${flash_cond}:\n - ${image}>")
endforeach()
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/domains.yaml CONTENT "${domains_yaml}")