cmake: sysbuild PRE_CMAKE, POST_CMAKE, PRE_DOMAINS, POST_DOMAINS hooks
Provide a uniform way for sysbuild modules to create hooks that are called at specific time during sysbuild CMake configure time. A module can create functions following the scheme: - <module-name>_pre_cmake - <module-name>_post_cmake - <module-name>_pre_domains - <module-name>_post_domains those functions, if defined, will be called by sysbuild CMake at the location indicated by the function name. A new global variable `SYSBUILD_CURRENT_MODULE_NAME` is created, which a module can use to know it's own name when defining those functions during sysbuild module CMake inclusion. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
3d76ee8f25
commit
9940940cea
2 changed files with 44 additions and 3 deletions
|
@ -31,17 +31,17 @@ get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE)
|
||||||
get_filename_component(app_name ${APP_DIR} NAME)
|
get_filename_component(app_name ${APP_DIR} NAME)
|
||||||
|
|
||||||
# Include zephyr modules generated sysbuild CMake file.
|
# Include zephyr modules generated sysbuild CMake file.
|
||||||
foreach(module_name ${SYSBUILD_MODULE_NAMES})
|
foreach(SYSBUILD_CURRENT_MODULE_NAME ${SYSBUILD_MODULE_NAMES})
|
||||||
# Note the second, binary_dir parameter requires the added
|
# Note the second, binary_dir parameter requires the added
|
||||||
# subdirectory to have its own, local cmake target(s). If not then
|
# subdirectory to have its own, local cmake target(s). If not then
|
||||||
# this binary_dir is created but stays empty. Object files land in
|
# this binary_dir is created but stays empty. Object files land in
|
||||||
# the main binary dir instead.
|
# the main binary dir instead.
|
||||||
# https://cmake.org/pipermail/cmake/2019-June/069547.html
|
# https://cmake.org/pipermail/cmake/2019-June/069547.html
|
||||||
zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name})
|
zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${SYSBUILD_CURRENT_MODULE_NAME})
|
||||||
if(NOT ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "")
|
if(NOT ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "")
|
||||||
set(SYSBUILD_CURRENT_MODULE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_MODULE_DIR})
|
set(SYSBUILD_CURRENT_MODULE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_MODULE_DIR})
|
||||||
set(SYSBUILD_CURRENT_CMAKE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR})
|
set(SYSBUILD_CURRENT_CMAKE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR})
|
||||||
add_subdirectory(${SYSBUILD_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name})
|
add_subdirectory(${SYSBUILD_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${SYSBUILD_CURRENT_MODULE_NAME})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
# Done processing modules, clear SYSBUILD_CURRENT_MODULE_DIR and SYSBUILD_CURRENT_CMAKE_DIR.
|
# Done processing modules, clear SYSBUILD_CURRENT_MODULE_DIR and SYSBUILD_CURRENT_CMAKE_DIR.
|
||||||
|
@ -115,7 +115,12 @@ while(NOT "${images_length}" EQUAL "${processed_length}")
|
||||||
set(processed_length ${processed_length_new})
|
set(processed_length ${processed_length_new})
|
||||||
endwhile()
|
endwhile()
|
||||||
|
|
||||||
|
sysbuild_module_call(PRE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
|
||||||
foreach(image ${IMAGES})
|
foreach(image ${IMAGES})
|
||||||
ExternalZephyrProject_Cmake(APPLICATION ${image})
|
ExternalZephyrProject_Cmake(APPLICATION ${image})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
sysbuild_module_call(POST_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
|
||||||
|
|
||||||
|
sysbuild_module_call(PRE_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
|
||||||
include(cmake/domains.cmake)
|
include(cmake/domains.cmake)
|
||||||
|
sysbuild_module_call(POST_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
|
||||||
|
|
|
@ -346,3 +346,39 @@ function(ExternalZephyrProject_Cmake)
|
||||||
load_cache(IMAGE ${ZCMAKE_APPLICATION} BINARY_DIR ${BINARY_DIR})
|
load_cache(IMAGE ${ZCMAKE_APPLICATION} BINARY_DIR ${BINARY_DIR})
|
||||||
import_kconfig(CONFIG_ ${BINARY_DIR}/zephyr/.config TARGET ${ZCMAKE_APPLICATION})
|
import_kconfig(CONFIG_ ${BINARY_DIR}/zephyr/.config TARGET ${ZCMAKE_APPLICATION})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# sysbuild_module_call(<hook> MODULES <modules> [IMAGES <images>] [EXTRA_ARGS <arguments>])
|
||||||
|
#
|
||||||
|
# This function invokes the sysbuild hook provided as <hook> for <modules>.
|
||||||
|
#
|
||||||
|
# If `IMAGES` is passed, then the provided list of of images will be passed to
|
||||||
|
# the hook.
|
||||||
|
#
|
||||||
|
# `EXTRA_ARGS` can be used to pass extra arguments to the hook.
|
||||||
|
#
|
||||||
|
# Valid <hook> values:
|
||||||
|
# PRE_CMAKE : Invoke pre-CMake call for modules before CMake configure is invoked for images
|
||||||
|
# POST_CMAKE : Invoke post-CMake call for modules after CMake configure has been invoked for images
|
||||||
|
# PRE_DOMAINS : Invoke pre-domains call for modules before creating domains yaml.
|
||||||
|
# POST_DOMAINS: Invoke post-domains call for modules after creation of domains yaml.
|
||||||
|
#
|
||||||
|
function(sysbuild_module_call)
|
||||||
|
set(options "PRE_CMAKE;POST_CMAKE;PRE_DOMAINS;POST_DOMAINS")
|
||||||
|
set(multi_args "MODULES;IMAGES;EXTRA_ARGS")
|
||||||
|
cmake_parse_arguments(SMC "${options}" "${test_args}" "${multi_args}" ${ARGN})
|
||||||
|
|
||||||
|
zephyr_check_flags_required("sysbuild_module_call" SMC ${options})
|
||||||
|
zephyr_check_flags_exclusive("sysbuild_module_call" SMC ${options})
|
||||||
|
|
||||||
|
foreach(call ${options})
|
||||||
|
if(SMC_${call})
|
||||||
|
foreach(module ${SMC_MODULES})
|
||||||
|
if(COMMAND ${module}_${call})
|
||||||
|
cmake_language(CALL ${module}_${call} IMAGES ${SMC_IMAGES} ${SMC_EXTRA_ARGS})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue