Skip to content

Instantly share code, notes, and snippets.

@zeroxia
Created December 4, 2023 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeroxia/2bb1ab4d02a0aae5684c53dfc19a1c6d to your computer and use it in GitHub Desktop.
Save zeroxia/2bb1ab4d02a0aae5684c53dfc19a1c6d to your computer and use it in GitHub Desktop.
CMake to tweak about JSON strings
cmake_minimum_required(VERSION 3.19)
include(CMakePrintHelpers)
message(STATUS START)
set(jsonContent
[[
{
"key1": 123,
"key2": [4, 5, "test"],
"one": {
"two": {
"three": ["x", "y", "z"]
}
}
}
]]
)
message(STATUS "Get key1")
string(JSON outVar ERROR_VARIABLE errorVar GET ${jsonContent} key1)
cmake_print_variables(errorVar outVar)
message(STATUS "Set key2.[1]")
string(JSON outVar ERROR_VARIABLE errorVar SET ${jsonContent} key2 1 [["hello"]])
cmake_print_variables(errorVar outVar)
message(STATUS "Get key2.[1]")
string(JSON outVar ERROR_VARIABLE errorVar GET ${jsonContent} key2 1)
cmake_print_variables(errorVar outVar)
message(STATUS "Set one.two.three.[2]")
string(JSON outVar ERROR_VARIABLE errorVar GET ${jsonContent} one two three 2)
cmake_print_variables(errorVar outVar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment