Skip to content

Commit

Permalink
sysbuild: Add flag to customize variant app config
Browse files Browse the repository at this point in the history
Add a flag to allow for customizing the variant application Kconfig
values.

Ref: NCSDK-30812

Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
  • Loading branch information
tomchy committed Feb 27, 2025
1 parent bde6b19 commit 88a4f9d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
31 changes: 19 additions & 12 deletions cmake/modules/kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@
include_guard(GLOBAL)

if(CONFIG_NCS_IS_VARIANT_IMAGE)
# A variant build should reuse same .config and thus autoconf.h, therefore
# copy files from original and bypass Kconfig invocation.
set(AUTOCONF_H ${PROJECT_BINARY_DIR}/include/generated/zephyr/autoconf.h)
set(DOTCONFIG ${PROJECT_BINARY_DIR}/.config)

set(preload_autoconf_h ${PRELOAD_BINARY_DIR}/zephyr/include/generated/zephyr/autoconf.h)
set(preload_dotconfig ${PRELOAD_BINARY_DIR}/zephyr/.config)

file(COPY ${preload_dotconfig} DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${preload_autoconf_h} DESTINATION ${PROJECT_BINARY_DIR}/include/generated/zephyr)
file(APPEND ${AUTOCONF_H} "#define CONFIG_NCS_IS_VARIANT_IMAGE 1")

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${AUTOCONF_H})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${DOTCONFIG})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${preload_autoconf_h})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${preload_dotconfig})

import_kconfig("CONFIG" ${DOTCONFIG})
if(CONFIG_NCS_VARIANT_MERGE_KCONFIG)
# A variant build should reuse same .config and thus autoconf.h, therefore
# copy files from original and bypass Kconfig invocation.
set(preload_autoconf_h ${PRELOAD_BINARY_DIR}/zephyr/include/generated/zephyr/autoconf.h)
set(preload_dotconfig ${PRELOAD_BINARY_DIR}/zephyr/.config)

file(COPY ${preload_dotconfig} DESTINATION ${PROJECT_BINARY_DIR})
file(COPY ${preload_autoconf_h} DESTINATION ${PROJECT_BINARY_DIR}/include/generated/zephyr)

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${preload_autoconf_h})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${preload_dotconfig})

import_kconfig("CONFIG" ${DOTCONFIG})
else()
# First generate autoconf.h as well as .config files.
include(${ZEPHYR_BASE}/cmake/modules/kconfig.cmake)
endif()

file(APPEND ${AUTOCONF_H} "#define CONFIG_NCS_IS_VARIANT_IMAGE 1")
else()
include(${ZEPHYR_BASE}/cmake/modules/kconfig.cmake)
endif()
12 changes: 10 additions & 2 deletions cmake/sysbuild/modules/ncs_sysbuild_extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ include_guard(GLOBAL)
# APPLICATION <name>: Name of the application which is used as the source for
# the variant build.
# VARIANT <name>: Name of the variant build.
# SPLIT_KCONFIG: Flag indicating that the variant image should
# not reuse the same .config files.
function(ExternalNcsVariantProject_Add)
cmake_parse_arguments(VBUILD "" "APPLICATION;VARIANT" "" ${ARGN})
cmake_parse_arguments(VBUILD "SPLIT_KCONFIG" "APPLICATION;VARIANT" "" ${ARGN})

ExternalProject_Get_Property(${VBUILD_APPLICATION} SOURCE_DIR BINARY_DIR)
set(${VBUILD_APPLICATION}_BINARY_DIR ${BINARY_DIR})
Expand All @@ -41,9 +43,15 @@ function(ExternalNcsVariantProject_Add)
set_property(TARGET ${VBUILD_VARIANT} PROPERTY NCS_VARIANT_APPLICATION ${VBUILD_APPLICATION})
set_property(TARGET ${VBUILD_VARIANT} APPEND PROPERTY _EP_CMAKE_ARGS
-DCONFIG_NCS_IS_VARIANT_IMAGE=y
-DPRELOAD_BINARY_DIR=${${VBUILD_APPLICATION}_BINARY_DIR}
)

if(NOT VBUILD_SPLIT_KCONFIG)
set_property(TARGET ${VBUILD_VARIANT} APPEND PROPERTY _EP_CMAKE_ARGS
-DPRELOAD_BINARY_DIR=${${VBUILD_APPLICATION}_BINARY_DIR}
-DCONFIG_NCS_VARIANT_MERGE_KCONFIG=y
)
endif()

# Configure variant image after application so that the configuration is present
sysbuild_add_dependencies(CONFIGURE ${VBUILD_VARIANT} ${VBUILD_APPLICATION})
endfunction()

0 comments on commit 88a4f9d

Please sign in to comment.