mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-11 09:48:24 +02:00
Add cmake scripts.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
44
cmake/dict.cmake
Normal file
44
cmake/dict.cmake
Normal file
@@ -0,0 +1,44 @@
|
||||
function(dict command dict )
|
||||
if(command STREQUAL SET)
|
||||
set(arg_key ${ARGV2})
|
||||
set(arg_value ${ARGV3})
|
||||
|
||||
dict(_IDX ${dict} "${arg_key}" idx)
|
||||
if(NOT idx STREQUAL -1)
|
||||
list(REMOVE_AT ${dict} ${idx})
|
||||
endif()
|
||||
|
||||
list(APPEND ${dict} "${arg_key}=${arg_value}")
|
||||
set(${dict} "${${dict}}" PARENT_SCOPE)
|
||||
|
||||
elseif(command STREQUAL GET)
|
||||
set(arg_key ${ARGV2})
|
||||
set(arg_outvar ${ARGV3})
|
||||
|
||||
dict(_IDX ${dict} "${arg_key}" idx)
|
||||
if(idx STREQUAL -1)
|
||||
message(FATAL_ERROR "No key \"${arg_key}\" in dictionary")
|
||||
endif()
|
||||
|
||||
list(GET ${dict} ${idx} kv)
|
||||
string(REGEX REPLACE "^[^=]+=(.*)" "\\1" value "${kv}")
|
||||
set(${arg_outvar} "${value}" PARENT_SCOPE)
|
||||
|
||||
elseif(command STREQUAL _IDX)
|
||||
set(arg_key ${ARGV2})
|
||||
set(arg_outvar ${ARGV3})
|
||||
set(idx 0)
|
||||
foreach(kv IN LISTS ${dict})
|
||||
string(REGEX REPLACE "^([^=]+)=.*" "\\1" key "${kv}")
|
||||
if(arg_key STREQUAL key)
|
||||
set(${arg_outvar} "${idx}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
math(EXPR idx ${idx}+1)
|
||||
endforeach()
|
||||
set(${arg_outvar} "-1" PARENT_SCOPE)
|
||||
|
||||
else()
|
||||
message(FATAL_ERROR "dict does not recognize sub-command ${command}")
|
||||
endif()
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user