cmake: test_sysbuild() function

Introduce a `test_sysbuild()` function.

This function is intended to be used by samples that are dependent on
sysbuild. This function allows such samples to test if sysbuild was used
in the build process, and when sysbuild is not used, then print a
warning to the user, or even fail the build.

This is useful for samples that have two parts to function properly, for
example samples that needs to be build and flash on two or more cores.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2022-10-10 11:47:10 +02:00 committed by Carles Cufí
parent 303c1eb60c
commit d79d80518b

View file

@ -2577,6 +2577,36 @@ function(zephyr_get_targets directory types targets)
set(${targets} ${${targets}} PARENT_SCOPE)
endfunction()
# Usage:
# test_sysbuild([REQUIRED])
#
# Test that current sample is invoked through sysbuild.
#
# This function tests that current CMake configure was invoked through sysbuild.
# If CMake configure was not invoked through sysbuild, then a warning is printed
# to the user. The warning can be upgraded to an error by setting `REQUIRED` as
# argument the `test_sysbuild()`.
#
# This function allows samples that are multi-image samples by nature to ensure
# all samples are correctly built together.
function(test_sysbuild)
cmake_parse_arguments(TEST_SYSBUILD "REQUIRED" "" "" ${ARGN})
if(TEST_SYSBUILD_REQUIRED)
set(message_mode FATAL_ERROR)
else()
set(message_mode WARNING)
endif()
if(NOT SYSBUILD)
message(${message_mode}
"Project '${PROJECT_NAME}' is designed for sysbuild.\n"
"For correct user-experiences, please build '${PROJECT_NAME}' "
"using sysbuild."
)
endif()
endfunction()
# Usage:
# target_byproducts(TARGET <target> BYPRODUCTS <file> [<file>...])
#