snippets: basic build system boilerplate

Basic things needed to integrate the new 'snippets' feature into the
build system. The main CMake variable which controls snippets is
SNIPPET. It is a whitespace-or-semicolon-separated list of snippet
names.

- Add minimal new cmake module for processing snippets. This just has
  basic infrastructure for processing a SNIPPET variable into
  SNIPPET_AS_LIST, and warning the user if they try to change it too
  late.

- Integrate the new module into the build system, via
  zephyr_default.cmake

This is anologous to the shields and boards modules' boilerplate and
input variables.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Marti Bolivar 2023-01-06 16:49:23 -08:00 committed by Carles Cufí
commit 80ca540522
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,35 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2021, Nordic Semiconductor ASA
# Snippets support
#
# Outcome:
# The following variables will be defined when this module completes:
#
# - SNIPPET_AS_LIST: CMake list of snippet names, created from the
# SNIPPET variable
include_guard(GLOBAL)
include(extensions)
# Warn the user if SNIPPET changes later. Such changes are ignored.
zephyr_check_cache(SNIPPET WATCH)
# Putting the body into a function prevents us from polluting the
# parent scope. We'll set our outcome variables in the parent scope of
# the function to ensure the outcome of the module.
function(zephyr_process_snippets)
if (SNIPPET)
message(STATUS "Snippet(s): ${SNIPPET}")
else()
set(SNIPPET_AS_LIST "" PARENT_SCOPE)
return()
endif()
string(REPLACE " " ";" SNIPPET_AS_LIST "${SNIPPET}")
set(SNIPPET_AS_LIST "${SNIPPET_AS_LIST}" PARENT_SCOPE)
endfunction()
zephyr_process_snippets()