VTK  9.1.0
vtkModuleJson.cmake
Go to the documentation of this file.
1#[==[
2@ingroup module-impl
3@brief Output a boolean to JSON
4
5Appends a condition as a JSON boolean with the given dictionary key name to the
6given string variable.
7
8~~~
9_vtk_json_bool(<output> <name> <cond>)
10~~~
11#]==]
12macro (_vtk_json_bool output name cond)
13 if (${cond})
14 set(val "true")
15 else ()
16 set(val "false")
17 endif ()
18 string(APPEND "${output}" "\"${name}\": ${val}, ")
19 unset(val)
20endmacro ()
21
22#[==[
23@ingroup module-impl
24@brief Output a string list to JSON
25
26Appends a variable as a JSON list of strings with the given dictionary key name
27to the given string variable.
28
29~~~
30_vtk_json_string_list(<output> <name> <cond>)
31~~~
32#]==]
33macro (_vtk_json_string_list output name var)
34 set(list "[")
35 foreach (value IN LISTS "${var}")
36 string(APPEND list "\"${value}\", ")
37 endforeach ()
38 string(APPEND list "]")
39 string(REPLACE ", ]" "]" list "${list}")
40 string(APPEND "${output}" "\"${name}\": ${list}, ")
41 unset(value)
42 unset(list)
43endmacro ()
44
45#[==[
46@ingroup module-support
47@brief JSON metadata representation of modules
48
49Information about the modules built and/or available may be dumped to a JSON
50file.
51
52~~~
53vtk_module_json(
54 MODULES <module>...
55 OUTPUT <path>)
56~~~
57
58 * `MODULES`: (Required) The modules to output information for.
59 * `OUTPUT`: (Required) A JSON file describing the modules built will
60 be output to this path. Relative paths are rooted to `CMAKE_BINARY_DIR`.
61
62Example output:
63
64~~~{.json}
65{
66 "modules": [
67 {
68 "name": "...",
69 "library_name": "...",
70 "enabled": <bool>,
71 "implementable": <bool>,
72 "third_party": <bool>,
73 "wrap_exclude": <bool>,
74 "kit": "...",
75 "depends": [
76 "..."
77 ],
78 "optional_depends": [
79 "..."
80 ],
81 "private_depends": [
82 "..."
83 ],
84 "implements": [
85 "..."
86 ],
87 "headers": [
88 "..."
89 ]
90 }
91 ],
92 "kits": [
93 {
94 "name": "...",
95 "enabled": <bool>,
96 "modules": [
97 ]
98 }
99 ]
100}
101~~~
102#]==]
104 cmake_parse_arguments(PARSE_ARGV 0 _vtk_json
105 ""
106 "OUTPUT"
107 "MODULES")
108
109 if (_vtk_json_UNPARSED_ARGUMENTS)
110 message(FATAL_ERROR
111 "Unparsed arguments for vtk_module_json: "
112 "${_vtk_json_UNPARSED_ARGUMENTS}")
113 endif ()
114
115 if (NOT DEFINED _vtk_json_OUTPUT)
116 message(FATAL_ERROR
117 "The `OUTPUT` argument is required.")
118 endif ()
119
120 if (NOT _vtk_json_MODULES)
121 message(FATAL_ERROR "No modules given to output.")
122 endif ()
123
124 if (NOT IS_ABSOLUTE "${_vtk_json_OUTPUT}")
125 string(PREPEND _vtk_json_OUTPUT "${CMAKE_BINARY_DIR}/")
126 endif ()
127
128 set(_vtk_json_kits)
129
130 set(_vtk_json_contents "{")
131 string(APPEND _vtk_json_contents "\"modules\": {")
132 foreach (_vtk_json_module IN LISTS _vtk_json_MODULES)
133 get_property(_vtk_json_description GLOBAL
134 PROPERTY "_vtk_module_${_vtk_json_module}_description")
135 get_property(_vtk_json_implementable GLOBAL
136 PROPERTY "_vtk_module_${_vtk_json_module}_implementable")
137 get_property(_vtk_json_third_party GLOBAL
138 PROPERTY "_vtk_module_${_vtk_json_module}_third_party")
139 get_property(_vtk_json_wrap_exclude GLOBAL
140 PROPERTY "_vtk_module_${_vtk_json_module}_wrap_exclude")
141 get_property(_vtk_json_kit GLOBAL
142 PROPERTY "_vtk_module_${_vtk_json_module}_kit")
143 get_property(_vtk_json_depends GLOBAL
144 PROPERTY "_vtk_module_${_vtk_json_module}_depends")
145 get_property(_vtk_json_private_depends GLOBAL
146 PROPERTY "_vtk_module_${_vtk_json_module}_private_depends")
147 get_property(_vtk_json_optional_depends GLOBAL
148 PROPERTY "_vtk_module_${_vtk_json_module}_optional_depends")
149 get_property(_vtk_json_implements GLOBAL
150 PROPERTY "_vtk_module_${_vtk_json_module}_implements")
151 get_property(_vtk_json_library_name GLOBAL
152 PROPERTY "_vtk_module_${_vtk_json_module}_library_name")
153 get_property(_vtk_json_module_file GLOBAL
154 PROPERTY "_vtk_module_${_vtk_json_module}_file")
155
156 set(_vtk_json_kit_name "null")
157 if (_vtk_json_kit)
158 list(APPEND _vtk_json_kits
159 "${_vtk_json_kit}")
160 set(_vtk_json_kit_name "\"${_vtk_json_kit}\"")
161 endif ()
162 set(_vtk_json_headers "")
163 if (TARGET "${_vtk_json_module}")
164 _vtk_module_get_module_property("${_vtk_json_module}"
165 PROPERTY "headers"
166 VARIABLE _vtk_json_headers)
167 get_filename_component(_vtk_json_module_dir "${_vtk_json_module_file}" DIRECTORY)
168 file(RELATIVE_PATH _vtk_json_module_subdir "${CMAKE_SOURCE_DIR}" "${_vtk_json_module_dir}")
169 string(REPLACE "${CMAKE_SOURCE_DIR}/${_vtk_json_module_subdir}/" "" _vtk_json_headers "${_vtk_json_headers}")
170 string(REPLACE "${CMAKE_BINARY_DIR}/${_vtk_json_module_subdir}/" "" _vtk_json_headers "${_vtk_json_headers}")
171 endif ()
172
173 string(APPEND _vtk_json_contents "\"${_vtk_json_module}\": {")
174 string(APPEND _vtk_json_contents "\"library_name\": \"${_vtk_json_library_name}\", ")
175 string(APPEND _vtk_json_contents "\"description\": \"${_vtk_json_description}\", ")
176 _vtk_json_bool(_vtk_json_contents "enabled" "TARGET;${_vtk_json_module}")
177 _vtk_json_bool(_vtk_json_contents "implementable" _vtk_json_implementable)
178 _vtk_json_bool(_vtk_json_contents "third_party" _vtk_json_third_party)
179 _vtk_json_bool(_vtk_json_contents "wrap_exclude" _vtk_json_wrap_exclude)
180 string(APPEND _vtk_json_contents "\"kit\": ${_vtk_json_kit_name}, ")
181 _vtk_json_string_list(_vtk_json_contents "depends" _vtk_json_depends)
182 _vtk_json_string_list(_vtk_json_contents "optional_depends" _vtk_json_optional_depends)
183 _vtk_json_string_list(_vtk_json_contents "private_depends" _vtk_json_private_depends)
184 _vtk_json_string_list(_vtk_json_contents "implements" _vtk_json_implements)
185 _vtk_json_string_list(_vtk_json_contents "headers" _vtk_json_headers)
186 string(APPEND _vtk_json_contents "}, ")
187 endforeach ()
188 string(APPEND _vtk_json_contents "}, ")
189
190 string(APPEND _vtk_json_contents "\"kits\": {")
191 foreach (_vtk_json_kit IN LISTS _vtk_json_kits)
192 set(_vtk_json_library_name "null")
193 if (TARGET "${_vtk_json_kit}")
194 get_property(_vtk_json_library
195 TARGET "${_vtk_json_kit}"
196 PROPERTY LIBRARY_OUTPUT_NAME)
197 set(_vtk_json_library_name "\"${_vtk_json_library}\"")
198 endif ()
199
200 string(APPEND _vtk_json_contents "\"${_vtk_json_kit}\": {")
201 string(APPEND _vtk_json_contents "\"library_name\": ${_vtk_json_library_name}, ")
202 _vtk_json_bool(_vtk_json_contents "enabled" "TARGET;${_vtk_json_kit}")
203 string(APPEND _vtk_json_contents "}, ")
204 endforeach ()
205 string(APPEND _vtk_json_contents "}, ")
206
207 string(APPEND _vtk_json_contents "}")
208 string(REPLACE ", ]" "]" _vtk_json_contents "${_vtk_json_contents}")
209 string(REPLACE ", }" "}" _vtk_json_contents "${_vtk_json_contents}")
210 file(GENERATE
211 OUTPUT "${_vtk_json_OUTPUT}"
212 CONTENT "${_vtk_json_contents}")
213endfunction ()
macro _vtk_json_string_list(output, name, var)
Output a string list to JSON.
macro _vtk_json_bool(output, name, cond)
Output a boolean to JSON.
function vtk_module_json()
JSON metadata representation of modules.
@ key
Definition: vtkX3D.h:263
@ name
Definition: vtkX3D.h:225
@ string
Definition: vtkX3D.h:496