VTK  9.1.0
vtkModuleGraphviz.cmake
Go to the documentation of this file.
1#[==[
2@ingroup module-impl
3@brief Output a node in the graph
4
5Queries the properties for modules and generates the node for it in the graph
6and its outgoing dependency edges.
7#]==]
9 get_property(_vtk_graphviz_file GLOBAL
10 PROPERTY "_vtk_module_${module}_file")
11 if (_vtk_graphviz_file)
12 get_property(_vtk_graphviz_module_third_party GLOBAL
13 PROPERTY "_vtk_module_${module}_third_party")
14 get_property(_vtk_graphviz_module_exclude_wrap GLOBAL
15 PROPERTY "_vtk_module_${module}_exclude_wrap")
16 get_property(_vtk_graphviz_module_depends GLOBAL
17 PROPERTY "_vtk_module_${module}_depends")
18 get_property(_vtk_graphviz_module_private_depends GLOBAL
19 PROPERTY "_vtk_module_${module}_private_depends")
20 get_property(_vtk_graphviz_module_optional_depends GLOBAL
21 PROPERTY "_vtk_module_${module}_optional_depends")
22 get_property(_vtk_graphviz_module_implements GLOBAL
23 PROPERTY "_vtk_module_${module}_implements")
24 get_property(_vtk_graphviz_module_implementable GLOBAL
25 PROPERTY "_vtk_module_${module}_implementable")
26 else ()
27 get_property(_vtk_graphviz_module_third_party
28 TARGET "${module}"
29 PROPERTY "INTERFACE_vtk_module_third_party")
30 get_property(_vtk_graphviz_module_exclude_wrap
31 TARGET "${module}"
32 PROPERTY "INTERFACE_vtk_module_exclude_wrap")
33 get_property(_vtk_graphviz_module_depends
34 TARGET "${module}"
35 PROPERTY "INTERFACE_vtk_module_depends")
36 set(_vtk_graphviz_module_private_depends)
37 set(_vtk_graphviz_module_optional_depends)
38 get_property(_vtk_graphviz_module_implements
39 TARGET "${module}"
40 PROPERTY "INTERFACE_vtk_module_implements")
41 get_property(_vtk_graphviz_module_implementable
42 TARGET "${module}"
43 PROPERTY "INTERFACE_vtk_module_implementable")
44 endif ()
45
46 if (_vtk_graphviz_module_third_party)
47 set(_vtk_graphviz_shape "${_vtk_graphviz_third_party}")
48 else ()
49 set(_vtk_graphviz_shape "${_vtk_graphviz_first_party}")
50 endif ()
51
52 if (_vtk_graphviz_file)
53 if (DEFINED "VTK_MODULE_USE_EXTERNAL_${module}" AND VTK_MODULE_USE_EXTERNAL_${module})
54 set(_vtk_graphviz_fillcolor "${_vtk_graphviz_external}")
55 else ()
56 set(_vtk_graphviz_fillcolor "${_vtk_graphviz_internal}")
57 endif ()
58 else ()
59 set(_vtk_graphviz_fillcolor "${_vtk_graphviz_external}")
60 endif ()
61
62 if (_vtk_graphviz_module_exclude_wrap)
63 set(_vtk_graphviz_penwidth "${_vtk_graphviz_exclude_wrap}")
64 else ()
65 set(_vtk_graphviz_penwidth "${_vtk_graphviz_include_wrap}")
66 endif ()
67
68 if (_vtk_graphviz_module_implementable)
69 set(_vtk_graphviz_color "${_vtk_graphviz_implementable}")
70 else ()
71 set(_vtk_graphviz_color "${_vtk_graphviz_not_implementable}")
72 endif ()
73
74 set(_vtk_graphviz_node_block "\"${module}\" [
75 label=\"${module}\"
76 shape=${_vtk_graphviz_shape}
77 style=filled
78 color=${_vtk_graphviz_color}
79 fillcolor=${_vtk_graphviz_fillcolor}
80 penwidth=${_vtk_graphviz_penwidth}
81];\n")
82
83 foreach (_vtk_graphviz_module_implement IN LISTS _vtk_graphviz_module_implements)
84 string(APPEND _vtk_graphviz_node_block
85 "\"${module}\" -> \"${_vtk_graphviz_module_implement}\" [style=${_vtk_graphviz_implements}, arrowhead=${_vtk_graphviz_required_depends}];\n")
86 endforeach ()
87
88 foreach (_vtk_graphviz_module_depend IN LISTS _vtk_graphviz_module_depends)
89 string(APPEND _vtk_graphviz_node_block
90 "\"${module}\" -> \"${_vtk_graphviz_module_depend}\" [style=${_vtk_graphviz_public_depends}, arrowhead=${_vtk_graphviz_required_depends}];\n")
91 endforeach ()
92
93 if (_vtk_graphviz_PRIVATE_DEPENDENCIES)
94 foreach (_vtk_graphviz_module_private_depend IN LISTS _vtk_graphviz_module_private_depends)
95 string(APPEND _vtk_graphviz_node_block
96 "\"${module}\" -> \"${_vtk_graphviz_module_private_depend}\" [style=${_vtk_graphviz_private_depends}, arrowhead=${_vtk_graphviz_required_depends}];\n")
97 endforeach ()
98
99 foreach (_vtk_graphviz_module_optional_depend IN LISTS _vtk_graphviz_module_optional_depends)
100 string(APPEND _vtk_graphviz_node_block
101 "\"${module}\" -> \"${_vtk_graphviz_module_optional_depend}\" [style=${_vtk_graphviz_optional_depends}, arrowhead=${_vtk_graphviz_optional_depends}];\n")
102 endforeach ()
103 endif ()
104
105 set("${var}" "${_vtk_graphviz_node_block}" PARENT_SCOPE)
106endfunction ()
107
108#[==[
109@ingroup module-support
110@brief Generate graphviz output for a module dependency graph
111
112Information about the modules built and/or available may be dumped to a
113Graphviz `.dot` file.
114
115~~~
116vtk_module_graphviz(
117 MODULES <module>...
118 OUTPUT <path>
119
120 [PRIVATE_DEPENDENCIES <ON|OFF>]
121 [KIT_CLUSTERS <ON|OFF>])
122~~~
123
124 * `MODULES`: (Required) The modules to output information for.
125 * `OUTPUT`: (Required) A Graphviz file describing the modules built will
126 be output to this path. Relative paths are rooted to `CMAKE_BINARY_DIR`.
127 * `PRIVATE_DEPENDENCIES`: (Default `ON`) Whether to draw private dependency
128 edges or not..
129 * `KIT_CLUSTERS`: (Default `OFF`) Whether to draw modules as part of a kit as
130 a cluster or not.
131#]==]
132function (vtk_module_graphviz)
133 cmake_parse_arguments(PARSE_ARGV 0 _vtk_graphviz
134 ""
135 "PRIVATE_DEPENDENCIES;KIT_CLUSTERS;OUTPUT"
136 "MODULES")
137
138 if (_vtk_graphviz_UNPARSED_ARGUMENTS)
139 message(FATAL_ERROR
140 "Unparsed arguments for vtk_module_graphviz: "
141 "${_vtk_graphviz_UNPARSED_ARGUMENTS}")
142 endif ()
143
144 if (NOT DEFINED _vtk_graphviz_OUTPUT)
145 message(FATAL_ERROR
146 "The `OUTPUT` argument is required.")
147 endif ()
148
149 if (NOT _vtk_graphviz_MODULES)
150 message(FATAL_ERROR "No modules given to output.")
151 endif ()
152
153 if (NOT DEFINED _vtk_graphviz_PRIVATE_DEPENDENCIES)
154 set(_vtk_graphviz_PRIVATE_DEPENDENCIES ON)
155 endif ()
156
157 if (NOT DEFINED _vtk_graphviz_KIT_CLUSTERS)
158 set(_vtk_graphviz_KIT_CLUSTERS OFF)
159 endif ()
160
161 if (NOT IS_ABSOLUTE "${_vtk_graphviz_OUTPUT}")
162 string(PREPEND _vtk_graphviz_OUTPUT "${CMAKE_BINARY_DIR}/")
163 endif ()
164
165 set(_vtk_graphviz_kits)
166 set(_vtk_graphviz_no_kit_modules)
167
168 if (_vtk_graphviz_KIT_CLUSTERS)
169 # Get a list of all kits.
170 foreach (_vtk_graphviz_module IN LISTS _vtk_graphviz_MODULES)
171 get_property(_vtk_graphviz_kit GLOBAL
172 PROPERTY "_vtk_module_${_vtk_graphviz_module}_kit")
173 if (_vtk_graphviz_kit)
174 list(APPEND _vtk_graphviz_kits
175 "${_vtk_graphviz_kit}")
176 else ()
177 list(APPEND _vtk_graphviz_no_kit_modules
178 "${_vtk_graphviz_module}")
179 endif ()
180 endforeach ()
181 if (_vtk_graphviz_kits)
182 list(REMOVE_DUPLICATES _vtk_graphviz_kits)
183 endif ()
184 else ()
185 set(_vtk_graphviz_no_kit_modules "${_vtk_graphviz_MODULES}")
186 endif ()
187
188 # Shapes
189 set(_vtk_graphviz_first_party "rectangle")
190 set(_vtk_graphviz_third_party "cds")
191 set(_vtk_graphviz_internal "\"/svg/white\"")
192 set(_vtk_graphviz_external "\"/svg/cyan\"")
193
194 # Border style
195 set(_vtk_graphviz_include_wrap "5")
196 set(_vtk_graphviz_exclude_wrap "1")
197 set(_vtk_graphviz_implementable "\"/svg/darkorchid\"")
198 set(_vtk_graphviz_not_implementable "\"/svg/coral\"")
199
200 # Dependencies
201 set(_vtk_graphviz_public_depends "solid")
202 set(_vtk_graphviz_private_depends "dotted")
203 set(_vtk_graphviz_implements "bold")
204
205 set(_vtk_graphviz_required_depends "normal")
206 set(_vtk_graphviz_optional_depends "empty")
207
208 set(_vtk_graphviz_contents "strict digraph modules {\nclusterrank=local;\nrankdir=TB;\n")
209
210 # Output modules not part of a kit.
211 string(APPEND _vtk_graphviz_contents
212 "subgraph \"modules_without_kits\" {\n")
213 foreach (_vtk_graphviz_module IN LISTS _vtk_graphviz_no_kit_modules)
214 _vtk_module_graphviz_module_node(_vtk_graphviz_node "${_vtk_graphviz_module}")
215 string(APPEND _vtk_graphviz_contents
216 "${_vtk_graphviz_node}\n")
217 endforeach ()
218 string(APPEND _vtk_graphviz_contents
219 "}\n")
220
221 # Output kits as clusters.
222 foreach (_vtk_graphviz_kit IN LISTS _vtk_graphviz_kits)
223 string(APPEND _vtk_graphviz_contents
224 "subgraph \"cluster_${_vtk_graphviz_kit}\" {\nlabel=\"${_vtk_graphviz_kit}\"\n")
225
226 get_property(_vtk_graphviz_kit_modules GLOBAL
227 PROPERTY "_vtk_kit_${_vtk_graphviz_kit}_kit_modules")
228 foreach (_vtk_graphviz_kit_module IN LISTS _vtk_graphviz_kit_modules)
229 if (NOT _vtk_graphviz_kit_module IN_LIST _vtk_graphviz_MODULES)
230 continue ()
231 endif ()
232
233 _vtk_module_graphviz_module_node(_vtk_graphviz_node "${_vtk_graphviz_kit_module}")
234 string(APPEND _vtk_graphviz_contents
235 "${_vtk_graphviz_node}\n")
236
237 endforeach ()
238
239 string(APPEND _vtk_graphviz_contents
240 "}\n")
241 endforeach ()
242
243 # Write the key cluster.
244 string(APPEND _vtk_graphviz_contents "
245subgraph cluster_key {
246 label=Key;
247 subgraph cluster_party {
248 first_party [
249 label=\"First party\"
250 shape=${_vtk_graphviz_first_party}
251 style=filled
252 color=${_vtk_graphviz_not_implementable}
253 fillcolor=${_vtk_graphviz_internal}
254 penwidth=${_vtk_graphviz_include_wrap}
255 ];
256 third_party [
257 label=\"Third party\"
258 shape=${_vtk_graphviz_third_party}
259 style=filled
260 color=${_vtk_graphviz_not_implementable}
261 fillcolor=${_vtk_graphviz_internal}
262 penwidth=${_vtk_graphviz_include_wrap}
263 ];
264 }
265 subgraph cluster_whence {
266 internal [
267 label=\"Internal module\"
268 shape=${_vtk_graphviz_first_party}
269 style=filled
270 color=${_vtk_graphviz_not_implementable}
271 fillcolor=${_vtk_graphviz_internal}
272 penwidth=${_vtk_graphviz_include_wrap}
273 ];
274 external [
275 label=\"External module\"
276 shape=${_vtk_graphviz_first_party}
277 style=filled
278 color=${_vtk_graphviz_not_implementable}
279 fillcolor=${_vtk_graphviz_external}
280 penwidth=${_vtk_graphviz_include_wrap}
281 ];
282 }
283 subgraph cluster_wrapping {
284 include_wrap [
285 label=\"Wrappable\"
286 shape=${_vtk_graphviz_first_party}
287 style=filled
288 color=${_vtk_graphviz_not_implementable}
289 fillcolor=${_vtk_graphviz_internal}
290 penwidth=${_vtk_graphviz_include_wrap}
291 ];
292 exclude_wrap [
293 label=\"Not wrappable\"
294 shape=${_vtk_graphviz_first_party}
295 style=filled
296 color=${_vtk_graphviz_not_implementable}
297 fillcolor=${_vtk_graphviz_internal}
298 penwidth=${_vtk_graphviz_exclude_wrap}
299 ];
300 }
301 subgraph cluster_implementable {
302 implementable [
303 label=\"Implementable\"
304 shape=${_vtk_graphviz_first_party}
305 style=filled
306 color=${_vtk_graphviz_implementable}
307 fillcolor=${_vtk_graphviz_internal}
308 penwidth=${_vtk_graphviz_include_wrap}
309 ];
310 not_implementable [
311 label=\"Not implementable\"
312 shape=${_vtk_graphviz_first_party}
313 style=filled
314 color=${_vtk_graphviz_not_implementable}
315 fillcolor=${_vtk_graphviz_internal}
316 penwidth=${_vtk_graphviz_include_wrap}
317 ];
318 }
319 subgraph cluster_dependencies {
320 dependent [
321 label=\"Dependent\"
322 shape=${_vtk_graphviz_first_party}
323 style=filled
324 color=${_vtk_graphviz_not_implementable}
325 fillcolor=${_vtk_graphviz_internal}
326 penwidth=${_vtk_graphviz_include_wrap}
327 ];
328 private_dependee [
329 label=\"Private Dependee\"
330 shape=${_vtk_graphviz_first_party}
331 style=filled
332 color=${_vtk_graphviz_not_implementable}
333 fillcolor=${_vtk_graphviz_internal}
334 penwidth=${_vtk_graphviz_include_wrap}
335 ];
336 optional_dependee [
337 label=\"Optional Dependee\"
338 shape=${_vtk_graphviz_first_party}
339 style=filled
340 color=${_vtk_graphviz_not_implementable}
341 fillcolor=${_vtk_graphviz_internal}
342 penwidth=${_vtk_graphviz_include_wrap}
343 ];
344 public_dependee [
345 label=\"Public Dependee\"
346 shape=${_vtk_graphviz_first_party}
347 style=filled
348 color=${_vtk_graphviz_not_implementable}
349 fillcolor=${_vtk_graphviz_internal}
350 penwidth=${_vtk_graphviz_include_wrap}
351 ];
352 implemented [
353 label=\"Implemented\"
354 shape=${_vtk_graphviz_first_party}
355 style=filled
356 color=${_vtk_graphviz_implementable}
357 fillcolor=${_vtk_graphviz_internal}
358 penwidth=${_vtk_graphviz_include_wrap}
359 ];
360 dependent -> private_dependee [style=${_vtk_graphviz_private_depends}, arrowhead=${_vtk_graphviz_required_depends}];
361 dependent -> optional_dependee [style=${_vtk_graphviz_private_depends}, arrowhead=${_vtk_graphviz_optional_depends}];
362 dependent -> public_dependee [style=${_vtk_graphviz_public_depends}, arrowhead=${_vtk_graphviz_required_depends}];
363 dependent -> implemented [style=${_vtk_graphviz_implements}, arrowhead=${_vtk_graphviz_required_depends}];
364 }
365}
366")
367 string(APPEND _vtk_graphviz_contents "}\n")
368
369 #file(GENERATE
370 # OUTPUT "${_vtk_graphviz_OUTPUT}"
371 # CONTENT "${_vtk_graphviz_contents}")
372 file(WRITE "${_vtk_graphviz_OUTPUT}" "${_vtk_graphviz_contents}")
373endfunction ()
function _vtk_module_graphviz_module_node(var, module)
Output a node in the graph.
function vtk_module_graphviz()
Generate graphviz output for a module dependency graph.
@ function
Definition: vtkX3D.h:255
@ string
Definition: vtkX3D.h:496
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)