cmake: make WATCH an optional argument to zephyr_check_cache()

Watching of specific Zephyr CMake build variables ensure users cannot
accidentally set important variables, such as BOARD, SHIELD, CONF_FILES
late in the build process.

This was also added to zephyr_check_cache() function.
However, the BOARD provided by the user may look as `<board>@<revision>`
and will be kept in the cache in that form.

However, the BOARD value from cache is spit into internal build
variables as: BOARD=<board> and BOARD_REVISION=<revision>.
However, this is done after `zephyr_check_cache()` which then triggers
the variable watch to trigger, and printing a warning when using board
revisions.

Therefore WATCH is now optional for `zephyr_check_cache()` and watch for
BOARD variable will be enabled when boilerplate has completed all board
handling.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2021-03-16 10:07:47 +01:00 committed by Kumar Gala
parent 44a02c5ec5
commit b3bb1d6ad2
2 changed files with 10 additions and 4 deletions

View File

@ -224,6 +224,8 @@ if(NOT (REVISION_SEPARATOR_INDEX EQUAL -1))
string(SUBSTRING ${BOARD} 0 ${REVISION_SEPARATOR_INDEX} BOARD)
endif()
zephyr_boilerplate_watch(BOARD)
set(BOARD_MESSAGE "Board: ${BOARD}")
if(DEFINED ENV{ZEPHYR_BOARD_ALIASES})
@ -292,7 +294,7 @@ if(DEFINED BOARD_REVISION)
endif()
# Check that SHIELD has not changed.
zephyr_check_cache(SHIELD)
zephyr_check_cache(SHIELD WATCH)
if(SHIELD)
set(BOARD_MESSAGE "${BOARD_MESSAGE}, Shield(s): ${SHIELD}")

View File

@ -2026,6 +2026,8 @@ endfunction()
# variable: Name of <variable> to check and set, for example BOARD.
# REQUIRED: Optional flag. If specified, then an unset <variable> will be
# treated as an error.
# WATCH: Optional flag. If specified, watch the variable and print a warning if
# the variable is later being changed.
#
# Details:
# <variable> can be set by 3 sources.
@ -2056,7 +2058,7 @@ endfunction()
# <variable> the build directory must be cleaned.
#
function(zephyr_check_cache variable)
cmake_parse_arguments(CACHE_VAR "REQUIRED" "" "" ${ARGN})
cmake_parse_arguments(CACHE_VAR "REQUIRED;WATCH" "" "" ${ARGN})
string(TOLOWER ${variable} variable_text)
string(REPLACE "_" " " variable_text ${variable_text})
@ -2120,8 +2122,10 @@ function(zephyr_check_cache variable)
set(${variable} ${${variable}} PARENT_SCOPE)
set(CACHED_${variable} ${${variable}} CACHE STRING "Selected ${variable_text}")
# The variable is now set to its final value.
zephyr_boilerplate_watch(${variable})
if(CACHE_VAR_WATCH)
# The variable is now set to its final value.
zephyr_boilerplate_watch(${variable})
endif()
endfunction(zephyr_check_cache variable)