ParaViewPlugin.cmake 58.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
set(_ParaViewPlugin_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")

#[==[.md
# ParaView Plugin CMake API

# TODO

#]==]

#[==[.md
## Finding plugins

Similar to VTK modules, plugins first have to be discovered. The
`paraview_plugin_find_plugins` function does this. The output variable is the
list of discovered `paraview.plugin` files.

```
paraview_plugin_find_plugins(<output> [<directory>...])
```
#]==]
function (paraview_plugin_find_plugins output)
  set(_paraview_find_plugins_all)
  foreach (_paraview_find_plugins_directory IN LISTS ARGN)
    file(GLOB_RECURSE _paraview_find_plugins_plugins
      "${_paraview_find_plugins_directory}/paraview.plugin")
    list(APPEND _paraview_find_plugins_all
      ${_paraview_find_plugins_plugins})
  endforeach ()
  set("${output}" ${_paraview_find_plugins_all} PARENT_SCOPE)
endfunction ()

#[==[.md
## Plugin files

The `paraview.plugin` file is parsed and used as arguments to a CMake function.

Example:

```
NAME
  AdiosReaderPixie
CONDITION
  PARAVIEW_USE_MPI
DESCRIPTION
  Pixie file reader using ADIOS
REQUIRES_MODULES
  VTK:CommonCore
```

The supported arguments are:

  * `NAME`: (Required) The name of the plugin.
  * `DESCRIPTION`: (Recommended) Short text describing what the plugin does.
  * `CONDITION`: Arguments to CMake's `if` command which may be used to hide
    the plugin for certain platforms or other reasons. If the expression is
    false, the module is completely ignored.
  * `REQUIRES_MODULES`: If the plugin is enabled, these modules will be listed
    as those required to build the enabled plugins.
#]==]
macro (_paraview_plugin_parse_args name_output)
  cmake_parse_arguments("_name"
    ""
    "NAME"
    ""
    ${ARGN})

  if (NOT _name_NAME)
    message(FATAL_ERROR
      "A ParaView plugin requires a name (from ${_paraview_scan_plugin_file}).")
  endif ()
  set("${name_output}" "${_name_NAME}")

  cmake_parse_arguments("${_name_NAME}"
    ""
    "NAME"
    "DESCRIPTION;REQUIRES_MODULES;CONDITION"
    ${ARGN})

  if (${_name_NAME}_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for ${_name_NAME}: "
      "${${_name_NAME}_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT ${_name_NAME}_DESCRIPTION)
    message(WARNING "The ${_name_NAME} module should have a description")
  endif ()
  string(REPLACE ";" " " "${_name_NAME}_DESCRIPTION" "${${_name_NAME}_DESCRIPTION}")
endmacro ()

#[==[.md
## Scanning plugins

Once the `paraview.plugin` files have been found, they need to be scanned to
determine which should be built. Generally, plugins should be scanned first in
order to use the `REQUIRES_MODULES` list to enable them during the scan for
their required modules.

```
paraview_plugin_scan(
  PLUGIN_FILES              <file>...
  PROVIDES_PLUGINS          <variable>
  [ENABLE_BY_DEFAULT        <ON|OFF>]
  [HIDE_PLUGINS_FROM_CACHE  <ON|OFF>]
  [REQUIRES_MODULES         <variable>])
```

  * `PLUGIN_FILES`: (Required) The list of plugin files to scan.
  * `PROVIDES_PLUGINS`: (Required) This variable contains a list of the plugins
    to be built.
  * `ENABLE_BY_DEFAULT`: (Defaults to `OFF`) Whether to enable plugins by
    default or not.
  * `HIDE_PLUGINS_FROM_CACHE`: (Defaults to `OFF`) Whether to display options
    to enable and disable plugins in the cache or not.
  * `REQUIRES_MODULES`: The list of modules required by the enabled plugins.
#]==]

function (paraview_plugin_scan)
  cmake_parse_arguments(_paraview_scan
    ""
    "ENABLE_BY_DEFAULT;HIDE_PLUGINS_FROM_CACHE;REQUIRES_MODULES;PROVIDES_PLUGINS"
    "PLUGIN_FILES"
    ${ARGN})

  if (_paraview_scan_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_scan: "
      "${_paraview_scan_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_scan_ENABLE_BY_DEFAULT)
    set(_paraview_scan_ENABLE_BY_DEFAULT OFF)
  endif ()

  if (NOT DEFINED _paraview_scan_HIDE_PLUGINS_FROM_CACHE)
    set(_paraview_scan_HIDE_PLUGINS_FROM_CACHE OFF)
  endif ()

  if (NOT DEFINED _paraview_scan_PROVIDES_PLUGINS)
    message(FATAL_ERROR
      "The `PROVIDES_PLUGINS` argument is required.")
  endif ()

  if (NOT _paraview_scan_PLUGIN_FILES)
    message(FATAL_ERROR
      "No plugin files given to scan.")
  endif ()

  set(_paraview_scan_option_default_type BOOL)
  if (_paraview_scan_HIDE_PLUGINS_FROM_CACHE)
    set(_paraview_scan_option_default_type INTERNAL)
  endif ()

  set(_paraview_scan_provided_plugins)
  set(_paraview_scan_required_modules)

  foreach (_paraview_scan_plugin_file IN LISTS _paraview_scan_PLUGIN_FILES)
158
159
160
161
162
    if (NOT IS_ABSOLUTE "${_paraview_scan_plugin_file}")
      set(_paraview_scan_plugin_file
        "${CMAKE_CURRENT_SOURCE_DIR}/${_paraview_scan_plugin_file}")
    endif ()

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
    set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND
      PROPERTY
        CMAKE_CONFIGURE_DEPENDS "${_paraview_scan_plugin_file}")

    file(READ "${_paraview_scan_plugin_file}" _paraview_scan_plugin_args)
    # Replace comments.
    string(REGEX REPLACE "#[^\n]*\n" "\n" _paraview_scan_plugin_args "${_paraview_scan_plugin_args}")
    # Use argument splitting.
    string(REGEX REPLACE "( |\n)+" ";" _paraview_scan_plugin_args "${_paraview_scan_plugin_args}")
    _paraview_plugin_parse_args(_paraview_scan_plugin_name ${_paraview_scan_plugin_args})

    list(APPEND _paraview_scan_all_plugins
      "${_paraview_scan_plugin_name}")

    set(_paraview_scan_plugin_default "${_paraview_scan_ENABLE_BY_DEFAULT}")
    if (DEFINED "_paraview_plugin_default_${_paraview_scan_plugin_name}")
      set(_paraview_scan_plugin_default "${_paraview_plugin_default_${_paraview_scan_plugin_name}}")
    endif ()
    option("PARAVIEW_PLUGIN_ENABLE_${_paraview_scan_plugin_name}"
      "Enable the ${_paraview_scan_plugin_name} plugin. ${${_paraview_scan_plugin_name}_DESCRIPTION}"
      "${_paraview_scan_plugin_default}")
    set("_paraview_scan_enable_${_paraview_scan_plugin_name}"
      "${PARAVIEW_PLUGIN_ENABLE_${_paraview_scan_plugin_name}}")

    set_property(CACHE "PARAVIEW_PLUGIN_ENABLE_${_paraview_scan_plugin_name}"
      PROPERTY
        TYPE "${_paraview_scan_option_default_type}")

    if (NOT ${_paraview_scan_plugin_name}_REQUIRES_MODULES)
      message(WARNING
        "The ${_paraview_scan_plugin_name} plugin claims that it does not "
        "require any modules. This is probably an oversight.")
    endif ()

    if (DEFINED ${_paraview_scan_plugin_name}_CONDITION)
      if (NOT (${${_paraview_scan_plugin_name}_CONDITION}))
        if (DEFINED "PARAVIEW_PLUGIN_ENABLE_${_paraview_scan_plugin_name}")
          set_property(CACHE "PARAVIEW_PLUGIN_ENABLE_${_paraview_scan_plugin_name}"
            PROPERTY
              TYPE INTERNAL)
        endif ()
        continue ()
      endif ()
    endif ()

    if (_paraview_scan_enable_${_paraview_scan_plugin_name})
      list(APPEND _paraview_scan_provided_plugins
        "${_paraview_scan_plugin_name}")
      list(APPEND _paraview_scan_required_modules
        ${${_paraview_scan_plugin_name}_REQUIRES_MODULES})
    endif ()

    set_property(GLOBAL
      PROPERTY
        "_paraview_plugin_${_paraview_scan_plugin_name}_file" "${_paraview_scan_plugin_file}")
218
219
220
    set_property(GLOBAL
      PROPERTY
        "_paraview_plugin_${_paraview_scan_plugin_name}_description" "${${_paraview_scan_plugin_name}_DESCRIPTION}")
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    set_property(GLOBAL
      PROPERTY
      "_paraview_plugin_${_paraview_scan_plugin_name}_required_modules" "${${_paraview_scan_plugin_name}_REQUIRES_MODULES}")
  endforeach ()

  if (DEFINED _paraview_scan_REQUIRES_MODULES)
    set("${_paraview_scan_REQUIRES_MODULES}"
      ${_paraview_scan_required_modules}
      PARENT_SCOPE)
  endif ()

  set("${_paraview_scan_PROVIDES_PLUGINS}"
    ${_paraview_scan_provided_plugins}
    PARENT_SCOPE)
endfunction ()

#[==[.md
## Building plugins

Once all plugins have been scanned, they need to be built.

```
paraview_plugin_build(
  PLUGINS <plugin>...
  [TARGET <target>]
  [AUTOLOAD <plugin>...]

248
  [RUNTIME_DESTINATION <destination>]
249
250
251
252
253
254
255
256
257
258
259
260
  [LIBRARY_DESTINATION <destination>]
  [LIBRARY_SUBDIRECTORY <subdirectory>]

  [PLUGINS_FILE_NAME <filename>])
```

  * `PLUGINS`: (Required) The list of plugins to build. May be empty.
  * `TARGET`: (Recommended) The name of an interface target to generate. This
    provides. an initialization function `<TARGET>_initialize` which
    initializes static plugins. The function is provided, but is a no-op for
    shared plugin builds.
  * `AUTOLOAD`: A list of plugins to mark for autoloading.
261
262
  * `RUNTIME_DESTINATION`: (Defaults to `${CMAKE_INSTALL_BINDIR}`) Where to
    install runtime files.
263
264
265
266
  * `LIBRARY_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) Where to
    install modules built by plugins.
  * `LIBRARY_SUBDIRECTORY`: (Defaults to `""`) Where to install the plugins
    themselves. Each plugin lives in a directory of its name in
267
268
    `<RUNTIME_DESTINATION>/<LIBRARY_SUBDIRECTORY>` (for Windows) or
    `<LIBRARY_DESTINATION>/<LIBRARY_SUBDIRECTORY>` for other platforms.
269
270
271
272
273
274
275
276
  * `PLUGINS_FILE_NAME`: The name of the XML plugin file to generate for the
    built plugins. This file will be placed under
    `<LIBRARY_DESTINATION>/<LIBRARY_SUBDIRECTORY>`. It will be installed with
    the `plugin` component.
#]==]
function (paraview_plugin_build)
  cmake_parse_arguments(_paraview_build
    ""
277
    "RUNTIME_DESTINATION;LIBRARY_DESTINATION;LIBRARY_SUBDIRECTORY;TARGET;PLUGINS_FILE_NAME"
278
279
280
281
282
283
284
285
286
    "PLUGINS;AUTOLOAD"
    ${ARGN})

  if (_paraview_build_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_build: "
      "${_paraview_build_UNPARSED_ARGUMENTS}")
  endif ()

287
288
289
290
  if (NOT DEFINED _paraview_build_RUNTIME_DESTINATION)
    set(_paraview_build_RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}")
  endif ()

291
292
293
294
295
296
297
298
  if (NOT DEFINED _paraview_build_LIBRARY_DESTINATION)
    set(_paraview_build_LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
  endif ()

  if (NOT DEFINED _paraview_build_LIBRARY_SUBDIRECTORY)
    set(_paraview_build_LIBRARY_SUBDIRECTORY "")
  endif ()

299
300
301
302
303
304
305
  if (WIN32)
    set(_paraview_build_plugin_destination "${_paraview_build_RUNTIME_DESTINATION}")
  else ()
    set(_paraview_build_plugin_destination "${_paraview_build_LIBRARY_DESTINATION}")
  endif ()
  string(APPEND _paraview_build_plugin_destination "/${_paraview_build_LIBRARY_SUBDIRECTORY}")

306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
  foreach (_paraview_build_plugin IN LISTS _paraview_build_PLUGINS)
    get_property(_paraview_build_plugin_file GLOBAL
      PROPERTY  "_paraview_plugin_${_paraview_build_plugin}_file")
    if (NOT _paraview_build_plugin_file)
      message(FATAL_ERROR
        "The requested ${_paraview_build_plugin} plugin is not a ParaView plugin.")
    endif ()

    # TODO: Support external plugins?
    get_filename_component(_paraview_build_plugin_dir "${_paraview_build_plugin_file}" DIRECTORY)
    file(RELATIVE_PATH _paraview_build_plugin_subdir "${CMAKE_SOURCE_DIR}" "${_paraview_build_plugin_dir}")
    add_subdirectory(
      "${CMAKE_SOURCE_DIR}/${_paraview_build_plugin_subdir}"
      "${CMAKE_BINARY_DIR}/${_paraview_build_plugin_subdir}")
  endforeach ()

  if (DEFINED _paraview_build_TARGET)
    add_library("${_paraview_build_TARGET}" INTERFACE)
    target_include_directories("${_paraview_build_TARGET}"
      INTERFACE
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_paraview_build_TARGET}>")
    set(_paraview_build_include_file
      "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_paraview_build_TARGET}/${_paraview_build_TARGET}.h")

330
331
332
333
334
335
336
337
338
339
    set(_paraview_static_plugins)
    foreach (_paraview_build_plugin IN LISTS _paraview_build_PLUGINS)
      get_property(_paraview_build_plugin_type
        TARGET    "${_paraview_build_plugin}"
        PROPERTY  TYPE)
      if (_paraview_build_plugin_type STREQUAL "STATIC_LIBRARY")
        list(APPEND _paraview_static_plugins
          "${_paraview_build_plugin}")
      endif ()
    endforeach ()
340

341
    if (_paraview_static_plugins)
342
343
344
      target_link_libraries("${_paraview_build_TARGET}"
        INTERFACE
          ParaView::ClientServerCoreCore
345
          ${_paraview_static_plugins})
346
347
348

      set(_paraview_build_declarations)
      set(_paraview_build_calls)
349
      foreach (_paraview_build_plugin IN LISTS _paraview_static_plugins)
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
        string(APPEND _paraview_build_declarations
          "PV_PLUGIN_IMPORT_INIT(${_paraview_build_plugin});\n")
        string(APPEND _paraview_build_calls
          "  if (sname == \"${_paraview_build_plugin}\")
  {
    if (load)
    {
      static bool loaded = false;
      if (!loaded)
      {
        loaded = PV_PLUGIN_IMPORT(${_paraview_build_plugin});
      }
    }
    return true;
  }\n\n")
      endforeach ()

      set(_paraview_build_include_content
        "#ifndef ${_paraview_build_TARGET}_h
#define ${_paraview_build_TARGET}_h

#include \"vtkPVPlugin.h\"
#include \"vtkPVPluginLoader.h\"
#include \"vtkPVPluginTracker.h\"
#include <string>

${_paraview_build_declarations}
static bool ${_paraview_build_TARGET}_static_plugins_load(const char* name);
static bool ${_paraview_build_TARGET}_static_plugins_search(const char* name);

void ${_paraview_build_TARGET}_initialize()
{
  vtkPVPluginLoader::RegisterLoadPluginCallback(${_paraview_build_TARGET}_static_plugins_load);
  vtkPVPluginTracker::SetStaticPluginSearchFunction(${_paraview_build_TARGET}_static_plugins_search);
}

static bool ${_paraview_build_TARGET}_static_plugins_func(const char* name, bool load);

bool ${_paraview_build_TARGET}_static_plugins_load(const char* name)
{
  return ${_paraview_build_TARGET}_static_plugins_func(name, true);
}

bool ${_paraview_build_TARGET}_static_plugins_search(const char* name)
{
  return ${_paraview_build_TARGET}_static_plugins_func(name, false);
}

bool ${_paraview_build_TARGET}_static_plugins_func(const char* name, bool load)
{
  std::string sname = name;

  ${_paraview_build_calls}
  return false;
}

406
407
408
409
410
411
412
413
414
415
#endif\n")
    else ()
      set(_paraview_build_include_content
        "#ifndef ${_paraview_build_TARGET}_h
#define ${_paraview_build_TARGET}_h

void ${_paraview_build_TARGET}_initialize()
{
}

416
417
418
419
420
421
422
423
424
425
#endif\n")
    endif ()

    file(GENERATE
      OUTPUT  "${_paraview_build_include_file}"
      CONTENT "${_paraview_build_include_content}")
  endif ()

  if (DEFINED _paraview_build_PLUGINS_FILE_NAME)
    set(_paraview_build_xml_file
426
      "${CMAKE_BINARY_DIR}/${_paraview_build_plugin_destination}/${_paraview_build_PLUGINS_FILE_NAME}")
427
428
429
430
    set(_paraview_build_xml_content
      "<?xml version=\"1.0\"?>\n<Plugins>\n")
    foreach (_paraview_build_plugin IN LISTS _paraview_build_PLUGINS)
      set(_paraview_build_autoload 0)
431
      if (_paraview_build_plugin IN_LIST _paraview_build_AUTOLOAD)
432
433
434
435
436
437
438
439
440
441
442
443
444
        set(_paraview_build_autoload 1)
      endif ()
      string(APPEND _paraview_build_xml_content
        "  <Plugin name=\"${_paraview_build_plugin}\" auto_load=\"${_paraview_build_autoload}\"/>\n")
    endforeach ()
    string(APPEND _paraview_build_xml_content
      "</Plugins>\n")

    file(GENERATE
      OUTPUT  "${_paraview_build_xml_file}"
      CONTENT "${_paraview_build_xml_content}")
    install(
      FILES       "${_paraview_build_xml_file}"
445
      DESTINATION "${_paraview_build_plugin_destination}"
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
      COMPONENT   "plugin")
  endif ()
endfunction ()

set(_paraview_plugin_source_dir "${CMAKE_CURRENT_LIST_DIR}")

#[==[.md
## Adding a plugin

TODO: Describe.

```
paraview_add_plugin(<name>
  [REQUIRED_ON_SERVER] [REQUIRED_ON_CLIENT]
  VERSION <version>

462
463
  [MODULE_FILES <vtk.module>...]
  [MODULE_ARGS <arg>...]
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
  [MODULES <module>...]
  [SOURCES <source>...]
  [SERVER_MANAGER_XML <xml>...]

  [UI_INTERFACES <interface>...]
  [UI_RESOURCES <resource>...]
  [UI_FILES <file>...]

  [PYTHON_MODULES <module>...]

  [REQUIRED_PLUGINS <plugin>...]

  [EULA <eula>]
  [XML_DOCUMENTATION <ON|OFF>]
  [DOCUMENTATION_DIR <directory>]

480
481
482
  [EXPORT <export>]

  [FORCE_STATIC <ON|OFF>])
483
484
485
486
487
488
489
```

  * `REQUIRED_ON_SERVER`: The plugin is required to be loaded on the server for
    proper functionality.
  * `REQUIRED_ON_CLIENT`: The plugin is required to be loaded on the client for
    proper functionality.
  * `VERSION`: (Required) The version number of the plugin.
490
491
492
  * `MODULE_FILES`: Paths to `vtk.module` files describing modules to include
    in the plugin.
  * `MODULE_ARGS`: Arguments to pass to `vtk_module_build` for included modules.
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
  * `MODULES`: Modules to include in the plugin. These modules will be wrapped
    using client server and have their server manager XML files processed.
  * `SOURCES`: Source files for the plugin.
  * `SERVER_MANAGER_XML`: Server manager XML files for the plugin.
  * `UI_INTERFACES`: Interfaces to initialize. See the plugin interfaces
    section for more details.
  * `UI_RESOURCES`: Qt resource files to include with the plugin.
  * `UI_FILES`: Qt `.ui` files to include with the plugin.
  * `PYTHON_MODULES`: Python modules to embed into the plugin.
  * `REQUIRED_PLUGINS`: Plugins which must be loaded for this plugin to
    function. These plugins do not need to be available at build time and are
    therefore their existence is not checked here.
  * `EULA`: A file with content to display as an end-user license agreement
    before the plugin is initialized at runtime.
  * `XML_DOCUMENTATION`: (Defaults to `ON`) If set, documentation will be
    generated for the associated XML files.
509
510
511
  * `DOCUMENTATION_DIR`: If specified, `*.html`, `*.css`, `*.png`, and `*.jpg`
    files in this directory will be copied and made available to the
    documentation.
512
  * `EXPORT`: If provided, the plugin will be added to the given export set.
513
514
  * `FORCE_STATIC`: (Defaults to `OFF`) If set, the plugin will be built
    statically so that it can be embedded into an application.
515
516
517
518
519
520
521
522
523
524
#]==]
function (paraview_add_plugin name)
  if (NOT name STREQUAL _paraview_build_plugin)
    message(FATAL_ERROR
      "The ${_paraview_build_plugin}'s CMakeLists.txt may not add the ${name} "
      "plugin.")
  endif ()

  cmake_parse_arguments(_paraview_add_plugin
    "REQUIRED_ON_SERVER;REQUIRED_ON_CLIENT"
525
    "VERSION;EULA;EXPORT;XML_DOCUMENTATION;DOCUMENTATION_DIR;FORCE_STATIC"
526
    "REQUIRED_PLUGINS;SERVER_MANAGER_XML;SOURCES;MODULES;UI_INTERFACES;UI_RESOURCES;UI_FILES;PYTHON_MODULES;MODULE_FILES;MODULE_ARGS"
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
    ${ARGN})

  if (_paraview_add_plugin_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_add_plugin: "
      "${_paraview_add_plugin_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_add_plugin_VERSION)
    message(FATAL_ERROR
      "The `VERSION` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_add_plugin_XML_DOCUMENTATION)
    set(_paraview_add_plugin_XML_DOCUMENTATION ON)
  endif ()

544
545
546
547
  if (NOT DEFINED _paraview_add_plugin_FORCE_STATIC)
    set(_paraview_add_plugin_FORCE_STATIC OFF)
  endif ()

548
549
  if (DEFINED _paraview_add_plugin_DOCUMENTATION_DIR AND
      NOT _paraview_add_plugin_XML_DOCUMENTATION)
550
551
552
553
554
    message(FATAL_ERROR
      "Specifying `DOCUMENTATION_DIR` and turning off `XML_DOCUMENTATION` "
      "makes no sense.")
  endif ()

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
  if (_paraview_add_plugin_MODULE_ARGS)
    if (NOT _paraview_add_plugin_MODULES_FILES OR
        NOT _paraview_add_plugin_MODULES)
      message(FATAL_ERROR
        "The `MODULE_ARGS` argument requires `MODULE_FILES` and `MODULES` to be provided.")
    endif ()
  endif ()

  if (_paraview_add_plugin_MODULE_FILES)
    if (NOT _paraview_add_plugin_MODULES)
      message(FATAL_ERROR
        "The `MODULE_FILES` argument requires `MODULES` to be provided.")
    endif ()

    vtk_module_scan(
      MODULE_FILES      ${_paraview_add_plugin_MODULE_FILES}
      REQUEST_MODULES   ${_paraview_add_plugin_MODULES}
      PROVIDES_MODULES  plugin_modules
      REQUIRES_MODULES  required_modules
      HIDE_MODULES_FROM_CACHE ON)

    if (required_modules)
      foreach (required_module IN LISTS required_modules)
        if (NOT TARGET "${required_module}")
          message(FATAL_ERROR
            "Failed to find the required module ${required_module}.")
        endif ()
      endforeach ()
    endif ()

585
586
587
588
589
590
591
592
593
    if (WIN32)
      set(_paraview_plugin_subdir "${_paraview_build_RUNTIME_DESTINATION}")
    else ()
      set(_paraview_plugin_subdir "${_paraview_build_LIBRARY_DESTINATION}")
    endif ()
    if (DEFINED _paraview_build_LIBRARY_SUBDIRECTORY)
      string(APPEND _paraview_plugin_subdir "/${_paraview_build_LIBRARY_SUBDIRECTORY}")
    endif ()
    string(APPEND _paraview_plugin_subdir "/${_paraview_build_plugin}")
594
595
596
    set(_paraview_plugin_CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
    set(_paraview_plugin_CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(_paraview_plugin_CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
597
    set(_paraview_plugin_CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_NAME_DIR}")
598
599
600
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_paraview_plugin_subdir}")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_paraview_plugin_subdir}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_paraview_plugin_subdir}")
601
    set(CMAKE_INSTALL_NAME_DIR "@loader_path")
602

603
604
605
606
    vtk_module_build(
      MODULES             ${plugin_modules}
      PACKAGE             "${_paraview_build_plugin}"
      INSTALL_HEADERS     OFF
607
608
609
      ARCHIVE_DESTINATION "${_paraview_plugin_subdir}"
      LIBRARY_DESTINATION "${_paraview_plugin_subdir}"
      RUNTIME_DESTINATION "${_paraview_plugin_subdir}"
610
      ${_paraview_add_plugin_MODULE_ARGS})
611
612
613
614

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${_paraview_plugin_CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${_paraview_plugin_CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${_paraview_plugin_CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
615
    set(CMAKE_INSTALL_NAME_DIR "${_paraview_plugin_CMAKE_INSTALL_NAME_DIR}")
616
617
618
    unset(_paraview_plugin_CMAKE_RUNTIME_OUTPUT_DIRECTORY)
    unset(_paraview_plugin_CMAKE_LIBRARY_OUTPUT_DIRECTORY)
    unset(_paraview_plugin_CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
619
    unset(_paraview_plugin_CMAKE_INSTALL_NAME_DIR)
620
621
  endif ()

622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
  # TODO: resource initialization for static builds

  if (_paraview_add_plugin_REQUIRED_ON_SERVER)
    set(_paraview_add_plugin_required_on_server "true")
  else ()
    set(_paraview_add_plugin_required_on_server "false")
  endif ()

  if (_paraview_add_plugin_REQUIRED_ON_CLIENT)
    set(_paraview_add_plugin_required_on_client "true")
  else ()
    set(_paraview_add_plugin_required_on_client "false")
  endif ()

  set(_paraview_add_plugin_includes)
  set(_paraview_add_plugin_required_libraries)

  set(_paraview_add_plugin_module_xmls)
  set(_paraview_add_plugin_with_xml 0)
  if (_paraview_add_plugin_MODULES)
    set(_paraview_add_plugin_with_xml 1)

    list(APPEND _paraview_add_plugin_required_libraries
      ${_paraview_add_plugin_MODULES})

    set(_paraview_add_plugin_cs_args)
    if (_paraview_add_plugin_EXPORT)
      list(APPEND _paraview_add_plugin_cs_args
        INSTALL_EXPORT "${_paraview_add_plugin_EXPORT}")
    endif ()

    vtk_module_wrap_client_server(
      MODULES ${_paraview_add_plugin_MODULES}
      TARGET  "${_paraview_build_plugin}_client_server"
      ${_paraview_add_plugin_cs_args})
    paraview_server_manager_process(
      MODULES   ${_paraview_add_plugin_MODULES}
      TARGET    "${_paraview_build_plugin}_server_manager_modules"
      XML_FILES _paraview_add_plugin_module_xmls)

    list(APPEND _paraview_add_plugin_required_libraries
      "${_paraview_build_plugin}_client_server"
      "${_paraview_build_plugin}_server_manager_modules")
  endif ()

  set(_paraview_add_plugin_binary_resources "")
  set(_paraview_add_plugin_binary_headers)
  if (_paraview_add_plugin_SERVER_MANAGER_XML)
    set(_paraview_add_plugin_with_xml 1)

    set(_paraview_add_plugin_xmls)
    foreach (_paraview_add_plugin_xml IN LISTS _paraview_add_plugin_SERVER_MANAGER_XML)
      if (NOT IS_ABSOLUTE "${_paraview_add_plugin_xml}")
        set(_paraview_add_plugin_xml "${CMAKE_CURRENT_SOURCE_DIR}/${_paraview_add_plugin_xml}")
      endif ()

      list(APPEND _paraview_add_plugin_xmls
        "${_paraview_add_plugin_xml}")
    endforeach ()

    paraview_server_manager_process_files(
      TARGET    "${_paraview_build_plugin}_server_manager"
      FILES     ${_paraview_add_plugin_xmls})
    list(APPEND _paraview_add_plugin_required_libraries
      "${_paraview_build_plugin}_server_manager")
  endif ()

  if ((_paraview_add_plugin_module_xmls OR _paraview_add_plugin_xmls) AND
      PARAVIEW_BUILD_QT_GUI AND _paraview_add_plugin_XML_DOCUMENTATION)
691
692
693
    set(_paraview_build_plugin_docdir
      "${CMAKE_CURRENT_BINARY_DIR}/paraview_help")

694
    paraview_client_documentation(
695
696
697
698
      TARGET      "${_paraview_build_plugin}_doc"
      OUTPUT_DIR  "${_paraview_build_plugin_docdir}"
      XMLS        ${_paraview_add_plugin_module_xmls}
                  ${_paraview_add_plugin_xmls})
699
700
701
702
703
704
705

    set(_paraview_build_plugin_doc_source_args)
    if (DEFINED _paraview_add_plugin_DOCUMENTATION_DIR)
      set(_paraview_build_plugin_doc_source_args
        SOURCE_DIR "${_paraview_add_plugin_DOCUMENTATION_DIR}")
    endif ()

706
707
    paraview_client_generate_help(
      NAME        "${_paraview_build_plugin}"
708
      OUTPUT_PATH _paraview_build_plugin_qch_path
709
      OUTPUT_DIR  "${_paraview_build_plugin_docdir}"
710
      TARGET      "${_paraview_build_plugin}_qch"
711
      ${_paraview_build_plugin_doc_source_args}
712
713
714
715
      DEPENDS     "${_paraview_build_plugin}_doc"
      PATTERNS    "*.html" "*.css" "*.png" "*.jpg")

    list(APPEND _paraview_add_plugin_extra_include_dirs
716
      "${CMAKE_CURRENT_BINARY_DIR}")
717
    set(_paraview_add_plugin_qch_output
718
      "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_build_plugin}_qch.h")
719
720
721
722
723
724
725
726
727
728
    list(APPEND _paraview_add_plugin_binary_headers
      "${_paraview_add_plugin_qch_output}")
    add_custom_command(
      OUTPUT "${_paraview_add_plugin_qch_output}"
      COMMAND ParaView::ProcessXML
              -base64
              "${_paraview_add_plugin_qch_output}"
              \"\"
              "_qch"
              "_qch"
729
730
              "${_paraview_build_plugin_qch_path}"
      DEPENDS "${_paraview_build_plugin_qch_path}"
731
              "${_paraview_build_plugin}_qch"
732
              "$<TARGET_FILE:ParaView::ProcessXML>"
733
      COMMENT "Generating header for ${_paraview_build_plugin} documentation")
734
735
736
    set_property(SOURCE "${_paraview_add_plugin_qch_output}"
      PROPERTY
        SKIP_AUTOMOC 1)
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778

    string(APPEND _paraview_add_plugin_includes
      "#include \"${_paraview_build_plugin}_qch.h\"\n")
    string(APPEND _paraview_add_plugin_binary_resources
      "  {
    const char *text = ${_paraview_build_plugin}_qch();
    resources.push_back(text);
    delete [] text;
  }\n")
  endif ()

  set(_paraview_add_plugin_eula_sources)
  if (_paraview_add_plugin_EULA)
    vtk_encode_string(
      INPUT "${_paraview_add_plugin_EULA}"
      NAME  "${_paraview_build_plugin}_EULA"
      HEADER_OUTPUT _paraview_add_plugin_eula_header
      SOURCE_OUTPUT _paraview_add_plugin_eula_source)
    list(APPEND _paraview_add_plugin_eula_sources
      "${_paraview_add_plugin_eula_header}"
      "${_paraview_add_plugin_eula_source}")
  endif ()

  set(_paraview_add_plugin_with_ui 0)
  set(_paraview_add_plugin_ui_sources)
  if (_paraview_add_plugin_UI_INTERFACES)
    set(_paraview_add_plugin_with_ui 1)
    set(CMAKE_AUTOMOC 1)
    set(_paraview_add_plugin_push_back_interfaces
      "#define PARAVIEW_ADD_INTERFACES(arg) \\\n")
    set(_paraview_add_plugin_include_interfaces "")

    foreach (_paraview_add_plugin_ui_interface IN LISTS _paraview_add_plugin_UI_INTERFACES)
      string(APPEND _paraview_add_plugin_push_back_interfaces
        "  arg.push_back(new ${_paraview_add_plugin_ui_interface}(this)); \\\n")
      string(APPEND _paraview_add_plugin_include_interfaces
        "#include \"${_paraview_add_plugin_ui_interface}.h\"\n")
    endforeach ()
    list(APPEND _paraview_add_plugin_required_libraries
      ParaView::pqComponents)
  endif ()

779
  set(_paraview_add_plugin_with_resources 0)
780
781
  set(_paraview_add_plugin_resources_init)
  if (_paraview_add_plugin_UI_RESOURCES)
782
    set(_paraview_add_plugin_with_resources 1)
783
    set(CMAKE_AUTORCC 1)
784
    if (NOT BUILD_SHARED_LIBS OR _paraview_add_plugin_FORCE_STATIC)
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
      foreach (_paraview_add_plugin_ui_resource IN LISTS _paraview_add_plugin_UI_RESOURCES)
        get_filename_component(_paraview_add_plugin_ui_resource_base "${_paraview_add_plugin_ui_resource}" NAME_WE)
        string(APPEND _paraview_add_plugin_resources_init
          "  Q_INIT_RESOURCE(${_paraview_add_plugin_ui_resource_base});\n")
      endforeach ()
    endif ()
    list(APPEND _paraview_add_plugin_ui_sources
      ${_paraview_add_plugin_UI_RESOURCES})
  endif ()

  set(_paraview_add_plugin_qt_extra_components)
  if (_paraview_add_plugin_UI_FILES)
    set(_paraview_add_plugin_with_ui 1)
    set(CMAKE_AUTOUIC 1)
    list(APPEND _paraview_add_plugin_qt_extra_components
      Widgets)
    list(APPEND _paraview_add_plugin_required_libraries
      Qt5::Widgets)
    list(APPEND _paraview_add_plugin_ui_sources
      ${_paraview_add_plugin_UI_FILES})
  endif ()

807
  if (_paraview_add_plugin_with_ui OR _paraview_add_plugin_with_resources)
808
    include("${CMAKE_CURRENT_LIST_DIR}/paraview-find-package-helpers.cmake" OPTIONAL)
809
810
811
    find_package(Qt5 QUIET REQUIRED COMPONENTS Core ${_paraview_add_plugin_qt_extra_components})
    list(APPEND _paraview_add_plugin_required_libraries
      Qt5::Core)
812
813
814
815
    if (_paraview_add_plugin_with_ui)
      list(APPEND _paraview_add_plugin_required_libraries
        ParaView::pqCore)
    endif ()
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833

    # CMake 3.13 started using Qt5's version variables to detect what version
    # of Qt's tools to run for automoc, autouic, and autorcc. However, they are
    # looked up using the target's directory scope, but these are here in a
    # local scope and unset when AutoGen gets around to asking about the
    # variables at generate time.

    # Fix for 3.13.0–3.13.3. Does not work if `paraview_add_plugin` is called
    # from another function.
    set(Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}" PARENT_SCOPE)
    set(Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MINOR}" PARENT_SCOPE)
    # Fix for 3.13.4+.
    set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
      PROPERTY
        Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}")
    set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
      PROPERTY
        Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MAJOR}")
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
  endif ()

  set(_paraview_add_plugin_with_python 0)
  set(_paraview_add_plugin_python_sources)
  set(_paraview_add_plugin_python_includes)
  set(_paraview_add_plugin_python_modules)
  set(_paraview_add_plugin_python_module_sources)
  set(_paraview_add_plugin_python_package_flags)
  if (_paraview_add_plugin_PYTHON_MODULES)
    set(_paraview_add_plugin_with_python 1)
    foreach (_paraview_add_plugin_python_module IN LISTS _paraview_add_plugin_PYTHON_MODULES)
      set(_paraview_add_plugin_python_path
        "${CMAKE_CURRENT_SOURCE_DIR}/${_paraview_add_plugin_python_module}")
      get_filename_component(_paraview_add_plugin_python_package "${_paraview_add_plugin_python_module}" PATH)
      get_filename_component(_paraview_add_plugin_python_name "${_paraview_add_plugin_python_module}" NAME_WE)
      if (_paraview_add_plugin_python_package)
        set(_paraview_add_plugin_python_full_name
          "${_paraview_add_plugin_python_package}.${_paraview_add_plugin_python_name}")
      else ()
        set(_paraview_add_plugin_python_full_name
          "${_paraview_add_plugin_python_name}")
      endif ()
      string(REPLACE "." "_" _paraview_add_plugin_python_module_mangled "${_paraview_add_plugin_python_full_name}")
      set(_paraview_add_plugin_python_is_package 0)
      set(_paraview_add_plugin_python_import
        "${_paraview_add_plugin_python_full_name}")
      if (_paraview_add_plugin_python_name STREQUAL "__init__")
        set(_paraview_add_plugin_python_is_package 1)
        set(_paraview_add_plugin_python_import
          "${_paraview_add_plugin_python_package}")
      endif ()
      set(_paraview_add_plugin_python_header_name
        "WrappedPython_${_paraview_build_plugin}_${_paraview_add_plugin_python_module_mangled}.h")
      set(_paraview_add_plugin_python_header
        "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_add_plugin_python_header_name}")
      add_custom_command(
        OUTPUT  "${_paraview_add_plugin_python_header}"
        COMMAND ParaView::ProcessXML
                "${_paraview_add_plugin_python_header}"
                "module_${_paraview_add_plugin_python_module_mangled}_"
                "_string"
                "_source"
                "${_paraview_add_plugin_python_path}"
        DEPENDS "${_paraview_add_plugin_python_path}"
878
                "$<TARGET_FILE:ParaView::ProcessXML>"
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
        COMMENT "Convert Python module ${_paraview_add_plugin_python_module_name} for ${_paraview_build_plugin}")

      list(APPEND _paraview_add_plugin_python_sources
        "${_paraview_add_plugin_python_header}")
      string(APPEND _paraview_add_plugin_python_includes
        "#include \"${_paraview_add_plugin_python_header_name}\"\n")
      string(APPEND _paraview_add_plugin_python_modules
        "    \"${_paraview_add_plugin_python_import}\",\n")
      string(APPEND _paraview_add_plugin_python_module_sources
        "    module_${_paraview_add_plugin_python_module_mangled}_${_paraview_add_plugin_python_name}_source(),\n")
      string(APPEND _paraview_add_plugin_python_package_flags
        "    ${_paraview_add_plugin_python_is_package},\n")
    endforeach ()

    # Add terminators to the list.
    string(APPEND _paraview_add_plugin_python_modules
      "    nullptr")
    string(APPEND _paraview_add_plugin_python_module_sources
      "    nullptr")
    string(APPEND _paraview_add_plugin_python_package_flags
      "    -1")
  endif ()

  set(_paraview_add_plugin_header
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_build_plugin}Plugin.h")
  set(_paraview_add_plugin_source
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_build_plugin}Plugin.cxx")

907
908
909
  get_property(_paraview_add_plugin_description GLOBAL
    PROPERTY "_paraview_plugin_${_paraview_build_plugin}_description")

910
911
912
913
914
915
916
  set(_paraview_build_plugin_type MODULE)
  set(_paraview_add_plugin_built_shared 1)
  if (NOT BUILD_SHARED_LIBS OR _paraview_add_plugin_FORCE_STATIC)
    set(_paraview_build_plugin_type STATIC)
    set(_paraview_add_plugin_built_shared 0)
  endif ()

917
918
919
920
921
922
923
  configure_file(
    "${_paraview_plugin_source_dir}/paraview_plugin.h.in"
    "${_paraview_add_plugin_header}")
  configure_file(
    "${_paraview_plugin_source_dir}/paraview_plugin.cxx.in"
    "${_paraview_add_plugin_source}")

924
925
926
927
928
  if (WIN32)
    # On Windows, we want `MODULE` libraries to go to the runtime directory,
    # but CMake always uses `CMAKE_LIBRARY_OUTPUT_DIRECTORY`.
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
  endif ()
929
930
931
932
933
934
935
936
937
938
939
940
941
  if (DEFINED _paraview_build_LIBRARY_SUBDIRECTORY)
    string(APPEND CMAKE_LIBRARY_OUTPUT_DIRECTORY "/${_paraview_build_LIBRARY_SUBDIRECTORY}")
  endif ()
  string(APPEND CMAKE_LIBRARY_OUTPUT_DIRECTORY "/${_paraview_build_plugin}")

  add_library("${_paraview_build_plugin}" "${_paraview_build_plugin_type}"
    ${_paraview_add_plugin_header}
    ${_paraview_add_plugin_source}
    ${_paraview_add_plugin_eula_sources}
    ${_paraview_add_plugin_binary_headers}
    ${_paraview_add_plugin_ui_sources}
    ${_paraview_add_plugin_python_sources}
    ${_paraview_add_plugin_SOURCES})
942
  if (NOT BUILD_SHARED_LIBS OR _paraview_add_plugin_FORCE_STATIC)
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
    target_compile_definitions("${_paraview_build_plugin}"
      PRIVATE
        QT_STATICPLUGIN)
  endif ()
  target_link_libraries("${_paraview_build_plugin}"
    PRIVATE
      ParaView::ClientServerCoreCore
      ${_paraview_add_plugin_required_libraries})
  target_include_directories("${_paraview_build_plugin}"
    PRIVATE
      "${CMAKE_CURRENT_SOURCE_DIR}"
      ${_paraview_add_plugin_extra_include_dirs})
  set_property(TARGET "${_paraview_build_plugin}"
    PROPERTY
      PREFIX "")

  set(_paraview_add_plugin_destination
960
    "${_paraview_build_plugin_destination}/${_paraview_build_plugin}")
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
  install(
    TARGETS "${_paraview_build_plugin}"
    COMPONENT "plugin"
    ARCHIVE DESTINATION "${_paraview_add_plugin_destination}"
    LIBRARY DESTINATION "${_paraview_add_plugin_destination}")
endfunction ()

#[==[.md
## Plugin interfaces

ParaView plugins may satisfy a number of interfaces. These functions all take a
`INTERFACES` argument which takes the name of a variable to set with the name
of the interface generated. This variable's should be passed to
`paraview_add_plugin`'s `UI_INTERFACES` argument.
#]==]

#[==[.md
### Property widget

TODO: What is a property widget?

```
paraview_plugin_add_property_widget(
  KIND  <WIDGET|GROUP_WIDGET|WIDGET_DECORATOR>
985
  TYPE <type>
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
  CLASS_NAME <name>
  INTERFACES <variable>
  SOURCES <variable>)
```

  * `KIND`: The kind of widget represented.
  * `TYPE`: The name of the property type.
  * `CLASS_NAME`: The name of the property widget class.
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_property_widget)
  cmake_parse_arguments(_paraview_property_widget
    ""
    "KIND;TYPE;CLASS_NAME;INTERFACES;SOURCES"
    ""
    ${ARGN})

  if (_paraview_property_widget_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_add_property_widget: "
      "${_paraview_property_widget_UNPARSED_ARGUMENTS}")
  endif ()

  set(_paraview_property_widget_kind_widget 0)
  set(_paraview_property_widget_kind_group_widget 0)
  set(_paraview_property_widget_kind_widget_decorator 0)
  if (_paraview_property_widget_KIND STREQUAL "WIDGET")
    set(_paraview_property_widget_kind_widget 1)
  elseif (_paraview_property_widget_KIND STREQUAL "GROUP_WIDGET")
    set(_paraview_property_widget_kind_group_widget 1)
  elseif (_paraview_property_widget_KIND STREQUAL "WIDGET_DECORATOR")
    set(_paraview_property_widget_kind_widget_decorator 1)
  else ()
    message(FATAL_ERROR
      "The `KIND` argument must be one of `WIDGET`, `GROUP_WIDGET`, or "
      "`WIDGET_DECORATOR`.")
  endif ()

  if (NOT DEFINED _paraview_property_widget_TYPE)
    message(FATAL_ERROR
      "The `TYPE` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_property_widget_CLASS_NAME)
    message(FATAL_ERROR
      "The `CLASS_NAME` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_property_widget_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_property_widget_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqPropertyWidgetInterface.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_property_widget_CLASS_NAME}PWIImplementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqPropertyWidgetInterface.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_property_widget_CLASS_NAME}PWIImplementation.cxx"
    @ONLY)

  set("${_paraview_property_widget_INTERFACES}"
    "${_paraview_property_widget_CLASS_NAME}PWIImplementation"
    PARENT_SCOPE)

  set("${_paraview_property_widget_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_property_widget_CLASS_NAME}PWIImplementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_property_widget_CLASS_NAME}PWIImplementation.h"
    PARENT_SCOPE)
endfunction ()

#[==[.md
### Dock window

TODO: What is a dock window?

```
paraview_plugin_add_dock_window(
  CLASS_NAME <name>
1072
  [DOCK_AREA <Right|Left|Top|Bottom>]
1073
1074
1075
1076
1077
  INTERFACES <variable>
  SOURCES <variable>)
```

  * `CLASS_NAME`: The name of the dock window class.
1078
1079
  * `DOCK_AREA`: (Default `Left`) Where to dock the window within the
    application.
1080
1081
1082
1083
1084
1085
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_dock_window)
  cmake_parse_arguments(_paraview_dock_window
    ""
1086
    "DOCK_AREA;CLASS_NAME;INTERFACES;SOURCES"
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
    ""
    ${ARGN})

  if (_paraview_dock_window_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_add_dock_window: "
      "${_paraview_dock_window_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_dock_window_CLASS_NAME)
    message(FATAL_ERROR
      "The `CLASS_NAME` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_dock_window_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_dock_window_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
  if (NOT DEFINED _paraview_dock_window_DOCK_AREA)
    set(_paraview_dock_window_DOCK_AREA "Left")
  endif ()

  if (NOT _paraview_dock_window_DOCK_AREA STREQUAL "Left" AND
      NOT _paraview_dock_window_DOCK_AREA STREQUAL "Right" AND
      NOT _paraview_dock_window_DOCK_AREA STREQUAL "Top" AND
      NOT _paraview_dock_window_DOCK_AREA STREQUAL "Bottom")
    message(FATAL_ERROR
      "`DOCK_AREA` must be one of `Left`, `Right`, `Top`, or `Bottom`. Got "
      "`${_paraview_dock_window_DOCK_AREA}`.")
  endif ()

1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqDockWindowImplementation.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_dock_window_CLASS_NAME}Implementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqDockWindowImplementation.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_dock_window_CLASS_NAME}Implementation.cxx"
    @ONLY)

  set("${_paraview_dock_window_INTERFACES}"
    "${_paraview_dock_window_CLASS_NAME}Implementation"
    PARENT_SCOPE)

  set("${_paraview_dock_window_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_dock_window_CLASS_NAME}Implementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_dock_window_CLASS_NAME}Implementation.h"
    PARENT_SCOPE)
endfunction ()

#[==[.md
### Action group

TODO: What is an action group?

```
paraview_plugin_add_action_group(
  CLASS_NAME <name>
  GROUP_NAME <name>
  INTERFACES <variable>
  SOURCES <variable>)
```

  * `CLASS_NAME`: The name of the action group class.
  * `GROUP_NAME`: The name of the action group.
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_action_group)
  cmake_parse_arguments(_paraview_action_group
    ""
    "CLASS_NAME;GROUP_NAME;INTERFACES;SOURCES"
    ""
    ${ARGN})

  if (_paraview_action_group_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_add_action_group: "
      "${_paraview_action_group_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_action_group_CLASS_NAME)
    message(FATAL_ERROR
      "The `CLASS_NAME` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_action_group_GROUP_NAME)
    message(FATAL_ERROR
      "The `GROUP_NAME` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_action_group_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_action_group_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqActionGroupImplementation.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_action_group_CLASS_NAME}Implementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqActionGroupImplementation.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_action_group_CLASS_NAME}Implementation.cxx"
    @ONLY)

  set("${_paraview_action_group_INTERFACES}"
    "${_paraview_action_group_CLASS_NAME}Implementation"
    PARENT_SCOPE)

  set("${_paraview_action_group_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_action_group_CLASS_NAME}Implementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_action_group_CLASS_NAME}Implementation.h"
    PARENT_SCOPE)
endfunction ()

#[==[.md
### Toolbar

TODO: What is a toolbar?

```
paraview_plugin_add_toolbar(
  CLASS_NAME <name>
  INTERFACES <variable>
  SOURCES <variable>)
```

  * `CLASS_NAME`: The name of the toolbar class.
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_toolbar)
  cmake_parse_arguments(_paraview_toolbar
    ""
    "CLASS_NAME;INTERFACES;SOURCES"
    ""
    ${ARGN})

  if (_paraview_toolbar_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_add_toolbar: "
      "${_paraview_toolbar_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_toolbar_CLASS_NAME)
    message(FATAL_ERROR
      "The `CLASS_NAME` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_toolbar_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_toolbar_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqToolBarImplementation.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_toolbar_CLASS_NAME}Implementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqToolBarImplementation.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_toolbar_CLASS_NAME}Implementation.cxx"
    @ONLY)

  set("${_paraview_toolbar_INTERFACES}"
    "${_paraview_toolbar_CLASS_NAME}Implementation"
    PARENT_SCOPE)

  set("${_paraview_toolbar_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_toolbar_CLASS_NAME}Implementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_toolbar_CLASS_NAME}Implementation.h"
    PARENT_SCOPE)
endfunction ()

#[==[.md
### View frame action group

TODO: What is a view frame action group?

```
paraview_plugin_add_view_frame_action_group(
  CLASS_NAME <name>
  INTERFACES <variable>
  SOURCES <variable>)
```

  * `CLASS_NAME`: The name of the view frame action group class.
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_view_frame_action_group)
  cmake_parse_arguments(_paraview_view_frame_action_group
    ""
    "CLASS_NAME;INTERFACES;SOURCES"
    ""
    ${ARGN})

  if (_paraview_view_frame_action_group_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_add_view_frame_action_group: "
      "${_paraview_view_frame_action_group_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_view_frame_action_group_CLASS_NAME)
    message(FATAL_ERROR
      "The `CLASS_NAME` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_view_frame_action_group_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_view_frame_action_group_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqViewFrameActionGroupImplementation.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_view_frame_action_group_CLASS_NAME}Implementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqViewFrameActionGroupImplementation.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_view_frame_action_group_CLASS_NAME}Implementation.cxx"
    @ONLY)

  set("${_paraview_view_frame_action_group_INTERFACES}"
    "${_paraview_view_frame_action_group_CLASS_NAME}Implementation"
    PARENT_SCOPE)

  set("${_paraview_view_frame_action_group_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_view_frame_action_group_CLASS_NAME}Implementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_view_frame_action_group_CLASS_NAME}Implementation.h"
    PARENT_SCOPE)
endfunction ()

#[==[.md
### Auto start

TODO: What is an auto start?

```
paraview_plugin_add_auto_start(
  CLASS_NAME <name>
  [STARTUP <function>]
  [SHUTDOWN <function>]
  INTERFACES <variable>
  SOURCES <variable>)
```

  * `CLASS_NAME`: The name of the auto start class.
  * `STARTUP`: (Defaults to `startup`) The name of the method to call on
    startup.
  * `SHUTDOWN`: (Defaults to `shutdown`) The name of the method to call on
    shutdown.
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_auto_start)
  cmake_parse_arguments(_paraview_auto_start
    ""
    "CLASS_NAME;INTERFACES;SOURCES;STARTUP;SHUTDOWN"
    ""
    ${ARGN})

  if (_paraview_auto_start_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_add_auto_start: "
      "${_paraview_auto_start_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_auto_start_CLASS_NAME)
    message(FATAL_ERROR
      "The `CLASS_NAME` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_auto_start_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_auto_start_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_auto_start_STARTUP)
    set(_paraview_auto_start_STARTUP "startup")
  endif ()

  if (NOT DEFINED _paraview_auto_start_SHUTDOWN)
    set(_paraview_auto_start_SHUTDOWN "shutdown")
  endif ()

  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqAutoStartImplementation.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_auto_start_CLASS_NAME}Implementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqAutoStartImplementation.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_auto_start_CLASS_NAME}Implementation.cxx"
    @ONLY)

  set("${_paraview_auto_start_INTERFACES}"
    "${_paraview_auto_start_CLASS_NAME}Implementation"
    PARENT_SCOPE)

  set("${_paraview_auto_start_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_auto_start_CLASS_NAME}Implementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_auto_start_CLASS_NAME}Implementation.h"
    PARENT_SCOPE)
endfunction ()

#[==[.md
### Tree layout strategy

TODO: What is a tree layout strategy?

```
paraview_plugin_add_tree_layout_strategy(
  STRATEGY_TYPE <type>
  STRATEGY_LABEL <label>
  INTERFACES <variable>
  SOURCES <variable>)
```

  * `STRATEGY_TYPE`: The name of the tree layout strategy class.
  * `STRATEGY_LABEL`: The label to use for the strategy.
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_tree_layout_strategy)
  cmake_parse_arguments(_paraview_tree_layout_strategy
    ""
    "INTERFACES;SOURCES;STRATEGY_TYPE;STRATEGY_LABEL"
    ""
    ${ARGN})

  if (_paraview_tree_layout_strategy_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR
      "Unparsed arguments for paraview_plugin_add_tree_layout_strategy: "
      "${_paraview_tree_layout_strategy_UNPARSED_ARGUMENTS}")
  endif ()

  if (NOT DEFINED _paraview_tree_layout_strategy_STRATEGY_TYPE)
    message(FATAL_ERROR
      "The `STRATEGY_TYPE` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_tree_layout_strategy_STRATEGY_LABEL)
    message(FATAL_ERROR
      "The `STRATEGY_LABEL` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_tree_layout_strategy_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_tree_layout_strategy_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqTreeLayoutStrategyImplementation.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_tree_layout_strategy_STRATEGY_TYPE}Implementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqTreeLayoutStrategyImplementation.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_tree_layout_strategy_STRATEGY_TYPE}Implementation.cxx"
    @ONLY)

  set("${_paraview_tree_layout_strategy_INTERFACES}"
    "${_paraview_tree_layout_strategy_STRATEGY_TYPE}Implementation"
    PARENT_SCOPE)

  set("${_paraview_tree_layout_strategy_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_tree_layout_strategy_STRATEGY_TYPE}Implementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_tree_layout_strategy_STRATEGY_TYPE}Implementation.h"
    PARENT_SCOPE)
endfunction ()

#[==[.md
### Proxy

TODO: What is a proxy?

```
paraview_plugin_add_proxy(
  NAME <name>
  INTERFACES <variable>
  SOURCES <variable>
  [PROXY_TYPE <type>
1497
    [CLASS_NAME               <class>]
1498
1499
1500
1501
1502
1503
1504
1505
1506
    XML_GROUP                 <group>
    <XML_NAME|XML_NAME_REGEX> <name>]...)
```

  * `NAME`: The name of the proxy.
  * `INTERFACES`: The name of the generated interface.
  * `SOURCES`: The source files generated by the interface.

At least one `PROXY_TYPE` must be specified. Each proxy type must be given an
1507
1508
`XML_GROUP` and either an `XML_NAME` or `XML_NAME_REGEX`. If `CLASS_NAME` is
not given, the `PROXY_TYPE` name is used instead.
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
#]==]
function (paraview_plugin_add_proxy)
  cmake_parse_arguments(_paraview_proxy
    ""
    "INTERFACES;SOURCES;NAME"
    ""
    ${ARGN})

  if (NOT DEFINED _paraview_proxy_INTERFACES)
    message(FATAL_ERROR
      "The `INTERFACES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_proxy_SOURCES)
    message(FATAL_ERROR
      "The `SOURCES` argument is required.")
  endif ()

  if (NOT DEFINED _paraview_proxy_NAME)
    message(FATAL_ERROR
      "The `NAME` argument is required.")
  endif ()

  set(_paraview_proxy_parse "")
  set(_paraview_proxy_type)
  set(_paraview_proxy_types)
  foreach (_paraview_proxy_arg IN LISTS _paraview_proxy_UNPARSED_ARGUMENTS)
    if (_paraview_proxy_parse STREQUAL "")
      set(_paraview_proxy_parse "${_paraview_proxy_arg}")
    elseif (_paraview_proxy_parse STREQUAL "PROXY_TYPE")
      set(_paraview_proxy_type "${_paraview_proxy_arg}")
      list(APPEND _paraview_proxy_types "${_paraview_proxy_type}")
      set(_paraview_proxy_parse "")
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
    elseif (_paraview_proxy_parse STREQUAL "CLASS_NAME")
      if (NOT _paraview_proxy_type)
        message(FATAL_ERROR
          "Missing `PROXY_TYPE` for `CLASS_NAME`")
      endif ()
      if (DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_class_name")
        message(FATAL_ERROR
          "Duplicate `CLASS_NAME` for `${_paraview_proxy_type}`")
      endif ()
      set("_paraview_proxy_type_${_paraview_proxy_type}_class_name"
        "${_paraview_proxy_arg}")
      set(_paraview_proxy_parse "")
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
    elseif (_paraview_proxy_parse STREQUAL "XML_GROUP")
      if (NOT _paraview_proxy_type)
        message(FATAL_ERROR
          "Missing `PROXY_TYPE` for `XML_GROUP`")
      endif ()
      if (DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_group")
        message(FATAL_ERROR
          "Duplicate `XML_GROUP` for `${_paraview_proxy_type}`")
      endif ()
      set("_paraview_proxy_type_${_paraview_proxy_type}_xml_group"
        "${_paraview_proxy_arg}")
      set(_paraview_proxy_parse "")
    elseif (_paraview_proxy_parse STREQUAL "XML_NAME")
      if (NOT _paraview_proxy_type)
        message(FATAL_ERROR
          "Missing `PROXY_TYPE` for `XML_NAME`")
      endif ()
      if (DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_name" OR
1572
          DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_name_regex")
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
        message(FATAL_ERROR
          "Duplicate `XML_NAME` or `XML_NAME_REGEX` for `${_paraview_proxy_type}`")
      endif ()
      set("_paraview_proxy_type_${_paraview_proxy_type}_xml_name"
        "${_paraview_proxy_arg}")
      set(_paraview_proxy_parse "")
    elseif (_paraview_proxy_parse STREQUAL "XML_NAME_REGEX")
      if (NOT _paraview_proxy_type)
        message(FATAL_ERROR
          "Missing `PROXY_TYPE` for `XML_NAME_REGEX`")
      endif ()
      if (DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_name" OR
1585
          DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_name_regex")
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
        message(FATAL_ERROR
          "Duplicate `XML_NAME` or `XML_NAME_REGEX` for `${_paraview_proxy_type}`")
      endif ()
      set("_paraview_proxy_type_${_paraview_proxy_type}_xml_name_regex"
        "${_paraview_proxy_arg}")
      set(_paraview_proxy_parse "")
    else ()
      message(FATAL_ERROR
        "Unknown argument `${_paraview_proxy_parse}`")
    endif ()
  endforeach ()

  if (_paraview_proxy_parse)
    message(FATAL_ERROR
      "Missing argument for `${_paraview_proxy_parse}`")
  endif ()

  if (NOT _paraview_proxy_types)
    message(FATAL_ERROR
      "No `PROXY_TYPE` arguments given")
  endif ()

  set(_paraview_proxy_includes)
  set(_paraview_proxy_body)
  foreach (_paraview_proxy_type IN LISTS _paraview_proxy_types)
    if (NOT DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_group")
      message(FATAL_ERROR
        "Missing `XML_GROUP` for `${_paraview_proxy_type}`")
    endif ()
1615
    if (NOT DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_name" AND
1616
1617
1618
1619
        NOT DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_name_regex")
      message(FATAL_ERROR
        "Missing `XML_NAME` or `XML_NAME_REGEX` for `${_paraview_proxy_type}`")
    endif ()
1620
1621
1622
1623
1624
1625
1626
    if (DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_class_name")
      set(_paraview_proxy_class
        "${_paraview_proxy_type_${_paraview_proxy_type}_class_name}")
    else ()
      set(_paraview_proxy_class
        "${_paraview_proxy_type}")
    endif ()
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638

    set(_paraview_proxy_group "${_paraview_proxy_type_${_paraview_proxy_type}_xml_group}")
    if (DEFINED "_paraview_proxy_type_${_paraview_proxy_type}_xml_name")
      set(_paraview_proxy_name "${_paraview_proxy_type_${_paraview_proxy_type}_xml_name}")
      set(_paraview_proxy_name_type "QString")
      set(_paraview_proxy_cmp "name == proxy->GetXMLName()")
    else ()
      set(_paraview_proxy_name "${_paraview_proxy_type_${_paraview_proxy_type}_xml_name_regex}")
      set(_paraview_proxy_name_type "QRegularExpression")
      set(_paraview_proxy_cmp "QString(proxy->GetXMLName()).contains(name)")
    endif ()

1639
1640
1641
1642
1643
    if (NOT DEFINED "_paraview_proxy_included_${_paraview_proxy_class}")
      string(APPEND _paraview_proxy_includes
        "#include \"${_paraview_proxy_class}.h\"\n")
      set("_paraview_proxy_included_${_paraview_proxy_class}" 1)
    endif ()
1644
1645
1646
1647
1648
1649
    string(APPEND _paraview_proxy_body
      "  {
    static const QString group(\"${_paraview_proxy_group}\");
    static const ${_paraview_proxy_name_type} name(\"${_paraview_proxy_name}\");
    if (group == proxy->GetXMLGroup() && ${_paraview_proxy_cmp})
    {
1650
      return new ${_paraview_proxy_class}(regGroup, regName, proxy, server, nullptr);
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
    }
  }\n")
  endforeach ()

  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqServerManagerModelImplementation.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_proxy_NAME}ServerManagerModelImplementation.h"
    @ONLY)
  configure_file(
    "${_ParaViewPlugin_cmake_dir}/pqServerManagerModelImplementation.cxx.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_proxy_NAME}ServerManagerModelImplementation.cxx"
    @ONLY)

  set("${_paraview_proxy_INTERFACES}"
    "${_paraview_proxy_NAME}ServerManagerModelImplementation"
    PARENT_SCOPE)

  set("${_paraview_proxy_SOURCES}"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_proxy_NAME}ServerManagerModelImplementation.cxx"
    "${CMAKE_CURRENT_BINARY_DIR}/${_paraview_proxy_NAME}ServerManagerModelImplementation.h"
    PARENT_SCOPE)
endfunction ()