diff --git a/share/sysbuild-package/cmake/SysbuildConfig.cmake b/share/sysbuild-package/cmake/SysbuildConfig.cmake new file mode 100644 index 00000000000..37343583bd8 --- /dev/null +++ b/share/sysbuild-package/cmake/SysbuildConfig.cmake @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +if(Sysbuild_FIND_COMPONENTS) + set(Zephyr_FIND_COMPONENTS ${Sysbuild_FIND_COMPONENTS}) +else() + set(Zephyr_FIND_COMPONENTS sysbuild_default) +endif() +include(${CMAKE_CURRENT_LIST_DIR}/../../zephyr-package/cmake/ZephyrConfig.cmake) +set(Sysbuild_FOUND True) diff --git a/share/sysbuild-package/cmake/SysbuildConfigVersion.cmake b/share/sysbuild-package/cmake/SysbuildConfigVersion.cmake new file mode 100644 index 00000000000..1dede077c1d --- /dev/null +++ b/share/sysbuild-package/cmake/SysbuildConfigVersion.cmake @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +include(${CMAKE_CURRENT_LIST_DIR}/../../zephyr-package/cmake/ZephyrConfigVersion.cmake) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../sysbuild/cmake/modules) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) diff --git a/share/sysbuild/CMakeLists.txt b/share/sysbuild/CMakeLists.txt index 4a6fde214d5..f4d5178448b 100644 --- a/share/sysbuild/CMakeLists.txt +++ b/share/sysbuild/CMakeLists.txt @@ -12,38 +12,12 @@ endif() # If APP_DIR is a relative path, then CMake will adjust to absolute path based # on current working dir. set(APP_DIR ${APP_DIR} CACHE PATH "Main Application Source Directory") +set(Sysbuild_DIR ${CMAKE_CURRENT_LIST_DIR}/../sysbuild-package/cmake) -# Add sysbuild/cmake/modules to CMAKE_MODULE_PATH which allows us to integrate -# sysbuild CMake modules with general Zephyr CMake modules. -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules) -# List of Zephyr and sysbuild CMake modules we need for sysbuild. -# Note: sysbuild_kconfig will internally load kconfig CMake module. -set(zephyr_modules extensions - sysbuild_extensions python west root zephyr_module boards shields hwm_v2 - sysbuild_kconfig native_simulator_sb_extensions - ) +project(sysbuild_toplevel LANGUAGES) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS ${zephyr_modules}) - -project(sysbuild LANGUAGES) - -get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE) -get_filename_component(app_name ${APP_DIR} NAME) -set(DEFAULT_IMAGE "${app_name}") - -# This is where all Zephyr applications are added to the multi-image build. -sysbuild_add_subdirectory(images) - -get_property(IMAGES GLOBAL PROPERTY sysbuild_images) -sysbuild_module_call(PRE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) -sysbuild_images_order(IMAGES_CONFIGURATION_ORDER CONFIGURE IMAGES ${IMAGES}) -foreach(image ${IMAGES_CONFIGURATION_ORDER}) - sysbuild_module_call(PRE_IMAGE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES} IMAGE ${image}) - ExternalZephyrProject_Cmake(APPLICATION ${image}) - sysbuild_module_call(POST_IMAGE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES} IMAGE ${image}) -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) -sysbuild_module_call(POST_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) +if(EXISTS ${APP_DIR}/sysbuild/CMakeLists.txt) + add_subdirectory(${APP_DIR}/sysbuild sysbuild/application) +else() + add_subdirectory(template sysbuild/application) +endif() diff --git a/share/sysbuild/cmake/modules/sysbuild_default.cmake b/share/sysbuild/cmake/modules/sysbuild_default.cmake new file mode 100644 index 00000000000..6bcf714de95 --- /dev/null +++ b/share/sysbuild/cmake/modules/sysbuild_default.cmake @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +# +# Sysbuild default list of CMake modules to include in a regular sysbuild session. +# +include(extensions) +include(sysbuild_extensions) +include(python) +include(west) +include(root) +include(zephyr_module) +include(boards) +include(shields) +include(hwm_v2) +include(sysbuild_kconfig) +include(native_simulator_sb_extensions) +include(sysbuild_images) diff --git a/share/sysbuild/cmake/modules/sysbuild_images.cmake b/share/sysbuild/cmake/modules/sysbuild_images.cmake new file mode 100644 index 00000000000..eb73ec99448 --- /dev/null +++ b/share/sysbuild/cmake/modules/sysbuild_images.cmake @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +# This module is responsible for including images into sysbuild and to call +# pre and post hooks. + +get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE) +get_filename_component(app_name ${APP_DIR} NAME) +set(DEFAULT_IMAGE "${app_name}") + +# This is where all Zephyr applications are added to the multi-image build. +sysbuild_add_subdirectory(${sysbuild_toplevel_SOURCE_DIR}/images sysbuild/images) + +get_property(IMAGES GLOBAL PROPERTY sysbuild_images) +sysbuild_module_call(PRE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) +sysbuild_images_order(IMAGES_CONFIGURATION_ORDER CONFIGURE IMAGES ${IMAGES}) +foreach(image ${IMAGES_CONFIGURATION_ORDER}) + sysbuild_module_call(PRE_IMAGE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES} IMAGE ${image}) + ExternalZephyrProject_Cmake(APPLICATION ${image}) + sysbuild_module_call(POST_IMAGE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES} IMAGE ${image}) +endforeach() +sysbuild_module_call(POST_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) + +sysbuild_module_call(PRE_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) +include(${sysbuild_toplevel_SOURCE_DIR}/cmake/domains.cmake) +sysbuild_module_call(POST_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) diff --git a/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake b/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake index d18b5b7978d..531e670dbc9 100644 --- a/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake @@ -56,7 +56,7 @@ endif() # Empty files to make kconfig.py happy. file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/empty.conf) -set(APPLICATION_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(APPLICATION_SOURCE_DIR ${sysbuild_toplevel_SOURCE_DIR}) set(AUTOCONF_H ${CMAKE_CURRENT_BINARY_DIR}/autoconf.h) set(CONF_FILE ${SB_CONF_FILE}) set(EXTRA_CONF_FILE "${SB_EXTRA_CONF_FILE}") diff --git a/share/sysbuild/template/CMakeLists.txt b/share/sysbuild/template/CMakeLists.txt new file mode 100644 index 00000000000..fc348a8dafb --- /dev/null +++ b/share/sysbuild/template/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +# Generic sysbuild CMakeLists.txt file used as sysbuild entry point for multi-image builds. +# +# Applications which requires custom handling when built using sysbuild may copy this +# file to the folder `/sysbuild` and use as a template and extend as needed. + +find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(sysbuild LANGUAGES)