From ffff2124d3bfb018e35208ab52db9fb5d82d89bc Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Tue, 16 Mar 2021 09:25:30 +0100 Subject: [PATCH] cmake: zephyr_file() now accepts BOARD and BOARD_REVISION as argument With the introduction of #32556 changing the BOARD now prints a warning. Zephyr provides `zephyr_file()` to look up overlays and Kconfig fragments for a specified board, and it used to be possible and safe to do: ``` function(my_func) set(BOARD ) zephyr_file(CONF_FILES ...) endfunction(my_func) ``` As the BOARD inside `my_func` is locally scoped, this is safe to do. But with introduction of #32556 a warning is now printed when running CMake. Therefore `zephyr_file` has been extended to allow for optional BOARD and BOARD_REVISION arguments. If BOARD is not given as argument the current BOARD in the build system will be used. Signed-off-by: Torsten Rasmussen --- cmake/extensions.cmake | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index 655600bcf4b..60bb69d3118 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -1874,6 +1874,13 @@ endfunction() # The conf file search will return existing configuration # files for the current board. # CONF_FILES takes the following additional arguments: +# BOARD : Find configuration files for specified board. +# BOARD_REVISION : Find configuration files for specified board +# revision. Requires BOARD to be specified. +# +# If no board is given the current BOARD and +# BOARD_REVISION will be used. +# # DTS : List to populate with DTS overlay files # KCONF : List to populate with Kconfig fragment files # BUILD : Build type to include for search. @@ -1892,7 +1899,7 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES") if(${ARGV0} STREQUAL APPLICATION_ROOT) set(single_args APPLICATION_ROOT) elseif(${ARGV0} STREQUAL CONF_FILES) - set(single_args CONF_FILES DTS KCONF BUILD) + set(single_args CONF_FILES BOARD BOARD_REVISION DTS KCONF BUILD) endif() cmake_parse_arguments(FILE "" "${single_args}" "" ${ARGN}) @@ -1937,10 +1944,26 @@ Relative paths are only allowed with `-D${ARGV1}=`") endif() if(FILE_CONF_FILES) - set(FILENAMES ${BOARD}) + if(DEFINED FILE_BOARD_REVISION AND NOT FILE_BOARD) + message(FATAL_ERROR + "zephyr_file(${ARGV0} BOARD_REVISION ${FILE_BOARD_REVISION} ...)" + " given without BOARD argument, please specify BOARD" + ) + endif() - if(DEFINED BOARD_REVISION) - list(APPEND FILENAMES "${BOARD}_${BOARD_REVISION_STRING}") + if(NOT DEFINED FILE_BOARD) + # Defaulting to system wide settings when BOARD is not given as argument + set(FILE_BOARD ${BOARD}) + if(DEFINED BOARD_REVISION) + set(FILE_BOARD_REVISION ${BOARD_REVISION}) + endif() + endif() + + set(FILENAMES ${FILE_BOARD}) + + if(DEFINED FILE_BOARD_REVISION) + string(REPLACE "." "_" revision_string ${FILE_BOARD_REVISION}) + list(APPEND FILENAMES "${FILE_BOARD}_${revision_string}") endif() if(FILE_DTS)