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  [TRANSLATIONS_DIRECTORY <directory>]
71  [TRANSLATIONS_TARGET <target>])
72 ```
73 
74 The `MODULES` argument contains the modules to include in the server manager
75 target. The function gathers the XML files declared using
76 `paraview_add_server_manager_xmls` and then calls
77 `paraview_server_manager_process_files`. If additional, non-module related XML
78 files are required, they may be passed via `FILES`.
79 
80 If `XML_FILES` is given, the list of process XML files are set on the given
81 variable.
82 
83 If `INSTALL_EXPORT` is given, the interface target will be added to the given
84 export set.
85 #]==]
87  cmake_parse_arguments(_paraview_sm_process
88  ""
89  "TARGET;XML_FILES;INSTALL_EXPORT;TRANSLATIONS_DIRECTORY;TRANSLATIONS_TARGET"
90  "MODULES;FILES"
91  ${ARGN})
92 
93  if (_paraview_sm_process_UNPARSED_ARGUMENTS)
94  message(FATAL_ERROR
95  "Unparsed arguments for paraview_server_manager_process: "
96  "${_paraview_sm_process_UNPARSED_ARGUMENTS}")
97  endif ()
98 
99  if (NOT _paraview_sm_process_MODULES)
100  message(FATAL_ERROR
101  "The `MODULES` argument is required.")
102  endif ()
103 
104  if (NOT DEFINED _paraview_sm_process_TARGET)
105  message(FATAL_ERROR
106  "The `TARGET` argument is required.")
107  endif ()
108 
109  # Topologically sort modules so that XML definitions that depend on each
110  # other are loaded in the right order.
111  set(_paraview_sm_process_sorted_modules ${_paraview_sm_process_MODULES})
112  set(_paraview_sm_process_module_stack ${_paraview_sm_process_MODULES})
113  set(_paraview_sm_process_module_seen)
114  while (_paraview_sm_process_module_stack)
115  list(GET _paraview_sm_process_module_stack 0 _paraview_sm_process_module)
116  list(REMOVE_AT _paraview_sm_process_module_stack 0)
117  if (_paraview_sm_process_module IN_LIST _paraview_sm_process_module_seen)
118  continue ()
119  endif ()
120  list(APPEND _paraview_sm_process_module_seen
121  "${_paraview_sm_process_module}")
122 
123  get_property(_paraview_sm_process_module_is_imported
124  TARGET "${_paraview_sm_process_module}"
125  PROPERTY IMPORTED)
126  if (_paraview_sm_process_module_is_imported)
127  _vtk_module_get_module_property("${_paraview_sm_process_module}"
128  PROPERTY "depends"
129  VARIABLE "_paraview_sm_process_depends")
130  _vtk_module_get_module_property("${_paraview_sm_process_module}"
131  PROPERTY "private_depends"
132  VARIABLE "_paraview_sm_process_private_depends")
133  _vtk_module_get_module_property("${_paraview_sm_process_module}"
134  PROPERTY "optional_depends"
135  VARIABLE "_paraview_sm_process_optional_depends")
136  else ()
137  get_property("_paraview_sm_process_depends" GLOBAL
138  PROPERTY "_vtk_module_${_paraview_sm_process_module}_depends")
139  get_property("_paraview_sm_process_private_depends" GLOBAL
140  PROPERTY "_vtk_module_${_paraview_sm_process_module}_private_depends")
141  get_property("_paraview_sm_process_optional_depends" GLOBAL
142  PROPERTY "_vtk_module_${_paraview_sm_process_module}_optional_depends")
143  endif ()
144 
145  # Prune optional dependencies that do not exist.
146  set(_paraview_sm_process_optional_depends_exists)
147  foreach (_paraview_sm_process_optional_depend IN LISTS _paraview_sm_process_optional_depends)
148  if (TARGET "${_paraview_sm_process_optional_depend}")
149  list(APPEND _paraview_sm_process_optional_depends_exists
150  "${_paraview_sm_process_optional_depend}")
151  endif ()
152  endforeach ()
153 
154  # Put all of the dependencies into a single variable.
155  set("_paraview_sm_process_${_paraview_sm_process_module}_all_depends"
156  ${_paraview_sm_process_depends}
157  ${_paraview_sm_process_private_depends}
158  ${_paraview_sm_process_optional_depends_exists})
159  list(APPEND _paraview_sm_process_module_stack
160  ${_paraview_sm_process_depends}
161  ${_paraview_sm_process_private_depends}
162  ${_paraview_sm_process_optional_depends_exists})
163  endwhile ()
164 
165  # Topologically sort according to dependencies.
166  vtk_topological_sort(_paraview_sm_process_sorted_modules "_paraview_sm_process_" "_all_depends")
167 
168  # Limit the sorted modules to those that are actually in the pass module list.
169  set(_paraview_sm_process_modules)
170  foreach (_paraview_sm_process_sorted_module IN LISTS _paraview_sm_process_sorted_modules)
171  if (_paraview_sm_process_sorted_module IN_LIST _paraview_sm_process_MODULES)
172  list(APPEND _paraview_sm_process_modules
173  "${_paraview_sm_process_sorted_module}")
174  endif ()
175  endforeach ()
176 
177  set(_paraview_sm_process_files)
178  foreach (_paraview_sm_process_module IN LISTS _paraview_sm_process_modules)
179  _vtk_module_get_module_property("${_paraview_sm_process_module}"
180  PROPERTY "paraview_server_manager_xml"
181  VARIABLE _paraview_sm_process_module_files)
182  list(APPEND _paraview_sm_process_files
183  ${_paraview_sm_process_module_files})
184  endforeach ()
185 
186  list(APPEND _paraview_sm_process_files
187  ${_paraview_sm_process_FILES})
188 
189  set(_paraview_sm_process_export_args)
190  if (DEFINED _paraview_sm_process_INSTALL_EXPORT)
191  list(APPEND _paraview_sm_process_export_args
192  INSTALL_EXPORT "${_paraview_sm_process_INSTALL_EXPORT}")
193  endif ()
194 
196  TARGET ${_paraview_sm_process_TARGET}
197  FILES ${_paraview_sm_process_files}
198  ${_paraview_sm_process_export_args})
199 
200  if (DEFINED _paraview_sm_process_XML_FILES)
201  set("${_paraview_sm_process_XML_FILES}"
202  "${_paraview_sm_process_files}"
203  PARENT_SCOPE)
204  endif ()
205 
206  if (NOT DEFINED _paraview_sm_process_TRANSLATIONS_DIRECTORY)
207  set(_paraview_sm_process_TRANSLATIONS_DIRECTORY
208  "${CMAKE_CURRENT_BINARY_DIR}/Translations")
209  endif ()
210  get_property(_header_name TARGET "${_paraview_sm_process_TARGET}" PROPERTY "NAME")
211  if (DEFINED _paraview_sm_process_TRANSLATIONS_TARGET)
212  set(xml_header "${CMAKE_CURRENT_BINARY_DIR}/translationSources${_header_name}.h")
214  TARGET "${_paraview_sm_process_TRANSLATIONS_TARGET}Header"
215  INPUT_FILES ${_paraview_sm_process_files}
216  RESULT_FILE "${xml_header}")
218  TARGET "${_paraview_sm_process_TRANSLATIONS_TARGET}"
219  FILES "${xml_header}"
220  OUTPUT_TS "${_paraview_sm_process_TRANSLATIONS_DIRECTORY}/${_paraview_sm_process_TRANSLATIONS_TARGET}")
221  add_dependencies("${_paraview_sm_process_TRANSLATIONS_TARGET}"
222  "${_paraview_sm_process_TRANSLATIONS_TARGET}Header")
223  endif ()
224 endfunction ()
225 
226 #[==[.md
227 The second way to process XML files directly.
228 
229 ```
231  FILES <file>...
232  TARGET <target>
233  [INSTALL_EXPORT <export>])
234 ```
235 
236 The files passed to the `FILES` argument will be processed in to functions
237 which are then consumed by ParaView applications.
238 
239 The name of the target is given to the `TARGET` argument. By default, the
240 filename is `<TARGET>.h` and it contains a function named
241 `<TARGET>_initialize`. They may be changed using the `FILE_NAME` and
242 `FUNCTION_NAME` arguments. The target has an interface usage requirement that
243 will allow the generated header to be included.
244 
245 If `INSTALL_EXPORT` is given, the interface target will be added to the given
246 export set.
247 #]==]
249  cmake_parse_arguments(_paraview_sm_process_files
250  ""
251  "TARGET;INSTALL_EXPORT"
252  "FILES"
253  ${ARGN})
254 
255  if (_paraview_sm_process_files_UNPARSED_ARGUMENTS)
256  message(FATAL_ERROR
257  "Unparsed arguments for paraview_server_manager_process_files: "
258  "${_paraview_sm_process_files_UNPARSED_ARGUMENTS}")
259  endif ()
260 
261  if (NOT DEFINED _paraview_sm_process_files_TARGET)
262  message(FATAL_ERROR
263  "The `TARGET` argument is required.")
264  endif ()
265 
266  set(_paraview_sm_process_files_output_dir
267  "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_paraview_sm_process_files_TARGET}")
268  set(_paraview_sm_process_files_output
269  "${_paraview_sm_process_files_output_dir}/${_paraview_sm_process_files_TARGET}_data.h")
270  set(_paraview_sm_process_files_response_file
271  "${_paraview_sm_process_files_output_dir}/${_paraview_sm_process_files_TARGET}.args")
272 
273  string(REPLACE ";" "\n" _paraview_sm_process_files_input_file_content
274  "${_paraview_sm_process_files_FILES}")
275  file(GENERATE
276  OUTPUT "${_paraview_sm_process_files_response_file}"
277  CONTENT "${_paraview_sm_process_files_input_file_content}")
278 
279  set(_paraview_sm_process_files_depends_args)
280  if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.27")
281  list(APPEND _paraview_sm_process_files_depends_args
282  DEPENDS_EXPLICIT_ONLY)
283  endif ()
284 
285  add_custom_command(
286  OUTPUT "${_paraview_sm_process_files_output}"
287  DEPENDS ${_paraview_sm_process_files_FILES}
288  "$<TARGET_FILE:ParaView::ProcessXML>"
289  "${_paraview_sm_process_files_response_file}"
290  COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
291  "$<TARGET_FILE:ParaView::ProcessXML>"
292  "${_paraview_sm_process_files_output}"
293  "${_paraview_sm_process_files_TARGET}"
294  "Interface"
295  "GetInterfaces"
296  "@${_paraview_sm_process_files_response_file}"
297  COMMENT "Generating server manager headers for ${_paraview_sm_process_files_TARGET}."
298  ${_paraview_sm_process_files_depends_args})
299  add_custom_target("${_paraview_sm_process_files_TARGET}_xml_content"
300  DEPENDS
301  "${_paraview_sm_process_files_output}")
302 
303  set(_paraview_sm_process_files_init_content
304  "#ifndef ${_paraview_sm_process_files_TARGET}_h
305 #define ${_paraview_sm_process_files_TARGET}_h
306 
307 #include \"${_paraview_sm_process_files_TARGET}_data.h\"
308 #include <string>
309 #include <vector>
310 
311 inline void ${_paraview_sm_process_files_TARGET}_initialize(std::vector<std::string>& xmls)
312 {\n (void)xmls;\n")
313  foreach (_paraview_sm_process_files_file IN LISTS _paraview_sm_process_files_FILES)
314  get_filename_component(_paraview_sm_process_files_name "${_paraview_sm_process_files_file}" NAME_WE)
315  string(APPEND _paraview_sm_process_files_init_content
316  " {
317  char *init_string = ${_paraview_sm_process_files_TARGET}${_paraview_sm_process_files_name}GetInterfaces();
318  xmls.emplace_back(init_string);
319  delete [] init_string;
320  }\n")
321  endforeach ()
322  string(APPEND _paraview_sm_process_files_init_content
323  "}
324 
325 #endif\n")
326 
327  file(GENERATE
328  OUTPUT "${_paraview_sm_process_files_output_dir}/${_paraview_sm_process_files_TARGET}.h"
329  CONTENT "${_paraview_sm_process_files_init_content}")
330 
331  add_library("${_paraview_sm_process_files_TARGET}" INTERFACE)
332  add_dependencies("${_paraview_sm_process_files_TARGET}"
333  "${_paraview_sm_process_files_TARGET}_xml_content")
334  target_include_directories("${_paraview_sm_process_files_TARGET}"
335  INTERFACE
336  "$<BUILD_INTERFACE:${_paraview_sm_process_files_output_dir}>")
337  _vtk_module_apply_properties("${_paraview_sm_process_files_TARGET}")
338  if (DEFINED _paraview_sm_process_files_INSTALL_EXPORT)
339  set(_vtk_build_INSTALL_EXPORT
340  "${_paraview_sm_process_files_INSTALL_EXPORT}")
341  endif ()
342  _vtk_module_install("${_paraview_sm_process_files_TARGET}")
343 endfunction ()
344 
345 cmake_policy(POP)
function paraview_create_translation()
Generate a Qt translation source file from the given source files.
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
on
string
function paraview_server_manager_process()
.md Building XML files
function paraview_server_manager_process_files()
.md The second way to process XML files directly.
name
function paraview_add_server_manager_xmls()
.md Server Manager XMLs
function paraview_generate_translation_header()
Generate a C++ header with input XML labels and UI strings that can be parsed by Qt Linguist tools...