ParaViewClient.cmake
Go to the documentation of this file.
1 set(_ParaViewClient_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
2 set(_ParaViewClient_script_file "${CMAKE_CURRENT_LIST_FILE}")
3 
4 #[==[.md
5 ## Building a client
6 
7 TODO: Document
8 
9 ```
11  NAME <name>
12  VERSION <version>
13  SOURCES <source>...
14  [APPLICATION_XMLS <xml>...]
15  [QCH_FILES <file>...]
16 
17  [MAIN_WINDOW_CLASS <class>]
18  [MAIN_WINDOW_INCLUDE <include>]
19 
20  [PLUGINS_TARGETS <target>...]
21  [REQUIRED_PLUGINS <plugin>...]
22  [OPTIONAL_PLUGINS <plugin>...]
23 
24  [APPLICATION_NAME <name>]
25  [ORGANIZATION <organization>]
26  [TITLE <title>]
27 
28  [DEFAULT_STYLE <style>]
29 
30  [APPLICATION_ICON <icon>]
31  [BUNDLE_ICON <icon>]
32  [BUNDLE_PLIST <plist>]
33  [SPLASH_IMAGE <image>]
34 
35  [NAMESPACE <namespace>]
36  [EXPORT <export>]
37  [FORCE_UNIX_LAYOUT <ON|OFF>]
38  [BUNDLE_DESTINATION <directory>]
39  [RUNTIME_DESTINATION <directory>]
40  [LIBRARY_DESTINATION <directory>]
41 
42  [TRANSLATE_XML <ON|OFF>]
43  [TRANSLATIONS_DIRECTORY <directory>]
44  [TRANSLATION_TARGET <target>])
45 ```
46 
47  * `NAME`: (Required) The name of the application. This is used as the target
48  name as well.
49  * `VERSION`: (Required) The version of the application.
50  * `SOURCES`: (Required) Source files for the application.
51  * `APPLICATION_XMLS`: Server manager XML files.
52  * `QCH_FILES`: Any `.qch` files containing documentation.
53  * `MAIN_WINDOW_CLASS`: (Defaults to `QMainWindow`) The name of the main
54  window class.
55  * `MAIN_WINDOW_INCLUDE`: (Defaults to `QMainWindow` or
56  `<MAIN_WINDOW_CLASS>.h` if it is specified) The include file for the main
57  window.
58  * `PLUGINS_TARGETS`: The targets for plugins. The associated functions
59  will be called upon startup.
60  * `REQUIRED_PLUGINS`: Plugins to load upon startup.
61  * `OPTIONAL_PLUGINS`: Plugins to load upon startup if available.
62  * `APPLICATION_NAME`: (Defaults to `<NAME>`) The displayed name of the
63  application.
64  * `ORGANIZATION`: (Defaults to `Anonymous`) The organization for the
65  application. This is used for the macOS GUI identifier.
66  * `TITLE`: The window title for the application.
67  * `DEFAULT_STYLE`: The default Qt style for the application.
68  * `APPLICATION_ICON`: The path to the icon for the Windows application.
69  * `BUNDLE_ICON`: The path to the icon for the macOS bundle.
70  * `BUNDLE_PLIST`: The path to the `Info.plist.in` template.
71  * `SPLASH_IMAGE`: The image to display upon startup.
72  * `NAMESPACE`: If provided, an alias target `<NAMESPACE>::<NAME>` will be
73  created.
74  * `EXPORT`: If provided, the target will be exported.
75  * `FORCE_UNIX_LAYOUT`: (Defaults to `OFF`) Forces a Unix-style layout even on
76  platforms for which they are not the norm for GUI applications (e.g.,
77  macOS).
78  * `BUNDLE_DESTINATION`: (Defaults to `Applications`) Where to place the
79  bundle executable.
80  * `RUNTIME_DESTINATION`: (Defaults to `${CMAKE_INSTALL_BINDIR}`) Where to
81  place the binary.
82  * `LIBRARY_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) Where
83  libraries are placed. Sets up `RPATH` on ELF platforms (e.g., Linux and the
84  BSD family).
85  * `TRANSLATE_XML`: (Defaults to `OFF`) Produce a translations source file
86  from APPLICATION_XMLS files.
87  * `TRANSLATIONS_DIRECTORY`: (Defaults to `${CMAKE_CURRENT_BINARY_DIR}/Translations`)
88  The path of the directory where translation source files are stored.
89  * `TRANSLATION_TARGET` : The name of the target on which to add the ts file as
90  dependency.
91 #]==]
93  cmake_parse_arguments(_paraview_client
94  ""
95  "NAME;APPLICATION_NAME;ORGANIZATION;TITLE;SPLASH_IMAGE;BUNDLE_DESTINATION;BUNDLE_ICON;BUNDLE_PLIST;APPLICATION_ICON;MAIN_WINDOW_CLASS;MAIN_WINDOW_INCLUDE;VERSION;FORCE_UNIX_LAYOUT;PLUGINS_TARGET;DEFAULT_STYLE;RUNTIME_DESTINATION;LIBRARY_DESTINATION;NAMESPACE;EXPORT;TRANSLATION_TARGET;TRANSLATE_XML;TRANSLATIONS_DIRECTORY"
96  "REQUIRED_PLUGINS;OPTIONAL_PLUGINS;APPLICATION_XMLS;SOURCES;QCH_FILES;QCH_FILE;PLUGINS_TARGETS"
97  ${ARGN})
98 
99  if (_paraview_client_UNPARSED_ARGUMENTS)
100  message(FATAL_ERROR
101  "Unparsed arguments for paraview_client_add: "
102  "${_paraview_client_UNPARSED_ARGUMENTS}")
103  endif ()
104 
105  # TODO: Installation.
106 
107  if (DEFINED _paraview_client_PLUGINS_TARGET)
108  if (DEFINED _paraview_client_PLUGINS_TARGETS)
109  message(FATAL_ERROR
110  "The `paraview_client_add(PLUGINS_TARGET)` argument is incompatible "
111  "with `PLUGINS_TARGETS`.")
112  else ()
113  message(DEPRECATION
114  "The `paraview_client_add(PLUGINS_TARGET)` argument is deprecated in "
115  "favor of `PLUGINS_TARGETS`.")
116  set(_paraview_client_PLUGINS_TARGETS
117  "${_paraview_client_PLUGINS_TARGET}")
118  endif ()
119  endif ()
120 
121  if (NOT DEFINED _paraview_client_NAME)
122  message(FATAL_ERROR
123  "The `NAME` argument is required.")
124  endif ()
125 
126  if (NOT DEFINED _paraview_client_VERSION)
127  message(FATAL_ERROR
128  "The `VERSION` argument is required.")
129  endif ()
130 
131  if (NOT DEFINED _paraview_client_SOURCES)
132  message(FATAL_ERROR
133  "The `SOURCES` argument is required.")
134  endif ()
135 
136  if (NOT DEFINED _paraview_client_APPLICATION_NAME)
137  set(_paraview_client_APPLICATION_NAME
138  "${_paraview_client_NAME}")
139  endif ()
140 
141  if (NOT DEFINED _paraview_client_ORGANIZATION)
142  set(_paraview_client_ORGANIZATION
143  "Anonymous")
144  endif ()
145 
146  if (NOT DEFINED _paraview_client_FORCE_UNIX_LAYOUT)
147  set(_paraview_client_FORCE_UNIX_LAYOUT
148  OFF)
149  endif ()
150 
151  if (NOT DEFINED _paraview_client_BUNDLE_DESTINATION)
152  set(_paraview_client_BUNDLE_DESTINATION
153  "Applications")
154  endif ()
155 
156  if (NOT DEFINED _paraview_client_RUNTIME_DESTINATION)
157  set(_paraview_client_RUNTIME_DESTINATION
158  "${CMAKE_INSTALL_BINDIR}")
159  endif ()
160 
161  if (NOT DEFINED _paraview_client_LIBRARY_DESTINATION)
162  set(_paraview_client_LIBRARY_DESTINATION
163  "${CMAKE_INSTALL_LIBDIR}")
164  endif ()
165 
166  if (DEFINED _paraview_client_QCH_FILE)
167  if (DEFINED _paraview_client_QCH_FILES)
168  message(FATAL_ERROR
169  "The `paraview_client_add(QCH_FILE)` argument is incompatible "
170  "with `QCH_FILES`.")
171  else ()
172  message(DEPRECATION
173  "The `paraview_client_add(QCH_FILE)` argument is deprecated in "
174  "favor of `QCH_FILES`.")
175  set(_paraview_client_QCH_FILES
176  "${_paraview_client_QCH_FILE}")
177  endif ()
178  endif ()
179 
180  if (NOT DEFINED _paraview_client_MAIN_WINDOW_CLASS)
181  if (DEFINED _paraview_client_MAIN_WINDOW_INCLUDE)
182  message(FATAL_ERROR
183  "The `MAIN_WINDOW_INCLUDE` argument cannot be specified without "
184  "`MAIN_WINDOW_CLASS`.")
185  endif ()
186 
187  set(_paraview_client_MAIN_WINDOW_CLASS
188  "QMainWindow")
189  set(_paraview_client_MAIN_WINDOW_INCLUDE
190  "QMainWindow")
191  endif ()
192 
193  if (NOT DEFINED _paraview_client_MAIN_WINDOW_INCLUDE)
194  set(_paraview_client_MAIN_WINDOW_INCLUDE
195  "${_paraview_client_MAIN_WINDOW_CLASS}.h")
196  endif ()
197 
198  set(_paraview_client_extra_sources)
199  set(_paraview_client_bundle_args)
200 
201  set(_paraview_client_executable_flags)
202  if (WIN32)
203  if (DEFINED _paraview_client_APPLICATION_ICON)
204  set(_paraview_client_appicon_file
205  "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_NAME}_appicon.rc")
206  file(WRITE "${_paraview_client_appicon_file}.tmp"
207  "// Icon with the lowest ID value placed first to ensure that the application
208 // icon remains consistent on all systems.
209 IDI_ICON1 ICON \"${_paraview_client_APPLICATION_ICON}\"\n")
210  configure_file(
211  "${_paraview_client_appicon_file}.tmp"
212  "${_paraview_client_appicon_file}"
213  COPYONLY)
214 
215  list(APPEND _paraview_client_extra_sources
216  "${_paraview_client_appicon_file}")
217  endif ()
218 
219  list(APPEND _paraview_client_executable_flags
220  WIN32)
221  elseif (APPLE)
222  # TODO: nib files
223 
224  list(APPEND _paraview_client_bundle_args
225  BUNDLE DESTINATION "${_paraview_client_BUNDLE_DESTINATION}")
226  list(APPEND _paraview_client_executable_flags
227  MACOSX_BUNDLE)
228  endif ()
229 
230  set(_paraview_client_resource_files "")
231  set(_paraview_client_resource_init "")
232 
233  if (DEFINED _paraview_client_SPLASH_IMAGE)
234  set(_paraview_client_splash_base_name
235  "${_paraview_client_NAME}_splash")
236  set(_paraview_client_splash_image_name
237  "${_paraview_client_splash_base_name}.img")
238  set(_paraview_client_splash_resource
239  ":/${_paraview_client_NAME}/${_paraview_client_splash_base_name}")
240 
241  set(_paraview_client_splash_resource_file
242  "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_splash_base_name}.qrc")
243 
244  paraview_client_qt_resource(
245  OUTPUT "${_paraview_client_splash_resource_file}"
246  PREFIX "/${_paraview_client_NAME}"
247  ALIAS "${_paraview_client_splash_base_name}"
248  FILE "${_paraview_client_SPLASH_IMAGE}")
249 
250  list(APPEND _paraview_client_resource_files
251  "${_paraview_client_splash_resource_file}")
252  string(APPEND _paraview_client_resource_init
253  " Q_INIT_RESOURCE(${_paraview_client_splash_base_name});\n")
254  set(CMAKE_AUTORCC 1)
255  endif ()
256 
257  if (DEFINED _paraview_client_APPLICATION_XMLS)
258  set(_paraview_client_application_base_name
259  "${_paraview_client_NAME}_configuration")
260  set(_paraview_client_application_resource_file
261  "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_application_base_name}.qrc")
262 
263  paraview_client_qt_resources(
264  OUTPUT "${_paraview_client_application_resource_file}"
265  PREFIX "/${_paraview_client_NAME}/Configuration"
266  FILES "${_paraview_client_APPLICATION_XMLS}")
267 
268  list(APPEND _paraview_client_resource_files
269  "${_paraview_client_application_resource_file}")
270  string(APPEND _paraview_client_resource_init
271  " Q_INIT_RESOURCE(${_paraview_client_application_base_name});\n")
272  set(CMAKE_AUTORCC 1)
273  endif ()
274 
275  if (DEFINED _paraview_client_QCH_FILES)
276  set(_paraview_client_documentation_base_name
277  "${_paraview_client_NAME}_documentation")
278  set(_paraview_client_documentation_resource_file
279  "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_documentation_base_name}.qrc")
280 
281  paraview_client_qt_resources(
282  OUTPUT "${_paraview_client_documentation_resource_file}"
283  # This prefix is part of the API.
284  PREFIX "/${_paraview_client_NAME}/Documentation"
285  FILES ${_paraview_client_QCH_FILES})
286  set_property(SOURCE "${_paraview_client_documentation_resource_file}"
287  PROPERTY
288  OBJECT_DEPENDS "${_paraview_client_QCH_FILES}")
289 
290  list(APPEND _paraview_client_resource_files
291  "${_paraview_client_documentation_resource_file}")
292  string(APPEND _paraview_client_resource_init
293  " Q_INIT_RESOURCE(${_paraview_client_documentation_base_name});\n")
294  set(CMAKE_AUTORCC 1)
295  endif ()
296 
297  include("${_ParaViewClient_cmake_dir}/paraview-find-package-helpers.cmake" OPTIONAL)
298  find_package("Qt${PARAVIEW_QT_MAJOR_VERSION}" REQUIRED QUIET COMPONENTS Core Widgets)
299 
300  # CMake 3.13 started using Qt5's version variables to detect what version
301  # of Qt's tools to run for autorcc. However, they are looked up using the
302  # target's directory scope, but these are here in a local scope and unset
303  # when AutoGen gets around to asking about the variables at generate time.
304 
305  # Fix for 3.13.0–3.13.3. Does not work if `paraview_client_add` is called
306  # from another function.
307  set("Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MAJOR" "${Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MAJOR}" PARENT_SCOPE)
308  set("Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MINOR" "${Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MINOR}" PARENT_SCOPE)
309  # Fix for 3.13.4+.
310  set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
311  PROPERTY
312  "Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MAJOR" "${Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MAJOR}")
313  set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
314  PROPERTY
315  "Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MINOR" "${Qt${PARAVIEW_QT_MAJOR_VERSION}Core_VERSION_MAJOR}")
316 
317  set(_paraview_client_built_shared 0)
318  if (BUILD_SHARED_LIBS)
319  set(_paraview_client_built_shared 1)
320  endif ()
321 
322  set(_paraview_client_have_plugins 0)
323  set(_paraview_client_plugins_includes)
324  set(_paraview_client_plugins_calls)
325  if (_paraview_client_PLUGINS_TARGETS)
326  set(_paraview_client_have_plugins 1)
327  foreach (_paraview_client_plugin_target IN LISTS _paraview_client_PLUGINS_TARGETS)
328  string(REPLACE "::" "_" _paraview_client_plugin_target_safe "${_paraview_client_plugin_target}")
329  string(APPEND _paraview_client_plugins_includes
330  "#include \"${_paraview_client_plugin_target_safe}.h\"\n")
331  string(APPEND _paraview_client_plugins_calls
332  " ${_paraview_client_plugin_target_safe}_initialize();\n")
333  endforeach ()
334  endif ()
335 
336  set(_paraview_client_source_files
337  "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_NAME}_main.cxx"
338  "${CMAKE_CURRENT_BINARY_DIR}/pq${_paraview_client_NAME}Initializer.cxx"
339  "${CMAKE_CURRENT_BINARY_DIR}/pq${_paraview_client_NAME}Initializer.h")
340  configure_file(
341  "${_ParaViewClient_cmake_dir}/paraview_client_main.cxx.in"
342  "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_client_NAME}_main.cxx"
343  @ONLY)
344  configure_file(
345  "${_ParaViewClient_cmake_dir}/paraview_client_initializer.cxx.in"
346  "${CMAKE_CURRENT_BINARY_DIR}/pq${_paraview_client_NAME}Initializer.cxx"
347  @ONLY)
348  configure_file(
349  "${_ParaViewClient_cmake_dir}/paraview_client_initializer.h.in"
350  "${CMAKE_CURRENT_BINARY_DIR}/pq${_paraview_client_NAME}Initializer.h"
351  @ONLY)
352 
353  # Set up rpaths
354  set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
355  if (UNIX AND NOT APPLE)
356  file(RELATIVE_PATH _paraview_client_relpath
357  "/prefix/${_paraview_client_RUNTIME_DESTINATION}"
358  "/prefix/${_paraview_client_LIBRARY_DESTINATION}")
359  set(_paraview_client_origin_rpath
360  "$ORIGIN/${_paraview_client_relpath}")
361 
362  list(APPEND CMAKE_INSTALL_RPATH
363  "${_paraview_client_origin_rpath}")
364  endif ()
365 
366  if (_paraview_client_resource_files)
367  source_group("resources"
368  FILES
369  ${_paraview_client_resource_files})
370  endif ()
371 
372  ## Translation Management
373  if (NOT DEFINED _paraview_client_TRANSLATIONS_DIRECTORY)
374  set(_paraview_client_TRANSLATIONS_DIRECTORY
375  "${CMAKE_CURRENT_BINARY_DIR}/Translations")
376  endif ()
377  if (NOT DEFINED _paraview_client_TRANSLATE_XML)
378  set(_paraview_client_TRANSLATE_XML "OFF")
379  endif ()
380  if (_paraview_client_TRANSLATE_XML)
381  if (NOT DEFINED _paraview_client_TRANSLATION_TARGET)
382  message(FATAL_ERROR "The `TRANSLATION_TARGET` argument is required.")
383  endif ()
384  endif ()
385  if (DEFINED _paraview_client_TRANSLATION_TARGET)
386  find_package("Qt${PARAVIEW_QT_MAJOR_VERSION}" QUIET COMPONENTS LinguistTools REQUIRED)
387  if (_paraview_client_TRANSLATE_XML)
388  set(xml_header "${CMAKE_CURRENT_BINARY_DIR}/translationSources${_paraview_client_NAME}ClientXMLs.h")
389  paraview_generate_translation_header(
390  TARGET "${_paraview_client_TRANSLATION_TARGET}Header"
391  INPUT_FILES ${_paraview_client_APPLICATION_XMLS}
392  RESULT_FILE "${xml_header}")
393  paraview_create_translation(
394  TARGET "${_paraview_client_TRANSLATION_TARGET}XMLs"
395  FILES "${xml_header}"
396  OUTPUT_TS "${_paraview_client_TRANSLATIONS_DIRECTORY}/Clients_${_paraview_client_APPLICATION_NAME}-XMLs.ts")
397  add_dependencies("${_paraview_client_TRANSLATION_TARGET}XMLs" "${_paraview_client_TRANSLATION_TARGET}Header")
398  endif ()
399  paraview_create_translation(
400  TARGET "${_paraview_client_TRANSLATION_TARGET}"
401  FILES ${_paraview_client_SOURCES}
402  OUTPUT_TS "${_paraview_client_TRANSLATIONS_DIRECTORY}/Clients_${_paraview_client_APPLICATION_NAME}.ts")
403  if (_paraview_client_TRANSLATE_XML)
404  add_dependencies("${_paraview_client_TRANSLATION_TARGET}" "${_paraview_client_TRANSLATION_TARGET}XMLs")
405  endif()
406  endif ()
407 
408  add_executable("${_paraview_client_NAME}" ${_paraview_client_executable_flags}
409  ${_paraview_client_SOURCES}
410  ${_paraview_client_resource_files}
411  ${_paraview_client_source_files}
412  ${_paraview_client_extra_sources})
413  if (DEFINED _paraview_client_NAMESPACE)
414  add_executable("${_paraview_client_NAMESPACE}::${_paraview_client_NAME}" ALIAS "${_paraview_client_NAME}")
415  endif ()
416  target_include_directories("${_paraview_client_NAME}"
417  PRIVATE
418  "${CMAKE_CURRENT_SOURCE_DIR}"
419  "${CMAKE_CURRENT_BINARY_DIR}"
420  # https://gitlab.kitware.com/cmake/cmake/-/issues/18049
421  "$<TARGET_PROPERTY:VTK::vtksys,INTERFACE_INCLUDE_DIRECTORIES>")
422  target_link_libraries("${_paraview_client_NAME}"
423  PRIVATE
424  ParaView::pqApplicationComponents
425  "Qt${PARAVIEW_QT_MAJOR_VERSION}::Widgets"
426  VTK::vtksys)
427  if (PARAVIEW_USE_QTWEBENGINE)
428  find_package("Qt${PARAVIEW_QT_MAJOR_VERSION}" REQUIRED QUIET COMPONENTS WebEngineWidgets)
429  target_link_libraries("${_paraview_client_NAME}"
430  PRIVATE "Qt${PARAVIEW_QT_MAJOR_VERSION}::WebEngineWidgets")
431  endif ()
432 
433  set(_paraview_client_export)
434  if (DEFINED _paraview_client_EXPORT)
435  list(APPEND _paraview_client_export
436  EXPORT "${_paraview_client_EXPORT}")
437  endif ()
438 
439  install(
440  TARGETS "${_paraview_client_NAME}"
441  ${_paraview_client_export}
442  COMPONENT "runtime"
443  ${_paraview_client_bundle_args}
444  RUNTIME DESTINATION "${_paraview_client_RUNTIME_DESTINATION}")
445 
446  if (DEFINED _paraview_client_PLUGINS_TARGETS)
447  target_link_libraries("${_paraview_client_NAME}"
448  PRIVATE
449  ${_paraview_client_PLUGINS_TARGETS})
450 
451  set(_paraview_client_binary_destination
452  "${_paraview_client_RUNTIME_DESTINATION}")
453  set(_paraview_client_conf_destination
454  "${_paraview_client_binary_destination}")
455  if (APPLE)
456  string(APPEND _paraview_client_binary_destination
457  "/${_paraview_client_NAME}.app/Contents/Resources")
458  set(_paraview_client_conf_destination
459  "${_paraview_client_BUNDLE_DESTINATION}/${_paraview_client_NAME}.app/Contents/Resources")
460  endif ()
461 
462  paraview_plugin_write_conf(
463  NAME "${_paraview_client_NAME}"
464  PLUGINS_TARGETS ${_paraview_client_PLUGINS_TARGETS}
465  BUILD_DESTINATION "${_paraview_client_binary_destination}"
466  INSTALL_DESTINATION "${_paraview_client_conf_destination}"
467  COMPONENT "runtime")
468  endif ()
469 
470  if (APPLE)
471  if (DEFINED _paraview_client_BUNDLE_ICON)
472  get_filename_component(_paraview_client_bundle_icon_file "${_paraview_client_BUNDLE_ICON}" NAME)
473  set_property(TARGET "${_paraview_client_NAME}"
474  PROPERTY
475  MACOSX_BUNDLE_ICON_FILE "${_paraview_client_bundle_icon_file}")
476  install(
477  FILES "${_paraview_client_BUNDLE_ICON}"
478  DESTINATION "${_paraview_client_BUNDLE_DESTINATION}/${_paraview_client_APPLICATION_NAME}.app/Contents/Resources"
479  COMPONENT "runtime")
480  endif ()
481  if (DEFINED _paraview_client_BUNDLE_PLIST)
482  set_property(TARGET "${_paraview_client_NAME}"
483  PROPERTY
484  MACOSX_BUNDLE_INFO_PLIST "${_paraview_client_BUNDLE_PLIST}")
485  endif ()
486  string(TOLOWER "${_paraview_client_ORGANIZATION}" _paraview_client_organization)
487  set_target_properties("${_paraview_client_NAME}"
488  PROPERTIES
489  MACOSX_BUNDLE_BUNDLE_NAME "${_paraview_client_APPLICATION_NAME}"
490  MACOSX_BUNDLE_GUI_IDENTIFIER "org.${_paraview_client_organization}.${_paraview_client_APPLICATION_NAME}"
491  MACOSX_BUNDLE_SHORT_VERSION_STRING "${_paraview_client_VERSION}")
492  endif ()
493 endfunction ()
494 
495 #[==[.md INTERNAL
496 ## Quoting
497 
498 Passing CMake lists down to the help generation and proxy documentation steps
499 requires escaping the `;` in them. These functions escape and unescape the
500 variable passed in. The new value is placed in the same variable in the calling
501 scope.
502 #]==]
503 
504 function (_paraview_client_escape_cmake_list variable)
505  string(REPLACE "_" "_u" _escape_tmp "${${variable}}")
506  string(REPLACE ";" "_s" _escape_tmp "${_escape_tmp}")
507  set("${variable}"
508  "${_escape_tmp}"
509  PARENT_SCOPE)
510 endfunction ()
511 
512 function (_paraview_client_unescape_cmake_list variable)
513  string(REPLACE "_s" ";" _escape_tmp "${${variable}}")
514  string(REPLACE "_u" "_" _escape_tmp "${_escape_tmp}")
515  set("${variable}"
516  "${_escape_tmp}"
517  PARENT_SCOPE)
518 endfunction ()
519 
520 #[==[.md
521 ## Documentation from XML files
522 
523 Documentation can be generated from server manager XML files. The
524 `paraview_client_documentation` generates Qt help, HTML, and Wiki documentation
525 from them.
526 
527 ```
528 paraview_client_documentation(
529  TARGET <target>
530  XMLS <xml>...
531  [OUTPUT_DIR <directory>])
532 ```
533 
534  * `TARGET`: (Required) The name of the target to generate.
535  * `XMLS`: (Required) The list of XML files to process.
536  * `OUTPUT_DIR`: (Defaults to `${CMAKE_CURRENT_BINARY_DIR}`) Where to place
537  generated documentation.
538 #]==]
539 function (paraview_client_documentation)
540  cmake_parse_arguments(_paraview_client_doc
541  ""
542  "TARGET;OUTPUT_DIR"
543  "XMLS"
544  ${ARGN})
545 
546  if (_paraview_client_doc_UNPARSED_ARGUMENTS)
547  message(FATAL_ERROR
548  "Unparsed arguments for paraview_client_documentation: "
549  "${_paraview_client_doc_UNPARSED_ARGUMENTS}")
550  endif ()
551 
552  if (NOT DEFINED _paraview_client_doc_OUTPUT_DIR)
553  set(_paraview_client_doc_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
554  endif ()
555 
556  if (NOT DEFINED _paraview_client_doc_TARGET)
557  message(FATAL_ERROR
558  "The `TARGET` argument is required.")
559  endif ()
560 
561  if (NOT DEFINED _paraview_client_doc_XMLS)
562  message(FATAL_ERROR
563  "The `XMLS` argument is required.")
564  endif ()
565 
566  include("${_ParaViewClient_cmake_dir}/paraview-find-package-helpers.cmake" OPTIONAL)
567  find_program(qt_xmlpatterns_executable
568  NAMES xmlpatterns-qt5 xmlpatterns
569  HINTS "${Qt5_DIR}/../../../bin"
570  "${Qt5_DIR}/../../../libexec/qt5/bin"
571  DOC "Path to xmlpatterns")
572  mark_as_advanced(qt_xmlpatterns_executable)
573 
574  if (NOT qt_xmlpatterns_executable)
575  message(FATAL_ERROR
576  "Cannot find the xmlpatterns executable.")
577  endif ()
578 
579  set(_paraview_client_doc_xmls)
580  foreach (_paraview_client_doc_xml IN LISTS _paraview_client_doc_XMLS)
581  get_filename_component(_paraview_client_doc_xml "${_paraview_client_doc_xml}" ABSOLUTE)
582  list(APPEND _paraview_client_doc_xmls
583  "${_paraview_client_doc_xml}")
584  endforeach ()
585 
586  # Save xmls to a temporary file.
587  set (_paraview_client_doc_xmls_file
588  "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_paraview_client_doc_TARGET}-xmls.txt")
589  file(GENERATE
590  OUTPUT "${_paraview_client_doc_xmls_file}"
591  CONTENT "${_paraview_client_doc_xmls}")
592 
593  add_custom_command(
594  OUTPUT "${_paraview_client_doc_OUTPUT_DIR}/${_paraview_client_doc_TARGET}.xslt"
595  ${_paraview_client_doc_outputs}
596  COMMAND "${CMAKE_COMMAND}"
597  "-Dxmlpatterns=${qt_xmlpatterns_executable}"
598  "-Doutput_dir=${_paraview_client_doc_OUTPUT_DIR}"
599  "-Doutput_file=${_paraview_client_doc_OUTPUT_DIR}/${_paraview_client_doc_TARGET}.xslt"
600  "-Dxmls_file=${_paraview_client_doc_xmls_file}"
601  -D_paraview_generate_proxy_documentation_run=ON
602  -P "${_ParaViewClient_script_file}"
603  DEPENDS ${_paraview_client_doc_xmls}
604  "${_paraview_client_doc_xmls_file}"
605  "${_ParaViewClient_script_file}"
606  "${_ParaViewClient_cmake_dir}/paraview_servermanager_convert_xml.xsl"
607  "${_ParaViewClient_cmake_dir}/paraview_servermanager_convert_categoryindex.xsl"
608  "${_ParaViewClient_cmake_dir}/paraview_servermanager_convert_html.xsl"
609  "${_ParaViewClient_cmake_dir}/paraview_servermanager_convert_wiki.xsl.in"
610  WORKING_DIRECTORY "${_paraview_client_doc_OUTPUT_DIR}"
611  COMMENT "Generating documentation for ${_paraview_client_doc_TARGET}")
612  add_custom_target("${_paraview_client_doc_TARGET}"
613  DEPENDS
614  "${_paraview_client_doc_OUTPUT_DIR}/${_paraview_client_doc_TARGET}.xslt"
615  ${_paraview_client_doc_outputs})
616 endfunction ()
617 
618 # Generate proxy documentation.
619 if (_paraview_generate_proxy_documentation_run AND CMAKE_SCRIPT_MODE_FILE)
620 
621  file(READ "${xmls_file}" xmls)
622 
623  set(_paraview_gpd_to_xml "${CMAKE_CURRENT_LIST_DIR}/paraview_servermanager_convert_xml.xsl")
624  set(_paraview_gpd_to_catindex "${CMAKE_CURRENT_LIST_DIR}/paraview_servermanager_convert_categoryindex.xsl")
625  set(_paraview_gpd_to_html "${CMAKE_CURRENT_LIST_DIR}/paraview_servermanager_convert_html.xsl")
626  set(_paraview_gpd_to_wiki "${CMAKE_CURRENT_LIST_DIR}/paraview_servermanager_convert_wiki.xsl.in")
627 
628  set(_paraview_gpd_xslt "<xml>\n")
629  file(MAKE_DIRECTORY "${output_dir}")
630  foreach (_paraview_gpd_xml IN LISTS xmls)
631  execute_process(
632  COMMAND "${xmlpatterns}"
633  "${_paraview_gpd_to_xml}"
634  "${_paraview_gpd_xml}"
635  OUTPUT_VARIABLE _paraview_gpd_output
636  ERROR_VARIABLE _paraview_gpd_error
637  RESULT_VARIABLE _paraview_gpd_result)
638  if (_paraview_gpd_result)
639  message(FATAL_ERROR
640  "Failed to convert servermanager XML: ${_paraview_gpd_error}")
641  endif ()
642 
643  string(APPEND _paraview_gpd_xslt
644  "${_paraview_gpd_output}")
645  endforeach ()
646  string(APPEND _paraview_gpd_xslt
647  "</xml>\n")
648 
649  file(WRITE "${output_file}.xslt"
650  "${_paraview_gpd_xslt}")
651  execute_process(
652  COMMAND "${xmlpatterns}"
653  -output "${output_file}"
654  "${_paraview_gpd_to_catindex}"
655  "${output_file}.xslt"
656  RESULT_VARIABLE _paraview_gpd_result)
657  if (_paraview_gpd_result)
658  message(FATAL_ERROR
659  "Failed to generate category index")
660  endif ()
661 
662  # Generate HTML files.
663  execute_process(
664  COMMAND "${xmlpatterns}"
665  "${_paraview_gpd_to_html}"
666  "${output_file}"
667  OUTPUT_VARIABLE _paraview_gpd_output
668  RESULT_VARIABLE _paraview_gpd_result
669  OUTPUT_STRIP_TRAILING_WHITESPACE)
670  if (_paraview_gpd_result)
671  message(FATAL_ERROR
672  "Failed to generate HTML output")
673  endif ()
674 
675  # Escape open/close brackets as HTML entities as they somehow interfere with the foreach loop below.
676  string(REPLACE "[" "&#91;" _paraview_gpd_output "${_paraview_gpd_output}")
677  string(REPLACE "]" "&#93;" _paraview_gpd_output "${_paraview_gpd_output}")
678 
679  # Escape semicolons.
680  _paraview_client_escape_cmake_list(_paraview_gpd_output)
681 
682  # Convert into a list of HTML documents.
683  string(REPLACE "</html>\n<html>" "</html>\n;<html>" _paraview_gpd_output "${_paraview_gpd_output}")
684 
685  foreach (_paraview_gpd_html_doc IN LISTS _paraview_gpd_output)
686  _paraview_client_unescape_cmake_list(_paraview_gpd_html_doc)
687  string(REGEX MATCH "<meta name=\"filename\" contents=\"([^\"]*)\"" _ "${_paraview_gpd_html_doc}")
688  set(_paraview_gpd_filename "${CMAKE_MATCH_1}")
689  if (NOT _paraview_gpd_filename)
690  message(FATAL_ERROR
691  "No filename for an HTML output?")
692  endif ()
693 
694  # Replace reStructured Text markup.
695  string(REGEX REPLACE "\\*\\*([^*]+)\\*\\*" "<b>\\1</b>" _paraview_gpd_html_doc "${_paraview_gpd_html_doc}")
696  string(REGEX REPLACE "\\*([^*]+)\\*" "<em>\\1</em>" _paraview_gpd_html_doc "${_paraview_gpd_html_doc}")
697  string(REGEX REPLACE "\n\n- " "\n<ul><li>" _paraview_gpd_html_doc "${_paraview_gpd_html_doc}")
698  string(REGEX REPLACE "\n-" "\n<li>" _paraview_gpd_html_doc "${_paraview_gpd_html_doc}")
699  string(REGEX REPLACE "<li>(.*)\n\n([^-])" "<li>\\1</ul>\n\\2" _paraview_gpd_html_doc "${_paraview_gpd_html_doc}")
700  string(REGEX REPLACE "\n\n" "\n<p>\n" _paraview_gpd_html_doc "${_paraview_gpd_html_doc}")
701  file(WRITE "${output_dir}/${_paraview_gpd_filename}"
702  "${_paraview_gpd_html_doc}\n")
703  endforeach ()
704 
705  # Generate Wiki files.
706  string(REGEX MATCHALL "proxy_group=\"[^\"]*\"" _paraview_gpd_groups "${_paraview_gpd_xslt}")
707  string(REGEX REPLACE "proxy_group=\"([^\"]*)\"" "\\1" _paraview_gpd_groups "${_paraview_gpd_groups}")
708  list(APPEND _paraview_gpd_groups readers)
709  if (_paraview_gpd_groups)
710  list(REMOVE_DUPLICATES _paraview_gpd_groups)
711  endif ()
712 
713  foreach (_paraview_gpd_group IN LISTS _paraview_gpd_groups)
714  if (_paraview_gpd_group STREQUAL "readers")
715  set(_paraview_gpd_query "contains(lower-case($proxy_name),'reader')")
716  set(_paraview_gpd_group_real "sources")
717  else ()
718  set(_paraview_gpd_query "not(contains(lower-case($proxy_name),'reader'))")
719  set(_paraview_gpd_group_real "${_paraview_gpd_group}")
720  endif ()
721 
722  set(_paraview_gpd_wiki_xsl
723  "${output_dir}/${_paraview_gpd_group}.xsl")
724  configure_file(
725  "${_paraview_gpd_to_wiki}"
726  "${_paraview_gpd_wiki_xsl}"
727  @ONLY)
728  execute_process(
729  COMMAND "${xmlpatterns}"
730  "${_paraview_gpd_wiki_xsl}"
731  "${output_file}"
732  OUTPUT_VARIABLE _paraview_gpd_output
733  RESULT_VARIABLE _paraview_gpd_result)
734  if (_paraview_gpd_result)
735  message(FATAL_ERROR
736  "Failed to generate Wiki output for ${_paraview_gpd_group}")
737  endif ()
738  string(REGEX REPLACE " +" " " _paraview_gpd_output "${_paraview_gpd_output}")
739  string(REPLACE "\n " "\n" _paraview_gpd_output "${_paraview_gpd_output}")
740  file(WRITE "${output_dir}/${_paraview_gpd_group}.wiki"
741  "${_paraview_gpd_output}")
742  endforeach ()
743 endif ()
744 
745 #[==[.md
746 ## Generating help documentation
747 
748 TODO: Document
749 
750 ```
751 paraview_client_generate_help(
752  NAME <name>
753  [TARGET <target>]
754 
755  OUTPUT_PATH <var>
756 
757  [OUTPUT_DIR <directory>]
758  [SOURCE_DIR <directory>]
759  [PATTERNS <pattern>...]
760  [DEPENDS <depend>...]
761 
762  [NAMESPACE <namespace>]
763  [FOLDER <folder>]
764 
765  [TABLE_OF_CONTENTS <toc>]
766  [TABLE_OF_CONTENTS_FILE <tocfile>]
767 
768  [RESOURCE_FILE <qrcfile>]
769  [RESOURCE_PREFIX <prefix>]
770 ```
771 
772  * `NAME`: (Required) The basename of the generated `.qch` file.
773  * `TARGET`: (Defaults to `<NAME>`) The name of the generated target.
774  * `OUTPUT_PATH`: (Required) This variable is set to the output path of the
775  generated `.qch` file.
776  * `OUTPUT_DIR`: (Defaults to `${CMAKE_CURRENT_BINARY_DIR}`) Where to place
777  generated files.
778  * `SOURCE_DIR`: Where to copy input files from.
779  * `PATTERNS`: (Defaults to `*.*`) If `SOURCE_DIR` is specified, files
780  matching these globs will be copied to `OUTPUT_DIR`.
781  * `DEPENDS`: A list of dependencies which are required before the help can be
782  generated. Note that file paths which are generated via
783  `add_custom_command` must be in the same directory as the
784  `paraview_client_generate_help` on non-Ninja generators.
785  * `NAMESPACE`: (Defaults to `<NAME>.org`) The namespace for the generated
786  help.
787  * `FOLDER`: (Defaults to `<NAME>`) The folder for the generated help.
788  * `TABLE_OF_CONTENTS` and `TABLE_OF_CONTENTS_FILE`: At most one may be
789  provided. This is used as the `<toc>` element in the generated help. If not
790  provided at all, a table of contents will be generated.
791  * `RESOURCE_FILE`: If provided, a Qt resource file providing the contents of
792  the generated help will be generated at this path. It will be available as
793  `<RESOURCE_PREFIX>/<NAME>`.
794  * `RESOURCE_PREFIX`: The prefix to use for the generated help's Qt resource.
795 #]==]
796 function (paraview_client_generate_help)
797  cmake_parse_arguments(_paraview_client_help
798  ""
799  "NAME;TARGET;OUTPUT_DIR;SOURCE_DIR;NAMESPACE;FOLDER;TABLE_OF_CONTENTS;TABLE_OF_CONTENTS_FILE;RESOURCE_FILE;RESOURCE_PREFIX;OUTPUT_PATH"
800  "PATTERNS;DEPENDS"
801  ${ARGN})
802 
803  if (_paraview_client_help_UNPARSED_ARGUMENTS)
804  message(FATAL_ERROR
805  "Unparsed arguments for paraview_client_generate_help: "
806  "${_paraview_client_help_UNPARSED_ARGUMENTS}")
807  endif ()
808 
809  if (NOT DEFINED _paraview_client_help_NAME)
810  message(FATAL_ERROR
811  "The `NAME` argument is required.")
812  endif ()
813 
814  if (NOT DEFINED _paraview_client_help_OUTPUT_PATH)
815  message(FATAL_ERROR
816  "The `OUTPUT_PATH` argument is required.")
817  endif ()
818 
819  if (NOT DEFINED _paraview_client_help_TARGET)
820  set(_paraview_client_help_TARGET
821  "${_paraview_client_help_NAME}")
822  endif ()
823 
824  if (NOT DEFINED _paraview_client_help_OUTPUT_DIR)
825  set(_paraview_client_help_OUTPUT_DIR
826  "${CMAKE_CURRENT_BINARY_DIR}/paraview_help")
827  endif ()
828 
829  if (NOT DEFINED _paraview_client_help_NAMESPACE)
830  set(_paraview_client_help_NAMESPACE
831  "${_paraview_client_help_NAME}.org")
832  endif ()
833 
834  if (NOT DEFINED _paraview_client_help_FOLDER)
835  set(_paraview_client_help_FOLDER
836  "${_paraview_client_help_NAME}")
837  endif ()
838 
839  if (DEFINED _paraview_client_help_TABLE_OF_CONTENTS_FILE)
840  file(READ "${_paraview_client_help_TABLE_OF_CONTENTS_FILE}"
841  _paraview_client_help_toc)
842  elseif (DEFINED _paraview_client_help_TABLE_OF_CONTENTS)
843  set(_paraview_client_help_toc
844  "${_paraview_client_help_TABLE_OF_CONTENTS}")
845  else ()
846  set(_paraview_client_help_toc)
847  endif ()
848  string(REPLACE "\n" " " _paraview_client_help_toc "${_paraview_client_help_toc}")
849 
850  if (NOT DEFINED _paraview_client_help_PATTERNS)
851  set(_paraview_client_help_PATTERNS
852  "*.*")
853  endif ()
854 
855  include("${_ParaViewClient_cmake_dir}/paraview-find-package-helpers.cmake" OPTIONAL)
856  set(_paraview_client_help_components
857  Help)
858  if (PARAVIEW_QT_MAJOR_VERSION GREATER "5")
859  list(APPEND _paraview_client_help_components
860  Tools)
861  endif ()
862  find_package("Qt${PARAVIEW_QT_MAJOR_VERSION}" QUIET REQUIRED COMPONENTS ${_paraview_client_help_components})
863 
864  set(_paraview_client_help_copy_sources)
865  set(_paraview_client_help_copied_sources)
866  if (DEFINED _paraview_client_help_SOURCE_DIR)
867  list(APPEND _paraview_client_help_copy_sources
868  COMMAND "${CMAKE_COMMAND}" -E copy_directory
869  "${_paraview_client_help_SOURCE_DIR}"
870  "${_paraview_client_help_OUTPUT_DIR}")
871 
872  file(GLOB _paraview_client_help_copied_sources
873  ${_paraview_client_help_PATTERNS})
874  endif ()
875 
876  file(MAKE_DIRECTORY "${_paraview_client_help_OUTPUT_DIR}")
877 
878  set(_paraview_client_help_patterns "${_paraview_client_help_PATTERNS}")
879  _paraview_client_escape_cmake_list(_paraview_client_help_patterns)
880 
881  set(_paraview_client_help_qhp
882  "${_paraview_client_help_OUTPUT_DIR}/${_paraview_client_help_NAME}.qhp")
883  set(_paraview_client_help_output
884  "${_paraview_client_help_OUTPUT_DIR}/${_paraview_client_help_NAME}.qch")
885  add_custom_command(
886  OUTPUT "${_paraview_client_help_output}"
887  DEPENDS "${_ParaViewClient_script_file}"
888  ${_paraview_client_help_copied_sources}
889  ${_paraview_client_help_DEPENDS}
890  ${_paraview_client_help_copy_sources}
891  COMMAND "${CMAKE_COMMAND}"
892  "-Doutput_dir=${_paraview_client_help_OUTPUT_DIR}"
893  "-Doutput_file=${_paraview_client_help_qhp}"
894  "-Dnamespace=${_paraview_client_help_NAMESPACE}"
895  "-Dfolder=${_paraview_client_help_FOLDER}"
896  "-Dname=${_paraview_client_help_NAME}"
897  "-Dtoc=${_paraview_client_help_toc}"
898  "-Dpatterns=${_paraview_client_help_patterns}"
899  -D_paraview_generate_help_run=ON
900  -P "${_ParaViewClient_script_file}"
901  VERBATIM
902  COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
903  "$<TARGET_FILE:Qt${PARAVIEW_QT_MAJOR_VERSION}::qhelpgenerator>"
904  "${_paraview_client_help_qhp}"
905  -s
906  -o "${_paraview_client_help_output}"
907  COMMENT "Compiling Qt help for ${_paraview_client_help_NAME}"
908  WORKING_DIRECTORY "${_paraview_client_help_OUTPUT_DIR}")
909  add_custom_target("${_paraview_client_help_TARGET}"
910  DEPENDS
911  "${_paraview_client_help_output}")
912 
913  if (DEFINED _paraview_client_help_RESOURCE_FILE)
914  if (NOT DEFINED _paraview_client_help_RESOURCE_PREFIX)
915  message(FATAL_ERROR
916  "The `RESOURCE_PREFIX` argument is required if `RESOURCE_FILE` is given.")
917  endif ()
918 
919  paraview_client_qt_resource(
920  OUTPUT "${_paraview_client_help_RESOURCE_FILE}"
921  PREFIX "${_paraview_client_help_RESOURCE_PREFIX}"
922  FILE "${_paraview_client_help_output}")
923  set_property(SOURCE "${_paraview_client_help_RESOURCE_FILE}"
924  PROPERTY
925  OBJECT_DEPENDS "${_paraview_client_help_output}")
926  endif ()
927 
928  set("${_paraview_client_help_OUTPUT_PATH}"
929  "${_paraview_client_help_output}"
930  PARENT_SCOPE)
931 endfunction ()
932 
933 # Handle the generation of the help file.
934 if (_paraview_generate_help_run AND CMAKE_SCRIPT_MODE_FILE)
935  _paraview_client_unescape_cmake_list(patterns)
936 
937  set(_paraview_help_patterns)
938  foreach (_paraview_help_pattern IN LISTS patterns)
939  if (IS_ABSOLUTE "${_paraview_help_pattern}")
940  list(APPEND _paraview_help_patterns
941  "${_paraview_help_pattern}")
942  else ()
943  list(APPEND _paraview_help_patterns
944  "${output_dir}/${_paraview_help_pattern}")
945  endif ()
946  endforeach ()
947 
948  file(GLOB _paraview_help_files
949  RELATIVE "${output_dir}"
950  ${_paraview_help_patterns})
951 
952  if (NOT toc)
953  if (NOT _paraview_help_files)
954  message(FATAL_ERROR
955  "No matching files given without a table of contents")
956  endif ()
957  set(_paraview_help_subsections "")
958  list(GET _paraview_help_files 0
959  _paraview_help_index)
960  set(_paraview_help_subsections "")
961  foreach (_paraview_help_file IN LISTS _paraview_help_files)
962  if (NOT _paraview_help_file MATCHES "\\.html$")
963  continue ()
964  endif ()
965  get_filename_component(_paraview_help_name "${_paraview_help_file}" NAME_WE)
966  set(_paraview_help_title "${_paraview_help_name}")
967  file(READ "${_paraview_help_file}" _paraview_help_contents)
968  string(REGEX MATCH "<title>([^<]*)</title>" _ "${_paraview_help_contents}")
969  if (CMAKE_MATCH_1)
970  set(_paraview_help_title "${CMAKE_MATCH_1}")
971  endif ()
972  string(APPEND _paraview_help_subsections
973  " <section title=\"${_paraview_help_title}\" ref=\"${_paraview_help_file}\" />\n")
974 
975  string(TOLOWER "${_paraview_help_name}" _paraview_help_name_lower)
976  if (_paraview_help_name_lower STREQUAL "index")
977  set(_paraview_help_index
978  "${_paraview_help_file}")
979  endif ()
980  endforeach ()
981  set(toc
982  "<toc>\n <section title=\"${name}\" ref=\"${_paraview_help_index}\">\n${_paraview_help_subsections} </section>\n</toc>")
983  endif ()
984 
985  set(_paraview_help_file_entries "")
986  foreach (_paraview_help_file IN LISTS _paraview_help_files)
987  string(APPEND _paraview_help_file_entries
988  " <file>${_paraview_help_file}</file>\n")
989  endforeach ()
990 
991  file(WRITE "${output_file}"
992  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
993 <QtHelpProject version=\"1.0\">
994  <namespace>${namespace}</namespace>
995  <virtualFolder>${folder}</virtualFolder>
996  <filterSection>
997  ${toc}
998  <keywords>
999  <!-- TODO: how to handle keywords? -->
1000  </keywords>
1001  <files>
1002 ${_paraview_help_file_entries}
1003  </files>
1004  </filterSection>
1005 </QtHelpProject>\n")
1006 endif ()
1007 
1008 #[==[.md
1009 ## Qt resources
1010 
1011 Compiling Qt resources into a client can be a little tedious. To help with
1012 this, some functions are provided to make it easier to embed content into the
1013 client.
1014 #]==]
1015 
1016 #[==[.md
1017 ### Single file
1018 
1019 ```
1021  OUTPUT <file>
1022  PREFIX <prefix>
1023  FILE <file>
1024  [ALIAS <alias>])
1025 ```
1026 
1027 Outputs a Qt resource to the file given to the `OUTPUT` argument. Its resource
1028 name is `<PREFIX>/<ALIAS>`. The contents are copied from the contents of the
1029 file specified by the `FILE` argument. If not given the name of the file is
1030 used as the `ALIAS`.
1031 #]==]
1033  cmake_parse_arguments(_paraview_client_resource
1034  ""
1035  "OUTPUT;PREFIX;ALIAS;FILE"
1036  ""
1037  ${ARGN})
1038 
1039  if (_paraview_client_resource_UNPARSED_ARGUMENTS)
1040  message(FATAL_ERROR
1041  "Unparsed arguments for paraview_client_qt_resource: "
1042  "${_paraview_client_resource_UNPARSED_ARGUMENTS}")
1043  endif ()
1044 
1045  if (NOT DEFINED _paraview_client_resource_OUTPUT)
1046  message(FATAL_ERROR
1047  "The `OUTPUT` argument is required.")
1048  endif ()
1049 
1050  if (NOT DEFINED _paraview_client_resource_PREFIX)
1051  message(FATAL_ERROR
1052  "The `PREFIX` argument is required.")
1053  endif ()
1054 
1055  if (NOT DEFINED _paraview_client_resource_FILE)
1056  message(FATAL_ERROR
1057  "The `FILE` argument is required.")
1058  endif ()
1059 
1060  if (NOT DEFINED _paraview_client_resource_ALIAS)
1061  get_filename_component(_paraview_client_resource_ALIAS
1062  "${_paraview_client_resource_FILE}"
1063  NAME)
1064  endif ()
1065 
1066  get_filename_component(_paraview_client_resource_file_path
1067  "${_paraview_client_resource_FILE}"
1068  ABSOLUTE)
1069  get_filename_component(_paraview_client_resource_file_path
1070  "${_paraview_client_resource_file_path}"
1071  REALPATH)
1072  if (WIN32)
1073  file(TO_NATIVE_PATH
1074  "${_paraview_client_resource_file_path}"
1075  _paraview_client_resource_file_path)
1076  endif ()
1077 
1078  # We cannot use file(GENERATE) because automoc doesn't like when generated
1079  # sources are in the source list.
1080  file(WRITE "${_paraview_client_resource_OUTPUT}.tmp"
1081  "<RCC>
1082  <qresource prefix=\"/${_paraview_client_resource_PREFIX}\">
1083  <file alias=\"${_paraview_client_resource_ALIAS}\">${_paraview_client_resource_file_path}</file>
1084  </qresource>
1085 </RCC>\n")
1086  configure_file(
1087  "${_paraview_client_resource_OUTPUT}.tmp"
1088  "${_paraview_client_resource_OUTPUT}"
1089  COPYONLY)
1090 endfunction ()
1091 
1092 #[==[.md
1093 ### Many files
1094 
1095 ```
1097  OUTPUT <file>
1098  PREFIX <prefix>
1099  FILES <file>...)
1100 ```
1101 
1102 Outputs a Qt resource to the file given to the `OUTPUT` argument. Its resource
1103 name is `<PREFIX>/<filename>` for each of the files in the given list. If
1104 aliases other than the filenames are required, the
1105 `paraview_client_qt_resource` function should be used instead.
1106 #]==]
1108  cmake_parse_arguments(_paraview_client_resources
1109  ""
1110  "OUTPUT;PREFIX"
1111  "FILES"
1112  ${ARGN})
1113 
1114  if (_paraview_client_resources_UNPARSED_ARGUMENTS)
1115  message(FATAL_ERROR
1116  "Unparsed arguments for paraview_client_qt_resources: "
1117  "${_paraview_client_resources_UNPARSED_ARGUMENTS}")
1118  endif ()
1119 
1120  if (NOT DEFINED _paraview_client_resources_OUTPUT)
1121  message(FATAL_ERROR
1122  "The `OUTPUT` argument is required.")
1123  endif ()
1124 
1125  if (NOT DEFINED _paraview_client_resources_PREFIX)
1126  message(FATAL_ERROR
1127  "The `PREFIX` argument is required.")
1128  endif ()
1129 
1130  if (NOT DEFINED _paraview_client_resources_FILES)
1131  message(FATAL_ERROR
1132  "The `FILES` argument is required.")
1133  endif ()
1134 
1135  set(_paraview_client_resources_contents)
1136 
1137  string(APPEND _paraview_client_resources_contents
1138  "<RCC>\n <qresource prefix=\"${_paraview_client_resources_PREFIX}\">\n")
1139  foreach (_paraview_client_resources_file IN LISTS _paraview_client_resources_FILES)
1140  get_filename_component(_paraview_client_resources_alias
1141  "${_paraview_client_resources_file}"
1142  NAME)
1143  get_filename_component(_paraview_client_resources_file_path
1144  "${_paraview_client_resources_file}"
1145  ABSOLUTE)
1146  get_filename_component(_paraview_client_resources_file_path
1147  "${_paraview_client_resources_file_path}"
1148  REALPATH)
1149  if (WIN32)
1150  file(TO_NATIVE_PATH
1151  "${_paraview_client_resources_file_path}"
1152  _paraview_client_resources_file_path)
1153  endif ()
1154  string(APPEND _paraview_client_resources_contents
1155  " <file alias=\"${_paraview_client_resources_alias}\">${_paraview_client_resources_file_path}</file>\n")
1156  endforeach ()
1157  string(APPEND _paraview_client_resources_contents
1158  " </qresource>\n</RCC>\n")
1159 
1160  # We cannot use file(GENERATE) because automoc doesn't like when generated
1161  # sources are in the source list.
1162  file(WRITE "${_paraview_client_resources_OUTPUT}.tmp"
1163  "${_paraview_client_resources_contents}")
1164  configure_file(
1165  "${_paraview_client_resources_OUTPUT}.tmp"
1166  "${_paraview_client_resources_OUTPUT}"
1167  COPYONLY)
1168 endfunction ()
function
function
style
style
content
content
pqTimelineColumn::NAME
@ NAME
Definition: pqTimelineModel.h:30
paraview_client_generate_help
function paraview_client_generate_help()
.md
Definition: ParaViewClient.cmake:796
on
on
title
title
meta
meta
SpyPlotHistoryReaderPrivate::convert
bool convert(const std::string &num, T &t)
Definition: vtkSpyPlotHistoryReaderPrivate.h:39
paraview_client_qt_resources
function paraview_client_qt_resources()
.md
Definition: ParaViewClient.cmake:1107
paraview_client_documentation
function paraview_client_documentation()
.md
Definition: ParaViewClient.cmake:539
name
name
string
string
documentation
documentation
paraview_client_add
function paraview_client_add()
.md
Definition: ParaViewClient.cmake:92
version
version
index
index
paraview_client_qt_resource
function paraview_client_qt_resource()
.md
Definition: ParaViewClient.cmake:1032