ParaViewServerManager.cmake
Go to the documentation of this file.
1 #[==[.md
2 # Server Manager XMLs
3 
4 ParaView uses XML files to describe filters available in its user interface.
5 Modules may add filters to the UI by providing XML files.
6 
7 TODO: Document the ServerManager XML format.
8 #]==]
9 
10 cmake_policy(PUSH)
11 cmake_policy(SET CMP0057 NEW)
12 
13 #[==[.md
14 ## Adding XMLs to modules
15 
16 Modules may have associated XML files. They can be added to the module target
17 using this function.
18 
19 ```
21  XMLS <xml>...)
22 ```
23 #]==]
25  cmake_parse_arguments(_paraview_add_sm
26  ""
27  "MODULE"
28  "XMLS"
29  ${ARGN})
30 
31  if (_paraview_add_sm_UNPARSED_ARGUMENTS)
32  message(FATAL_ERROR
33  "Unparsed arguments for paraview_add_server_manager_xmls: "
34  "${_paraview_add_sm_UNPARSED_ARGUMENTS}")
35  endif ()
36 
37  if (NOT _paraview_add_sm_XMLS)
38  message(FATAL_ERROR
39  "The `XMLS` argument is required.")
40  endif ()
41 
42  if (NOT DEFINED _paraview_add_sm_MODULE)
43  set(_paraview_add_sm_MODULE "${_vtk_build_module}")
44  endif ()
45 
46  foreach (_paraview_add_sm_xml IN LISTS _paraview_add_sm_XMLS)
47  if (NOT IS_ABSOLUTE "${_paraview_add_sm_xml}")
48  string(PREPEND _paraview_add_sm_xml "${CMAKE_CURRENT_SOURCE_DIR}/")
49  endif ()
50 
51  _vtk_module_set_module_property("${_paraview_add_sm_MODULE}" APPEND
52  PROPERTY "paraview_server_manager_xml"
53  VALUE "${_paraview_add_sm_xml}")
54  endforeach ()
55 endfunction ()
56 
57 #[==[.md
58 ## Building XML files
59 
60 There are two functions offered to build server manager XML files. The first
61 uses modules:
62 
63 ```
65  MODULES <module>...
66  TARGET <target>
67  [INSTALL_EXPORT <export>]
68  [FILES <file>...]
69  [XML_FILES <variable>])
70 ```
71 
72 The `MODULES` argument contains the modules to include in the server manager
73 target. The function gathers the XML files declared using
74 `paraview_add_server_manager_xmls` and then calls
75 `paraview_server_manager_process_files`. If additional, non-module related XML
76 files are required, they may be passed via `FILES`.
77 
78 If `XML_FILES` is given, the list of process XML files are set on the given
79 variable.
80 
81 If `INSTALL_EXPORT` is given, the interface target will be added to the given
82 export set.
83 #]==]
85  cmake_parse_arguments(_paraview_sm_process
86  ""
87  "TARGET;XML_FILES;INSTALL_EXPORT"
88  "MODULES;FILES"
89  ${ARGN})
90 
91  if (_paraview_sm_process_UNPARSED_ARGUMENTS)
92  message(FATAL_ERROR
93  "Unparsed arguments for paraview_server_manager_process: "
94  "${_paraview_sm_process_UNPARSED_ARGUMENTS}")
95  endif ()
96 
97  if (NOT _paraview_sm_process_MODULES)
98  message(FATAL_ERROR
99  "The `MODULES` argument is required.")
100  endif ()
101 
102  if (NOT DEFINED _paraview_sm_process_TARGET)
103  message(FATAL_ERROR
104  "The `TARGET` argument is required.")
105  endif ()
106 
107  # Topologically sort modules so that XML definitions that depend on each
108  # other are loaded in the right order.
109  set(_paraview_sm_process_sorted_modules ${_paraview_sm_process_MODULES})
110  set(_paraview_sm_process_module_stack ${_paraview_sm_process_MODULES})
111  set(_paraview_sm_process_module_seen)
112  while (_paraview_sm_process_module_stack)
113  list(GET _paraview_sm_process_module_stack 0 _paraview_sm_process_module)
114  list(REMOVE_AT _paraview_sm_process_module_stack 0)
115  if (_paraview_sm_process_module IN_LIST _paraview_sm_process_module_seen)
116  continue ()
117  endif ()
118  list(APPEND _paraview_sm_process_module_seen
119  "${_paraview_sm_process_module}")
120 
121  get_property(_paraview_sm_process_module_is_imported
122  TARGET "${_paraview_sm_process_module}"
123  PROPERTY IMPORTED)
124  if (_paraview_sm_process_module_is_imported)
125  _vtk_module_get_module_property("${_paraview_sm_process_module}"
126  PROPERTY "depends"
127  VARIABLE "_paraview_sm_process_depends")
128  _vtk_module_get_module_property("${_paraview_sm_process_module}"
129  PROPERTY "private_depends"
130  VARIABLE "_paraview_sm_process_private_depends")
131  _vtk_module_get_module_property("${_paraview_sm_process_module}"
132  PROPERTY "optional_depends"
133  VARIABLE "_paraview_sm_process_optional_depends")
134  else ()
135  get_property("_paraview_sm_process_depends" GLOBAL
136  PROPERTY "_vtk_module_${_paraview_sm_process_module}_depends")
137  get_property("_paraview_sm_process_private_depends" GLOBAL
138  PROPERTY "_vtk_module_${_paraview_sm_process_module}_private_depends")
139  get_property("_paraview_sm_process_optional_depends" GLOBAL
140  PROPERTY "_vtk_module_${_paraview_sm_process_module}_optional_depends")
141  endif ()
142 
143  # Prune optional dependencies that do not exist.
144  set(_paraview_sm_process_optional_depends_exists)
145  foreach (_paraview_sm_process_optional_depend IN LISTS _paraview_sm_process_optional_depends)
146  if (TARGET "${_paraview_sm_process_optional_depend}")
147  list(APPEND _paraview_sm_process_optional_depends_exists
148  "${_paraview_sm_process_optional_depend}")
149  endif ()
150  endforeach ()
151 
152  # Put all of the dependencies into a single variable.
153  set("_paraview_sm_process_${_paraview_sm_process_module}_all_depends"
154  ${_paraview_sm_process_depends}
155  ${_paraview_sm_process_private_depends}
156  ${_paraview_sm_process_optional_depends_exists})
157  list(APPEND _paraview_sm_process_module_stack
158  ${_paraview_sm_process_depends}
159  ${_paraview_sm_process_private_depends}
160  ${_paraview_sm_process_optional_depends_exists})
161  endwhile ()
162 
163  # Topologically sort according to dependencies.
164  vtk_topological_sort(_paraview_sm_process_sorted_modules "_paraview_sm_process_" "_all_depends")
165 
166  # Limit the sorted modules to those that are actually in the pass module list.
167  set(_paraview_sm_process_modules)
168  foreach (_paraview_sm_process_sorted_module IN LISTS _paraview_sm_process_sorted_modules)
169  if (_paraview_sm_process_sorted_module IN_LIST _paraview_sm_process_MODULES)
170  list(APPEND _paraview_sm_process_modules
171  "${_paraview_sm_process_sorted_module}")
172  endif ()
173  endforeach ()
174 
175  set(_paraview_sm_process_files)
176  foreach (_paraview_sm_process_module IN LISTS _paraview_sm_process_modules)
177  _vtk_module_get_module_property("${_paraview_sm_process_module}"
178  PROPERTY "paraview_server_manager_xml"
179  VARIABLE _paraview_sm_process_module_files)
180  list(APPEND _paraview_sm_process_files
181  ${_paraview_sm_process_module_files})
182  endforeach ()
183 
184  list(APPEND _paraview_sm_process_files
185  ${_paraview_sm_process_FILES})
186 
187  set(_paraview_sm_process_export_args)
188  if (DEFINED _paraview_sm_process_INSTALL_EXPORT)
189  list(APPEND _paraview_sm_process_export_args
190  INSTALL_EXPORT "${_paraview_sm_process_INSTALL_EXPORT}")
191  endif ()
192 
194  TARGET ${_paraview_sm_process_TARGET}
195  FILES ${_paraview_sm_process_files}
196  ${_paraview_sm_process_export_args})
197 
198  if (DEFINED _paraview_sm_process_XML_FILES)
199  set("${_paraview_sm_process_XML_FILES}"
200  "${_paraview_sm_process_files}"
201  PARENT_SCOPE)
202  endif ()
203 endfunction ()
204 
205 #[==[.md
206 The second way to process XML files directly.
207 
208 ```
210  FILES <file>...
211  TARGET <target>
212  [INSTALL_EXPORT <export>])
213 ```
214 
215 The files passed to the `FILES` argument will be processed in to functions
216 which are then consumed by ParaView applications.
217 
218 The name of the target is given to the `TARGET` argument. By default, the
219 filename is `<TARGET>.h` and it contains a function named
220 `<TARGET>_initialize`. They may be changed using the `FILE_NAME` and
221 `FUNCTION_NAME` arguments. The target has an interface usage requirement that
222 will allow the generated header to be included.
223 
224 If `INSTALL_EXPORT` is given, the interface target will be added to the given
225 export set.
226 #]==]
228  cmake_parse_arguments(_paraview_sm_process_files
229  ""
230  "TARGET;INSTALL_EXPORT"
231  "FILES"
232  ${ARGN})
233 
234  if (_paraview_sm_process_files_UNPARSED_ARGUMENTS)
235  message(FATAL_ERROR
236  "Unparsed arguments for paraview_server_manager_process_files: "
237  "${_paraview_sm_process_files_UNPARSED_ARGUMENTS}")
238  endif ()
239 
240  if (NOT DEFINED _paraview_sm_process_files_TARGET)
241  message(FATAL_ERROR
242  "The `TARGET` argument is required.")
243  endif ()
244 
245  set(_paraview_sm_process_files_output_dir
246  "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_paraview_sm_process_files_TARGET}")
247  set(_paraview_sm_process_files_output
248  "${_paraview_sm_process_files_output_dir}/${_paraview_sm_process_files_TARGET}_data.h")
249  set(_paraview_sm_process_files_response_file
250  "${_paraview_sm_process_files_output_dir}/${_paraview_sm_process_files_TARGET}.args")
251 
252  string(REPLACE ";" "\n" _paraview_sm_process_files_input_file_content
253  "${_paraview_sm_process_files_FILES}")
254  file(GENERATE
255  OUTPUT "${_paraview_sm_process_files_response_file}"
256  CONTENT "${_paraview_sm_process_files_input_file_content}")
257 
258  add_custom_command(
259  OUTPUT "${_paraview_sm_process_files_output}"
260  DEPENDS ${_paraview_sm_process_files_FILES}
261  "$<TARGET_FILE:ParaView::ProcessXML>"
262  "${_paraview_sm_process_files_response_file}"
263  COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
264  $<TARGET_FILE:ParaView::ProcessXML>
265  "${_paraview_sm_process_files_output}"
266  "${_paraview_sm_process_files_TARGET}"
267  "Interface"
268  "GetInterfaces"
269  "@${_paraview_sm_process_files_response_file}"
270  COMMENT "Generating server manager headers for ${_paraview_sm_process_files_TARGET}.")
271  add_custom_target("${_paraview_sm_process_files_TARGET}_xml_content"
272  DEPENDS
273  "${_paraview_sm_process_files_output}")
274 
275  set(_paraview_sm_process_files_init_content
276  "#ifndef ${_paraview_sm_process_files_TARGET}_h
277 #define ${_paraview_sm_process_files_TARGET}_h
278 
279 #include \"${_paraview_sm_process_files_TARGET}_data.h\"
280 #include <string>
281 #include <vector>
282 
283 void ${_paraview_sm_process_files_TARGET}_initialize(std::vector<std::string>& xmls)
284 {\n (void)xmls;\n")
285  foreach (_paraview_sm_process_files_file IN LISTS _paraview_sm_process_files_FILES)
286  get_filename_component(_paraview_sm_process_files_name "${_paraview_sm_process_files_file}" NAME_WE)
287  string(APPEND _paraview_sm_process_files_init_content
288  " {
289  char *init_string = ${_paraview_sm_process_files_TARGET}${_paraview_sm_process_files_name}GetInterfaces();
290  xmls.push_back(init_string);
291  delete [] init_string;
292  }\n")
293  endforeach ()
294  string(APPEND _paraview_sm_process_files_init_content
295  "}
296 
297 #endif\n")
298 
299  file(GENERATE
300  OUTPUT "${_paraview_sm_process_files_output_dir}/${_paraview_sm_process_files_TARGET}.h"
301  CONTENT "${_paraview_sm_process_files_init_content}")
302 
303  add_library("${_paraview_sm_process_files_TARGET}" INTERFACE)
304  add_dependencies("${_paraview_sm_process_files_TARGET}"
305  "${_paraview_sm_process_files_TARGET}_xml_content")
306  target_include_directories("${_paraview_sm_process_files_TARGET}"
307  INTERFACE
308  "$<BUILD_INTERFACE:${_paraview_sm_process_files_output_dir}>")
309  _vtk_module_apply_properties("${_paraview_sm_process_files_TARGET}")
310  if (DEFINED _paraview_sm_process_files_INSTALL_EXPORT)
311  set(_vtk_build_INSTALL_EXPORT
312  "${_paraview_sm_process_files_INSTALL_EXPORT}")
313  endif ()
314  _vtk_module_install("${_paraview_sm_process_files_TARGET}")
315 endfunction ()
316 
317 cmake_policy(POP)
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
function _vtk_module_get_module_property(module)
Get a module property.
on
string
function vtk_topological_sort(LIST, PREFIX, SUFFIX)
function paraview_add_server_manager_xmls()
.md Server Manager XMLs
name
function _vtk_module_apply_properties(target)
Apply properties to a module.
function _vtk_module_install(target)
Install a module target.
function _vtk_module_set_module_property(module)
Set a module property.
function paraview_server_manager_process()
.md Building XML files
function paraview_server_manager_process_files()
.md The second way to process XML files directly.