sysbuild: Add support for snippets

Adds support for sysbuild loading snippets, these can be included
by using e.g.: cmake ... -DSB_SNIPPET=blah for sysbuild
directly or can be used with an application and sysbuild using
-DSNIPPET. Snippets for sysbuild can use SB_EXTRA_CONF_FILE in the
snippet file to specify an extra Kconfig fragment for sysbuild

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2024-05-24 07:46:33 +01:00 committed by Benjamin Cabé
commit 0711f42e3a
8 changed files with 58 additions and 12 deletions

View file

@ -45,19 +45,23 @@ zephyr_check_cache(SNIPPET WATCH)
function(zephyr_process_snippets)
set(snippets_py ${ZEPHYR_BASE}/scripts/snippets.py)
set(snippets_generated ${CMAKE_BINARY_DIR}/zephyr/snippets_generated.cmake)
set_ifndef(SNIPPET_NAMESPACE SNIPPET)
set_ifndef(SNIPPET_PYTHON_EXTRA_ARGS "")
set_ifndef(SNIPPET_APP_DIR "${APPLICATION_SOURCE_DIR}")
# Set SNIPPET_AS_LIST, removing snippets_generated.cmake if we are
# running cmake again and snippets are no longer requested.
if (NOT DEFINED SNIPPET)
if(NOT DEFINED SNIPPET)
set(SNIPPET_AS_LIST "" PARENT_SCOPE)
file(REMOVE ${snippets_generated})
else()
string(REPLACE " " ";" SNIPPET_AS_LIST "${SNIPPET}")
string(REPLACE " " ";" SNIPPET_AS_LIST "${${SNIPPET_NAMESPACE}}")
set(SNIPPET_AS_LIST "${SNIPPET_AS_LIST}" PARENT_SCOPE)
endif()
# Set SNIPPET_ROOT.
list(APPEND SNIPPET_ROOT ${APPLICATION_SOURCE_DIR})
zephyr_get(SNIPPET_ROOT MERGE SYSBUILD GLOBAL)
list(APPEND SNIPPET_ROOT ${SNIPPET_APP_DIR})
list(APPEND SNIPPET_ROOT ${ZEPHYR_BASE})
unset(real_snippet_root)
foreach(snippet_dir ${SNIPPET_ROOT})
@ -85,6 +89,7 @@ function(zephyr_process_snippets)
${snippet_root_args}
${requested_snippet_args}
--cmake-out ${snippets_generated}
${SNIPPET_PYTHON_EXTRA_ARGS}
OUTPUT_VARIABLE output
ERROR_VARIABLE output
RESULT_VARIABLE ret)