Created
December 4, 2023 02:49
-
-
Save zeroxia/2bb1ab4d02a0aae5684c53dfc19a1c6d to your computer and use it in GitHub Desktop.
CMake to tweak about JSON strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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