mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
feat(cmakev2/utilities): add __make_json_list helper
Helper function for converting a CMake list to a JSON list. Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
@@ -812,3 +812,32 @@ function(__get_executable_library_or_die)
|
||||
endif()
|
||||
set(${ARG_OUTPUT} "${library}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
#[[
|
||||
__make_json_list(<list> OUTPUT <variable>)
|
||||
|
||||
:list[in]: CMake string containing a list to be converted into JSON
|
||||
format.
|
||||
:OUTPUT[out]: Output variable name to store the JSON list.
|
||||
|
||||
Convert a CMake list to a JSON list and store it in a OUTPUT
|
||||
variable.
|
||||
#]]
|
||||
function(__make_json_list input)
|
||||
set(options)
|
||||
set(one_value OUTPUT)
|
||||
set(multi_value)
|
||||
cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN})
|
||||
|
||||
if(NOT DEFINED ARG_OUTPUT)
|
||||
idf_die("OUTPUT option is required")
|
||||
endif()
|
||||
|
||||
list(LENGTH input length)
|
||||
if(${length})
|
||||
string(REPLACE ";" "\", \"" result "[ \"${input}\" ]")
|
||||
else()
|
||||
set(result "[]")
|
||||
endif()
|
||||
set("${ARG_OUTPUT}" "${result}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
Reference in New Issue
Block a user