qmk_firmware/cmake/Utils.cmake
2023-04-07 16:25:51 -04:00

25 lines
850 B
CMake

macro(json_get_with_default KEY_STR JSON_STR DEFAULT)
# message(STATUS "Getting ${ARGN} for ${KEY_STR}")
string(JSON ${KEY_STR} ERROR_VARIABLE JSON_ERROR GET ${JSON_STR} ${ARGN})
if(NOT ${JSON_ERROR} STREQUAL "NOTFOUND")
set(${KEY_STR} ${DEFAULT})
endif()
endmacro()
macro(json_get KEY_STR JSON_STR)
# message(STATUS "Getting ${ARGN} for ${KEY_STR}")
string(JSON ${KEY_STR} ERROR_VARIABLE JSON_ERROR GET ${JSON_STR} ${ARGN})
if(NOT ${JSON_ERROR} STREQUAL "NOTFOUND")
unset(${KEY_STR})
endif()
endmacro()
macro(parent_list ACTION LIST_STR)
set(ARGS ${ARGN})
string(REPLACE ";" " " ARGS ${ARGS})
set(LOCAL_LIST ${${LIST_STR}})
list(${ACTION} LOCAL_LIST ${ARGS})
# set in current scope too
set(${LIST_STR} ${LOCAL_LIST})
set(${LIST_STR} ${LOCAL_LIST} PARENT_SCOPE)
endmacro()