rapids_json_parse#
Added in version v27.02.00.
Extract the members of a JSON object into CMake variables.
rapids_json_parse(<prefix> (FILE <file> | STRING <json>) [KEY <member|index>...] [BASE_DIR <dir>] [VALUES <key>...] [LISTS <key>...] [PATHS <key>...] [OBJECTS <key>...] )
Reads a JSON object and stores the members that the caller has asked for in
variables named <prefix>_<key>. The layout of the JSON document is
described by the keywords given to the call, in the same way
cmake_parse_arguments
describes the layout of command line arguments. The members of each record of
an array can be parsed by giving the record to this function as STRING,
after extracting it with string(JSON ... GET_RAW).
<prefix>Prefix of the variables that are set in the calling scope. All variables that could be set by this call are unset first, so it is safe to re-use a
<prefix>for multiple invocations.FILEPath to the JSON file to read. If relative, it is evaluated relative to
CMAKE_CURRENT_LIST_DIR. The file is added to theCMAKE_CONFIGURE_DEPENDSdirectory property so that editing it re-runs the CMake configuration. Mutually exclusive withSTRING.STRINGString containing the JSON document to read. Mutually exclusive with
FILE.KEYSequence of object members and array indices, in the same form as accepted by
string(JSON), that locates the object to parse. When not provided the document itself is parsed.BASE_DIRAn absolute path of the directory that relative entries of
PATHSare evaluated relative to.VALUESMembers that hold a single value. The value is stored as is.
LISTSMembers that hold an array. The array is stored as a CMake list with an entry for each element of the array.
Only supports string, number, or boolean elements.
PATHSMembers that hold a path, or an array of paths. A member that is neither a string nor an array is an error. The result is always a CMake list of absolute paths, which has a single entry when the member is a string. Absolute paths are used as is, and relative paths are made absolute by:
BASE_DIRwhen provided.When
FILEis used, the directory containing the JSON file.When
STRINGis used, theCMAKE_CURRENT_LIST_DIRof the caller.
Paths are not normalized, so entries such as
../a.cppkeep their..component.OBJECTSMembers that hold an object. The object is stored as a JSON string that can be given to another call of
rapids_json_parseas theSTRINGargument.
A member can be declared by a single keyword only. Members that exist in the JSON object, but are not declared, are ignored. All declared members are optional, callers that need a member should check that its variable is defined.
Example on how to properly use rapids_json_parse():
# kernel.json: # { # "name": "scan_@type@", # "input": "scan.cu.in", # "headers": [ "<common.hpp>", "<scan.hpp>" ], # "output_dir": "generated" # } rapids_json_parse(_kernel FILE kernel.json VALUES name output_dir PATHS input LISTS headers ) message(STATUS "input is ${_kernel_input}") message(STATUS "headers are ${_kernel_headers}")
Result Variables#
<prefix>_<key>Set for each declared member that exists in the JSON object. Members that don’t exist leave the variable unset.
Limitations#
A
;is supported in theSTRINGdocument and inVALUESandOBJECTSmembers. It is not supported in the elements ofLISTSandPATHSmembers, since they are returned as CMake lists.