cmake: modules: dts: extract overlay helper function
This list processing procedure will be useful elsewhere, so prep for not repeating ourselves. Put it in a new zephyr_list() function whose signature has room to grow if we keep adding list processing extensions. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
f680c9db8d
commit
c3004a10f9
2 changed files with 53 additions and 7 deletions
|
@ -150,13 +150,8 @@ set(dts_files
|
|||
)
|
||||
|
||||
if(DTC_OVERLAY_FILE)
|
||||
# Convert from space-separated files into file list
|
||||
string(CONFIGURE "${DTC_OVERLAY_FILE}" DTC_OVERLAY_FILE_EXPANDED)
|
||||
string(REPLACE " " ";" DTC_OVERLAY_FILE_RAW_LIST "${DTC_OVERLAY_FILE_EXPANDED}")
|
||||
foreach(file ${DTC_OVERLAY_FILE_RAW_LIST})
|
||||
file(TO_CMAKE_PATH "${file}" cmake_path_file)
|
||||
list(APPEND DTC_OVERLAY_FILE_AS_LIST ${cmake_path_file})
|
||||
endforeach()
|
||||
zephyr_list(TRANSFORM DTC_OVERLAY_FILE NORMALIZE_PATHS
|
||||
OUTPUT_VARIABLE DTC_OVERLAY_FILE_AS_LIST)
|
||||
list(APPEND
|
||||
dts_files
|
||||
${DTC_OVERLAY_FILE_AS_LIST}
|
||||
|
|
|
@ -2410,6 +2410,57 @@ function(zephyr_string)
|
|||
set(${return_arg} ${work_string} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Usage:
|
||||
# zephyr_list(TRANSFORM <list> <ACTION>
|
||||
# [OUTPUT_VARIABLE <output variable])
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# zephyr_list(TRANSFORM my_input_var NORMALIZE_PATHS
|
||||
# OUTPUT_VARIABLE my_input_as_list)
|
||||
#
|
||||
# Like CMake's list(TRANSFORM ...). This is intended as a placeholder
|
||||
# for storing current and future Zephyr-related extensions for list
|
||||
# processing.
|
||||
#
|
||||
# <ACTION>: This currently must be NORMALIZE_PATHS. This action
|
||||
# converts the argument list <list> to a ;-list with
|
||||
# CMake path names, after passing its contents through
|
||||
# a configure_file() transformation. The input list
|
||||
# may be whitespace- or semicolon-separated.
|
||||
#
|
||||
# OUTPUT_VARIABLE: the result is normally stored in place, but
|
||||
# an alternative variable to store the result
|
||||
# can be provided with this.
|
||||
function(zephyr_list transform list_var action)
|
||||
# Parse arguments.
|
||||
if(NOT "${transform}" STREQUAL "TRANSFORM")
|
||||
message(FATAL_ERROR "the first argument must be TRANSFORM")
|
||||
endif()
|
||||
if(NOT "${action}" STREQUAL "NORMALIZE_PATHS")
|
||||
message(FATAL_ERROR "the third argument must be NORMALIZE_PATHS")
|
||||
endif()
|
||||
set(single_args OUTPUT_VARIABLE)
|
||||
cmake_parse_arguments(ZEPHYR_LIST "" "${single_args}" "" ${ARGN})
|
||||
if(DEFINED ZEPHYR_LIST_OUTPUT_VARIABLE)
|
||||
set(out_var ${ZEPHYR_LIST_OUTPUT_VARIABLE})
|
||||
else()
|
||||
set(out_var ${list_var})
|
||||
endif()
|
||||
set(input ${${list_var}})
|
||||
|
||||
# Perform the transformation.
|
||||
set(ret)
|
||||
string(CONFIGURE "${input}" input_expanded)
|
||||
string(REPLACE " " ";" input_raw_list "${input_expanded}")
|
||||
foreach(file ${input_raw_list})
|
||||
file(TO_CMAKE_PATH "${file}" cmake_path_file)
|
||||
list(APPEND ret ${cmake_path_file})
|
||||
endforeach()
|
||||
|
||||
set(${out_var} ${ret} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Usage:
|
||||
# zephyr_get(<variable>)
|
||||
# zephyr_get(<variable> SYSBUILD [LOCAL|GLOBAL])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue