Skip to content

Commit d79d805

Browse files
tejlmandcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 303c1eb commit d79d805

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

cmake/modules/extensions.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,36 @@ function(zephyr_get_targets directory types targets)
25772577
set(${targets} ${${targets}} PARENT_SCOPE)
25782578
endfunction()
25792579

2580+
# Usage:
2581+
# test_sysbuild([REQUIRED])
2582+
#
2583+
# Test that current sample is invoked through sysbuild.
2584+
#
2585+
# This function tests that current CMake configure was invoked through sysbuild.
2586+
# If CMake configure was not invoked through sysbuild, then a warning is printed
2587+
# to the user. The warning can be upgraded to an error by setting `REQUIRED` as
2588+
# argument the `test_sysbuild()`.
2589+
#
2590+
# This function allows samples that are multi-image samples by nature to ensure
2591+
# all samples are correctly built together.
2592+
function(test_sysbuild)
2593+
cmake_parse_arguments(TEST_SYSBUILD "REQUIRED" "" "" ${ARGN})
2594+
2595+
if(TEST_SYSBUILD_REQUIRED)
2596+
set(message_mode FATAL_ERROR)
2597+
else()
2598+
set(message_mode WARNING)
2599+
endif()
2600+
2601+
if(NOT SYSBUILD)
2602+
message(${message_mode}
2603+
"Project '${PROJECT_NAME}' is designed for sysbuild.\n"
2604+
"For correct user-experiences, please build '${PROJECT_NAME}' "
2605+
"using sysbuild."
2606+
)
2607+
endif()
2608+
endfunction()
2609+
25802610
# Usage:
25812611
# target_byproducts(TARGET <target> BYPRODUCTS <file> [<file>...])
25822612
#

0 commit comments

Comments
 (0)