sysbuild: support sysbuild/CMakeLists.txt as entry point for samples

This commit refactors sysbuild entry code by creating a CMake sysbuild
module for image processing and place sysbuild entry code in a
<app>/sysbuild/CMakeLists.txt file.

A template/CMakeLists.txt file will be use as template for applications
which doesn't provide their own entry file.

An application may create a sysbuild/CMakeLists.txt file.
The sysbuild/CMakeLists.txt file is similar in nature to the
toplevel CMakeLists.txt file but intended to used by sysbuild.
This allows application developers to adjust how an application is
built with sysbuild.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2024-05-17 10:26:44 +02:00 committed by Fabio Baltieri
parent e65c6328ce
commit fc1884ecf5
7 changed files with 80 additions and 34 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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})

View File

@ -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}")

View File

@ -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 `<app-dir>/sysbuild` and use as a template and extend as needed.
find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(sysbuild LANGUAGES)