VTK  9.0.1
vtkModule.cmake
Go to the documentation of this file.
1 #[==[
2 @defgroup module Module CMake APIs
3 @defgroup module-internal Module Internal CMake APIs
4 @defgroup module-impl Module Implementation CMake APIs
5 @defgroup module-support Module Support CMake APIs
6 #]==]
7 
8 #[==[
9 @ingroup module
10 @page module-api-overview Module API
11 
12 This module includes functions to find and build VTK modules. A module is a set
13 of related functionality. These are then compiled together into libraries at
14 the "kit" level. Each module may be enabled or disabled individually and its
15 dependencies will be built as needed.
16 
17 All functions strictly check their arguments. Any unrecognized or invalid
18 values for a function cause errors to be raised.
19 #]==]
20 
21 #[==[
22 @ingroup module-internal
23 @page module-internal-api Internal API
24 
25 The VTK module system provides some API functions for use by other code which
26 consumes VTK modules (primarily language wrappers). This file documents these
27 APIs. They may start with `_vtk_module`, but they are intended for use in cases
28 of language wrappers or dealing with trickier third party packages.
29 #]==]
30 
31 #[==[
32 @ingroup module-impl
33 @page module-impl-api Implementation API
34 
35 These functions are purely internal implementation details. No guarantees are
36 made for them and they may change at any time (including wrapping code calls).
37 Note that these functions are usually very lax in their argument parsing.
38 #]==]
39 
40 #[==[
41 @ingroup module-internal
42 @brief Conditionally output debug statements
43 
44 The @ref _vtk_module_debug function is provided to assist in debugging. It is
45 controlled by the `_vtk_module_log` variable which contains a list of "domains"
46 to debug.
47 
48 ~~~
49 _vtk_module_debug(<domain> <format>)
50 ~~~
51 
52 If the `domain` is enabled for debugging, the `format` argument is configured
53 and printed. It should contain `@` variable expansions to replace rather than
54 it being done outside. This helps to avoid the cost of generating large strings
55 when debugging is disabled.
56 #]==]
57 function (_vtk_module_debug domain format)
58  if (NOT _vtk_module_log STREQUAL "ALL" AND
59  NOT domain IN_LIST _vtk_module_log)
60  return ()
61  endif ()
62 
63  string(CONFIGURE "${format}" _vtk_module_debug_msg)
64  if (_vtk_module_debug_msg)
65  message(STATUS
66  "VTK module debug ${domain}: ${_vtk_module_debug_msg}")
67  endif ()
68 endfunction ()
69 
70 # TODO: Support finding `vtk.module` and `vtk.kit` contents in the
71 # `CMakeLists.txt` files for the module via a comment header.
72 
73 #[==[
74 @ingroup module
75 @brief Find `vtk.kit` files in a set of directories
76 
77 ~~~
78 vtk_module_find_kits(<output> [<directory>...])
79 ~~~
80 
81 This scans the given directories recursively for `vtk.kit` files and put the
82 paths into the output variable.
83 #]==]
84 function (vtk_module_find_kits output)
85  set(_vtk_find_kits_all)
86  foreach (_vtk_find_kits_directory IN LISTS ARGN)
87  file(GLOB_RECURSE _vtk_find_kits_kits
88  "${_vtk_find_kits_directory}/vtk.kit")
89  list(APPEND _vtk_find_kits_all
90  ${_vtk_find_kits_kits})
91  endforeach ()
92  set("${output}" ${_vtk_find_kits_all} PARENT_SCOPE)
93 endfunction ()
94 
95 #[==[
96 @ingroup module
97 @brief Find `vtk.module` files in a set of directories
98 
99 ~~~
100 vtk_module_find_modules(<output> [<directory>...])
101 ~~~
102 
103 This scans the given directories recursively for `vtk.module` files and put the
104 paths into the output variable. Note that module files are assumed to live next
105 to the `CMakeLists.txt` file which will build the module.
106 #]==]
107 function (vtk_module_find_modules output)
108  set(_vtk_find_modules_all)
109  foreach (_vtk_find_modules_directory IN LISTS ARGN)
110  file(GLOB_RECURSE _vtk_find_modules_modules
111  "${_vtk_find_modules_directory}/vtk.module")
112  list(APPEND _vtk_find_modules_all
113  ${_vtk_find_modules_modules})
114  endforeach ()
115  set("${output}" ${_vtk_find_modules_all} PARENT_SCOPE)
116 endfunction ()
117 
118 #[==[
119 @ingroup module-internal
120 @brief Split a module name into a namespace and target component
121 
122 Module names may include a namespace. This function splits the name into a
123 namespace and target name part.
124 
125 ~~~
126 _vtk_module_split_module_name(<name> <prefix>)
127 ~~~
128 
129 The `<prefix>_NAMESPACE` and `<prefix>_TARGET_NAME` variables will be set in
130 the calling scope.
131 #]==]
132 function (_vtk_module_split_module_name name prefix)
133  string(FIND "${name}" "::" namespace_pos)
134  if (namespace_pos EQUAL -1)
135  set(namespace "")
136  set(target_name "${name}")
137  else ()
138  string(SUBSTRING "${name}" 0 "${namespace_pos}" namespace)
139  math(EXPR name_pos "${namespace_pos} + 2")
140  string(SUBSTRING "${name}" "${name_pos}" -1 target_name)
141  endif ()
142 
143  set("${prefix}_NAMESPACE"
144  "${namespace}"
145  PARENT_SCOPE)
146  set("${prefix}_TARGET_NAME"
147  "${target_name}"
148  PARENT_SCOPE)
149 endfunction ()
150 
151 #[==[
152 @ingroup module
153 @page module-overview Module overview
154 
155 @section module-parse-module vtk.module file contents
156 
157 The `vtk.module` file is parsed and used as arguments to a CMake function which
158 stores information about the module for use when building it. Note that no
159 variable expansion is allowed and it is not CMake code, so no control flow is
160 allowed. Comments are supported and any content after a `#` on a line is
161 treated as a comment. Due to the breakdown of the content, quotes are not
162 meaningful within the files.
163 
164 Example:
165 
166 ~~~
167 NAME
168  VTK::CommonCore
169 LIBRARY_NAME
170  vtkCommonCore
171 DESCRIPTION
172  The base VTK library.
173 GROUPS
174  StandAlone
175 DEPENDS
176  VTK::kwiml
177 PRIVATE_DEPENDS
178  VTK::vtksys
179  VTK::utf8
180 ~~~
181 
182 All values are optional unless otherwise noted. The following arguments are
183 supported:
184 
185  * `NAME`: (Required) The name of the module.
186  * `LIBRARY_NAME`: The base name of the library file. It defaults to the
187  module name, but any namespaces are removed. For example, a `NS::Foo`
188  module will have a default `LIBRARY_NAME` of `Foo`.
189  * `DESCRIPTION`: (Recommended) Short text describing what the module is for.
190  * `KIT`: The name of the kit the module belongs to (see `Kits files` for more
191  information).
192  * `IMPLEMENTABLE`: If present, the module contains logic which supports the
193  autoinit functionality.
194  * `GROUPS`: Modules may belong to "groups" which is exposed as a build
195  option. This allows for enabling a set of modules with a single build
196  option.
197  * `CONDITION`: Arguments to CMake's `if` command which may be used to hide
198  the module for certain platforms or other reasons. If the expression is
199  false, the module is completely ignored.
200  * `DEPENDS`: A list of modules which are required by this module and modules
201  using this module.
202  * `PRIVATE_DEPENDS`: A list of modules which are required by this module, but
203  not by those using this module.
204  * `OPTIONAL_DEPENDS`: A list of modules which are used by this module if
205  enabled; these are treated as `PRIVATE_DEPENDS` if they exist.
206  * `ORDER_DEPENDS`: Dependencies which only matter for ordering. This does not
207  mean that the module will be enabled, just guaranteed to build before this
208  module.
209  * `IMPLEMENTS`: A list of modules for which this module needs to register
210  with.
211  * `TEST_DEPENDS`: Modules required by the test suite for this module.
212  * `TEST_OPTIONAL_DEPENDS`: Modules used by the test suite for this module if
213  available.
214  * `TEST_LABELS`: Labels to apply to the tests of this module. By default, the
215  module name is applied as a label.
216  * `EXCLUDE_WRAP`: If present, this module should not be wrapped in any
217  language.
218  * `THIRD_PARTY`: If present, this module is a third party module.
219 #]==]
220 
221 #[==[
222 @ingroup module-impl
223 @brief Parse `vtk.module` file contents
224 
225 This macro places all `vtk.module` keyword "arguments" into the caller's scope
226 prefixed with the value of `name_output` which is set to the `NAME` of the
227 module.
228 
229 ~~~
230 _vtk_module_parse_module_args(name_output <vtk.module args...>)
231 ~~~
232 
233 For example, this `vtk.module` file:
234 
235 ~~~
236 NAME
237  Namespace::Target
238 LIBRARY_NAME
239  nsTarget
240 ~~~
241 
242 called with `_vtk_module_parse_module_args(name ...)` will set the following
243 variables in the calling scope:
244 
245  - `name`: `Namespace::Target`
246  - `Namespace::Target_LIBRARY_NAME`: `nsTarget`
247 
248 With namespace support for module names, the variable should instead be
249 referenced via `${${name}_LIBRARY_NAME}` instead.
250 #]==]
251 macro (_vtk_module_parse_module_args name_output)
252  cmake_parse_arguments("_name"
253  ""
254  "NAME"
255  ""
256  ${ARGN})
257 
258  if (NOT _name_NAME)
259  message(FATAL_ERROR
260  "A VTK module requires a name (from ${_vtk_scan_module_file}).")
261  endif ()
262  set("${name_output}" "${_name_NAME}")
263 
264  cmake_parse_arguments("${_name_NAME}"
265  "IMPLEMENTABLE;EXCLUDE_WRAP;THIRD_PARTY"
266  "LIBRARY_NAME;NAME;KIT"
267  "GROUPS;DEPENDS;PRIVATE_DEPENDS;OPTIONAL_DEPENDS;ORDER_DEPENDS;TEST_DEPENDS;TEST_OPTIONAL_DEPENDS;TEST_LABELS;DESCRIPTION;CONDITION;IMPLEMENTS"
268  ${ARGN})
269 
270  if (${_name_NAME}_UNPARSED_ARGUMENTS)
271  message(FATAL_ERROR
272  "Unparsed arguments for ${_name_NAME}: "
273  "${${_name_NAME}_UNPARSED_ARGUMENTS}")
274  endif ()
275 
276  if (NOT ${_name_NAME}_DESCRIPTION AND _vtk_module_warnings)
277  message(WARNING "The ${_name_NAME} module should have a description")
278  endif ()
279  string(REPLACE ";" " " "${_name_NAME}_DESCRIPTION" "${${_name_NAME}_DESCRIPTION}")
280 
281  _vtk_module_split_module_name("${_name_NAME}" "${_name_NAME}")
282 
283  if (NOT DEFINED "${_name_NAME}_LIBRARY_NAME")
284  set("${_name_NAME}_LIBRARY_NAME" "${${_name_NAME}_TARGET_NAME}")
285  endif ()
286 
287  if (NOT ${_name_NAME}_LIBRARY_NAME)
288  message(FATAL_ERROR "The ${_name_NAME} module must have a non-empty `LIBRARY_NAME`.")
289  endif ()
290 
291  list(APPEND "${_name_NAME}_TEST_LABELS"
292  "${${_name_NAME}_NAME}"
293  "${${_name_NAME}_LIBRARY_NAME}")
294 endmacro ()
295 
296 #[==[
297 @page module-overview
298 
299 @section module-parse-kit vtk.kit file contents
300 
301 The `vtk.kit` file is parsed similarly to `vtk.module` files. Kits are intended
302 to bring together related modules into a single library in order to reduce the
303 number of objects that linkers need to deal with.
304 
305 Example:
306 
307 ~~~
308 NAME
309  VTK::Common
310 LIBRARY_NAME
311  vtkCommon
312 DESCRIPTION
313  Core utilities for VTK.
314 ~~~
315 
316 All values are optional unless otherwise noted. The following arguments are
317 supported:
318 
319  * `NAME`: (Required) The name of the kit.
320  * `LIBRARY_NAME`: The base name of the library file. It defaults to the
321  module name, but any namespaces are removed. For example, a `NS::Foo`
322  module will have a default `LIBRARY_NAME` of `Foo`.
323  * `DESCRIPTION`: (Recommended) Short text describing what the kit contains.
324 #]==]
325 
326 #[==[
327 @ingroup module-impl
328 @brief Parse `vtk.kit` file contents
329 
330 Just like @ref _vtk_module_parse_module_args, but for kits.
331 #]==]
332 macro (_vtk_module_parse_kit_args name_output)
333  cmake_parse_arguments("_name"
334  ""
335  "NAME"
336  ""
337  ${ARGN})
338 
339  if (NOT _name_NAME)
340  message(FATAL_ERROR
341  "A VTK kit requires a name (from ${_vtk_scan_kit_file}).")
342  endif ()
343  set("${name_output}" "${_name_NAME}")
344 
345  cmake_parse_arguments("${_name_NAME}"
346  ""
347  "NAME;LIBRARY_NAME"
348  "DESCRIPTION"
349  ${ARGN})
350 
351  if (${_name_NAME}_UNPARSED_ARGUMENTS)
352  message(FATAL_ERROR
353  "Unparsed arguments for ${_name_NAME}: "
354  "${${_name_NAME}_UNPARSED_ARGUMENTS}")
355  endif ()
356 
357  _vtk_module_split_module_name("${_name_NAME}" "${_name_NAME}")
358 
359  if (NOT DEFINED "${_name_NAME}_LIBRARY_NAME")
360  set("${_name_NAME}_LIBRARY_NAME" "${${_name_NAME}_TARGET_NAME}")
361  endif ()
362 
363  if (NOT ${_name_NAME}_LIBRARY_NAME)
364  message(FATAL_ERROR "The ${_name_NAME} module must have a non-empty `LIBRARY_NAME`.")
365  endif ()
366 
367  if (NOT ${_name_NAME}_DESCRIPTION AND _vtk_module_warnings)
368  message(WARNING "The ${_name_NAME} kit should have a description")
369  endif ()
370  string(REPLACE ";" " " "${_name_NAME}_DESCRIPTION" "${${_name_NAME}_DESCRIPTION}")
371 endmacro ()
372 
373 #[==[
374 @page module-overview
375 
376 @ingroup module
377 @section module-enable-status Enable status values
378 
379 Modules and groups are enable and disable preferences are specified using a
380 5-way flag setting:
381 
382  - `YES`: The module or group must be built.
383  - `NO`: The module or group must not be built.
384  - `WANT`: The module or group should be built if possible.
385  - `DONT_WANT`: The module or group should only be built if required (e.g.,
386  via a dependency).
387  - `DEFAULT`: Acts as either `WANT` or `DONT_WANT` based on the group settings
388  for the module or `WANT_BY_DEFAULT` option to @ref vtk_module_scan if no
389  other preference is specified. This is usually handled via another setting
390  in the main project.
391 
392 If a `YES` module preference requires a module with a `NO` preference, an error
393 is raised.
394 
395 A module with a setting of `DEFAULT` will look for its first non-`DEFAULT`
396 group setting and only if all of those are set to `DEFAULT` is the
397 `WANT_BY_DEFAULT` setting used.
398 #]==]
399 
400 #[==[
401 @ingroup module-impl
402 @brief Verify enable values
403 
404 Verifies that the variable named as the first parameter is a valid `enable
405 status` value.
406 
407 ~~~
408 _vtk_module_verify_enable_value(var)
409 ~~~
410 #]==]
411 function (_vtk_module_verify_enable_value var)
412  if (NOT (${var} STREQUAL "YES" OR
413  ${var} STREQUAL "WANT" OR
414  ${var} STREQUAL "DONT_WANT" OR
415  ${var} STREQUAL "NO" OR
416  ${var} STREQUAL "DEFAULT"))
417  message(FATAL_ERROR
418  "The `${var}` variable must be one of `YES`, `WANT`, `DONT_WANT`, `NO`, "
419  "or `DEFAULT`. Found `${${var}}`.")
420  endif ()
421 endfunction ()
422 
423 include("${CMAKE_CURRENT_LIST_DIR}/vtkTopologicalSort.cmake")
424 
425 #[==[
426 @ingroup module
427 @brief Scan modules and kits
428 
429 Once all of the modules and kits files have been found, they are "scanned" to
430 determine what modules are enabled or required.
431 
432 ~~~
433 vtk_module_scan(
434  MODULE_FILES <file>...
435  [KIT_FILES <file>...]
436  PROVIDES_MODULES <variable>
437  [PROVIDES_KITS <variable>]
438  [REQUIRES_MODULES <variable>]
439  [REQUEST_MODULES <module>...]
440  [REJECT_MODULES <module>...]
441  [UNRECOGNIZED_MODULES <variable>]
442  [WANT_BY_DEFAULT <ON|OFF>]
443  [HIDE_MODULES_FROM_CACHE <ON|OFF>]
444  [ENABLE_TESTS <ON|OFF|WANT|DEFAULT>])
445 ~~~
446 
447 The `MODULE_FILES` and `PROVIDES_MODULES` arguments are required. Modules which
448 refer to kits must be scanned at the same time as their kits. This is so that
449 modules may not add themselves to kits declared prior. The arguments are as follows:
450 
451  * `MODULE_FILES`: (Required) The list of module files to scan.
452  * `KIT_FILES`: The list of kit files to scan.
453  * `PROVIDES_MODULES`: (Required) This variable will contain the list of
454  modules which are enabled due to this scan.
455  * `PROVIDES_KITS`: (Required if `KIT_FILES` are provided) This variable will
456  contain the list of kits which are enabled due to this scan.
457  * `REQUIRES_MODULES`: This variable will contain the list of modules required
458  by the enabled modules that were not scanned.
459  * `REQUEST_MODULES`: The list of modules required by previous scans.
460  * `REJECT_MODULES`: The list of modules to exclude from the scan. If any of
461  these modules are required, an error will be raised.
462  * `UNRECOGNIZED_MODULES`: This variable will contain the list of requested
463  modules that were not scanned.
464  * `WANT_BY_DEFAULT`: (Defaults to `OFF`) Whether modules should default to
465  being built or not.
466  * `HIDE_MODULES_FROM_CACHE`: (Defaults to `OFF`) Whether or not to hide the
467  control variables from the cache or not. If enabled, modules will not be
468  built unless they are required elsewhere.
469  * `ENABLE_TESTS`: (Defaults to `WANT`) Whether or not modules required by
470  the tests for the scanned modules should be enabled or not.
471  - `ON`: Modules listed as `TEST_DEPENDS` will be required.
472  - `OFF`: Test modules will not be considered.
473  - `WANT`: Test dependencies will enable modules if possible.
474  - `DEFAULT`: Test modules will be enabled if their required dependencies
475  are satisfied and skipped otherwise.
476 
477 @section module-scanning-multiple Scanning multiple groups of modules
478 
479 When scanning complicated projects, multiple scans may be required to get
480 defaults set properly. The `REQUIRES_MODULES`, `REQUEST_MODULES`, and
481 `UNRECOGNIZED_MODULES` arguments are meant to deal with this case. As an
482 example, imagine a project with its source code, third party dependencies, as
483 well as some utility modules which should only be built as necessary. Here, the
484 project would perform three scans, one for each "grouping" of modules:
485 
486 ~~~{.cmake}
487 # Scan our modules first because we need to know what of the other groups we
488 # need.
489 vtk_module_find_modules(our_modules "${CMAKE_CURRENT_SOURCE_DIR}/src")
490 vtk_module_scan(
491  MODULE_FILES ${our_modules}
492  PROVIDES_MODULES our_enabled_modules
493  REQUIRES_MODULES required_modules)
494 
495 # Scan the third party modules, requesting only those that are necessary, but
496 # allowing them to be toggled during the build.
497 vtk_module_find_modules(third_party_modules "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
498 vtk_module_scan(
499  MODULE_FILES ${third_party_modules}
500  PROVIDES_MODULES third_party_enabled_modules
501  # These modules were requested by an earlier scan.
502  REQUEST_MODULES ${required_modules}
503  REQUIRES_MODULES required_modules
504  UNRECOGNIZED_MODULES unrecognized_modules)
505 
506 # These modules are internal and should only be built if necessary. There is no
507 # need to support them being enabled independently, so hide them from the
508 # cache.
509 vtk_module_find_modules(utility_modules "${CMAKE_CURRENT_SOURCE_DIR}/utilities")
510 vtk_module_scan(
511  MODULE_FILES ${utility_modules}
512  PROVIDES_MODULES utility_enabled_modules
513  # These modules were either requested or unrecognized by an earlier scan.
514  REQUEST_MODULES ${required_modules}
515  ${unrecognized_modules}
516  REQUIRES_MODULES required_modules
517  UNRECOGNIZED_MODULES unrecognized_modules
518  HIDE_MODULES_FROM_CACHE ON)
519 
520 if (required_modules OR unrecognized_modules)
521  # Not all of the modules we required were found. This should probably error out.
522 endif ()
523 ~~~
524 #]==]
525 function (vtk_module_scan)
526  cmake_parse_arguments(_vtk_scan
527  ""
528  "WANT_BY_DEFAULT;HIDE_MODULES_FROM_CACHE;PROVIDES_MODULES;REQUIRES_MODULES;UNRECOGNIZED_MODULES;ENABLE_TESTS;PROVIDES_KITS"
529  "MODULE_FILES;KIT_FILES;REQUEST_MODULES;REJECT_MODULES"
530  ${ARGN})
531 
532  if (_vtk_scan_UNPARSED_ARGUMENTS)
533  message(FATAL_ERROR
534  "Unparsed arguments for vtk_module_scan: "
535  "${_vtk_scan_UNPARSED_ARGUMENTS}")
536  endif ()
537 
538  if (NOT DEFINED _vtk_scan_WANT_BY_DEFAULT)
539  set(_vtk_scan_WANT_BY_DEFAULT OFF)
540  endif ()
541 
542  if (NOT DEFINED _vtk_scan_HIDE_MODULES_FROM_CACHE)
543  set(_vtk_scan_HIDE_MODULES_FROM_CACHE OFF)
544  endif ()
545 
546  if (NOT DEFINED _vtk_scan_PROVIDES_MODULES)
547  message(FATAL_ERROR
548  "The `PROVIDES_MODULES` argument is required.")
549  endif ()
550 
551  if (NOT DEFINED _vtk_scan_PROVIDES_KITS AND _vtk_scan_KIT_FILES)
552  message(FATAL_ERROR
553  "The `PROVIDES_KITS` argument is required.")
554  endif ()
555 
556  if (NOT DEFINED _vtk_scan_ENABLE_TESTS)
557  set(_vtk_scan_ENABLE_TESTS "WANT")
558  endif ()
559 
560  if (NOT (_vtk_scan_ENABLE_TESTS STREQUAL "ON" OR
561  _vtk_scan_ENABLE_TESTS STREQUAL "OFF" OR
562  _vtk_scan_ENABLE_TESTS STREQUAL "WANT" OR
563  _vtk_scan_ENABLE_TESTS STREQUAL "DEFAULT"))
564  message(FATAL_ERROR
565  "The `ENABLE_TESTS` argument must be one of `ON`, `OFF`, `WANT`, or "
566  "`DEFAULT`. " "Received `${_vtk_scan_ENABLE_TESTS}`.")
567  endif ()
568 
569  if (NOT _vtk_scan_MODULE_FILES)
570  message(FATAL_ERROR
571  "No module files given to scan.")
572  endif ()
573 
574  set(_vtk_scan_option_default_type STRING)
575  if (_vtk_scan_HIDE_MODULES_FROM_CACHE)
576  set(_vtk_scan_option_default_type INTERNAL)
577  endif ()
578 
579  set(_vtk_scan_all_kits)
580 
581  foreach (_vtk_scan_kit_file IN LISTS _vtk_scan_KIT_FILES)
582  if (NOT IS_ABSOLUTE "${_vtk_scan_kit_file}")
583  set(_vtk_scan_kit_file "${CMAKE_CURRENT_SOURCE_DIR}/${_vtk_scan_kit_file}")
584  endif ()
585  set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND
586  PROPERTY
587  CMAKE_CONFIGURE_DEPENDS "${_vtk_scan_kit_file}")
588 
589  file(READ "${_vtk_scan_kit_file}" _vtk_scan_kit_args)
590  # Replace comments.
591  string(REGEX REPLACE "#[^\n]*\n" "\n" _vtk_scan_kit_args "${_vtk_scan_kit_args}")
592  # Use argument splitting.
593  string(REGEX REPLACE "( |\n)+" ";" _vtk_scan_kit_args "${_vtk_scan_kit_args}")
594  _vtk_module_parse_kit_args(_vtk_scan_kit_name ${_vtk_scan_kit_args})
595  _vtk_module_debug(kit "@_vtk_scan_kit_name@ declared by @_vtk_scan_kit_file@")
596 
597  list(APPEND _vtk_scan_all_kits
598  "${_vtk_scan_kit_name}")
599 
600  # Set properties for building.
601  set_property(GLOBAL
602  PROPERTY
603  "_vtk_kit_${_vtk_scan_kit_name}_namespace" "${${_vtk_scan_kit_name}_NAMESPACE}")
604  set_property(GLOBAL
605  PROPERTY
606  "_vtk_kit_${_vtk_scan_kit_name}_target_name" "${${_vtk_scan_kit_name}_TARGET_NAME}")
607  set_property(GLOBAL
608  PROPERTY
609  "_vtk_kit_${_vtk_scan_kit_name}_library_name" "${${_vtk_scan_kit_name}_LIBRARY_NAME}")
610  endforeach ()
611 
612  set(_vtk_scan_all_modules)
613  set(_vtk_scan_all_groups)
614  set(_vtk_scan_rejected_modules)
615 
616  # Read all of the module files passed in.
617  foreach (_vtk_scan_module_file IN LISTS _vtk_scan_MODULE_FILES)
618  if (NOT IS_ABSOLUTE "${_vtk_scan_module_file}")
619  set(_vtk_scan_module_file "${CMAKE_CURRENT_SOURCE_DIR}/${_vtk_scan_module_file}")
620  endif ()
621  set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND
622  PROPERTY
623  CMAKE_CONFIGURE_DEPENDS "${_vtk_scan_module_file}")
624 
625  file(READ "${_vtk_scan_module_file}" _vtk_scan_module_args)
626  # Replace comments.
627  string(REGEX REPLACE "#[^\n]*\n" "\n" _vtk_scan_module_args "${_vtk_scan_module_args}")
628  # Use argument splitting.
629  string(REGEX REPLACE "( |\n)+" ";" _vtk_scan_module_args "${_vtk_scan_module_args}")
630  _vtk_module_parse_module_args(_vtk_scan_module_name ${_vtk_scan_module_args})
631  _vtk_module_debug(module "@_vtk_scan_module_name@ declared by @_vtk_scan_module_file@")
632  string(REPLACE "::" "_" _vtk_scan_module_name_safe "${_vtk_scan_module_name}")
633 
634  if (${_vtk_scan_module_name}_THIRD_PARTY)
635  if (_vtk_module_warnings)
636  if (${_vtk_scan_module_name}_EXCLUDE_WRAP)
637  message(WARNING
638  "The third party ${_vtk_scan_module_name} module does not need to "
639  "declare `EXCLUDE_WRAP` also.")
640  endif ()
641  endif ()
642  if (${_vtk_scan_module_name}_IMPLEMENTABLE)
643  message(FATAL_ERROR
644  "The third party ${_vtk_scan_module_name} module may not be "
645  "`IMPLEMENTABLE`.")
646  endif ()
647  if (${_vtk_scan_module_name}_IMPLEMENTS)
648  message(FATAL_ERROR
649  "The third party ${_vtk_scan_module_name} module may not "
650  "`IMPLEMENTS` another module.")
651  endif ()
652  if (${_vtk_scan_module_name}_KIT)
653  message(FATAL_ERROR
654  "The third party ${_vtk_scan_module_name} module may not be part of "
655  "a kit (${${_vtk_scan_module_name}_KIT}).")
656  endif ()
657  endif ()
658 
659  if (${_vtk_scan_module_name}_KIT)
660  if (NOT ${_vtk_scan_module_name}_KIT IN_LIST _vtk_scan_all_kits)
661  message(FATAL_ERROR
662  "The ${_vtk_scan_module_name} belongs to the "
663  "${${_vtk_scan_module_name}_KIT} kit, but it has not been scanned.")
664  endif ()
665  endif ()
666 
667  # Check if the module is visible. Modules which have a failing condition
668  # are basically invisible.
669  if (DEFINED ${_vtk_scan_module_name}_CONDITION)
670  if (NOT (${${_vtk_scan_module_name}_CONDITION}))
671  if (DEFINED "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}")
672  set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}"
673  PROPERTY
674  TYPE INTERNAL)
675  endif ()
676  _vtk_module_debug(module "@_vtk_scan_module_name@ hidden by its `CONDITION`")
677  continue ()
678  endif ()
679  endif ()
680 
681  # Determine whether we should provide a user-visible option for this
682  # module.
683  set(_vtk_build_use_option 1)
684  if (DEFINED _vtk_scan_REQUEST_MODULE)
685  if (_vtk_scan_module_name IN_LIST _vtk_scan_REQUEST_MODULE)
686  set("_vtk_scan_enable_${_vtk_scan_module_name}" YES)
687  set(_vtk_build_use_option 0)
688  endif ()
689  endif ()
690  if (DEFINED _vtk_scan_REJECT_MODULES)
691  if (_vtk_scan_module_name IN_LIST _vtk_scan_REJECT_MODULES)
692  if (NOT _vtk_build_use_option)
693  message(FATAL_ERROR
694  "The ${_vtk_scan_module_name} module has been requested and rejected.")
695  endif ()
696  # Rejected modules should not have a build option.
697  set(_vtk_build_use_option 0)
698  list(APPEND _vtk_scan_rejected_modules
699  "${_vtk_scan_module_name}")
700  endif ()
701  endif ()
702 
703  # Handle cache entries and determine the enabled state of the module from
704  # the relevant cache variables.
705  if (_vtk_build_use_option)
706  set("VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}" "DEFAULT"
707  CACHE STRING "Enable the ${_vtk_scan_module_name} module. ${${_vtk_scan_module_name}_DESCRIPTION}")
708  mark_as_advanced("VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}")
709  set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}"
710  PROPERTY
711  STRINGS "YES;WANT;DONT_WANT;NO;DEFAULT")
712  _vtk_module_verify_enable_value("VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}")
713 
714  if (NOT VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe} STREQUAL "DEFAULT")
715  set("_vtk_scan_enable_${_vtk_scan_module_name}" "${VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}}")
716  _vtk_module_debug(enable "@_vtk_scan_module_name@ is `${_vtk_scan_enable_${_vtk_scan_module_name}}` by cache value")
717  endif ()
718 
719  # Check the state of any groups the module belongs to.
720  foreach (_vtk_scan_group IN LISTS "${_vtk_scan_module_name}_GROUPS")
721  if (NOT DEFINED "VTK_GROUP_ENABLE_${_vtk_scan_group}")
722  set(_vtk_scan_group_default "DEFAULT")
723  if (DEFINED "_vtk_module_group_default_${_vtk_scan_group}")
724  set(_vtk_scan_group_default "${_vtk_module_group_default_${_vtk_scan_group}}")
725  endif ()
726  set("VTK_GROUP_ENABLE_${_vtk_scan_group}" "${_vtk_scan_group_default}"
727  CACHE STRING "Enable the ${_vtk_scan_group} group modules.")
728  set_property(CACHE "VTK_GROUP_ENABLE_${_vtk_scan_group}"
729  PROPERTY
730  STRINGS "YES;WANT;DONT_WANT;NO;DEFAULT")
731  set_property(CACHE "VTK_GROUP_ENABLE_${_vtk_scan_group}"
732  PROPERTY
733  TYPE "${_vtk_scan_option_default_type}")
734  endif ()
735  _vtk_module_verify_enable_value("VTK_GROUP_ENABLE_${_vtk_scan_group}")
736 
737  if (NOT VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe} STREQUAL "DEFAULT")
738  continue ()
739  endif ()
740 
741  # Determine the state of the group.
742  set(_vtk_scan_group_enable "${VTK_GROUP_ENABLE_${_vtk_scan_group}}")
743  if (NOT _vtk_scan_group_enable STREQUAL "DEFAULT")
744  set("_vtk_scan_enable_${_vtk_scan_module_name}" "${_vtk_scan_group_enable}")
745  _vtk_module_debug(enable "@_vtk_scan_module_name@ is DEFAULT, using group `@_vtk_scan_group@` setting: @_vtk_scan_group_enable@")
746  endif ()
747  endforeach ()
748 
749  set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}"
750  PROPERTY
751  TYPE "${_vtk_scan_option_default_type}")
752  endif ()
753 
754  if (NOT DEFINED "_vtk_scan_enable_${_vtk_scan_module_name}" AND
755  VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe} STREQUAL "DEFAULT")
756  if (_vtk_scan_WANT_BY_DEFAULT)
757  set("_vtk_scan_enable_${_vtk_scan_module_name}" "WANT")
758  else ()
759  set("_vtk_scan_enable_${_vtk_scan_module_name}" "DONT_WANT")
760  endif ()
761  _vtk_module_debug(enable "@_vtk_scan_module_name@ is DEFAULT, using `WANT_BY_DEFAULT`: ${_vtk_scan_enable_${_vtk_scan_module_name}}")
762  endif ()
763 
764  list(APPEND _vtk_scan_all_modules
765  "${_vtk_scan_module_name}")
766  set("_vtk_scan_${_vtk_scan_module_name}_all_depends"
767  ${${_vtk_scan_module_name}_DEPENDS}
768  ${${_vtk_scan_module_name}_PRIVATE_DEPENDS})
769 
770  if (${_vtk_scan_module_name}_THIRD_PARTY)
771  set("${_vtk_scan_module_name}_EXCLUDE_WRAP" TRUE)
772  set("${_vtk_scan_module_name}_IMPLEMENTABLE" FALSE)
773  set("${_vtk_scan_module_name}_IMPLEMENTS")
774  endif ()
775 
776  if (${_vtk_scan_module_name}_KIT)
777  _vtk_module_debug(kit "@_vtk_scan_module_name@ belongs to the ${${_vtk_scan_module_name}_KIT} kit")
778  endif ()
779 
780  # Set properties for building.
781  set_property(GLOBAL
782  PROPERTY
783  "_vtk_module_${_vtk_scan_module_name}_file" "${_vtk_scan_module_file}")
784  set_property(GLOBAL
785  PROPERTY
786  "_vtk_module_${_vtk_scan_module_name}_namespace" "${${_vtk_scan_module_name}_NAMESPACE}")
787  set_property(GLOBAL
788  PROPERTY
789  "_vtk_module_${_vtk_scan_module_name}_target_name" "${${_vtk_scan_module_name}_TARGET_NAME}")
790  set_property(GLOBAL
791  PROPERTY
792  "_vtk_module_${_vtk_scan_module_name}_library_name" "${${_vtk_scan_module_name}_LIBRARY_NAME}")
793  set_property(GLOBAL
794  PROPERTY
795  "_vtk_module_${_vtk_scan_module_name}_third_party" "${${_vtk_scan_module_name}_THIRD_PARTY}")
796  set_property(GLOBAL
797  PROPERTY
798  "_vtk_module_${_vtk_scan_module_name}_exclude_wrap" "${${_vtk_scan_module_name}_EXCLUDE_WRAP}")
799  set_property(GLOBAL
800  PROPERTY
801  "_vtk_module_${_vtk_scan_module_name}_kit" "${${_vtk_scan_module_name}_KIT}")
802  set_property(GLOBAL
803  PROPERTY
804  "_vtk_module_${_vtk_scan_module_name}_depends" "${${_vtk_scan_module_name}_DEPENDS}")
805  set_property(GLOBAL
806  PROPERTY
807  "_vtk_module_${_vtk_scan_module_name}_order_depends" "${${_vtk_scan_module_name}_ORDER_DEPENDS}")
808  set_property(GLOBAL
809  PROPERTY
810  "_vtk_module_${_vtk_scan_module_name}_private_depends" "${${_vtk_scan_module_name}_PRIVATE_DEPENDS}")
811  set_property(GLOBAL
812  PROPERTY
813  "_vtk_module_${_vtk_scan_module_name}_optional_depends" "${${_vtk_scan_module_name}_OPTIONAL_DEPENDS}")
814  set_property(GLOBAL
815  PROPERTY
816  "_vtk_module_${_vtk_scan_module_name}_test_depends" "${${_vtk_scan_module_name}_TEST_DEPENDS}")
817  set_property(GLOBAL
818  PROPERTY
819  "_vtk_module_${_vtk_scan_module_name}_test_optional_depends" "${${_vtk_scan_module_name}_TEST_OPTIONAL_DEPENDS}")
820  set_property(GLOBAL
821  PROPERTY
822  "_vtk_module_${_vtk_scan_module_name}_test_labels" "${${_vtk_scan_module_name}_TEST_LABELS}")
823  set_property(GLOBAL
824  PROPERTY
825  "_vtk_module_${_vtk_scan_module_name}_implements" "${${_vtk_scan_module_name}_IMPLEMENTS}")
826  set_property(GLOBAL
827  PROPERTY
828  "_vtk_module_${_vtk_scan_module_name}_implementable" "${${_vtk_scan_module_name}_IMPLEMENTABLE}")
829  endforeach ()
830 
831  set(_vtk_scan_current_modules "${_vtk_scan_all_modules}")
832  vtk_topological_sort(_vtk_scan_all_modules "_vtk_scan_" "_all_depends")
833 
834  set(_vtk_scan_provided_modules)
835  set(_vtk_scan_required_modules)
836  set(_vtk_scan_disabled_modules)
837 
838  # Seed the `_vtk_scan_provide_` variables with modules requested and rejected
839  # as arguments.
840  foreach (_vtk_scan_request_module IN LISTS _vtk_scan_REQUEST_MODULES)
841  set("_vtk_scan_provide_${_vtk_scan_request_module}" ON)
842  _vtk_module_debug(provide "@_vtk_scan_request_module@ is provided via `REQUEST_MODULES`")
843  endforeach ()
844  foreach (_vtk_scan_reject_module IN LISTS _vtk_scan_REJECT_MODULES)
845  set("_vtk_scan_provide_${_vtk_scan_reject_module}" OFF)
846  _vtk_module_debug(provide "@_vtk_scan_reject_module@ is not provided via `REJECT_MODULES`")
847  endforeach ()
848 
849  # Traverse the graph classifying the quad-state for enabling modules into a
850  # boolean stored in the `_vtk_scan_provide_` variables.
851  foreach (_vtk_scan_module IN LISTS _vtk_scan_all_modules)
852  if (NOT _vtk_scan_module IN_LIST _vtk_scan_current_modules)
853  _vtk_module_debug(provide "@_vtk_scan_module@ is ignored because it is not in the current scan set")
854  continue ()
855  endif ()
856 
857  if (DEFINED "_vtk_scan_provide_${_vtk_scan_module}")
858  # Already done.
859  elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "YES")
860  # Mark enabled modules as to-be-provided. Any errors with requiring a
861  # disabled module will be dealt with later.
862  set("_vtk_scan_provide_${_vtk_scan_module}" ON)
863  _vtk_module_debug(provide "@_vtk_scan_module@ is provided due to `YES` setting")
864  elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "WANT")
865  # Check to see if we can provide this module by checking of any of its
866  # dependencies have been disabled.
867  set(_vtk_scan_test_depends)
868  if (NOT ${_vtk_scan_module}_THIRD_PARTY AND _vtk_scan_ENABLE_TESTS STREQUAL "ON")
869  # If the tests have to be on, we also need the test dependencies.
870  set(_vtk_scan_test_depends "${${_vtk_scan_module}_TEST_DEPENDS}")
871  endif ()
872 
873  set("_vtk_scan_provide_${_vtk_scan_module}" ON)
874  _vtk_module_debug(provide "@_vtk_scan_module@ is provided due to `WANT` setting")
875  foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends)
876  if (DEFINED "_vtk_scan_provide_${_vtk_scan_module_depend}" AND NOT _vtk_scan_provide_${_vtk_scan_module_depend})
877  set("_vtk_scan_provide_${_vtk_scan_module}" OFF)
878  _vtk_module_debug(provide "@_vtk_scan_module@ is not provided due to not provided dependency @_vtk_scan_module_depend@")
879  break ()
880  endif ()
881  endforeach ()
882  elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "DONT_WANT")
883  # Check for disabled dependencies and disable if so.
884  foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends)
885  if (DEFINED "_vtk_scan_provide_${_vtk_scan_module_depend}" AND NOT _vtk_scan_provide_${_vtk_scan_module_depend})
886  set("_vtk_scan_provide_${_vtk_scan_module}" OFF)
887  _vtk_module_debug(provide "@_vtk_scan_module@ is not provided due to not provided dependency @_vtk_scan_module_depend@")
888  break ()
889  endif ()
890  endforeach ()
891  elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "NO")
892  # Disable the module.
893  set("_vtk_scan_provide_${_vtk_scan_module}" OFF)
894  _vtk_module_debug(provide "@_vtk_scan_module@ is not provided due to `NO` setting")
895  endif ()
896 
897  # Collect disabled modules into a list.
898  if (DEFINED "_vtk_scan_provide_${_vtk_scan_module}" AND NOT _vtk_scan_provide_${_vtk_scan_module})
899  list(APPEND _vtk_scan_disabled_modules
900  "${_vtk_scan_module}")
901  endif ()
902 
903  if (NOT DEFINED "_vtk_scan_provide_${_vtk_scan_module}")
904  _vtk_module_debug(provide "@_vtk_scan_module@ is indeterminite (${_vtk_scan_enable_${_vtk_scan_module}})")
905  endif ()
906  endforeach ()
907 
908  # Scan all modules from the top of tree to the bottom.
909  list(REVERSE _vtk_scan_all_modules)
910  foreach (_vtk_scan_module IN LISTS _vtk_scan_all_modules)
911  if (NOT _vtk_scan_module IN_LIST _vtk_scan_current_modules)
912  continue ()
913  endif ()
914 
915  # If we're providing this module...
916  if (_vtk_scan_provide_${_vtk_scan_module})
917  list(APPEND _vtk_scan_provided_modules
918  "${_vtk_scan_module}")
919 
920  # Grab any test dependencies that are required.
921  set(_vtk_scan_test_depends)
922  set(_vtk_scan_test_wants)
923  if (NOT ${_vtk_scan_module}_THIRD_PARTY)
924  if (_vtk_scan_ENABLE_TESTS STREQUAL "ON")
925  set_property(GLOBAL APPEND
926  PROPERTY
927  "_vtk_module_test_modules" "${_vtk_scan_module}")
928  set(_vtk_scan_test_depends "${${_vtk_scan_module}_TEST_DEPENDS}")
929  elseif (_vtk_scan_ENABLE_TESTS STREQUAL "WANT")
930  set_property(GLOBAL APPEND
931  PROPERTY
932  "_vtk_module_test_modules" "${_vtk_scan_module}")
933  set(_vtk_scan_test_wants _vtk_scan_wants_marker ${${_vtk_scan_module}_TEST_DEPENDS})
934  elseif (_vtk_scan_ENABLE_TESTS STREQUAL "DEFAULT")
935  set_property(GLOBAL APPEND
936  PROPERTY
937  "_vtk_module_test_modules" "${_vtk_scan_module}")
938  elseif (_vtk_scan_ENABLE_TESTS STREQUAL "OFF")
939  # Nothing to do.
940  else ()
941  message(FATAL_ERROR
942  "Unrecognized option for ENABLE_TESTS: ${_vtk_module_ENABLE_TESTS}.")
943  endif ()
944  endif ()
945 
946  # Add all dependent modules to the list of required or provided modules.
947  set(_vtk_scan_is_wanting 0)
948  foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends _vtk_scan_test_wants)
949  if (_vtk_scan_module_depend STREQUAL "_vtk_scan_wants_marker")
950  set(_vtk_scan_is_wanting 1)
951  continue ()
952  endif ()
953  # Though we need to error if this would cause a disabled module to be
954  # provided.
955  if (_vtk_scan_module_depend IN_LIST _vtk_scan_disabled_modules)
956  if (_vtk_scan_is_wanting)
957  continue ()
958  else ()
959  message(FATAL_ERROR
960  "The ${_vtk_scan_module} module requires the disabled module ${_vtk_scan_module_depend}.")
961  endif ()
962  endif ()
963 
964  if (DEFINED "_vtk_scan_provide_${_vtk_scan_module_depend}")
965  if (NOT _vtk_scan_provide_${_vtk_scan_module_depend})
966  message(FATAL_ERROR
967  "The `${_vtk_scan_module_depend} should be provided, but is disabled.")
968  endif ()
969  continue ()
970  endif ()
971  set("_vtk_scan_provide_${_vtk_scan_module_depend}" ON)
972 
973  if (NOT _vtk_scan_module_depend IN_LIST _vtk_scan_current_modules)
974  if (NOT TARGET "${_vtk_scan_module_depend}")
975  _vtk_module_debug(provide "@_vtk_scan_module_depend@ is external and required due to dependency from @_vtk_scan_module@")
976  endif ()
977  list(APPEND _vtk_scan_required_modules
978  "${_vtk_scan_module_depend}")
979  else ()
980  _vtk_module_debug(provide "@_vtk_scan_module_depend@ is provided due to dependency from @_vtk_scan_module@")
981  list(APPEND _vtk_scan_provided_modules
982  "${_vtk_scan_module_depend}")
983  endif ()
984  endforeach ()
985  endif ()
986  endforeach ()
987 
988  if (_vtk_scan_provided_modules)
989  list(REMOVE_DUPLICATES _vtk_scan_provided_modules)
990  endif ()
991 
992  set(_vtk_scan_provided_kits)
993 
994  # Build a list of kits which contain the provided modules.
995  foreach (_vtk_scan_provided_module IN LISTS _vtk_scan_provided_modules)
996  if (${_vtk_scan_provided_module}_KIT)
997  list(APPEND _vtk_scan_provided_kits
998  "${${_vtk_scan_provided_module}_KIT}")
999  set_property(GLOBAL APPEND
1000  PROPERTY
1001  "_vtk_kit_${${_vtk_scan_provided_module}_KIT}_kit_modules" "${_vtk_scan_provided_module}")
1002  endif ()
1003  endforeach ()
1004 
1005  if (_vtk_scan_provided_kits)
1006  list(REMOVE_DUPLICATES _vtk_scan_provided_kits)
1007  endif ()
1008 
1009  if (_vtk_scan_required_modules)
1010  list(REMOVE_DUPLICATES _vtk_scan_required_modules)
1011  endif ()
1012 
1013  set(_vtk_scan_unrecognized_modules
1014  ${_vtk_scan_REQUEST_MODULES}
1015  ${_vtk_scan_REJECT_MODULES})
1016 
1017  if (_vtk_scan_unrecognized_modules AND (_vtk_scan_provided_modules OR _vtk_scan_rejected_modules))
1018  list(REMOVE_ITEM _vtk_scan_unrecognized_modules
1019  ${_vtk_scan_provided_modules}
1020  ${_vtk_scan_rejected_modules})
1021  endif ()
1022 
1023  set("${_vtk_scan_PROVIDES_MODULES}"
1024  ${_vtk_scan_provided_modules}
1025  PARENT_SCOPE)
1026 
1027  if (DEFINED _vtk_scan_REQUIRES_MODULES)
1028  set("${_vtk_scan_REQUIRES_MODULES}"
1029  ${_vtk_scan_required_modules}
1030  PARENT_SCOPE)
1031  endif ()
1032 
1033  if (DEFINED _vtk_scan_UNRECOGNIZED_MODULES)
1034  set("${_vtk_scan_UNRECOGNIZED_MODULES}"
1035  ${_vtk_scan_unrecognized_modules}
1036  PARENT_SCOPE)
1037  endif ()
1038 
1039  if (DEFINED _vtk_scan_PROVIDES_KITS)
1040  set("${_vtk_scan_PROVIDES_KITS}"
1041  ${_vtk_scan_provided_kits}
1042  PARENT_SCOPE)
1043  endif ()
1044 endfunction ()
1045 
1046 #[==[
1047 @page module-overview
1048 
1049 @section module-target-functions Module-as-target functions
1050 
1051 Due to the nature of VTK modules supporting being built as kits, the module
1052 name might not be usable as a target to CMake's `target_` family of commands.
1053 Instead, there are various wrappers around them which take the module name as
1054 an argument. These handle the forwarding of relevant information to the kit
1055 library as well where necessary.
1056 
1057  - @ref vtk_module_set_properties
1058  - @ref vtk_module_set_property
1059  - @ref vtk_module_get_property
1060  - @ref vtk_module_depend
1061  - @ref vtk_module_include
1062  - @ref vtk_module_definitions
1063  - @ref vtk_module_compile_options
1064  - @ref vtk_module_compile_features
1065  - @ref vtk_module_link
1066  - @ref vtk_module_link_options
1067 #]==]
1068 
1069 #[==[
1070 @page module-internal-api
1071 
1072 @section module-target-internals Module target internals
1073 
1074 When manipulating modules as targets, there are a few functions provided for
1075 use in wrapping code to more easily access them.
1076 
1077  - @ref _vtk_module_real_target
1078  - @ref _vtk_module_real_target_kit
1079 #]==]
1080 
1081 #[==[
1082 @ingroup module-internal
1083 @brief The real target for a module
1084 
1085 ~~~
1086 _vtk_module_real_target(<var> <module>)
1087 ~~~
1088 
1089 Sometimes the actual, core target for a module is required (e.g., setting
1090 CMake-level target properties or install rules). This function returns the real
1091 target for a module.
1092 #]==]
1093 function (_vtk_module_real_target var module)
1094  if (ARGN)
1095  message(FATAL_ERROR
1096  "Unparsed arguments for _vtk_module_real_target: ${ARGN}.")
1097  endif ()
1098 
1099  set(_vtk_real_target_res "")
1100  if (TARGET "${module}")
1101  get_property(_vtk_real_target_imported
1102  TARGET "${module}"
1103  PROPERTY IMPORTED)
1104  if (_vtk_real_target_imported)
1105  set(_vtk_real_target_res "${module}")
1106  endif ()
1107  endif ()
1108 
1109  if (NOT _vtk_real_target_res)
1110  get_property(_vtk_real_target_res GLOBAL
1111  PROPERTY "_vtk_module_${module}_target_name")
1112  # Querying during the build.
1113  if (DEFINED _vtk_build_BUILD_WITH_KITS AND _vtk_build_BUILD_WITH_KITS)
1114  get_property(_vtk_real_target_kit GLOBAL
1115  PROPERTY "_vtk_module_${module}_kit")
1116  if (_vtk_real_target_kit)
1117  set(_vtk_real_target_res "${_vtk_real_target_res}-objects")
1118  endif ()
1119  # A query for after the module is built.
1120  elseif (TARGET "${_vtk_real_target_res}-objects")
1121  set(_vtk_real_target_res "${_vtk_real_target_res}-objects")
1122  endif ()
1123  endif ()
1124 
1125  if (NOT _vtk_real_target_res)
1126  get_target_property(_vtk_real_target_res "${module}" NAME)
1127  endif()
1128 
1129  if (NOT _vtk_real_target_res)
1130  set(_vtk_real_target_msg "")
1131  if (NOT TARGET "${module}")
1132  if (DEFINED _vtk_build_module)
1133  set(_vtk_real_target_msg
1134  " Is a module dependency missing?")
1135  else ()
1136  set(_vtk_real_target_msg
1137  " Is a `find_package` missing a required component?")
1138  endif ()
1139  endif ()
1140  message(FATAL_ERROR
1141  "Failed to determine the real target for the `${module}` "
1142  "module.${_vtk_real_target_msg}")
1143  endif ()
1144 
1145  set("${var}"
1146  "${_vtk_real_target_res}"
1147  PARENT_SCOPE)
1148 endfunction ()
1149 
1150 #[==[
1151 @ingroup module-internal
1152 @brief The real target for a kit
1153 
1154 ~~~
1155 _vtk_module_real_target_kit(<var> <kit>)
1156 ~~~
1157 
1158 Sometimes the actual, core target for a module is required (e.g., setting
1159 CMake-level target properties or install rules). This function returns the real
1160 target for a kit.
1161 #]==]
1162 function (_vtk_module_real_target_kit var kit)
1163  if (ARGN)
1164  message(FATAL_ERROR
1165  "Unparsed arguments for _vtk_module_real_target_kit: ${ARGN}.")
1166  endif ()
1167 
1168  set(_vtk_real_target_res "")
1169  if (TARGET "${kit}")
1170  get_property(_vtk_real_target_imported
1171  TARGET "${kit}"
1172  PROPERTY IMPORTED)
1173  if (_vtk_real_target_imported)
1174  set(_vtk_real_target_res "${kit}")
1175  endif ()
1176  endif ()
1177 
1178  if (NOT _vtk_real_target_res)
1179  get_property(_vtk_real_target_res GLOBAL
1180  PROPERTY "_vtk_kit_${kit}_target_name")
1181  endif ()
1182 
1183  if (NOT _vtk_real_target_res)
1184  message(FATAL_ERROR
1185  "Failed to determine the real target for the `${kit}` kit.")
1186  endif ()
1187 
1188  set("${var}"
1189  "${_vtk_real_target_res}"
1190  PARENT_SCOPE)
1191 endfunction ()
1192 
1193 #[==[
1194 @ingroup module
1195 @brief Set multiple properties on a module
1196 
1197 A wrapper around `set_target_properties` that works for modules.
1198 
1199 ~~~
1200 vtk_module_set_properties(<module>
1201  [<property> <value>]...)
1202 ~~~
1203 #]==]
1204 function (vtk_module_set_properties module)
1205  _vtk_module_real_target(_vtk_set_properties_target "${module}")
1206 
1207  set_target_properties("${_vtk_set_properties_target}"
1208  PROPERTIES
1209  ${ARGN})
1210 endfunction ()
1211 
1212 #[==[
1213 @ingroup module
1214 @brief Set a property on a module
1215 
1216 A wrapper around `set_property(TARGET)` that works for modules.
1217 
1218 ~~~
1219 vtk_module_set_property(<module>
1220  [APPEND] [APPEND_STRING]
1221  PROPERTY <property>
1222  VALUE <value>...)
1223 ~~~
1224 #]==]
1225 function (vtk_module_set_property module)
1226  cmake_parse_arguments(_vtk_property
1227  "APPEND;APPEND_STRING"
1228  "PROPERTY"
1229  "VALUE"
1230  ${ARGN})
1231 
1232  if (_vtk_property_UNPARSED_ARGUMENTS)
1233  message(FATAL_ERROR
1234  "Unparsed arguments for vtk_module_set_property: "
1235  "${_vtk_property_UNPARSED_ARGUMENTS}.")
1236  endif ()
1237 
1238  if (NOT DEFINED _vtk_property_PROPERTY)
1239  message(FATAL_ERROR
1240  "The `PROPERTY` argument is required.")
1241  endif ()
1242 
1243  if (NOT DEFINED _vtk_property_VALUE)
1244  message(FATAL_ERROR
1245  "The `VALUE` argument is required.")
1246  endif ()
1247 
1248  if (_vtk_property_APPEND AND _vtk_property_APPEND_STRING)
1249  message(FATAL_ERROR
1250  "`APPEND` and `APPEND_STRING` may not be used at the same time.")
1251  endif ()
1252 
1253  set(_vtk_property_args)
1254  if (_vtk_property_APPEND)
1255  list(APPEND _vtk_property_args
1256  APPEND)
1257  endif ()
1258  if (_vtk_property_APPEND_STRING)
1259  list(APPEND _vtk_property_args
1260  APPEND_STRING)
1261  endif ()
1262 
1263  _vtk_module_real_target(_vtk_property_target "${module}")
1264 
1265  set_property(TARGET "${_vtk_property_target}"
1266  ${_vtk_property_args}
1267  PROPERTY
1268  "${_vtk_property_PROPERTY}" "${_vtk_property_VALUE}")
1269 endfunction ()
1270 
1271 #[==[
1272 @ingroup module
1273 @brief Get a property from a module
1274 
1275 A wrapper around `get_property(TARGET)` that works for modules.
1276 
1277 ~~~
1278 vtk_module_get_property(<module>
1279  PROPERTY <property>
1280  VARIABLE <variable>)
1281 ~~~
1282 
1283 The variable name passed to the `VARIABLE` argument will be unset if the
1284 property is not set (rather than the empty string).
1285 #]==]
1286 function (vtk_module_get_property module)
1287  cmake_parse_arguments(_vtk_property
1288  ""
1289  "PROPERTY;VARIABLE"
1290  ""
1291  ${ARGN})
1292 
1293  if (_vtk_property_UNPARSED_ARGUMENTS)
1294  message(FATAL_ERROR
1295  "Unparsed arguments for vtk_module_get_property: "
1296  "${_vtk_property_UNPARSED_ARGUMENTS}.")
1297  endif ()
1298 
1299  if (NOT DEFINED _vtk_property_PROPERTY)
1300  message(FATAL_ERROR
1301  "The `PROPERTY` argument is required.")
1302  endif ()
1303 
1304  if (NOT DEFINED _vtk_property_VARIABLE)
1305  message(FATAL_ERROR
1306  "The `VARIABLE` argument is required.")
1307  endif ()
1308 
1309  _vtk_module_real_target(_vtk_property_target "${module}")
1310 
1311  get_property(_vtk_property_is_set
1312  TARGET "${_vtk_property_target}"
1313  PROPERTY "${_vtk_property_PROPERTY}"
1314  SET)
1315  if (_vtk_property_is_set)
1316  get_property(_vtk_property_value
1317  TARGET "${_vtk_property_target}"
1318  PROPERTY "${_vtk_property_PROPERTY}")
1319 
1320  set("${_vtk_property_VARIABLE}"
1321  "${_vtk_property_value}"
1322  PARENT_SCOPE)
1323  else ()
1324  unset("${_vtk_property_VARIABLE}"
1325  PARENT_SCOPE)
1326  endif ()
1327 endfunction ()
1328 
1329 #[==[
1330 @ingroup module-impl
1331 @brief Generate arguments for target function wrappers
1332 
1333 Create the `INTERFACE`, `PUBLIC`, and `PRIVATE` arguments for a function
1334 wrapping CMake's `target_` functions to call the wrapped function.
1335 
1336 This is necessary because not all of the functions support empty lists given a
1337 keyword.
1338 #]==]
1339 function (_vtk_module_target_function prefix)
1340  foreach (visibility IN ITEMS INTERFACE PUBLIC PRIVATE)
1341  if (${prefix}_${visibility})
1342  set("${prefix}_${visibility}_args"
1343  "${visibility}"
1344  ${${prefix}_${visibility}}
1345  PARENT_SCOPE)
1346  endif ()
1347  endforeach ()
1348 endfunction ()
1349 
1350 #[==[
1351 @ingroup module
1352 @brief Add dependencies to a module
1353 
1354 A wrapper around `add_dependencies` that works for modules.
1355 
1356 ~~~
1357 vtk_module_depend(<module> <depend>...)
1358 ~~~
1359 #]==]
1360 function (vtk_module_depend module)
1361  _vtk_module_real_target(_vtk_depend_target "${module}")
1362 
1363  add_dependencies("${_vtk_depend_target}"
1364  ${ARGN})
1365 endfunction ()
1366 
1367 #[==[
1368 @ingroup module
1369 @brief Add include directories to a module
1370 
1371 A wrapper around `add_dependencies` that works for modules.
1372 
1373 ~~~
1374 vtk_module_include(<module>
1375  [SYSTEM]
1376  [PUBLIC <directory>...]
1377  [PRIVATE <directory>...]
1378  [INTERFACE <directory>...])
1379 ~~~
1380 #]==]
1381 function (vtk_module_include module)
1382  cmake_parse_arguments(_vtk_include
1383  "SYSTEM"
1384  ""
1385  "INTERFACE;PUBLIC;PRIVATE"
1386  ${ARGN})
1387 
1388  if (_vtk_include_UNPARSED_ARGUMENTS)
1389  message(FATAL_ERROR
1390  "Unparsed arguments for vtk_module_include: "
1391  "${_vtk_include_UNPARSED_ARGUMENTS}.")
1392  endif ()
1393 
1394  _vtk_module_real_target(_vtk_include_target "${module}")
1395  _vtk_module_target_function(_vtk_include)
1396 
1397  set(_vtk_include_system_arg)
1398  if (_vtk_include_SYSTEM)
1399  set(_vtk_include_system_arg SYSTEM)
1400  endif ()
1401 
1402  target_include_directories("${_vtk_include_target}"
1403  ${_vtk_include_system_arg}
1404  ${_vtk_include_INTERFACE_args}
1405  ${_vtk_include_PUBLIC_args}
1406  ${_vtk_include_PRIVATE_args})
1407 endfunction ()
1408 
1409 #[==[
1410 @ingroup module
1411 @brief Add compile definitions to a module
1412 
1413 A wrapper around `target_compile_definitions` that works for modules.
1414 
1415 ~~~
1416 vtk_module_definitions(<module>
1417  [PUBLIC <directory>...]
1418  [PRIVATE <directory>...]
1419  [INTERFACE <directory>...])
1420 ~~~
1421 #]==]
1422 function (vtk_module_definitions module)
1423  cmake_parse_arguments(_vtk_definitions
1424  ""
1425  ""
1426  "INTERFACE;PUBLIC;PRIVATE"
1427  ${ARGN})
1428 
1429  if (_vtk_definitions_UNPARSED_ARGUMENTS)
1430  message(FATAL_ERROR
1431  "Unparsed arguments for vtk_module_definitions: "
1432  "${_vtk_definitions_UNPARSED_ARGUMENTS}.")
1433  endif ()
1434 
1435  _vtk_module_real_target(_vtk_definitions_target "${module}")
1436  _vtk_module_target_function(_vtk_definitions)
1437 
1438  target_compile_definitions("${_vtk_definitions_target}"
1439  ${_vtk_definitions_INTERFACE_args}
1440  ${_vtk_definitions_PUBLIC_args}
1441  ${_vtk_definitions_PRIVATE_args})
1442 endfunction ()
1443 
1444 #[==[
1445 @ingroup module
1446 @brief Add compile options to a module
1447 
1448 A wrapper around `target_compile_options` that works for modules.
1449 
1450 ~~~
1451 vtk_module_compile_options(<module>
1452  [PUBLIC <directory>...]
1453  [PRIVATE <directory>...]
1454  [INTERFACE <directory>...])
1455 ~~~
1456 #]==]
1457 function (vtk_module_compile_options module)
1458  cmake_parse_arguments(_vtk_compile_options
1459  ""
1460  ""
1461  "INTERFACE;PUBLIC;PRIVATE"
1462  ${ARGN})
1463 
1464  if (_vtk_compile_options_UNPARSED_ARGUMENTS)
1465  message(FATAL_ERROR
1466  "Unparsed arguments for vtk_module_compile_options: "
1467  "${_vtk_compile_options_UNPARSED_ARGUMENTS}.")
1468  endif ()
1469 
1470  _vtk_module_real_target(_vtk_compile_options_target "${module}")
1471  _vtk_module_target_function(_vtk_compile_options)
1472 
1473  target_compile_options("${_vtk_compile_options_target}"
1474  ${_vtk_compile_options_INTERFACE_args}
1475  ${_vtk_compile_options_PUBLIC_args}
1476  ${_vtk_compile_options_PRIVATE_args})
1477 endfunction ()
1478 
1479 #[==[
1480 @ingroup module
1481 @brief Add compile features to a module
1482 
1483 A wrapper around `target_compile_features` that works for modules.
1484 
1485 ~~~
1486 vtk_module_compile_features(<module>
1487  [PUBLIC <directory>...]
1488  [PRIVATE <directory>...]
1489  [INTERFACE <directory>...])
1490 ~~~
1491 #]==]
1492 function (vtk_module_compile_features module)
1493  cmake_parse_arguments(_vtk_compile_features
1494  ""
1495  ""
1496  "INTERFACE;PUBLIC;PRIVATE"
1497  ${ARGN})
1498 
1499  if (_vtk_compile_features_UNPARSED_ARGUMENTS)
1500  message(FATAL_ERROR
1501  "Unparsed arguments for vtk_module_compile_features: "
1502  "${_vtk_compile_features_UNPARSED_ARGUMENTS}.")
1503  endif ()
1504 
1505  _vtk_module_real_target(_vtk_compile_features_target "${module}")
1506  _vtk_module_target_function(_vtk_compile_features)
1507 
1508  target_compile_features("${_vtk_compile_features_target}"
1509  ${_vtk_compile_features_INTERFACE_args}
1510  ${_vtk_compile_features_PUBLIC_args}
1511  ${_vtk_compile_features_PRIVATE_args})
1512 endfunction ()
1513 
1514 #[==[
1515 @ingroup module
1516 @brief Add link libraries to a module
1517 
1518 A wrapper around `target_link_libraries` that works for modules. Note that this
1519 function does extra work in kit builds, so circumventing it may break in kit
1520 builds.
1521 
1522 ~~~
1523 vtk_module_link(<module>
1524  [PUBLIC <directory>...]
1525  [PRIVATE <directory>...]
1526  [INTERFACE <directory>...])
1527 ~~~
1528 #]==]
1529 function (vtk_module_link module)
1530  cmake_parse_arguments(_vtk_link
1531  ""
1532  ""
1533  "INTERFACE;PUBLIC;PRIVATE"
1534  ${ARGN})
1535 
1536  if (_vtk_link_UNPARSED_ARGUMENTS)
1537  message(FATAL_ERROR
1538  "Unparsed arguments for vtk_module_link: "
1539  "${_vtk_link_UNPARSED_ARGUMENTS}.")
1540  endif ()
1541 
1542  _vtk_module_real_target(_vtk_link_target "${module}")
1543  _vtk_module_target_function(_vtk_link)
1544 
1545  get_property(_vtk_link_kit GLOBAL
1546  PROPERTY "_vtk_module_${module}_kit")
1547  if (_vtk_link_kit AND NOT CMAKE_VERSION VERSION_LESS "3.12")
1548  foreach (_vtk_link_private IN LISTS _vtk_link_PRIVATE)
1549  if (NOT TARGET "${_vtk_link_private}")
1550  continue ()
1551  endif ()
1552 
1553  get_property(_vtk_link_private_imported
1554  TARGET "${_vtk_link_private}"
1555  PROPERTY IMPORTED)
1556  if (_vtk_link_private_imported)
1557  get_property(_vtk_link_private_imported_global
1558  TARGET "${_vtk_link_private}"
1559  PROPERTY IMPORTED_GLOBAL)
1560  if (NOT _vtk_link_private_imported_global)
1561  set_property(TARGET "${_vtk_link_private}"
1562  PROPERTY
1563  IMPORTED_GLOBAL TRUE)
1564  endif ()
1565  endif ()
1566  endforeach ()
1567  set_property(GLOBAL APPEND
1568  PROPERTY
1569  "_vtk_kit_${_vtk_link_kit}_private_links" ${_vtk_link_PRIVATE})
1570  endif ()
1571 
1572  target_link_libraries("${_vtk_link_target}"
1573  ${_vtk_link_INTERFACE_args}
1574  ${_vtk_link_PUBLIC_args}
1575  ${_vtk_link_PRIVATE_args})
1576 endfunction ()
1577 
1578 #[==[
1579 @ingroup module
1580 @brief Add link options to a module
1581 
1582 A wrapper around `target_link_options` that works for modules.
1583 
1584 ~~~
1585 vtk_module_link_options(<module>
1586  [PUBLIC <directory>...]
1587  [PRIVATE <directory>...]
1588  [INTERFACE <directory>...])
1589 ~~~
1590 #]==]
1591 function (vtk_module_link_options module)
1592  cmake_parse_arguments(_vtk_link_options
1593  ""
1594  ""
1595  "INTERFACE;PUBLIC;PRIVATE"
1596  ${ARGN})
1597 
1598  if (_vtk_link_options_UNPARSED_ARGUMENTS)
1599  message(FATAL_ERROR
1600  "Unparsed arguments for vtk_module_link_options: "
1601  "${_vtk_link_options_UNPARSED_ARGUMENTS}.")
1602  endif ()
1603 
1604  _vtk_module_real_target(_vtk_link_options_target "${module}")
1605  _vtk_module_target_function(_vtk_link_options)
1606 
1607  target_link_options("${_vtk_link_options_target}"
1608  ${_vtk_link_options_INTERFACE_args}
1609  ${_vtk_link_options_PUBLIC_args}
1610  ${_vtk_link_options_PRIVATE_args})
1611 endfunction ()
1612 
1613 #[==[
1614 @page module-internal-api
1615 
1616 @ingroup module-internal
1617 @section module-properties Module properties
1618 
1619 The VTK module system leverages CMake's target propagation and storage. As
1620 such, there are a number of properties added to the targets representing
1621 modules. These properties are intended for use by the module system and
1622 associated functionality. In particular, more properties may be available by
1623 language wrappers.
1624 
1625 @subsection module-properties-naming Naming properties
1626 
1627 When creating properties for use with the module system, they should be
1628 prefixed with `INTERFACE_vtk_module_`. The `INTERFACE_` portion is required in
1629 order to work with interface libraries. The `vtk_module_` portion is to avoid
1630 colliding with any other properties. This function assumes this naming scheme
1631 for some of its convenience features as well.
1632 
1633 Properties should be the same in the local build as well as when imported to
1634 ease use.
1635 
1636 @subsection module-properties-system VTK module system properties
1637 
1638 There are a number of properties that are used and expected by the core of the
1639 module system. These are generally module metadata (module dependencies,
1640 whether to wrap or not, etc.). The properties all have the
1641 `INTERFACE_vtk_module_` prefix mentioned in the previous section.
1642 
1643  * `third_party`: If set, the module represents a third party
1644  dependency and should be treated specially. Third party modules are very
1645  restricted and generally do not have any other properties set on them.
1646  * `exclude_wrap`: If set, the module should not be wrapped by an external
1647  language.
1648  * `depends`: The list of dependent modules. Language wrappers will generally
1649  require this to satisfy references to parent classes of the classes in the
1650  module.
1651  * `private_depends`: The list of privately dependent modules. Language
1652  wrappers may require this to satisfy references to parent classes of the
1653  classes in the module.
1654  * `optional_depends`: The list of optionally dependent modules. Language
1655  wrappers may require this to satisfy references to parent classes of the
1656  classes in the module.
1657  * `kit`: The kit the module is a member of. Only set if the module is
1658  actually a member of the kit (i.e., the module was built with
1659  `BUILD_WITH_KITS ON`).
1660  * `implements`: The list of modules for which this module registers to. This
1661  is used by the autoinit subsystem and generally is not required.
1662  * `implementable`: If set, this module provides registries which may be
1663  populated by dependent modules. It is used to check the `implements`
1664  property to help minimize unnecessary work from the autoinit subsystem.
1665  * `needs_autoinit`: If set, linking to this module requires the autoinit
1666  subsystem to ensure that registries in modules are fully populated.
1667  * `headers`: Paths to the public headers from the module. These are the
1668  headers which should be handled by language wrappers.
1669  * `hierarchy`: The path to the hierarchy file describing inheritance of the
1670  classes for use in language wrappers.
1671  * `forward_link`: Usage requirements that must be forwarded even though the
1672  module is linked to privately.
1673 
1674 Kits have the following properties available (but only if kits are enabled):
1675 
1676  * `kit_modules`: Modules which are compiled into the kit.
1677 #]==]
1678 
1679 #[==[
1680 @ingroup module-internal
1681 @brief Set a module property
1682 
1683 This function sets a [module property](@ref module-properties) on a module. The
1684 required prefix will automatically be added to the passed name.
1685 
1686 ~~~
1687 _vtk_module_set_module_property(<module>
1688  [APPEND] [APPEND_STRING]
1689  PROPERTY <property>
1690  VALUE <value>...)
1691 ~~~
1692 #]==]
1693 function (_vtk_module_set_module_property module)
1694  cmake_parse_arguments(_vtk_property
1695  "APPEND;APPEND_STRING"
1696  "PROPERTY"
1697  "VALUE"
1698  ${ARGN})
1699 
1700  if (_vtk_property_UNPARSED_ARGUMENTS)
1701  message(FATAL_ERROR
1702  "Unparsed arguments for vtk_module_set_module_property: "
1703  "${_vtk_property_UNPARSED_ARGUMENTS}.")
1704  endif ()
1705 
1706  if (NOT DEFINED _vtk_property_PROPERTY)
1707  message(FATAL_ERROR
1708  "The `PROPERTY` argument is required.")
1709  endif ()
1710 
1711  if (NOT DEFINED _vtk_property_VALUE)
1712  message(FATAL_ERROR
1713  "The `VALUE` argument is required.")
1714  endif ()
1715 
1716  if (_vtk_property_APPEND AND _vtk_property_APPEND_STRING)
1717  message(FATAL_ERROR
1718  "`APPEND` and `APPEND_STRING` may not be used at the same time.")
1719  endif ()
1720 
1721  set(_vtk_property_args)
1722  if (_vtk_property_APPEND)
1723  list(APPEND _vtk_property_args
1724  APPEND)
1725  endif ()
1726  if (_vtk_property_APPEND_STRING)
1727  list(APPEND _vtk_property_args
1728  APPEND_STRING)
1729  endif ()
1730 
1731  get_property(_vtk_property_is_alias
1732  TARGET "${module}"
1733  PROPERTY ALIASED_TARGET
1734  SET)
1735  if (_vtk_property_is_alias)
1736  _vtk_module_real_target(_vtk_property_target "${module}")
1737  else ()
1738  set(_vtk_property_target "${module}")
1739  endif ()
1740 
1741  set_property(TARGET "${_vtk_property_target}"
1742  ${_vtk_property_args}
1743  PROPERTY
1744  "INTERFACE_vtk_module_${_vtk_property_PROPERTY}" "${_vtk_property_VALUE}")
1745 endfunction ()
1746 
1747 #[==[
1748 @ingroup module-internal
1749 @brief Get a module property
1750 
1751 Get a [module property](@ref module-properties) from a module.
1752 
1753 ~~~
1754 _vtk_module_get_module_property(<module>
1755  PROPERTY <property>
1756  VARIABLE <variable>)
1757 ~~~
1758 
1759 As with @ref vtk_module_get_property, the output variable will be unset if the
1760 property is not set. The property name is automatically prepended with the
1761 required prefix.
1762 #]==]
1763 function (_vtk_module_get_module_property module)
1764  cmake_parse_arguments(_vtk_property
1765  ""
1766  "PROPERTY;VARIABLE"
1767  ""
1768  ${ARGN})
1769 
1770  if (_vtk_property_UNPARSED_ARGUMENTS)
1771  message(FATAL_ERROR
1772  "Unparsed arguments for vtk_module_get_module_property: "
1773  "${_vtk_property_UNPARSED_ARGUMENTS}.")
1774  endif ()
1775 
1776  if (NOT DEFINED _vtk_property_PROPERTY)
1777  message(FATAL_ERROR
1778  "The `PROPERTY` argument is required.")
1779  endif ()
1780 
1781  if (NOT DEFINED _vtk_property_VARIABLE)
1782  message(FATAL_ERROR
1783  "The `VARIABLE` argument is required.")
1784  endif ()
1785 
1786  get_property(_vtk_property_is_alias
1787  TARGET "${module}"
1788  PROPERTY ALIASED_TARGET
1789  SET)
1790  if (_vtk_property_is_alias)
1791  _vtk_module_real_target(_vtk_property_target "${module}")
1792  else ()
1793  set(_vtk_property_target "${module}")
1794  endif ()
1795 
1796  get_property(_vtk_property_is_set
1797  TARGET "${_vtk_property_target}"
1798  PROPERTY "INTERFACE_vtk_module_${_vtk_property_PROPERTY}"
1799  SET)
1800  if (_vtk_property_is_set)
1801  get_property(_vtk_property_value
1802  TARGET "${_vtk_property_target}"
1803  PROPERTY "INTERFACE_vtk_module_${_vtk_property_PROPERTY}")
1804 
1805  set("${_vtk_property_VARIABLE}"
1806  "${_vtk_property_value}"
1807  PARENT_SCOPE)
1808  else ()
1809  unset("${_vtk_property_VARIABLE}"
1810  PARENT_SCOPE)
1811  endif ()
1812 endfunction ()
1813 
1814 #[==[
1815 @ingroup module-internal
1816 @brief Check that destinations are valid
1817 
1818 All installation destinations are expected to be relative so that
1819 `CMAKE_INSTALL_PREFIX` can be relied upon in all code paths. This function may
1820 be used to verify that destinations are relative.
1821 
1822 ~~~
1823 _vtk_module_check_destinations(<prefix> [<suffix>...])
1824 ~~~
1825 
1826 For each `suffix`, `prefix` is prefixed to it and the resulting variable name
1827 is checked for validity as an install prefix. Raises an error if any is
1828 invalid.
1829 #]==]
1830 function (_vtk_module_check_destinations prefix)
1831  foreach (suffix IN LISTS ARGN)
1832  if (IS_ABSOLUTE "${${prefix}${suffix}}")
1833  message(FATAL_ERROR
1834  "The `${suffix}` must not be an absolute path. Use "
1835  "`CMAKE_INSTALL_PREFIX` to keep everything in a single installation "
1836  "prefix.")
1837  endif ()
1838  endforeach ()
1839 endfunction ()
1840 
1841 #[==[
1842 @ingroup module-internal
1843 @brief Write an import prefix statement
1844 
1845 CMake files, once installed, may need to construct paths to other locations
1846 within the install prefix. This function writes a prefix computation for file
1847 given its install destination.
1848 
1849 ~~~
1850 _vtk_module_write_import_prefix(<file> <destination>)
1851 ~~~
1852 
1853 The passed file is cleared so that it occurs at the top of the file. The prefix
1854 is available in the file as the `_vtk_module_import_prefix` variable. It is
1855 recommended to unset the variable at the end of the file.
1856 #]==]
1857 function (_vtk_module_write_import_prefix file destination)
1858  if (IS_ABSOLUTE "${destination}")
1859  message(FATAL_ERROR
1860  "An import prefix cannot be determined from an absolute installation "
1861  "destination. Use `CMAKE_INSTALL_PREFIX` to keep everything in a single "
1862  "installation prefix.")
1863  endif ()
1864 
1865  file(WRITE "${file}"
1866  "set(_vtk_module_import_prefix \"\${CMAKE_CURRENT_LIST_DIR}\")\n")
1867  while (destination)
1868  get_filename_component(destination "${destination}" DIRECTORY)
1869  file(APPEND "${file}"
1870  "get_filename_component(_vtk_module_import_prefix \"\${_vtk_module_import_prefix}\" DIRECTORY)\n")
1871  endwhile ()
1872 endfunction ()
1873 
1874 #[==[
1875 @ingroup module-internal
1876 @brief Export properties on modules and targets
1877 
1878 This function is intended for use in support functions which leverage the
1879 module system, not by general system users. This function supports exporting
1880 properties from the build into dependencies via target properties which are
1881 loaded from a project's config file which is loaded via CMake's `find_package`
1882 function.
1883 
1884 ~~~
1886  [MODULE <module>]
1887  [KIT <kit>]
1888  BUILD_FILE <path>
1889  INSTALL_FILE <path>
1890  [PROPERTIES <property>...]
1891  [FROM_GLOBAL_PROPERTIES <property fragment>...]
1892  [SPLIT_INSTALL_PROPERTIES <property fragment>...])
1893 ~~~
1894 
1895 The `BUILD_FILE` and `INSTALL_FILE` arguments are required. Exactly one of
1896 `MODULE` and `KIT` is also required. The `MODULE` or `KIT` argument holds the
1897 name of the module or kit that will have properties exported. The `BUILD_FILE`
1898 and `INSTALL_FILE` paths are *appended to*. As such, when setting up these
1899 files, it should be preceded with:
1900 
1901 ~~~{.cmake}
1902 file(WRITE "${build_file}")
1903 file(WRITE "${install_file}")
1904 ~~~
1905 
1906 To avoid accidental usage of the install file from the build tree, it is
1907 recommended to store it under a `CMakeFiles/` directory in the build tree with
1908 an additional `.install` suffix and use `install(RENAME)` to rename it at
1909 install time.
1910 
1911 The set of properties exported is computed as follows:
1912 
1913  * `PROPERTIES` queries the module target for the given property and exports
1914  its value as-is to both the build and install files. In addition, these
1915  properties are set on the target directly as the same name.
1916  * `FROM_GLOBAL_PROPERTIES` queries the global
1917  `_vtk_module_<MODULE>_<fragment>` property and exports it to both the build
1918  and install files as `INTERFACE_vtk_module_<fragment>`.
1919  * `SPLIT_INSTALL_PROPERTIES` queries the target for
1920  `INTERFACE_vtk_module_<fragment>` and exports its value to the build file
1921  and `INTERFACE_vtk_module_<fragment>_install` to the install file as the
1922  non-install property name. This is generally useful for properties which
1923  change between the build and installation.
1924 #]==]
1926  cmake_parse_arguments(_vtk_export_properties
1927  ""
1928  "BUILD_FILE;INSTALL_FILE;MODULE;KIT"
1929  "FROM_GLOBAL_PROPERTIES;PROPERTIES;SPLIT_INSTALL_PROPERTIES"
1930  ${ARGN})
1931 
1932  if (_vtk_export_properties_UNPARSED_ARGUMENTS)
1933  message(FATAL_ERROR
1934  "Unparsed arguments for _vtk_export_properties: "
1935  "${_vtk_export_properties_UNPARSED_ARGUMENTS}.")
1936  endif ()
1937 
1938  if (DEFINED _vtk_export_properties_MODULE)
1939  if (DEFINED _vtk_export_properties_KIT)
1940  message(FATAL_ERROR
1941  "Only one of `MODULE` or `KIT` is required to export properties.")
1942  endif ()
1943  set(_vtk_export_properties_type "module")
1944  set(_vtk_export_properties_name "${_vtk_export_properties_MODULE}")
1945  elseif (_vtk_export_properties_KIT)
1946  set(_vtk_export_properties_type "kit")
1947  set(_vtk_export_properties_name "${_vtk_export_properties_KIT}")
1948  else ()
1949  message(FATAL_ERROR
1950  "A module or kit is required to export properties.")
1951  endif ()
1952 
1953  if (NOT _vtk_export_properties_BUILD_FILE)
1954  message(FATAL_ERROR
1955  "Exporting properties requires a build file to write to.")
1956  endif ()
1957 
1958  if (NOT _vtk_export_properties_INSTALL_FILE)
1959  message(FATAL_ERROR
1960  "Exporting properties requires an install file to write to.")
1961  endif ()
1962 
1963  if (_vtk_export_properties_type STREQUAL "module")
1964  _vtk_module_real_target(_vtk_export_properties_target_name "${_vtk_export_properties_name}")
1965  elseif (_vtk_export_properties_type STREQUAL "kit")
1966  _vtk_module_real_target_kit(_vtk_export_properties_target_name "${_vtk_export_properties_name}")
1967  endif ()
1968 
1969  foreach (_vtk_export_properties_global IN LISTS _vtk_export_properties_FROM_GLOBAL_PROPERTIES)
1970  get_property(_vtk_export_properties_is_set GLOBAL
1971  PROPERTY "_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_name}_${_vtk_export_properties_global}"
1972  SET)
1973  if (NOT _vtk_export_properties_is_set)
1974  continue ()
1975  endif ()
1976 
1977  get_property(_vtk_export_properties_value GLOBAL
1978  PROPERTY "_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_name}_${_vtk_export_properties_global}")
1979  set(_vtk_export_properties_set_property
1980  "set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_global}\" \"${_vtk_export_properties_value}\")\n")
1981 
1982  set_property(TARGET "${_vtk_export_properties_target_name}"
1983  PROPERTY
1984  "INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_global}" "${_vtk_export_properties_value}")
1985  file(APPEND "${_vtk_export_properties_BUILD_FILE}"
1986  "${_vtk_export_properties_set_property}")
1987  file(APPEND "${_vtk_export_properties_INSTALL_FILE}"
1988  "${_vtk_export_properties_set_property}")
1989  endforeach ()
1990 
1991  foreach (_vtk_export_properties_target IN LISTS _vtk_export_properties_PROPERTIES)
1992  get_property(_vtk_export_properties_is_set
1993  TARGET "${_vtk_export_properties_target_name}"
1994  PROPERTY "${_vtk_export_properties_target}"
1995  SET)
1996  if (NOT _vtk_export_properties_is_set)
1997  continue ()
1998  endif ()
1999 
2000  get_property(_vtk_export_properties_value
2001  TARGET "${_vtk_export_properties_target_name}"
2002  PROPERTY "${_vtk_export_properties_target}")
2003  set(_vtk_export_properties_set_property
2004  "set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"${_vtk_export_properties_target}\" \"${_vtk_export_properties_value}\")\n")
2005 
2006  file(APPEND "${_vtk_export_properties_BUILD_FILE}"
2007  "${_vtk_export_properties_set_property}")
2008  file(APPEND "${_vtk_export_properties_INSTALL_FILE}"
2009  "${_vtk_export_properties_set_property}")
2010  endforeach ()
2011 
2012  foreach (_vtk_export_properties_split IN LISTS _vtk_export_properties_SPLIT_INSTALL_PROPERTIES)
2013  get_property(_vtk_export_properties_is_set
2014  TARGET "${_vtk_export_properties_target_name}"
2015  PROPERTY "INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_split}"
2016  SET)
2017  if (NOT _vtk_export_properties_is_set)
2018  continue ()
2019  endif ()
2020 
2021  get_property(_vtk_export_properties_value
2022  TARGET "${_vtk_export_properties_target_name}"
2023  PROPERTY "INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_split}")
2024  set(_vtk_export_properties_set_property
2025  "set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"INTERFACE_vtk_module_${_vtk_export_properties_split}\" \"${_vtk_export_properties_value}\")\n")
2026  file(APPEND "${_vtk_export_properties_BUILD_FILE}"
2027  "${_vtk_export_properties_set_property}")
2028 
2029  get_property(_vtk_export_properties_value
2030  TARGET "${_vtk_export_properties_target_name}"
2031  PROPERTY "INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_split}_install")
2032  set(_vtk_export_properties_set_property
2033  "set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"INTERFACE_vtk_module_${_vtk_export_properties_split}\" \"${_vtk_export_properties_value}\")\n")
2034  file(APPEND "${_vtk_export_properties_INSTALL_FILE}"
2035  "${_vtk_export_properties_set_property}")
2036  endforeach ()
2037 endfunction ()
2038 
2039 include("${CMAKE_CURRENT_LIST_DIR}/vtkModuleTesting.cmake")
2040 
2041 #[==[
2042 @ingroup module
2043 @brief Build modules and kits
2044 
2045 Once all of the modules have been scanned, they need to be built. Generally,
2046 there will be just one build necessary for a set of scans, though they may be
2047 built distinctly as well. If there are multiple calls to this function, they
2048 should generally in reverse order of their scans.
2049 
2050 ~~~
2051 vtk_module_build(
2052  MODULES <module>...
2053  [KITS <kit>...]
2054 
2055  [LIBRARY_NAME_SUFFIX <suffix>]
2056  [VERSION <version>]
2057  [SOVERSION <soversion>]
2058 
2059  [PACKAGE <package>]
2060 
2061  [BUILD_WITH_KITS <ON|OFF>]
2062 
2063  [ENABLE_WRAPPING <ON|OFF>]
2064 
2065  [USE_EXTERNAL <ON|OFF>]
2066 
2067  [INSTALL_HEADERS <ON|OFF>]
2068  [HEADERS_COMPONENT <component>]
2069 
2070  [TARGETS_COMPONENT <component>]
2071  [INSTALL_EXPORT <export>]
2072 
2073  [TEST_DIRECTORY_NAME <name>]
2074  [TEST_DATA_TARGET <target>]
2075  [TEST_INPUT_DATA_DIRECTORY <directory>]
2076  [TEST_OUTPUT_DATA_DIRECTORY <directory>]
2077  [TEST_OUTPUT_DIRECTORY <directory>]
2078 
2079  [ARCHIVE_DESTINATION <destination>]
2080  [HEADERS_DESTINATION <destination>]
2081  [LIBRARY_DESTINATION <destination>]
2082  [RUNTIME_DESTINATION <destination>]
2083  [CMAKE_DESTINATION <destination>]
2084  [LICENSE_DESTINATION <destination>]
2085  [HIERARCHY_DESTINATION <destination>])
2086 ~~~
2087 
2088 The only requirement of the function is the list of modules to build, the rest
2089 have reasonable defaults if not specified.
2090 
2091  * `MODULES`: (Required) The list of modules to build.
2092  * `KITS`: (Required if `BUILD_WITH_KITS` is `ON`) The list of kits to build.
2093  * `LIBRARY_NAME_SUFFIX`: (Defaults to `""`) A suffix to add to library names.
2094  If it is not empty, it is prefixed with `-` to separate it from the kit
2095  name.
2096  * `VERSION`: If specified, the `VERSION` property on built libraries will be
2097  set to this value.
2098  * `SOVERSION`: If specified, the `SOVERSION` property on built libraries will
2099  be set to this value.
2100  * `PACKAGE`: (Defaults to `${CMAKE_PROJECT_NAME}`) The name the build is
2101  meant to be found as when using `find_package`. Note that separate builds
2102  will require distinct `PACKAGE` values.
2103  * `BUILD_WITH_KITS`: (Defaults to `OFF`) If enabled, kit libraries will be
2104  built.
2105  * `ENABLE_WRAPPING`: (Default depends on the existence of
2106  `VTK::WrapHierarchy` or `VTKCompileTools::WrapHierarchy` targets) If
2107  enabled, wrapping will be available to the modules built in this call.
2108  * `USE_EXTERNAL`: (Defaults to `OFF`) Whether third party modules should find
2109  external copies rather than building their own copy.
2110  * `INSTALL_HEADERS`: (Defaults to `ON`) Whether or not to install public headers.
2111  * `HEADERS_COMPONENT`: (Defaults to `development`) The install component to
2112  use for header installation. Note that other SDK-related bits use the same
2113  component (e.g., CMake module files).
2114  * `TARGETS_COMPONENT`: `Defaults to `runtime`) The install component to use
2115  for the libraries built.
2116  * `TARGET_NAMESPACE`: `Defaults to `<AUTO>`) The namespace for installed
2117  targets. All targets must have the same namespace. If set to `<AUTO>`,
2118  the namespace will be detected automatically.
2119  * `INSTALL_EXPORT`: (Defaults to `""`) If non-empty, targets will be added to
2120  the given export. The export will also be installed as part of this build
2121  command.
2122  * `TEST_DIRECTORY_NAME`: (Defaults to `Testing`) The name of the testing
2123  directory to look for in each module. Set to `NONE` to disable automatic
2124  test management.
2125  * `TEST_DATA_TARGET`: (Defaults to `<PACKAGE>-data`) The target to add
2126  testing data download commands to.
2127  * `TEST_INPUT_DATA_DIRECTORY`: (Defaults to
2128  `${CMAKE_CURRENT_SOURCE_DIR}/Data`) The directory which will contain data
2129  for use by tests.
2130  * `TEST_OUTPUT_DATA_DIRECTORY`: (Defaults to
2131  `${CMAKE_CURRENT_BINARY_DIR}/Data`) The directory which will contain data
2132  for use by tests.
2133  * `TEST_OUTPUT_DIRECTORY`: (Defaults to
2134  `${CMAKE_BINARY_DIR}/<TEST_DIRECTORY_NAME>/Temporary`) The directory which
2135  tests may write any output files to.
2136 
2137 The remaining arguments control where to install files related to the build.
2138 See CMake documentation for the difference between `ARCHIVE`, `LIBRARY`, and
2139 `RUNTIME`.
2140 
2141  * `ARCHIVE_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) The install
2142  destination for archive files.
2143  * `HEADERS_DESTINATION`: (Defaults to `${CMAKE_INSTALL_INCLUDEDIR}`) The
2144  install destination for header files.
2145  * `LIBRARY_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) The install
2146  destination for library files.
2147  * `RUNTIME_DESTINATION`: (Defaults to `${CMAKE_INSTALL_BINDIR}`) The install
2148  destination for runtime files.
2149  * `CMAKE_DESTINATION`: (Defaults to `<library destination>/cmake/<package>`)
2150  The install destination for CMake files.
2151  * `LICENSE_DESTINATION`: (Defaults to `${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}`)
2152  The install destination for license files (relevant for third party
2153  packages).
2154  * `HIERARCHY_DESTINATION`: (Defaults to `<library
2155  destination>/vtk/hierarchy/<PACKAGE>`) The install destination
2156  for hierarchy files (used for language wrapping).
2157 #]==]
2158 function (vtk_module_build)
2159  set(_vtk_build_install_arguments
2160  # Headers
2161  INSTALL_HEADERS
2162  HEADERS_COMPONENT
2163 
2164  # Targets
2165  INSTALL_EXPORT
2166  TARGETS_COMPONENT
2167  TARGET_NAMESPACE
2168 
2169  # Destinations
2170  ARCHIVE_DESTINATION
2171  HEADERS_DESTINATION
2172  LIBRARY_DESTINATION
2173  RUNTIME_DESTINATION
2174  CMAKE_DESTINATION
2175  LICENSE_DESTINATION
2176  HIERARCHY_DESTINATION)
2177  set(_vtk_build_test_arguments
2178  # Testing
2179  TEST_DIRECTORY_NAME
2180  TEST_DATA_TARGET
2181  TEST_INPUT_DATA_DIRECTORY
2182  TEST_OUTPUT_DATA_DIRECTORY
2183  TEST_OUTPUT_DIRECTORY)
2184 
2185  # TODO: Add an option to build statically? Currently, `BUILD_SHARED_LIBS` is
2186  # used.
2187 
2188  cmake_parse_arguments(_vtk_build
2189  ""
2190  "BUILD_WITH_KITS;USE_EXTERNAL;LIBRARY_NAME_SUFFIX;VERSION;SOVERSION;PACKAGE;ENABLE_WRAPPING;${_vtk_build_install_arguments};${_vtk_build_test_arguments}"
2191  "MODULES;KITS"
2192  ${ARGN})
2193 
2194  if (_vtk_build_UNPARSED_ARGUMENTS)
2195  message(FATAL_ERROR
2196  "Unparsed arguments for vtk_module_build: "
2197  "${_vtk_build_UNPARSED_ARGUMENTS}")
2198  endif ()
2199 
2200  if (NOT DEFINED _vtk_build_USE_EXTERNAL)
2201  set(_vtk_build_USE_EXTERNAL OFF)
2202  endif ()
2203 
2204  if (NOT DEFINED _vtk_build_PACKAGE)
2205  set(_vtk_build_PACKAGE "${CMAKE_PROJECT_NAME}")
2206  endif ()
2207  get_property(_vtk_build_package_exists GLOBAL
2208  PROPERTY "_vtk_module_package_${_vtk_build_PACKAGE}"
2209  SET)
2210  if (_vtk_build_package_exists)
2211  message(FATAL_ERROR
2212  "A set of modules have already been built using the "
2213  "`${_vtk_build_PACKAGE}` package.")
2214  else ()
2215  set_property(GLOBAL
2216  PROPERTY
2217  "_vtk_module_package_${_vtk_build_PACKAGE}" "ON")
2218  endif ()
2219 
2220  if (NOT DEFINED _vtk_build_INSTALL_HEADERS)
2221  set(_vtk_build_INSTALL_HEADERS ON)
2222  endif ()
2223 
2224  if (NOT DEFINED _vtk_build_ENABLE_WRAPPING)
2225  if (TARGET "VTKCompileTools::WrapHierarchy" OR
2226  TARGET "VTK::WrapHierarchy")
2227  set(_vtk_build_ENABLE_WRAPPING ON)
2228  else ()
2229  set(_vtk_build_ENABLE_WRAPPING OFF)
2230  endif ()
2231  endif ()
2232 
2233  if (NOT DEFINED _vtk_build_TARGET_NAMESPACE)
2234  set(_vtk_build_TARGET_NAMESPACE "<AUTO>")
2235  endif ()
2236 
2237  if (NOT DEFINED _vtk_build_BUILD_WITH_KITS)
2238  set(_vtk_build_BUILD_WITH_KITS OFF)
2239  endif ()
2240 
2241  if (_vtk_build_BUILD_WITH_KITS AND CMAKE_VERSION VERSION_LESS "3.12")
2242  message(FATAL_ERROR
2243  "Building with kits enabled requires CMake 3.12 which introduced "
2244  "support for OBJECT libraries to have and utilize usage requirements.")
2245  endif ()
2246 
2247  if (_vtk_build_BUILD_WITH_KITS AND NOT DEFINED _vtk_build_KITS)
2248  message(FATAL_ERROR
2249  "Building with kits was requested, but no kits were specified.")
2250  endif ()
2251 
2252  if (NOT DEFINED _vtk_build_TEST_DIRECTORY_NAME)
2253  set(_vtk_build_TEST_DIRECTORY_NAME "Testing")
2254  endif ()
2255 
2256  if (NOT DEFINED _vtk_build_TEST_DATA_TARGET)
2257  set(_vtk_build_TEST_DATA_TARGET "${_vtk_build_PACKAGE}-data")
2258  endif ()
2259 
2260  if (NOT DEFINED _vtk_build_TEST_INPUT_DATA_DIRECTORY)
2261  set(_vtk_build_TEST_INPUT_DATA_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Data")
2262  endif ()
2263 
2264  if (NOT DEFINED _vtk_build_TEST_OUTPUT_DATA_DIRECTORY)
2265  set(_vtk_build_TEST_OUTPUT_DATA_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Data")
2266  endif ()
2267 
2268  if (NOT DEFINED _vtk_build_TEST_OUTPUT_DIRECTORY)
2269  set(_vtk_build_TEST_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_TEST_DIRECTORY_NAME}/Temporary")
2270  endif ()
2271 
2272  if (NOT DEFINED _vtk_build_HEADERS_COMPONENT)
2273  set(_vtk_build_HEADERS_COMPONENT "development")
2274  endif ()
2275 
2276  if (NOT DEFINED _vtk_build_ARCHIVE_DESTINATION)
2277  set(_vtk_build_ARCHIVE_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
2278  endif ()
2279 
2280  if (NOT DEFINED _vtk_build_HEADERS_DESTINATION)
2281  set(_vtk_build_HEADERS_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
2282  endif ()
2283 
2284  if (NOT DEFINED _vtk_build_LIBRARY_DESTINATION)
2285  set(_vtk_build_LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
2286  endif ()
2287 
2288  if (NOT DEFINED _vtk_build_RUNTIME_DESTINATION)
2289  set(_vtk_build_RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}")
2290  endif ()
2291 
2292  if (NOT DEFINED _vtk_build_CMAKE_DESTINATION)
2293  set(_vtk_build_CMAKE_DESTINATION "${_vtk_build_LIBRARY_DESTINATION}/cmake/${_vtk_build_PACKAGE}")
2294  endif ()
2295 
2296  if (NOT DEFINED _vtk_build_LICENSE_DESTINATION)
2297  set(_vtk_build_LICENSE_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}")
2298  endif ()
2299 
2300  if (NOT DEFINED _vtk_build_HIERARCHY_DESTINATION)
2301  set(_vtk_build_HIERARCHY_DESTINATION "${_vtk_build_LIBRARY_DESTINATION}/vtk/hierarchy/${_vtk_build_PACKAGE}")
2302  endif ()
2303 
2304  if (NOT DEFINED _vtk_build_TARGETS_COMPONENT)
2305  set(_vtk_build_TARGETS_COMPONENT "runtime")
2306  endif ()
2307 
2308  if (NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
2309  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_ARCHIVE_DESTINATION}")
2310  endif ()
2311  if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
2312  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_LIBRARY_DESTINATION}")
2313  endif ()
2314  if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
2315  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_RUNTIME_DESTINATION}")
2316  endif ()
2317 
2318  if (NOT _vtk_build_MODULES)
2319  message(FATAL_ERROR
2320  "No modules given to build.")
2321  endif ()
2322 
2323  _vtk_module_check_destinations(_vtk_build_
2324  ARCHIVE_DESTINATION
2325  HEADERS_DESTINATION
2326  RUNTIME_DESTINATION
2327  CMAKE_DESTINATION
2328  LICENSE_DESTINATION
2329  HIERARCHY_DESTINATION)
2330 
2331  foreach (_vtk_build_module IN LISTS _vtk_build_MODULES)
2332  get_property("_vtk_build_${_vtk_build_module}_depends" GLOBAL
2333  PROPERTY "_vtk_module_${_vtk_build_module}_depends")
2334  get_property("_vtk_build_${_vtk_build_module}_private_depends" GLOBAL
2335  PROPERTY "_vtk_module_${_vtk_build_module}_private_depends")
2336  get_property("_vtk_build_${_vtk_build_module}_optional_depends" GLOBAL
2337  PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
2338  get_property("_vtk_build_${_vtk_build_module}_order_depends" GLOBAL
2339  PROPERTY "_vtk_module_${_vtk_build_module}_order_depends")
2340  set("_vtk_build_${_vtk_build_module}_all_depends"
2341  ${_vtk_build_${_vtk_build_module}_depends}
2342  ${_vtk_build_${_vtk_build_module}_private_depends}
2343  ${_vtk_build_${_vtk_build_module}_optional_depends}
2344  ${_vtk_build_${_vtk_build_module}_order_depends})
2345  endforeach ()
2346 
2347  set(_vtk_build_sorted_modules "${_vtk_build_MODULES}")
2348  vtk_topological_sort(_vtk_build_sorted_modules "_vtk_build_" "_all_depends")
2349 
2350  foreach (_vtk_build_module IN LISTS _vtk_build_sorted_modules)
2351  if (NOT _vtk_build_module IN_LIST _vtk_build_MODULES)
2352  continue ()
2353  endif ()
2354 
2355  if (TARGET "${_vtk_build_module}")
2356  get_property(_vtk_build_is_imported
2357  TARGET "${_vtk_build_module}"
2358  PROPERTY IMPORTED)
2359 
2360  # TODO: Is this right?
2361  if (NOT _vtk_build_is_imported)
2362  message(FATAL_ERROR
2363  "The ${_vtk_build_module} module has been requested to be built, but "
2364  "it is already built by this project.")
2365  endif ()
2366 
2367  continue ()
2368  endif ()
2369 
2370  foreach (_vtk_build_depend IN LISTS "_vtk_build_${_vtk_build_module}_depends" "_vtk_build_${_vtk_build_module}_private_depends")
2371  if (NOT TARGET "${_vtk_build_depend}")
2372  message(FATAL_ERROR
2373  "The ${_vtk_build_depend} dependency is missing for ${_vtk_build_module}.")
2374  endif ()
2375  endforeach ()
2376 
2377  get_property(_vtk_build_module_file GLOBAL
2378  PROPERTY "_vtk_module_${_vtk_build_module}_file")
2379  if (NOT _vtk_build_module_file)
2380  message(FATAL_ERROR
2381  "The requested ${_vtk_build_module} module is not a VTK module.")
2382  endif ()
2383 
2384  _vtk_module_debug(building "@_vtk_build_module@ is being built")
2385 
2386  get_filename_component(_vtk_build_module_dir "${_vtk_build_module_file}" DIRECTORY)
2387  file(RELATIVE_PATH _vtk_build_module_subdir "${CMAKE_SOURCE_DIR}" "${_vtk_build_module_dir}")
2388  add_subdirectory(
2389  "${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}"
2390  "${CMAKE_BINARY_DIR}/${_vtk_build_module_subdir}")
2391 
2392  if (NOT TARGET "${_vtk_build_module}")
2393  message(FATAL_ERROR
2394  "The ${_vtk_build_module} is being built, but a matching target was "
2395  "not created.")
2396  endif ()
2397  endforeach ()
2398 
2399  if (_vtk_build_BUILD_WITH_KITS)
2400  foreach (_vtk_build_kit IN LISTS _vtk_build_KITS)
2401  get_property(_vtk_build_target_name GLOBAL
2402  PROPERTY "_vtk_kit_${_vtk_build_kit}_target_name")
2403  set(_vtk_kit_source_file
2404  "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/vtk_module_kit_${_vtk_build_target_name}.c")
2405  file(GENERATE
2406  OUTPUT "${_vtk_kit_source_file}"
2407  CONTENT "void vtk_module_kit_${_vtk_build_target_name}() {}\n")
2408  add_library("${_vtk_build_target_name}"
2409  "${_vtk_kit_source_file}")
2410  get_property(_vtk_build_namespace GLOBAL
2411  PROPERTY "_vtk_kit_${_vtk_build_kit}_namespace")
2412  if (_vtk_build_TARGET_NAMESPACE STREQUAL "<AUTO>")
2413  set(_vtk_build_TARGET_NAMESPACE "${_vtk_build_namespace}")
2414  endif ()
2415  if (NOT _vtk_build_namespace STREQUAL _vtk_build_TARGET_NAMESPACE)
2416  message(FATAL_ERROR
2417  "The `TARGET_NAMESPACE` (${_vtk_build_TARGET_NAMESPACE}) is not the "
2418  "same as the ${_vtk_build_kit} kit namespace "
2419  "(${_vtk_build_namespace}).")
2420  endif ()
2421  if (NOT _vtk_build_kit STREQUAL _vtk_build_target_name)
2422  add_library("${_vtk_build_kit}" ALIAS
2423  "${_vtk_build_target_name}")
2424  endif ()
2425  _vtk_module_apply_properties("${_vtk_build_target_name}")
2426  _vtk_module_install("${_vtk_build_target_name}")
2427 
2428  set(_vtk_build_kit_modules_object_libraries)
2429  set(_vtk_build_kit_modules_private_depends)
2430 
2431  get_property(_vtk_build_kit_modules GLOBAL
2432  PROPERTY "_vtk_kit_${_vtk_build_kit}_kit_modules")
2433  foreach (_vtk_build_kit_module IN LISTS _vtk_build_kit_modules)
2434  get_property(_vtk_build_kit_module_target_name GLOBAL
2435  PROPERTY "_vtk_module_${_vtk_build_kit_module}_target_name")
2436  list(APPEND _vtk_build_kit_modules_object_libraries
2437  "${_vtk_build_kit_module_target_name}-objects")
2438 
2439  # Since there is no link step for modules, we need to copy the private
2440  # dependencies of the constituent modules into the kit so that their
2441  # private dependencies are actually linked.
2442  get_property(_vtk_build_kit_module_private_depends GLOBAL
2443  PROPERTY "_vtk_module_${_vtk_build_kit_module}_private_depends")
2444  # Also grab optional dependencies since they end up being private
2445  # links.
2446  get_property(_vtk_build_kit_module_optional_depends GLOBAL
2447  PROPERTY "_vtk_module_${_vtk_build_kit_module}_optional_depends")
2448  foreach (_vtk_build_kit_module_private_depend IN LISTS _vtk_build_kit_module_private_depends _vtk_build_kit_module_optional_depends)
2449  if (NOT TARGET "${_vtk_build_kit_module_private_depend}")
2450  continue ()
2451  endif ()
2452 
2453  # But we don't need to link to modules that are part of the kit we are
2454  # building.
2455  if (NOT _vtk_build_kit_module_private_depend IN_LIST _vtk_build_kit_modules)
2456  list(APPEND _vtk_build_kit_modules_private_depends
2457  "$<LINK_ONLY:${_vtk_build_kit_module_private_depend}>")
2458  endif ()
2459  endforeach ()
2460  endforeach ()
2461 
2462  get_property(_vtk_build_kit_private_links GLOBAL
2463  PROPERTY "_vtk_kit_${_vtk_build_kit}_private_links")
2464 
2465  if (_vtk_build_kit_modules_private_depends)
2466  list(REMOVE_DUPLICATES _vtk_build_kit_modules_private_depends)
2467  endif ()
2468  if (_vtk_build_kit_modules_private_links)
2469  list(REMOVE_DUPLICATES _vtk_build_kit_modules_private_links)
2470  endif ()
2471 
2472  target_link_libraries("${_vtk_build_target_name}"
2473  PRIVATE
2474  ${_vtk_build_kit_modules_object_libraries}
2475  ${_vtk_build_kit_modules_private_depends}
2476  ${_vtk_build_kit_private_links})
2477  get_property(_vtk_build_kit_library_name GLOBAL
2478  PROPERTY "_vtk_kit_${_vtk_build_kit}_library_name")
2479  if (_vtk_build_LIBRARY_NAME_SUFFIX)
2480  string(APPEND _vtk_build_kit_library_name "-${_vtk_build_LIBRARY_NAME_SUFFIX}")
2481  endif ()
2482  set_target_properties("${_vtk_build_target_name}"
2483  PROPERTIES
2484  OUTPUT_NAME "${_vtk_build_kit_library_name}")
2485  endforeach ()
2486  endif ()
2487 
2488  set(_vtk_build_properties_filename "${_vtk_build_PACKAGE}-vtk-module-properties.cmake")
2489  set(_vtk_build_properties_install_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_build_properties_filename}.install")
2490  set(_vtk_build_properties_build_file "${CMAKE_BINARY_DIR}/${_vtk_build_CMAKE_DESTINATION}/${_vtk_build_properties_filename}")
2491 
2492  file(WRITE "${_vtk_build_properties_build_file}")
2493 
2494  _vtk_module_write_import_prefix(
2495  "${_vtk_build_properties_install_file}"
2496  "${_vtk_build_CMAKE_DESTINATION}")
2497 
2498  foreach (_vtk_build_module IN LISTS _vtk_build_MODULES)
2499  get_property(_vtk_build_namespace GLOBAL
2500  PROPERTY "_vtk_module_${_vtk_build_module}_namespace")
2501  if (_vtk_build_TARGET_NAMESPACE STREQUAL "<AUTO>")
2502  set(_vtk_build_TARGET_NAMESPACE "${_vtk_build_namespace}")
2503  endif ()
2504  if (NOT _vtk_build_namespace STREQUAL _vtk_build_TARGET_NAMESPACE)
2505  message(FATAL_ERROR
2506  "The `TARGET_NAMESPACE` (${_vtk_build_TARGET_NAMESPACE}) is not the "
2507  "same as the ${_vtk_build_module} module namespace "
2508  "(${_vtk_build_namespace}).")
2509  endif ()
2510 
2511  get_property(_vtk_build_is_third_party
2512  TARGET "${_vtk_build_module}"
2513  PROPERTY "INTERFACE_vtk_module_third_party")
2514  if (_vtk_build_is_third_party)
2515  _vtk_module_export_properties(
2516  BUILD_FILE "${_vtk_build_properties_build_file}"
2517  INSTALL_FILE "${_vtk_build_properties_install_file}"
2518  MODULE "${_vtk_build_module}"
2519  FROM_GLOBAL_PROPERTIES
2520  # Export the dependencies of a module.
2521  depends
2522  private_depends
2523  optional_depends
2524  # The library name of the module.
2525  library_name
2526  PROPERTIES
2527  # Export whether a module is third party or not.
2528  INTERFACE_vtk_module_third_party
2529  INTERFACE_vtk_module_exclude_wrap)
2530  continue ()
2531  endif ()
2532 
2533  set(_vtk_build_split_properties)
2534  get_property(_vtk_build_exclude_wrap
2535  TARGET "${_vtk_build_module}"
2536  PROPERTY "INTERFACE_vtk_module_${_vtk_build_module}_exclude_wrap")
2537  if (NOT _vtk_build_exclude_wrap)
2538  list(APPEND _vtk_build_split_properties
2539  headers)
2540  if (_vtk_build_ENABLE_WRAPPING)
2541  list(APPEND _vtk_build_split_properties
2542  hierarchy)
2543  endif ()
2544  endif ()
2545 
2546  set(_vtk_build_properties_kit_properties)
2547  if (_vtk_build_BUILD_WITH_KITS)
2548  list(APPEND _vtk_build_properties_kit_properties
2549  # Export the kit membership of a module.
2550  kit)
2551  endif ()
2552 
2553  _vtk_module_export_properties(
2554  BUILD_FILE "${_vtk_build_properties_build_file}"
2555  INSTALL_FILE "${_vtk_build_properties_install_file}"
2556  MODULE "${_vtk_build_module}"
2557  FROM_GLOBAL_PROPERTIES
2558  # Export whether the module should be excluded from wrapping or not.
2559  exclude_wrap
2560  # Export the dependencies of a module.
2561  depends
2562  private_depends
2563  optional_depends
2564  # Export what modules are implemented by the module.
2565  implements
2566  # Export whether the module contains autoinit logic.
2567  implementable
2568  # The library name of the module.
2569  library_name
2570  ${_vtk_build_properties_kit_properties}
2571  PROPERTIES
2572  # Export whether the module needs autoinit logic handled.
2573  INTERFACE_vtk_module_needs_autoinit
2574  # Forward private usage requirements with global effects.
2575  INTERFACE_vtk_module_forward_link
2576  SPLIT_INSTALL_PROPERTIES
2577  # Set the properties which differ between build and install trees.
2578  ${_vtk_build_split_properties})
2579  endforeach ()
2580 
2581  if (_vtk_build_BUILD_WITH_KITS)
2582  foreach (_vtk_build_kit IN LISTS _vtk_build_KITS)
2583  _vtk_module_export_properties(
2584  BUILD_FILE "${_vtk_build_properties_build_file}"
2585  INSTALL_FILE "${_vtk_build_properties_install_file}"
2586  KIT "${_vtk_build_kit}"
2587  FROM_GLOBAL_PROPERTIES
2588  # Export the list of modules in the kit.
2589  kit_modules)
2590  endforeach ()
2591  endif ()
2592 
2593  if (_vtk_build_INSTALL_EXPORT AND _vtk_build_INSTALL_HEADERS)
2594  set(_vtk_build_namespace)
2595  if (_vtk_build_TARGET_NAMESPACE)
2596  set(_vtk_build_namespace
2597  NAMESPACE "${_vtk_build_TARGET_NAMESPACE}::")
2598  endif ()
2599 
2600  export(
2601  EXPORT "${_vtk_build_INSTALL_EXPORT}"
2602  ${_vtk_build_namespace}
2603  FILE "${CMAKE_BINARY_DIR}/${_vtk_build_CMAKE_DESTINATION}/${_vtk_build_PACKAGE}-targets.cmake")
2604  install(
2605  EXPORT "${_vtk_build_INSTALL_EXPORT}"
2606  DESTINATION "${_vtk_build_CMAKE_DESTINATION}"
2607  ${_vtk_build_namespace}
2608  FILE "${_vtk_build_PACKAGE}-targets.cmake"
2609  COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
2610 
2611  if (_vtk_build_INSTALL_HEADERS)
2612  file(APPEND "${_vtk_build_properties_install_file}"
2613  "unset(_vtk_module_import_prefix)\n")
2614 
2615  install(
2616  FILES "${_vtk_build_properties_install_file}"
2617  DESTINATION "${_vtk_build_CMAKE_DESTINATION}"
2618  RENAME "${_vtk_build_properties_filename}"
2619  COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
2620  endif ()
2621  endif ()
2622 
2623  get_property(_vtk_build_test_modules GLOBAL
2624  PROPERTY "_vtk_module_test_modules")
2625  set(_vtk_build_tests_handled)
2626  foreach (_vtk_build_test IN LISTS _vtk_build_test_modules)
2627  if (NOT _vtk_build_test IN_LIST _vtk_build_MODULES)
2628  continue ()
2629  endif ()
2630  list(APPEND _vtk_build_tests_handled
2631  "${_vtk_build_test}")
2632 
2633  get_property(_vtk_build_test_depends GLOBAL
2634  PROPERTY "_vtk_module_${_vtk_build_test}_test_depends")
2635 
2636  set(_vtk_build_test_has_depends TRUE)
2637  foreach (_vtk_build_test_depend IN LISTS _vtk_build_test_depends)
2638  if (NOT TARGET "${_vtk_build_test_depend}")
2639  set(_vtk_build_test_has_depends FALSE)
2640  _vtk_module_debug(testing "@_vtk_build_test@ testing disabled due to missing @_vtk_build_test_depend@")
2641  endif ()
2642  endforeach ()
2643  if (NOT _vtk_build_test_has_depends)
2644  continue ()
2645  endif ()
2646 
2647  get_property(_vtk_build_module_file GLOBAL
2648  PROPERTY "_vtk_module_${_vtk_build_test}_file")
2649 
2650  if (NOT _vtk_build_TEST_DIRECTORY_NAME STREQUAL "NONE")
2651  get_filename_component(_vtk_build_module_dir "${_vtk_build_module_file}" DIRECTORY)
2652  file(RELATIVE_PATH _vtk_build_module_subdir "${CMAKE_SOURCE_DIR}" "${_vtk_build_module_dir}")
2653  if (EXISTS "${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}/${_vtk_build_TEST_DIRECTORY_NAME}")
2654  get_property(_vtk_build_test_labels GLOBAL
2655  PROPERTY "_vtk_module_${_vtk_build_test}_test_labels")
2656  add_subdirectory(
2657  "${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}/${_vtk_build_TEST_DIRECTORY_NAME}"
2658  "${CMAKE_BINARY_DIR}/${_vtk_build_module_subdir}/${_vtk_build_TEST_DIRECTORY_NAME}")
2659  endif ()
2660  endif ()
2661  endforeach ()
2662 
2663  if (_vtk_build_test_modules AND _vtk_build_tests_handled)
2664  list(REMOVE_ITEM _vtk_build_test_modules
2665  ${_vtk_build_tests_handled})
2666  set_property(GLOBAL
2667  PROPERTY
2668  _vtk_module_test_modules "${_vtk_build_test_modules}")
2669  endif ()
2670 endfunction ()
2671 
2672 #[==[
2673 @ingroup module-impl
2674 @brief Add "standard" include directories to a module
2675 
2676 Add the "standard" includes for a module to its interface. These are the source
2677 and build directories for the module itself. They are always either `PUBLIC` or
2678 `INTERFACE` (depending on the module's target type).
2679 
2680 ~~~
2681 _vtk_module_standard_includes(
2682  [SYSTEM]
2683  [INTERFACE]
2684  TARGET <target>
2685  [HEADERS_DESTINATION <destination>])
2686 ~~~
2687 #]==]
2688 function (_vtk_module_standard_includes)
2689  cmake_parse_arguments(_vtk_standard_includes
2690  "SYSTEM;INTERFACE"
2691  "TARGET;HEADERS_DESTINATION"
2692  ""
2693  ${ARGN})
2694 
2695  if (NOT _vtk_standard_includes_TARGET)
2696  message(FATAL_ERROR
2697  "The `TARGET` argument is required.")
2698  endif ()
2699  if (NOT TARGET "${_vtk_standard_includes_TARGET}")
2700  message(FATAL_ERROR
2701  "The `TARGET` argument is not a target.")
2702  endif ()
2703 
2704  if (_vtk_standard_includes_UNPARSED_ARGUMENTS)
2705  message(FATAL_ERROR
2706  "Unparsed arguments for vtk_module_standard_includes: "
2707  "${_vtk_standard_includes_UNPARSED_ARGUMENTS}")
2708  endif ()
2709 
2710  set(_vtk_standard_includes_system)
2711  if (_vtk_standard_includes_SYSTEM)
2712  set(_vtk_standard_includes_system SYSTEM)
2713  endif ()
2714 
2715  set(_vtk_standard_includes_visibility PUBLIC)
2716  if (_vtk_standard_includes_INTERFACE)
2717  set(_vtk_standard_includes_visibility INTERFACE)
2718  endif ()
2719 
2720  target_include_directories("${_vtk_standard_includes_TARGET}"
2721  ${_vtk_standard_includes_system}
2722  "${_vtk_standard_includes_visibility}"
2723  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
2724  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
2725 
2726  if (_vtk_build_INSTALL_HEADERS AND _vtk_standard_includes_HEADERS_DESTINATION)
2727  target_include_directories("${_vtk_standard_includes_TARGET}"
2728  ${_vtk_standard_includes_system}
2729  "${_vtk_standard_includes_visibility}"
2730  $<INSTALL_INTERFACE:${_vtk_standard_includes_HEADERS_DESTINATION}>)
2731  endif ()
2732 endfunction ()
2733 
2734 #[==[
2735 @ingroup module-impl
2736 @brief Determine the default export macro for a module
2737 
2738 Determines the export macro to be used for a module from its metadata. Assumes
2739 it is called from within a @ref vtk_module_build call.
2740 
2741 ~~~
2742 _vtk_module_default_library_name(<varname>)
2743 ~~~
2744 #]==]
2745 function (_vtk_module_default_export_macro_prefix varname)
2746  get_property(_vtk_module_default_library_name GLOBAL
2747  PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
2748  string(TOUPPER "${_vtk_module_default_library_name}" _vtk_default_export_macro_upper)
2749  set("${varname}"
2750  "${_vtk_default_export_macro_upper}"
2751  PARENT_SCOPE)
2752 endfunction ()
2753 
2754 # TODO: It would be nice to support `USE_LINK_PROPERTIES` instead of listing
2755 # the modules again here. However, the format of the `LINK_LIBRARIES` property
2756 # value may not be easy to handle.
2757 
2758 #[==[
2759 @page module-overview
2760 
2761 @ingroup module
2762 @section module-autoinit Autoinit
2763 
2764 When a module contains a factory which may be populated by other modules, these
2765 factories need to be populated when the modules are loaded by the dynamic linker
2766 (for shared builds) or program load time (for static builds). To provide for
2767 this, the module system contains an autoinit "subsystem".
2768 
2769 @subsection module-autoinit-leverage Leveraging the autoinit subsystem
2770 
2771 The subsystem provides the following hooks for use by projects:
2772 
2773  * In modules which `IMPLEMENTS` other modules, in the generated
2774  `<module>Module.h` header (which provides export symbols as well) will
2775  include the modules which are implemented.
2776  * In modules which are `IMPLEMENTABLE` or `IMPLEMENTS` another module, the
2777  generated `<module>Module.h` file will include the following block:
2778 
2779 ~~~{.c}
2780 #ifdef <module>_AUTOINIT_INCLUDE
2781 #include <module>_AUTOINIT_INCLUDE
2782 #endif
2783 #ifdef <module>_AUTOINIT
2784 #include <header>
2785 VTK_MODULE_AUTOINIT(<module>)
2786 #endif
2787 ~~~
2788 
2789 The @ref vtk_module_autoinit function will generate an include file and provide
2790 its path via the `<module>_AUTOINIT_INCLUDE` define. once it has been included,
2791 if the `<module>_AUTOINIT` symbol is defined, a header is included which is
2792 intended to provide the `VTK_MODULE_AUTOINIT` macro. This macro is given the
2793 module name and should use `<module>_AUTOINIT` to fill in the factories in the
2794 module with those from the `IMPLEMENTS` modules listed in that symbol.
2795 
2796 The `<module>_AUTOINIT` symbol's value is:
2797 
2798 ~~~
2799 <count>(<module1>,<module2>,<module3>)
2800 ~~~
2801 
2802 where `<count>` is the number of modules in the parentheses and each module
2803 listed need to register something to `<module>`.
2804 
2805 If not provided via the `AUTOINIT_INCLUDE` argument to the
2806 @ref vtk_module_add_module function, the header to use is fetched from the
2807 `_vtk_module_autoinit_include` global property. This only needs to be managed
2808 in modules that `IMPLEMENTS` or are `IMPLEMENTABLE`. This should be provided by
2809 projects using the module system at its lowest level. Projects not implementing
2810 the `VTK_MODULE_AUTOINIT` macro should have its value provided by
2811 `find_package` dependencies in some way.
2812 #]==]
2813 
2814 #[==[
2815 @ingroup module
2816 @brief Linking to autoinit-using modules
2817 
2818 When linking to modules, in order for the autoinit system to work, modules need
2819 to declare their registration. In order to do this, defines may need to be
2820 provided to targets in order to trigger registration. These defines may be
2821 added to targets by using this function.
2822 
2823 ~~~
2824 vtk_module_autoinit(
2825  TARGETS <target>...
2826  MODULES <module>...)
2827 ~~~
2828 
2829 After this call, the targets given to the `TARGETS` argument will gain the
2830 preprocessor definitions to trigger registrations properly.
2831 #]==]
2832 function (vtk_module_autoinit)
2833  cmake_parse_arguments(_vtk_autoinit
2834  ""
2835  ""
2836  "TARGETS;MODULES"
2837  ${ARGN})
2838 
2839  if (_vtk_autoinit_UNRECOGNIZED_ARGUMENTS)
2840  message(FATAL_ERROR
2841  "Unparsed arguments for vtk_module_autoinit: "
2842  "${_vtk_autoinit_UNRECOGNIZED_ARGUMENTS}.")
2843  endif ()
2844 
2845  if (NOT _vtk_autoinit_TARGETS)
2846  message(FATAL_ERROR
2847  "The `TARGETS` argument is required.")
2848  endif ()
2849 
2850  if (NOT _vtk_autoinit_MODULES)
2851  message(AUTHOR_WARNING
2852  "No `MODULES` passed to `vtk_modules_autoinit`.")
2853  endif ()
2854 
2855  set(_vtk_autoinit_module_stack
2856  ${_vtk_autoinit_TARGETS})
2857 
2858  set(_vtk_autoinit_needs_implements)
2859  set(_vtk_autoinit_seen)
2860  while (_vtk_autoinit_module_stack)
2861  list(GET _vtk_autoinit_module_stack 0 _vtk_autoinit_current_module)
2862  list(REMOVE_AT _vtk_autoinit_module_stack 0)
2863  if (_vtk_autoinit_current_module IN_LIST _vtk_autoinit_seen)
2864  continue ()
2865  endif ()
2866  list(APPEND _vtk_autoinit_seen
2867  "${_vtk_autoinit_current_module}")
2868 
2869  set(_vtk_autoinit_current_target "${_vtk_autoinit_current_module}")
2870  get_property(_vtk_autoinit_implements
2871  TARGET "${_vtk_autoinit_current_target}"
2872  PROPERTY "INTERFACE_vtk_module_implements")
2873 
2874  list(APPEND _vtk_autoinit_needs_implements
2875  ${_vtk_autoinit_current_target})
2876  foreach (_vtk_autoinit_implement IN LISTS _vtk_autoinit_implements)
2877  _vtk_module_real_target(_vtk_autoinit_implements_target "${_vtk_autoinit_implement}")
2878  get_property(_vtk_autoinit_implementable
2879  TARGET "${_vtk_autoinit_implements_target}"
2880  PROPERTY "INTERFACE_vtk_module_implementable")
2881 
2882  if (NOT _vtk_autoinit_implementable)
2883  message(FATAL_ERROR
2884  "The `${_vtk_autoinit_current_module}` module says that it "
2885  "implements the `${_vtk_autoinit_implement}` module, but it is not "
2886  "implementable.")
2887  endif ()
2888 
2889  list(APPEND "_vtk_autoinit_implements_${_vtk_autoinit_current_target}"
2890  "${_vtk_autoinit_current_module}")
2891  endforeach ()
2892  endwhile ()
2893 
2894  if (NOT _vtk_autoinit_needs_implements)
2895  return ()
2896  endif ()
2897  list(REMOVE_DUPLICATES _vtk_autoinit_needs_implements)
2898  list(SORT _vtk_autoinit_needs_implements)
2899 
2900  set(_vtk_autoinit_hash_content)
2901  foreach (_vtk_autoinit_need_implements IN LISTS _vtk_autoinit_needs_implements)
2902  if (NOT _vtk_autoinit_implements_${_vtk_autoinit_need_implements})
2903  continue ()
2904  endif ()
2905  list(SORT "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}")
2906 
2907  string(APPEND _vtk_autoinit_hash_content
2908  "${_vtk_autoinit_need_implements}: ${_vtk_autoinit_implements_${_vtk_autoinit_need_implements}}\n")
2909  endforeach ()
2910  string(MD5 _vtk_autoinit_header_tag "${_vtk_autoinit_hash_content}")
2911  set(_vtk_autoinit_header
2912  "${CMAKE_BINARY_DIR}/CMakeFiles/vtkModuleAutoInit_${_vtk_autoinit_header_tag}.h")
2913 
2914  get_property(_vtk_autoinit_header_generated GLOBAL
2915  PROPERTY "_vtk_autoinit_generated_${_vtk_autoinit_header_tag}")
2916 
2917  set(_vtk_autoinit_defines)
2918  set(_vtk_autoinit_header_content)
2919  foreach (_vtk_autoinit_need_implements IN LISTS _vtk_autoinit_needs_implements)
2920  if (NOT _vtk_autoinit_implements_${_vtk_autoinit_need_implements})
2921  continue ()
2922  endif ()
2923 
2924  get_property(_vtk_autoinit_implements_library_name
2925  TARGET "${_vtk_autoinit_need_implements}"
2926  PROPERTY "INTERFACE_vtk_module_library_name")
2927 
2928  if (NOT _vtk_autoinit_header_generated)
2929  list(LENGTH "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}"
2930  _vtk_autoinit_length)
2931  set(_vtk_autoinit_args)
2932  foreach (_vtk_autoinit_arg IN LISTS "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}")
2933  get_property(_vtk_autoinit_arg_library_name
2934  TARGET "${_vtk_autoinit_arg}"
2935  PROPERTY "INTERFACE_vtk_module_library_name")
2936  list(APPEND _vtk_autoinit_args
2937  "${_vtk_autoinit_arg_library_name}")
2938  endforeach ()
2939  string(REPLACE ";" "," _vtk_autoinit_args "${_vtk_autoinit_args}")
2940  string(APPEND _vtk_autoinit_header_content
2941  "#define ${_vtk_autoinit_implements_library_name}_AUTOINIT ${_vtk_autoinit_length}(${_vtk_autoinit_args})\n")
2942  endif ()
2943 
2944  list(APPEND _vtk_autoinit_defines
2945  "${_vtk_autoinit_implements_library_name}_AUTOINIT_INCLUDE=\"${_vtk_autoinit_header}\"")
2946  endforeach ()
2947 
2948  if (NOT _vtk_autoinit_header_generated)
2949  file(GENERATE
2950  OUTPUT "${_vtk_autoinit_header}"
2951  CONTENT "${_vtk_autoinit_header_content}")
2952 
2953  set_property(GLOBAL
2954  PROPERTY
2955  "_vtk_autoinit_generated_${_vtk_autoinit_header_tag}" TRUE)
2956  endif ()
2957 
2958  foreach (_vtk_autoinit_target IN LISTS _vtk_autoinit_TARGETS)
2959  get_property(_vtk_autoinit_target_type
2960  TARGET "${_vtk_autoinit_target}"
2961  PROPERTY TYPE)
2962  if (_vtk_autoinit_target_type STREQUAL "INTERFACE_LIBRARY")
2963  continue ()
2964  endif ()
2965 
2966  _vtk_module_real_target(_vtk_autoinit_real_target "${_vtk_autoinit_target}")
2967 
2968  target_compile_definitions("${_vtk_autoinit_real_target}"
2969  PRIVATE
2970  ${_vtk_autoinit_defines})
2971  endforeach ()
2972 endfunction ()
2973 
2974 #[==[
2975 @ingroup module-impl
2976 @brief Generate the hierarchy for a module
2977 
2978 Write wrap hierarchy files for the module currently being built. This also
2979 installs the hierarchy file for use by dependent projects if `INSTALL_HEADERS`
2980 is set.
2981 
2982 ~~~
2983 _vtk_module_write_wrap_hierarchy()
2984 ~~~
2985 #]==]
2986 function (_vtk_module_write_wrap_hierarchy)
2987  file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_HIERARCHY_DESTINATION}")
2988 
2989  get_property(_vtk_hierarchy_library_name GLOBAL
2990  PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
2991  set(_vtk_hierarchy_filename "${_vtk_hierarchy_library_name}-hierarchy.txt")
2992  set(_vtk_hierarchy_file "${CMAKE_BINARY_DIR}/${_vtk_build_HIERARCHY_DESTINATION}/${_vtk_hierarchy_filename}")
2993  set(_vtk_hierarchy_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.$<CONFIGURATION>.args")
2994  set(_vtk_hierarchy_data_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.data")
2995  set(_vtk_hierarchy_depends_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.depends.args")
2996 
2997  set_property(TARGET "${_vtk_add_module_real_target}"
2998  PROPERTY
2999  "INTERFACE_vtk_module_hierarchy" "${_vtk_hierarchy_file}")
3000 
3001  set(_vtk_add_module_target_name_iface "${_vtk_add_module_target_name}")
3002  if (_vtk_add_module_build_with_kit)
3003  set(_vtk_add_module_target_name_iface "${_vtk_add_module_target_name}-objects")
3004  endif ()
3005  set(_vtk_hierarchy_genex_compile_definitions
3006  "$<TARGET_PROPERTY:${_vtk_add_module_target_name_iface},COMPILE_DEFINITIONS>")
3007  set(_vtk_hierarchy_genex_include_directories
3008  "$<TARGET_PROPERTY:${_vtk_add_module_target_name_iface},INCLUDE_DIRECTORIES>")
3009  file(GENERATE
3010  OUTPUT "${_vtk_hierarchy_args_file}"
3011  CONTENT "$<$<BOOL:${_vtk_hierarchy_genex_compile_definitions}>:\n-D\'$<JOIN:${_vtk_hierarchy_genex_compile_definitions},\'\n-D\'>\'>\n
3012 $<$<BOOL:${_vtk_hierarchy_genex_include_directories}>:\n-I\'$<JOIN:${_vtk_hierarchy_genex_include_directories},\'\n-I\'>\'>\n")
3013 
3014  get_property(_vtk_hierarchy_depends_is_global GLOBAL
3015  PROPERTY "_vtk_module_${_vtk_build_module}_depends"
3016  SET)
3017  if (_vtk_hierarchy_depends_is_global)
3018  get_property(_vtk_hierarchy_depends GLOBAL
3019  PROPERTY "_vtk_module_${_vtk_build_module}_depends")
3020  else ()
3021  get_property(_vtk_hierarchy_depends GLOBAL
3022  TARGET "${_vtk_add_module_real_target}"
3023  PROPERTY "INTERFACE_vtk_module_depends")
3024  endif ()
3025 
3026  set(_vtk_hierarchy_depends_files)
3027  set(_vtk_hierarchy_depends_targets)
3028  foreach (_vtk_hierarchy_depend IN LISTS _vtk_hierarchy_depends)
3029  _vtk_module_get_module_property("${_vtk_hierarchy_depend}"
3030  PROPERTY "hierarchy"
3031  VARIABLE _vtk_hierarchy_depend_hierarchy)
3032  if (NOT DEFINED _vtk_hierarchy_depend_hierarchy)
3033  continue ()
3034  endif ()
3035 
3036  list(APPEND _vtk_hierarchy_depends_files
3037  "${_vtk_hierarchy_depend_hierarchy}")
3038 
3039  # Find the hierarchy target of the module.
3040  get_property(_vtk_hierarchy_module_is_imported
3041  TARGET "${_vtk_hierarchy_depend}"
3042  PROPERTY IMPORTED)
3043  # Imported target modules are external and should already have their file
3044  # generated.
3045  if (_vtk_hierarchy_module_is_imported)
3046  continue ()
3047  endif ()
3048 
3049  get_property(_vtk_hierarchy_depend_library_name GLOBAL
3050  PROPERTY "_vtk_module_${_vtk_hierarchy_depend}_library_name")
3051  if (TARGET "${_vtk_hierarchy_depend_library_name}-hierarchy")
3052  list(APPEND _vtk_hierarchy_depends_targets
3053  "${_vtk_hierarchy_depend_library_name}-hierarchy")
3054  endif ()
3055  endforeach ()
3056 
3057  set(_vtk_hierarchy_depends_files_arg)
3058  if (_vtk_hierarchy_depends_files)
3059  file(GENERATE
3060  OUTPUT "${_vtk_hierarchy_depends_args_file}"
3061  CONTENT "\"$<JOIN:${_vtk_hierarchy_depends_files},\"\n\">\"\n")
3062  else ()
3063  file(GENERATE
3064  OUTPUT "${_vtk_hierarchy_depends_args_file}"
3065  CONTENT "")
3066  endif ()
3067 
3068  _vtk_module_get_module_property("${_vtk_build_module}"
3069  PROPERTY "headers"
3070  VARIABLE _vtk_hierarchy_headers)
3071  set(_vtk_hierarchy_data_content "")
3072  foreach (_vtk_hierarchy_header IN LISTS _vtk_hierarchy_headers)
3073  string(APPEND _vtk_hierarchy_data_content
3074  "${_vtk_hierarchy_header};${_vtk_hierarchy_library_name}\n")
3075  endforeach ()
3076  file(GENERATE
3077  OUTPUT "${_vtk_hierarchy_data_file}"
3078  CONTENT "${_vtk_hierarchy_data_content}")
3079 
3080  if (CMAKE_GENERATOR MATCHES "Ninja")
3081  set(_vtk_hierarchy_command_depends ${_vtk_hierarchy_depends_files})
3082  else ()
3083  set(_vtk_hierarchy_command_depends ${_vtk_hierarchy_depends_targets})
3084  endif ()
3085 
3086  set(_vtk_hierarchy_tool_target "VTK::WrapHierarchy")
3087  set(_vtk_hierarchy_macros_args)
3088  if (TARGET VTKCompileTools::WrapHierarchy)
3089  set(_vtk_hierarchy_tool_target "VTKCompileTools::WrapHierarchy")
3090  if (TARGET VTKCompileTools_macros)
3091  list(APPEND _vtk_hierarchy_command_depends
3092  "VTKCompileTools_macros")
3093  list(APPEND _vtk_hierarchy_macros_args
3094  -undef
3095  -imacros "${_VTKCompileTools_macros_file}")
3096  endif ()
3097  endif ()
3098 
3099  add_custom_command(
3100  OUTPUT "${_vtk_hierarchy_file}"
3101  COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
3102  "$<TARGET_FILE:${_vtk_hierarchy_tool_target}>"
3103  "@${_vtk_hierarchy_args_file}"
3104  -o "${_vtk_hierarchy_file}"
3105  "${_vtk_hierarchy_data_file}"
3106  "@${_vtk_hierarchy_depends_args_file}"
3107  ${_vtk_hierarchy_macros_args}
3108  COMMENT "Generating the wrap hierarchy for ${_vtk_build_module}"
3109  DEPENDS
3110  ${_vtk_hierarchy_headers}
3111  "${_vtk_hierarchy_args_file}"
3112  "${_vtk_hierarchy_data_file}"
3113  "${_vtk_hierarchy_depends_args_file}"
3114  ${_vtk_hierarchy_command_depends})
3115  add_custom_target("${_vtk_add_module_library_name}-hierarchy" ALL
3116  DEPENDS
3117  "${_vtk_hierarchy_file}"
3118  "$<TARGET_FILE:${_vtk_hierarchy_tool_target}>")
3119  set_property(TARGET "${_vtk_add_module_real_target}"
3120  PROPERTY
3121  "INTERFACE_vtk_module_hierarchy" "${_vtk_hierarchy_file}")
3122 
3123  if (_vtk_build_INSTALL_HEADERS)
3124  set_property(TARGET "${_vtk_add_module_real_target}"
3125  PROPERTY
3126  "INTERFACE_vtk_module_hierarchy_install" "\${_vtk_module_import_prefix}/${_vtk_build_HIERARCHY_DESTINATION}/${_vtk_hierarchy_filename}")
3127  install(
3128  FILES "${_vtk_hierarchy_file}"
3129  DESTINATION "${_vtk_build_HIERARCHY_DESTINATION}"
3130  RENAME "${_vtk_hierarchy_filename}"
3131  COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
3132  endif ()
3133 endfunction ()
3134 
3135 include(GenerateExportHeader)
3136 
3137 #[==[
3138 @ingroup module
3139 @brief Create a module library
3140 
3141 ~~~
3142 vtk_module_add_module(<name>
3143  [FORCE_STATIC] [HEADER_ONLY]
3144  [EXPORT_MACRO_PREFIX <prefix>]
3145  [HEADERS_SUBDIR <subdir>]
3146  [LIBRARY_NAME_SUFFIX <suffix>]
3147  [CLASSES <class>...]
3148  [TEMPLATE_CLASSES <template class>...]
3149  [SOURCES <source>...]
3150  [HEADERS <header>...]
3151  [TEMPLATES <template>...]
3152  [PRIVATE_CLASSES <class>...]
3153  [PRIVATE_TEMPLATE_CLASSES <template class>...]
3154  [PRIVATE_HEADERS <header>...]
3155  [PRIVATE_TEMPLATES <template>...])
3156 ~~~
3157 
3158 The `PRIVATE_` arguments are analogous to their non-`PRIVATE_` arguments, but
3159 the associated files are not installed or available for wrapping (`SOURCES` are
3160 always private, so there is no `PRIVATE_` variant for that argument).
3161 
3162  * `FORCE_STATIC`: For a static library to be created. If not provided,
3163  `BUILD_SHARED_LIBS` will control the library type.
3164  * `HEADER_ONLY`: The module only contains headers (or templates) and contains
3165  no compilation steps. Mutually exclusive with `FORCE_STATIC`.
3166  * `EXPORT_MACRO_PREFIX`: The prefix for the export macro definitions.
3167  Defaults to the library name of the module in all uppercase.
3168  * `HEADERS_SUBDIR`: The subdirectory to install headers into in the install
3169  tree.
3170  * `LIBRARY_NAME_SUFFIX`: The suffix to the module's library name if
3171  additional information is required.
3172  * `CLASSES`: A list of classes in the module. This is a shortcut for adding
3173  `<class>.cxx` to `SOURCES` and `<class>.h` to `HEADERS`.
3174  * `TEMPLATE_CLASSES`: A list of template classes in the module. This is a
3175  shortcut for adding `<class>.txx` to `TEMPLATES` and `<class>.h` to
3176  `HEADERS`.
3177  * `SOURCES`: A list of source files which require compilation.
3178  * `HEADERS`: A list of header files which will be available for wrapping and
3179  installed.
3180  * `TEMPLATES`: A list of template files which will be installed.
3181 #]==]
3183  if (NOT name STREQUAL _vtk_build_module)
3184  message(FATAL_ERROR
3185  "The ${_vtk_build_module}'s CMakeLists.txt may not add the ${name} module.")
3186  endif ()
3187 
3188  set(_vtk_add_module_source_keywords)
3189  foreach (_vtk_add_module_kind IN ITEMS CLASSES TEMPLATE_CLASSES HEADERS TEMPLATES)
3190  list(APPEND _vtk_add_module_source_keywords
3191  "${_vtk_add_module_kind}"
3192  "PRIVATE_${_vtk_add_module_kind}")
3193  endforeach ()
3194 
3195  cmake_parse_arguments(_vtk_add_module
3196  "FORCE_STATIC;HEADER_ONLY"
3197  "EXPORT_MACRO_PREFIX;HEADERS_SUBDIR;LIBRARY_NAME_SUFFIX"
3198  "${_vtk_add_module_source_keywords};SOURCES"
3199  ${ARGN})
3200 
3201  if (_vtk_add_module_UNPARSED_ARGUMENTS)
3202  message(FATAL_ERROR
3203  "Unparsed arguments for vtk_module_add_module: "
3204  "${_vtk_add_module_UNPARSED_ARGUMENTS}")
3205  endif ()
3206 
3207  if (NOT DEFINED _vtk_add_module_EXPORT_MACRO_PREFIX)
3208  _vtk_module_default_export_macro_prefix(_vtk_add_module_EXPORT_MACRO_PREFIX)
3209  endif ()
3210 
3211  if (_vtk_add_module_HEADER_ONLY AND _vtk_add_module_FORCE_STATIC)
3212  message(FATAL_ERROR
3213  "The ${_vtk_build_module} module cannot be header only yet forced "
3214  "static.")
3215  endif ()
3216 
3217  foreach (_vtk_add_module_class IN LISTS _vtk_add_module_CLASSES)
3218  list(APPEND _vtk_add_module_SOURCES
3219  "${_vtk_add_module_class}.cxx")
3220  list(APPEND _vtk_add_module_HEADERS
3221  "${_vtk_add_module_class}.h")
3222  endforeach ()
3223 
3224  foreach (_vtk_add_module_template_class IN LISTS _vtk_add_module_TEMPLATE_CLASSES)
3225  list(APPEND _vtk_add_module_TEMPLATES
3226  "${_vtk_add_module_template_class}.txx")
3227  list(APPEND _vtk_add_module_HEADERS
3228  "${_vtk_add_module_template_class}.h")
3229  endforeach ()
3230 
3231  foreach (_vtk_add_module_class IN LISTS _vtk_add_module_PRIVATE_CLASSES)
3232  list(APPEND _vtk_add_module_SOURCES
3233  "${_vtk_add_module_class}.cxx")
3234  list(APPEND _vtk_add_module_PRIVATE_HEADERS
3235  "${_vtk_add_module_class}.h")
3236  endforeach ()
3237 
3238  foreach (_vtk_add_module_template_class IN LISTS _vtk_add_module_PRIVATE_TEMPLATE_CLASSES)
3239  list(APPEND _vtk_add_module_PRIVATE_TEMPLATES
3240  "${_vtk_add_module_template_class}.txx")
3241  list(APPEND _vtk_add_module_PRIVATE_HEADERS
3242  "${_vtk_add_module_template_class}.h")
3243  endforeach ()
3244 
3245  if (NOT _vtk_add_module_SOURCES AND NOT _vtk_add_module_HEADER_ONLY)
3246  message(WARNING
3247  "The ${_vtk_build_module} module has no source files.")
3248  endif ()
3249 
3250  get_property(_vtk_add_module_third_party GLOBAL
3251  PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
3252 
3253  get_property(_vtk_add_module_library_name GLOBAL
3254  PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
3255  set(_vtk_add_module_module_header_name
3256  "${_vtk_add_module_library_name}Module.h")
3257  if (NOT _vtk_add_module_HEADER_ONLY AND NOT _vtk_add_module_third_party)
3258  set(_vtk_add_module_generated_header
3259  "${CMAKE_CURRENT_BINARY_DIR}/${_vtk_add_module_module_header_name}")
3260  list(APPEND _vtk_add_module_HEADERS
3261  "${_vtk_add_module_generated_header}")
3262  endif ()
3263 
3264  vtk_module_install_headers(
3265  FILES ${_vtk_add_module_HEADERS}
3266  ${_vtk_add_module_TEMPLATES}
3267  SUBDIR "${_vtk_add_module_HEADERS_SUBDIR}")
3268 
3269  set(_vtk_add_module_type)
3270  if (_vtk_add_module_FORCE_STATIC)
3271  set(_vtk_add_module_type STATIC)
3272  endif ()
3273 
3274  set(_vtk_add_module_build_with_kit)
3275  if (_vtk_build_BUILD_WITH_KITS)
3276  get_property(_vtk_add_module_build_with_kit GLOBAL
3277  PROPERTY "_vtk_module_${_vtk_build_module}_kit")
3278  endif ()
3279 
3280  get_property(_vtk_add_module_namespace GLOBAL
3281  PROPERTY "_vtk_module_${_vtk_build_module}_namespace")
3282  get_property(_vtk_add_module_target_name GLOBAL
3283  PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
3284  set(_vtk_add_module_real_target "${_vtk_add_module_target_name}")
3285  if (_vtk_add_module_HEADER_ONLY)
3286  if (_vtk_add_module_build_with_kit)
3287  message(FATAL_ERROR
3288  "The module ${_vtk_build_module} is header-only, but is part of the "
3289  "${_vtk_add_module_build_with_kit} kit. Header-only modules do not "
3290  "belong in kits.")
3291  endif ()
3292 
3293  # XXX(cmake-3.12.0): This unset is no longer necessary when 3.12.0 is required.
3294  unset("${_vtk_build_module}_LIB_DEPENDS" CACHE)
3295  add_library("${_vtk_add_module_real_target}" INTERFACE)
3296 
3297  if (NOT _vtk_build_module STREQUAL _vtk_add_module_real_target)
3298  add_library("${_vtk_build_module}" ALIAS
3299  "${_vtk_add_module_real_target}")
3300  endif ()
3301  else ()
3302  if (_vtk_add_module_build_with_kit)
3303  add_library("${_vtk_add_module_real_target}" INTERFACE)
3304  target_link_libraries("${_vtk_add_module_real_target}"
3305  INTERFACE
3306  # For usage requirements.
3307  "${_vtk_add_module_real_target}-objects"
3308  # For the implementation.
3309  "$<LINK_ONLY:${_vtk_add_module_build_with_kit}>")
3310 
3311  if (NOT _vtk_build_module STREQUAL _vtk_add_module_real_target)
3312  add_library("${_vtk_build_module}" ALIAS
3313  "${_vtk_add_module_real_target}")
3314  endif ()
3315 
3316  # Set up properties necessary for other infrastructure.
3317  set_property(TARGET "${_vtk_add_module_real_target}"
3318  PROPERTY
3319  "INTERFACE_vtk_module_library_name" "${_vtk_add_module_library_name}")
3320 
3321  # XXX(cmake-3.12.0): This unset is no longer necessary when 3.12.0 is required.
3322  unset("${_vtk_build_module}_LIB_DEPENDS" CACHE)
3323  add_library("${_vtk_add_module_real_target}-objects" OBJECT
3324  ${_vtk_add_module_SOURCES}
3325  ${_vtk_add_module_TEMPLATES}
3326  ${_vtk_add_module_PRIVATE_TEMPLATES}
3327  ${_vtk_add_module_HEADERS}
3328  ${_vtk_add_module_PRIVATE_HEADERS})
3329  set_target_properties("${_vtk_add_module_real_target}-objects"
3330  PROPERTIES
3331  # Emulate the regular library as much as possible.
3332  DEFINE_SYMBOL "${_vtk_add_module_real_target}_EXPORT"
3333  POSITION_INDEPENDENT_CODE ON)
3334  target_compile_definitions("${_vtk_add_module_real_target}-objects"
3335  PRIVATE
3336  "${_vtk_add_module_real_target}_EXPORT")
3337  set(_vtk_add_module_real_target "${_vtk_add_module_real_target}-objects")
3338  else ()
3339  add_library("${_vtk_add_module_real_target}" ${_vtk_add_module_type}
3340  ${_vtk_add_module_SOURCES}
3341  ${_vtk_add_module_TEMPLATES}
3342  ${_vtk_add_module_HEADERS}
3343  ${_vtk_add_module_PRIVATE_HEADERS})
3344 
3345  set_property(TARGET "${_vtk_add_module_real_target}"
3346  PROPERTY
3347  POSITION_INDEPENDENT_CODE ON)
3348 
3349  if (NOT _vtk_build_module STREQUAL _vtk_add_module_real_target)
3350  add_library("${_vtk_build_module}" ALIAS
3351  "${_vtk_add_module_real_target}")
3352  endif ()
3353  endif ()
3354  endif ()
3355 
3356  set_property(TARGET "${_vtk_add_module_real_target}"
3357  PROPERTY
3358  "INTERFACE_vtk_module_library_name" "${_vtk_add_module_library_name}")
3359 
3360  get_property(_vtk_add_module_depends GLOBAL
3361  PROPERTY "_vtk_module_${_vtk_build_module}_depends")
3362  set_property(TARGET "${_vtk_add_module_real_target}"
3363  PROPERTY
3364  "INTERFACE_vtk_module_depends" "${_vtk_add_module_depends}")
3365  set(_vtk_add_module_includes_interface)
3366  if (_vtk_add_module_HEADER_ONLY)
3367  target_link_libraries("${_vtk_add_module_real_target}"
3368  INTERFACE
3369  ${_vtk_add_module_depends})
3370  set(_vtk_add_module_includes_interface INTERFACE)
3371  else ()
3372  get_property(_vtk_add_module_private_depends GLOBAL
3373  PROPERTY "_vtk_module_${_vtk_build_module}_private_depends")
3374 
3375  # XXX(cmake#18484): Linking dependencies directly currently creates
3376  # circular dependencies. This logic should be removed once the minimum for
3377  # kits contains a fix for the mentioned issue.
3378  #
3379  # When two modules are part of the same kit, we can get this problem:
3380  #
3381  # A - iface -> A-objects <- tll - K
3382  # ^ |
3383  # | |
3384  # B - iface -> B-objects <- tll -/
3385  #
3386  # If B depends on A, it ends up with a circular dependency since A has a
3387  # `$<LINK_ONLY:K>` link. instead, munge up dependencies of intra-kit
3388  # dependencies to link to the `-objects` target instead.
3389  if (_vtk_add_module_build_with_kit)
3390  set(_vtk_add_module_depends_link)
3391  set(_vtk_add_module_private_depends_link)
3392  foreach (_vtk_add_module_depend IN LISTS _vtk_add_module_depends)
3393  get_property(_vtk_add_module_depend_kit GLOBAL
3394  PROPERTY "_vtk_module_${_vtk_add_module_depend}_kit")
3395  if (_vtk_add_module_depend_kit STREQUAL _vtk_add_module_build_with_kit)
3396  # We're in the same kit; depend on the `-objects` library of the
3397  # module.
3398  get_property(_vtk_add_module_depend_target_name GLOBAL
3399  PROPERTY "_vtk_module_${_vtk_add_module_depend}_target_name")
3400  list(APPEND _vtk_add_module_depends_link
3401  "${_vtk_add_module_depend_target_name}-objects")
3402  else ()
3403  # Different kit, just use as normal.
3404  list(APPEND _vtk_add_module_depends_link
3405  "${_vtk_add_module_depend}")
3406  endif ()
3407  endforeach ()
3408  foreach (_vtk_add_module_private_depend IN LISTS _vtk_add_module_private_depends)
3409  get_property(_vtk_add_module_private_depend_kit GLOBAL
3410  PROPERTY "_vtk_module_${_vtk_add_module_private_depend}_kit")
3411  if (_vtk_add_module_private_depend_kit STREQUAL _vtk_add_module_build_with_kit)
3412  # We're in the same kit; depend on the `-objects` library of the
3413  # module.
3414  get_property(_vtk_add_module_private_depend_target_name GLOBAL
3415  PROPERTY "_vtk_module_${_vtk_add_module_private_depend}_target_name")
3416  list(APPEND _vtk_add_module_private_depends_link
3417  "${_vtk_add_module_private_depend_target_name}-objects")
3418  else ()
3419  # Different kit, just use as normal.
3420  list(APPEND _vtk_add_module_private_depends_link
3421  "${_vtk_add_module_private_depend}")
3422  endif ()
3423  endforeach ()
3424 
3425  # Add the `DEFINE_SYMBOL` for all other modules within the same kit which
3426  # have already been processed because the direct dependencies are not
3427  # sufficient: export symbols from any included header needs to be
3428  # correct. Since modules are built in topological order, a module can
3429  # only possibly include modules in the kit which have already been built.
3430  get_property(_vtk_add_module_kit_modules GLOBAL
3431  PROPERTY "_vtk_kit_${_vtk_add_module_build_with_kit}_kit_modules")
3432  list(REMOVE_ITEM _vtk_add_module_kit_modules "${_vtk_build_module}")
3433  foreach (_vtk_add_module_kit_module IN LISTS _vtk_add_module_kit_modules)
3434  get_property(_vtk_add_module_kit_module_target_name GLOBAL
3435  PROPERTY "_vtk_module_${_vtk_add_module_kit_module}_target_name")
3436  if (TARGET "${_vtk_add_module_kit_module_target_name}-objects")
3437  get_property(_vtk_add_module_kit_module_define_symbol
3438  TARGET "${_vtk_add_module_kit_module_target_name}-objects"
3439  PROPERTY DEFINE_SYMBOL)
3440  target_compile_definitions("${_vtk_add_module_real_target}"
3441  PRIVATE
3442  "${_vtk_add_module_kit_module_define_symbol}")
3443  endif ()
3444  endforeach ()
3445  else ()
3446  set(_vtk_add_module_depends_link ${_vtk_add_module_depends})
3447  set(_vtk_add_module_private_depends_link ${_vtk_add_module_private_depends})
3448  endif ()
3449  target_link_libraries("${_vtk_add_module_real_target}"
3450  PUBLIC
3451  ${_vtk_add_module_depends_link}
3452  PRIVATE
3453  ${_vtk_add_module_private_depends_link})
3454 
3455  set(_vtk_add_module_private_depends_forward_link)
3456  foreach (_vtk_add_module_private_depend IN LISTS _vtk_add_module_depends_link _vtk_add_module_private_depends)
3457  _vtk_module_get_module_property("${_vtk_add_module_private_depend}"
3458  PROPERTY "forward_link"
3459  VARIABLE _vtk_add_module_forward_link)
3460  list(APPEND _vtk_add_module_private_depends_forward_link
3461  ${_vtk_add_module_forward_link})
3462  endforeach ()
3463 
3464  get_property(_vtk_add_module_optional_depends GLOBAL
3465  PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
3466  foreach (_vtk_add_module_optional_depend IN LISTS _vtk_add_module_optional_depends)
3467  if (TARGET "${_vtk_add_module_optional_depend}")
3468  set(_vtk_add_module_have_optional_depend 1)
3469  set(_vtk_add_module_optional_depend_link "${_vtk_add_module_optional_depend}")
3470  if (_vtk_add_module_build_with_kit)
3471  get_property(_vtk_add_module_optional_depend_kit GLOBAL
3472  PROPERTY "_vtk_module_${_vtk_add_module_optional_depend}_kit")
3473  if (_vtk_add_module_optional_depend_kit STREQUAL _vtk_add_module_build_with_kit)
3474  # We're in the same kit; depend on the `-objects` library of the
3475  # module to avoid circular dependency (see explanation earlier)
3476  get_property(_vtk_add_module_optional_depend_target_name GLOBAL
3477  PROPERTY "_vtk_module_${_vtk_add_module_optional_depend}_target_name")
3478  set(_vtk_add_module_optional_depend_link "${_vtk_add_module_optional_depend_target_name}-objects")
3479  endif ()
3480  endif ()
3481  _vtk_module_get_module_property("${_vtk_add_module_optional_depend_link}"
3482  PROPERTY "forward_link"
3483  VARIABLE _vtk_add_module_forward_link)
3484  list(APPEND _vtk_add_module_private_depends_forward_link
3485  ${_vtk_add_module_forward_link})
3486  target_link_libraries("${_vtk_add_module_real_target}"
3487  PRIVATE
3488  "${_vtk_add_module_optional_depend_link}")
3489  else ()
3490  set(_vtk_add_module_have_optional_depend 0)
3491  endif ()
3492  string(REPLACE "::" "_" _vtk_add_module_optional_depend_safe "${_vtk_add_module_optional_depend}")
3493  target_compile_definitions("${_vtk_add_module_real_target}"
3494  PRIVATE
3495  "VTK_MODULE_ENABLE_${_vtk_add_module_optional_depend_safe}=${_vtk_add_module_have_optional_depend}")
3496  endforeach ()
3497 
3498  if (_vtk_add_module_private_depends_forward_link)
3499  list(REMOVE_DUPLICATES _vtk_add_module_private_depends_forward_link)
3500  _vtk_module_set_module_property("${_vtk_build_module}" APPEND
3501  PROPERTY "forward_link"
3502  VALUE "${_vtk_add_module_private_depends_forward_link}")
3503  target_link_libraries("${_vtk_add_module_real_target}"
3504  PUBLIC
3505  "${_vtk_add_module_private_depends_forward_link}")
3506  endif ()
3507  endif ()
3508  _vtk_module_standard_includes(
3509  TARGET "${_vtk_add_module_real_target}"
3510  ${_vtk_add_module_includes_interface}
3511  HEADERS_DESTINATION "${_vtk_build_HEADERS_DESTINATION}")
3512 
3513  set(_vtk_add_module_headers_build)
3514  set(_vtk_add_module_headers_install)
3515  # TODO: Perform this in `vtk_module_install_headers` so that manually
3516  # installed headers may participate in wrapping as well.
3517  foreach (_vtk_add_module_header IN LISTS _vtk_add_module_HEADERS)
3518  if (IS_ABSOLUTE "${_vtk_add_module_header}")
3519  list(APPEND _vtk_add_module_headers_build
3520  "${_vtk_add_module_header}")
3521  else ()
3522  list(APPEND _vtk_add_module_headers_build
3523  "${CMAKE_CURRENT_SOURCE_DIR}/${_vtk_add_module_header}")
3524  endif ()
3525 
3526  get_filename_component(_vtk_add_module_header_name "${_vtk_add_module_header}" NAME)
3527  list(APPEND _vtk_add_module_headers_install
3528  "\${_vtk_module_import_prefix}/${_vtk_build_HEADERS_DESTINATION}/${_vtk_add_module_header_name}")
3529  endforeach ()
3530 
3531  set_property(TARGET "${_vtk_add_module_real_target}"
3532  PROPERTY
3533  "INTERFACE_vtk_module_headers" "${_vtk_add_module_headers_build}")
3534  if (_vtk_build_INSTALL_HEADERS)
3535  set_property(TARGET "${_vtk_add_module_real_target}"
3536  PROPERTY
3537  "INTERFACE_vtk_module_headers_install" "${_vtk_add_module_headers_install}")
3538  endif ()
3539 
3540  get_property(_vtk_add_module_exclude_wrap GLOBAL
3541  PROPERTY "_vtk_module_${_vtk_build_module}_exclude_wrap")
3542  set_property(TARGET "${_vtk_add_module_real_target}"
3543  PROPERTY
3544  "INTERFACE_vtk_module_exclude_wrap" "${_vtk_add_module_exclude_wrap}")
3545  if (NOT _vtk_add_module_exclude_wrap AND _vtk_build_ENABLE_WRAPPING)
3546  _vtk_module_write_wrap_hierarchy()
3547  endif ()
3548 
3549  set(_vtk_add_module_module_content)
3550 
3551  if (NOT _vtk_add_module_AUTOINIT_INCLUDE)
3552  get_property(_vtk_add_module_AUTOINIT_INCLUDE GLOBAL
3553  PROPERTY "_vtk_module_autoinit_include")
3554  endif ()
3555 
3556  set(_vtk_add_module_autoinit_include_header)
3557  if (_vtk_add_module_AUTOINIT_INCLUDE)
3558  set(_vtk_add_module_autoinit_include_header
3559  "#include ${_vtk_add_module_AUTOINIT_INCLUDE}")
3560  endif ()
3561 
3562  set(_vtk_add_module_autoinit_depends_includes)
3563  foreach (_vtk_add_module_autoinit_dependency IN LISTS _vtk_add_module_depends)
3564  get_property(_vtk_add_module_autoinit_dependency_target_name GLOBAL
3565  PROPERTY "_vtk_module_${_vtk_add_module_autoinit_dependency}_target_name")
3566  if (_vtk_add_module_autoinit_dependency_target_name)
3567  get_property(_vtk_add_module_depends_needs_autoinit
3568  TARGET "${_vtk_add_module_autoinit_dependency_target_name}"
3569  PROPERTY "INTERFACE_vtk_module_needs_autoinit")
3570  else ()
3571  set(_vtk_add_module_autoinit_dependency_target_name
3572  "${_vtk_add_module_autoinit_dependency}")
3573  get_property(_vtk_add_module_depends_needs_autoinit
3574  TARGET "${_vtk_add_module_autoinit_dependency}"
3575  PROPERTY "INTERFACE_vtk_module_needs_autoinit")
3576  endif ()
3577  if (NOT _vtk_add_module_depends_needs_autoinit)
3578  continue ()
3579  endif ()
3580  get_property(_vtk_add_module_depends_library_name
3581  TARGET "${_vtk_add_module_autoinit_dependency_target_name}"
3582  PROPERTY "INTERFACE_vtk_module_library_name")
3583 
3584  string(APPEND _vtk_add_module_autoinit_depends_includes
3585  "#include \"${_vtk_add_module_depends_library_name}Module.h\"\n")
3586  endforeach ()
3587 
3588  set(_vtk_add_module_autoinit_content)
3589  if (_vtk_add_module_autoinit_depends_includes)
3590  set(_vtk_add_module_autoinit_content
3591  "${_vtk_add_module_autoinit_content}/* AutoInit dependencies. */\n${_vtk_add_module_autoinit_depends_includes}\n")
3592  endif ()
3593 
3594  get_property(_vtk_add_module_implementable GLOBAL
3595  PROPERTY "_vtk_module_${_vtk_build_module}_implementable")
3596  get_property(_vtk_add_module_implements GLOBAL
3597  PROPERTY "_vtk_module_${_vtk_build_module}_implements")
3598  if (_vtk_add_module_implementable)
3599  set_property(TARGET "${_vtk_add_module_real_target}"
3600  PROPERTY
3601  "INTERFACE_vtk_module_implementable" 1)
3602  endif ()
3603 
3604  if (_vtk_add_module_implementable OR _vtk_add_module_implements)
3605  set_property(TARGET "${_vtk_add_module_real_target}"
3606  PROPERTY
3607  "INTERFACE_vtk_module_implements" "${_vtk_add_module_implements}")
3608  set_property(TARGET "${_vtk_add_module_real_target}"
3609  PROPERTY
3610  "INTERFACE_vtk_module_needs_autoinit" 1)
3611 
3612  set(_vtk_add_module_autoinit_content
3613  "${_vtk_add_module_autoinit_content}
3614 /* AutoInit implementations. */
3615 #if !defined(__VTK_WRAP__)
3616 #ifdef ${_vtk_add_module_library_name}_AUTOINIT_INCLUDE
3617 #include ${_vtk_add_module_library_name}_AUTOINIT_INCLUDE
3618 #endif
3619 #ifdef ${_vtk_add_module_library_name}_AUTOINIT
3620 ${_vtk_add_module_autoinit_include_header}
3621 VTK_MODULE_AUTOINIT(${_vtk_add_module_library_name})
3622 #endif
3623 #endif
3624 ")
3625 
3626  set(_vtk_add_module_module_content
3627  "${_vtk_add_module_module_content}${_vtk_add_module_autoinit_content}")
3628  endif ()
3629 
3630  vtk_module_autoinit(
3631  MODULES ${_vtk_add_module_depends}
3632  ${_vtk_add_module_private_depends}
3633  "${_vtk_build_module}"
3634  TARGETS "${_vtk_build_module}")
3635 
3636  if (NOT _vtk_add_module_HEADER_ONLY AND NOT _vtk_add_module_third_party)
3637  generate_export_header("${_vtk_add_module_real_target}"
3638  EXPORT_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_EXPORT"
3639  NO_EXPORT_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_NO_EXPORT"
3640  DEPRECATED_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_DEPRECATED"
3641  NO_DEPRECATED_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_NO_DEPRECATED"
3642  STATIC_DEFINE "${_vtk_add_module_EXPORT_MACRO_PREFIX}_STATIC_DEFINE"
3643  EXPORT_FILE_NAME "${_vtk_add_module_module_header_name}"
3644  CUSTOM_CONTENT_FROM_VARIABLE _vtk_add_module_module_content)
3645  endif ()
3646 
3647  _vtk_module_apply_properties("${_vtk_add_module_target_name}")
3648  _vtk_module_install("${_vtk_add_module_target_name}")
3649  _vtk_module_add_header_tests()
3650 
3651  if (_vtk_add_module_build_with_kit)
3652  _vtk_module_install("${_vtk_add_module_target_name}-objects")
3653  endif ()
3654 endfunction ()
3655 
3656 #[==[
3657 @ingroup module-impl
3658 @brief Add header tests for a module
3659 
3660 @todo Move this function out to be VTK-specific, probably into
3661 `vtkModuleTesting.cmake`. Each module would then need to manually call this
3662 function. It currently assumes it is in VTK itself.
3663 
3664 ~~~
3665 _vtk_module_add_header_tests()
3666 ~~~
3667 #]==]
3668 function (_vtk_module_add_header_tests)
3669  if (NOT BUILD_TESTING)
3670  return ()
3671  endif ()
3672 
3673  get_property(_vtk_add_header_tests_is_third_party GLOBAL
3674  PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
3675  if (_vtk_add_header_tests_is_third_party)
3676  return ()
3677  endif ()
3678 
3679  # TODO: Add test compiles which include each header file to ensure that
3680  # public headers have their includes satisfied by a public dependency.
3681 
3682  # Bad...
3683  if (NOT "Python${VTK_PYTHON_VERSION}_EXECUTABLE")
3684  return ()
3685  endif ()
3686 
3687  # Worse...
3688  if (NOT VTK_SOURCE_DIR)
3689  return ()
3690  endif ()
3691 
3692  add_test(
3693  NAME "${_vtk_build_module}-HeaderTest"
3694  COMMAND "${Python${VTK_PYTHON_VERSION}_EXECUTABLE}"
3695  # TODO: What to do when using this from a VTK install?
3696  "${VTK_SOURCE_DIR}/Testing/Core/HeaderTesting.py"
3697  "${CMAKE_CURRENT_SOURCE_DIR}"
3698  "${_vtk_add_module_EXPORT_MACRO}")
3699 endfunction ()
3700 
3701 #[==[
3702 @ingroup module
3703 @brief Install headers
3704 
3705 Installing headers is done for normal modules by the @ref vtk_module_add_module
3706 function already. However, sometimes header structures are more complicated and
3707 need to be installed manually. This is common for third party modules or
3708 projects which use more than a single directory of headers for a module.
3709 
3710 To facilitate the installation of headers in various ways, the this function is
3711 available. This function honors the `INSTALL_HEADERS`, `HEADERS_DESTINATION`,
3712 and `HEADERS_COMPONENT` arguments to @ref vtk_module_build.
3713 
3714 ~~~
3715 vtk_module_install_headers(
3716  [DIRECTORIES <directory>...]
3717  [FILES <file>...]
3718  [SUBDIR <subdir>])
3719 ~~~
3720 
3721 Installation of header directories follows CMake's `install` function semantics
3722 with respect to trailing slashes.
3723 #]==]
3724 function (vtk_module_install_headers)
3725  cmake_parse_arguments(_vtk_install_headers
3726  ""
3727  "SUBDIR"
3728  "FILES;DIRECTORIES"
3729  ${ARGN})
3730 
3731  if (_vtk_install_headers_UNPARSED_ARGUMENTS)
3732  message(FATAL_ERROR
3733  "Unparsed arguments for vtk_module_install_headers: "
3734  "${_vtk_install_headers_UNPARSED_ARGUMENTS}")
3735  endif ()
3736 
3737  if (NOT _vtk_build_INSTALL_HEADERS)
3738  return ()
3739  endif ()
3740 
3741  if (NOT _vtk_install_headers_FILES AND NOT _vtk_install_headers_DIRECTORIES)
3742  return ()
3743  endif ()
3744 
3745  set(_vtk_install_headers_destination
3746  "${_vtk_build_HEADERS_DESTINATION}/${_vtk_install_headers_SUBDIR}")
3747  if (_vtk_install_headers_FILES)
3748  install(
3749  FILES ${_vtk_install_headers_FILES}
3750  DESTINATION "${_vtk_install_headers_destination}"
3751  COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
3752  endif ()
3753  foreach (_vtk_install_headers_directory IN LISTS _vtk_install_headers_DIRECTORIES)
3754  install(
3755  DIRECTORY "${_vtk_install_headers_directory}"
3756  DESTINATION "${_vtk_install_headers_destination}"
3757  COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
3758  endforeach ()
3759 endfunction ()
3760 
3761 #[==[
3762 @ingroup module-internal
3763 @brief Apply properties to a module
3764 
3765 Apply build properties to a target. Generally only useful to wrapping code or
3766 other modules that cannot use @ref vtk_module_add_module for some reason.
3767 
3768 ~~~
3769 _vtk_module_apply_properties(<target>
3770  [BASENAME <basename>])
3771 ~~~
3772 
3773 If `BASENAME` is given, it will be used instead of the target name as the basis
3774 for `OUTPUT_NAME`. Full modules (as opposed to third party or other non-module
3775 libraries) always use the module's `LIBRARY_NAME` setting.
3776 
3777 The following target properties are set based on the arguments to the calling
3778 @ref vtk_module_build call:
3779 
3780  - `OUTPUT_NAME` (based on the module's `LIBRARY_NAME` and
3781  `vtk_module_build(LIBRARY_NAME_SUFFIX)`)
3782  - `VERSION` (based on `vtk_module_build(VERSION)`)
3783  - `SOVERSION` (based on `vtk_module_build(SOVERSION)`)
3784  - `DEBUG_POSTFIX` (on Windows)
3785 #]==]
3786 function (_vtk_module_apply_properties target)
3787  cmake_parse_arguments(_vtk_apply_properties
3788  ""
3789  "BASENAME"
3790  ""
3791  ${ARGN})
3792 
3793  if (_vtk_apply_properties_UNPARSED_ARGUMENTS)
3794  message(FATAL_ERROR
3795  "Unparsed arguments for _vtk_module_apply_properties: "
3796  "${_vtk_apply_properties_UNPARSED_ARGUMENTS}.")
3797  endif ()
3798 
3799  if (NOT DEFINED _vtk_apply_properties_BASENAME)
3800  set(_vtk_apply_properties_BASENAME "${target}")
3801  endif ()
3802 
3803  get_property(_vtk_add_module_type
3804  TARGET "${target}"
3805  PROPERTY TYPE)
3806  if (_vtk_add_module_type STREQUAL "OBJECT_LIBRARY" OR
3807  _vtk_add_module_type STREQUAL "INTERFACE_LIBRARY")
3808  return ()
3809  endif ()
3810 
3811  set(_vtk_add_module_library_name "${_vtk_apply_properties_BASENAME}")
3812  get_property(_vtk_add_module_target_name GLOBAL
3813  PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
3814  if (_vtk_add_module_target_name STREQUAL "${target}")
3815  get_property(_vtk_add_module_library_name GLOBAL
3816  PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
3817  endif ()
3818  set(_vtk_add_module_output_name "${_vtk_add_module_library_name}${_vtk_add_module_LIBRARY_NAME_SUFFIX}")
3819  if (_vtk_build_LIBRARY_NAME_SUFFIX)
3820  string(APPEND _vtk_add_module_output_name "-${_vtk_build_LIBRARY_NAME_SUFFIX}")
3821  endif ()
3822 
3823  set_target_properties("${target}"
3824  PROPERTIES
3825  OUTPUT_NAME "${_vtk_add_module_output_name}")
3826 
3827  if (_vtk_build_VERSION AND NOT _vtk_add_module_type STREQUAL "EXECUTABLE")
3828  set_target_properties("${target}"
3829  PROPERTIES
3830  VERSION "${_vtk_build_VERSION}")
3831  endif ()
3832 
3833  if (_vtk_build_SOVERSION)
3834  set_target_properties("${target}"
3835  PROPERTIES
3836  SOVERSION "${_vtk_build_SOVERSION}")
3837  endif ()
3838 
3839  if (WIN32)
3840  set_target_properties("${target}"
3841  PROPERTIES
3842  DEBUG_POSTFIX "d")
3843  endif ()
3844 endfunction ()
3845 
3846 #[==[
3847 @ingroup module-internal
3848 @brief Install a module target
3849 
3850 Install a target within the module context. Generally only useful to wrapping
3851 code, modules that cannot use @ref vtk_module_add_module for some reason, or
3852 modules which create utility targets that need installed.
3853 
3854 ~~~
3855 _vtk_module_install(<target>)
3856 ~~~
3857 
3858 This function uses the various installation options to @ref vtk_module_build
3859 function to keep the install uniform.
3860 #]==]
3861 function (_vtk_module_install target)
3862  set(_vtk_install_export)
3863  if (_vtk_build_INSTALL_EXPORT)
3864  set(_vtk_install_export
3865  EXPORT "${_vtk_build_INSTALL_EXPORT}")
3866  endif ()
3867 
3868  set(_vtk_install_namelink_args)
3869  if(NOT CMAKE_VERSION VERSION_LESS 3.12)
3870  list(APPEND _vtk_install_namelink_args
3871  NAMELINK_COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
3872  endif()
3873  install(
3874  TARGETS "${target}"
3875  ${_vtk_install_export}
3876  ${ARGN}
3877  ARCHIVE
3878  DESTINATION "${_vtk_build_ARCHIVE_DESTINATION}"
3879  COMPONENT "${_vtk_build_HEADERS_COMPONENT}"
3880  LIBRARY
3881  DESTINATION "${_vtk_build_LIBRARY_DESTINATION}"
3882  COMPONENT "${_vtk_build_TARGETS_COMPONENT}"
3883  ${_vtk_install_namelink_args}
3884  RUNTIME
3885  DESTINATION "${_vtk_build_RUNTIME_DESTINATION}"
3886  COMPONENT "${_vtk_build_TARGETS_COMPONENT}")
3887 endfunction ()
3888 
3889 #[==[
3890 @ingroup module
3891 @brief Create a module executable
3892 
3893 Some modules may have associated executables with them. By using this function,
3894 the target will be installed following the options given to the associated
3895 @ref vtk_module_build command. Its name will also be changed according to the
3896 `LIBRARY_NAME_SUFFIX` option.
3897 
3898 ~~~
3899 vtk_module_add_executable(<name>
3900  [NO_INSTALL]
3901  [DEVELOPMENT]
3902  [BASENAME <basename>]
3903  <source>...)
3904 ~~~
3905 
3906 If `NO_INSTALL` is specified, the executable will not be installed. If
3907 `BASENAME` is given, it will be used as the name of the executable rather than
3908 the target name.
3909 
3910 If `DEVELOPMENT` is given, it marks the executable as a development tool and
3911 will not be installed if `INSTALL_HEADERS` is not set for the associated
3912 @ref vtk_module_build command.
3913 
3914 If the executable being built is the module, its module properties are used
3915 rather than `BASENAME`. In addition, the dependencies of the module will be
3916 linked.
3917 #]==]
3918 function (vtk_module_add_executable name)
3919  cmake_parse_arguments(_vtk_add_executable
3920  "NO_INSTALL;DEVELOPMENT"
3921  "BASENAME"
3922  ""
3923  ${ARGN})
3924 
3925  if (NOT _vtk_add_executable_UNPARSED_ARGUMENTS)
3926  message(FATAL_ERROR
3927  "The ${name} executable must have at least one source file.")
3928  endif ()
3929 
3930  if (_vtk_add_executable_NO_INSTALL AND _vtk_add_executable_DEVELOPMENT)
3931  message(FATAL_ERROR
3932  "Both `NO_INSTALL` and `DEVELOPMENT` may not be specified.")
3933  endif ()
3934 
3935  set(_vtk_add_executable_target_name "${name}")
3936  set(_vtk_add_executable_library_name "${name}")
3937  if (name STREQUAL _vtk_build_module)
3938  if (_vtk_add_executable_NO_INSTALL)
3939  message(FATAL_ERROR
3940  "The executable ${_vtk_build_module} module may not use `NO_INSTALL`.")
3941  endif ()
3942  if (DEFINED _vtk_add_executable_BASENAME)
3943  message(FATAL_ERROR
3944  "The executable ${_vtk_build_module} module may not pass `BASENAME` "
3945  "when adding the executable; it is controlled via `LIBRARY_NAME` in "
3946  "the associated `vtk.module` file.")
3947  endif ()
3948  get_property(_vtk_add_executable_target_name GLOBAL
3949  PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
3950  get_property(_vtk_add_executable_library_name GLOBAL
3951  PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
3952  endif ()
3953 
3954  if (_vtk_add_executable_DEVELOPMENT AND NOT _vtk_build_INSTALL_HEADERS)
3955  set(_vtk_add_executable_NO_INSTALL ON)
3956  endif ()
3957 
3958  # Set up rpaths
3959  set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
3960  if (UNIX)
3961  file(RELATIVE_PATH _vtk_add_executable_relpath
3962  "/prefix/${_vtk_build_RUNTIME_DESTINATION}"
3963  "/prefix/${_vtk_build_LIBRARY_DESTINATION}")
3964  if (APPLE)
3965  set(_vtk_add_executable_origin_rpath_prefix
3966  "@executable_path")
3967  else ()
3968  set(_vtk_add_executable_origin_rpath_prefix
3969  "$ORIGIN")
3970  endif ()
3971 
3972  list(APPEND CMAKE_INSTALL_RPATH
3973  "${_vtk_add_executable_origin_rpath_prefix}/${_vtk_add_executable_relpath}")
3974  endif ()
3975 
3976  add_executable("${_vtk_add_executable_target_name}"
3977  ${_vtk_add_executable_UNPARSED_ARGUMENTS})
3978 
3979  if (name STREQUAL _vtk_build_module AND NOT _vtk_add_executable_target_name STREQUAL _vtk_build_module)
3980  add_executable("${_vtk_build_module}" ALIAS
3981  "${_vtk_add_executable_target_name}")
3982  endif ()
3983 
3984  if (name STREQUAL _vtk_build_module)
3985  get_property(_vtk_real_target_kit GLOBAL
3986  PROPERTY "_vtk_module_${_vtk_build_module}_kit")
3987  if (_vtk_real_target_kit)
3988  message(FATAL_ERROR
3989  "Executable module ${_vtk_build_module} is declared to be part of a "
3990  "kit; this is not possible.")
3991  endif ()
3992 
3993  get_property(_vtk_add_executable_depends GLOBAL
3994  PROPERTY "_vtk_module_${_vtk_build_module}_depends")
3995  get_property(_vtk_add_executable_private_depends GLOBAL
3996  PROPERTY "_vtk_module_${_vtk_build_module}_private_depends")
3997  target_link_libraries("${_vtk_add_executable_target_name}"
3998  PUBLIC
3999  ${_vtk_add_executable_depends}
4000  PRIVATE
4001  ${_vtk_add_executable_private_depends})
4002  get_property(_vtk_add_executable_optional_depends GLOBAL
4003  PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
4004  foreach (_vtk_add_executable_optional_depend IN LISTS _vtk_add_executable_optional_depends)
4005  string(REPLACE "::" "_" _vtk_add_executable_optional_depend_safe "${_vtk_add_executable_optional_depend}")
4006  if (TARGET "${_vtk_add_executable_optional_depend}")
4007  set(_vtk_add_executable_have_optional_depend 1)
4008  else ()
4009  set(_vtk_add_executable_have_optional_depend 0)
4010  endif ()
4011  target_compile_definitions("${_vtk_add_executable_target_name}"
4012  PRIVATE
4013  "VTK_MODULE_ENABLE_${_vtk_add_executable_optional_depend_safe}=${_vtk_add_executable_have_optional_depend}")
4014  endforeach ()
4015 
4016  if (_vtk_module_warnings)
4017  if (_vtk_add_executable_depends)
4018  message(WARNING
4019  "Executable module ${_vtk_build_module} has public dependencies; this "
4020  "shouldn't be necessary.")
4021  endif ()
4022  endif ()
4023  endif ()
4024 
4025  set(_vtk_add_executable_property_args)
4026  if (DEFINED _vtk_add_executable_BASENAME)
4027  list(APPEND _vtk_add_executable_property_args
4028  BASENAME "${_vtk_add_executable_BASENAME}")
4029  endif ()
4030 
4031  _vtk_module_apply_properties("${_vtk_add_executable_target_name}"
4032  ${_vtk_add_executable_property_args})
4033  _vtk_module_standard_includes(TARGET "${_vtk_add_executable_target_name}")
4034 
4035  if (NOT _vtk_add_executable_NO_INSTALL)
4036  _vtk_module_install("${_vtk_add_executable_target_name}")
4037  endif ()
4038 endfunction ()
4039 
4040 #[==[
4041 @ingroup module
4042 @brief Find a package
4043 
4044 A wrapper around `find_package` that records information for use so that the
4045 same targets may be found when finding this package.
4046 
4047 Modules may need to find external dependencies. CMake often provides modules to
4048 find these dependencies, but when imported targets are involved, these.need to
4049 also be found from dependencies of the current project. Since the benefits of
4050 imported targets greatly outweighs not using them, it is preferred to use them.
4051 
4052 The module system provides the @ref vtk_module_find_package function in order
4053 to extend `find_package` support to include finding the dependencies from an
4054 install of the project.
4055 
4056 ~~~
4057 vtk_module_find_package(
4058  [PRIVATE] [CONFIG_MODE]
4059  PACKAGE <package>
4060  [VERSION <version>]
4061  [COMPONENTS <component>...]
4062  [OPTIONAL_COMPONENTS <component>...]
4063  [FORWARD_VERSION_REQ <MAJOR|MINOR|PATCH|EXACT>]
4064  [VERSION_VAR <variable>])
4065 ~~~
4066 
4067  * `PACKAGE`: The name of the package to find.
4068  * `VERSION`: The minimum version of the package that is required.
4069  * `COMPONENTS`: Components of the package which are required.
4070  * `OPTIONAL_COMPONENTS`: Components of the package which may be missing.
4071  * `FORWARD_VERSION_REQ`: If provided, the found version will be promoted to
4072  the minimum version required matching the given version scheme.
4073  * `VERSION_VAR`: The variable to use as the provided version (defaults to
4074  `<PACKAGE>_VERSION`). It may contain `@` in which case it will be
4075  configured. This is useful for modules which only provide components of the
4076  actual version number.
4077  * `CONFIG_MODE`: If present, pass `CONFIG` to the underlying `find_package`
4078  call.
4079  * `PRIVATE`: The dependency should not be exported to the install.
4080 
4081 The `PACKAGE` argument is the only required argument. The rest are optional.
4082 
4083 Note that `PRIVATE` is *only* applicable for private dependencies on interface
4084 targets (basically, header libraries) because some platforms require private
4085 shared libraries dependencies to be present when linking dependent libraries
4086 and executables as well.
4087 #]==]
4088 macro (vtk_module_find_package)
4089  # This needs to be a macro because find modules typically set variables which
4090  # may need to be available in the calling scope. If we declare that it only
4091  # works with imported targets (which is the primary motivating factor behind
4092  # this function), we can instead make it a function at the cost of any
4093  # non-target variables a module might want to set being available. It is
4094  # unlikely that this will be the case for all callers.
4095  if (NOT _vtk_build_module)
4096  message(FATAL_ERROR
4097  "`vtk_module_find_package` may only be called when building a VTK "
4098  "module.")
4099  endif ()
4100 
4101  # Note: when adding arguments here, add them to the `unset` block at the end
4102  # of the function.
4103  cmake_parse_arguments(_vtk_find_package
4104  "PRIVATE;CONFIG_MODE"
4105  "PACKAGE;VERSION;FORWARD_VERSION_REQ;VERSION_VAR"
4106  "COMPONENTS;OPTIONAL_COMPONENTS"
4107  ${ARGN})
4108 
4109  if (_vtk_find_package_UNPARSED_ARGUMENTS)
4110  message(FATAL_ERROR
4111  "Unparsed arguments for vtk_module_find_package: "
4112  "${_vtk_find_package_UNPARSED_ARGUMENTS}")
4113  endif ()
4114 
4115  if (NOT DEFINED _vtk_find_package_PACKAGE)
4116  message(FATAL_ERROR
4117  "The `PACKAGE` argument is required.")
4118  endif ()
4119 
4120  if (DEFINED _vtk_find_package_FORWARD_VERSION_REQ)
4121  if (_vtk_find_package_PRIVATE)
4122  message(FATAL_ERROR
4123  "The `FORWARD_VERSION_REQ` argument is incompatible with the "
4124  "`PRIVATE` flag.")
4125  endif ()
4126 
4127  if (NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MAJOR" AND
4128  NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MINOR" AND
4129  NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "PATCH" AND
4130  NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "EXACT")
4131  message(FATAL_ERROR
4132  "The `FORWARD_VERSION_REQ` argument must be one of `MAJOR`, `MINOR`, "
4133  "`PATCH`, or `EXACT`.")
4134  endif ()
4135  endif ()
4136 
4137  if (NOT DEFINED _vtk_find_package_VERSION_VAR)
4138  set(_vtk_find_package_VERSION_VAR
4139  "${_vtk_find_package_PACKAGE}_VERSION")
4140  endif ()
4141 
4142  set(_vtk_find_package_config)
4143  if (_vtk_find_package_CONFIG_MODE)
4144  set(_vtk_find_package_config "CONFIG")
4145  endif ()
4146 
4147  find_package("${_vtk_find_package_PACKAGE}"
4148  ${_vtk_find_package_VERSION}
4149  ${_vtk_find_package_config}
4150  COMPONENTS ${_vtk_find_package_COMPONENTS}
4151  OPTIONAL_COMPONENTS ${_vtk_find_package_OPTIONAL_COMPONENTS})
4152  if (NOT ${_vtk_find_package_PACKAGE}_FOUND)
4153  message(FATAL_ERROR
4154  "Could not find the ${_vtk_find_package_PACKAGE} external dependency.")
4155  return ()
4156  endif ()
4157 
4158  set(_vtk_find_package_optional_components_found)
4159  foreach (_vtk_find_package_optional_component IN LISTS _vtk_find_package_OPTIONAL_COMPONENTS)
4160  if (${_vtk_find_package_PACKAGE}_${_vtk_find_package_optional_component}_FOUND)
4161  list(APPEND _vtk_find_package_optional_components_found
4162  "${_vtk_find_package_optional_component}")
4163  endif ()
4164  endforeach ()
4165 
4166  if (NOT _vtk_find_package_PRIVATE)
4167  set_property(GLOBAL APPEND
4168  PROPERTY
4169  "_vtk_module_find_packages_${_vtk_build_PACKAGE}" "${_vtk_find_package_PACKAGE}")
4170  set(_vtk_find_package_base "_vtk_module_find_package_${_vtk_build_module}")
4171  set_property(GLOBAL APPEND
4172  PROPERTY
4173  "${_vtk_find_package_base}" "${_vtk_find_package_PACKAGE}")
4174  set(_vtk_find_package_base_package "${_vtk_find_package_base}_${_vtk_find_package_PACKAGE}")
4175  set_property(GLOBAL
4176  PROPERTY
4177  "${_vtk_find_package_base_package}_version" "${_vtk_find_package_VERSION}")
4178  set_property(GLOBAL
4179  PROPERTY
4180  "${_vtk_find_package_base_package}_config" "${_vtk_find_package_CONFIG_MODE}")
4181  set_property(GLOBAL APPEND
4182  PROPERTY
4183  "${_vtk_find_package_base_package}_components" "${_vtk_find_package_COMPONENTS}")
4184  set_property(GLOBAL APPEND
4185  PROPERTY
4186  "${_vtk_find_package_base_package}_optional_components" "${_vtk_find_package_OPTIONAL_COMPONENTS}")
4187  set_property(GLOBAL APPEND
4188  PROPERTY
4189  "${_vtk_find_package_base_package}_optional_components_found" "${_vtk_find_package_optional_components_found}")
4190  set_property(GLOBAL
4191  PROPERTY
4192  "${_vtk_find_package_base_package}_exact" "0")
4193  if (DEFINED _vtk_find_package_FORWARD_VERSION_REQ)
4194  string(FIND "${_vtk_find_package_VERSION_VAR}" "@" _vtk_find_package_idx)
4195  if (_vtk_find_package_idx EQUAL -1)
4196  if (NOT DEFINED "${_vtk_find_package_VERSION_VAR}")
4197  message(FATAL_ERROR
4198  "The `${_vtk_find_package_VERSION_VAR}` variable is not defined.")
4199  endif ()
4200  set(_vtk_find_package_version "${${_vtk_find_package_VERSION_VAR}}")
4201  else ()
4202  string(CONFIGURE "${_vtk_find_package_VERSION_VAR}" _vtk_find_package_version)
4203  endif ()
4204  unset(_vtk_find_package_idx)
4205 
4206  if ("${_vtk_find_package_version}" STREQUAL "")
4207  message(FATAL_ERROR
4208  "The `${_vtk_find_package_PACKAGE}` version is empty.")
4209  endif ()
4210 
4211  if (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MAJOR")
4212  set(_vtk_find_package_version_regex "^\([^.]*\).*")
4213  elseif (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MINOR")
4214  set(_vtk_find_package_version_regex "^\([^.]*.[^.]*\).*")
4215  elseif (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "PATCH")
4216  set(_vtk_find_package_version_regex "^\([^.]*.[^.]*.[^.]*\).*")
4217  elseif (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "EXACT")
4218  set(_vtk_find_package_version_regex "^\\(.*\\)$")
4219  set_property(GLOBAL
4220  PROPERTY
4221  "${_vtk_find_package_base_package}_exact" "1")
4222  endif ()
4223 
4224  string(REGEX REPLACE "${_vtk_find_package_version_regex}" "\\1"
4225  _vtk_find_package_found_version "${_vtk_find_package_version}")
4226  unset(_vtk_find_package_version_regex)
4227  unset(_vtk_find_package_version)
4228 
4229  set_property(GLOBAL
4230  PROPERTY
4231  "${_vtk_find_package_base_package}_version" "${_vtk_find_package_found_version}")
4232  unset(_vtk_find_package_found_version)
4233  endif ()
4234  endif ()
4235 
4236  unset(_vtk_find_package_base)
4237  unset(_vtk_find_package_base_package)
4238  unset(_vtk_find_package_COMPONENTS)
4239  unset(_vtk_find_package_FORWARD_VERSION_REQ)
4240  unset(_vtk_find_package_OPTIONAL_COMPONENTS)
4241  unset(_vtk_find_package_PACKAGE)
4242  unset(_vtk_find_package_PRIVATE)
4243  unset(_vtk_find_package_UNPARSED_ARGUMENTS)
4244  unset(_vtk_find_package_VERSION)
4245  unset(_vtk_find_package_VERSION_VAR)
4246 endmacro ()
4247 
4248 #[==[
4249 @ingroup module
4250 @brief Export find_package calls for dependencies
4251 
4252 When installing a project that is meant to be found via `find_package` from
4253 CMake, using imported targets in the build means that imported targets need to
4254 be created during the `find_package` as well. This function writes a file
4255 suitable for inclusion from a `<package>-config.cmake` file to satisfy
4256 dependencies. It assumes that the exported targets are named
4257 `${CMAKE_FIND_PACKAGE_NAME}::${component}`. Dependent packages will only be
4258 found if a requested component requires the package to be found either directly
4259 or transitively.
4260 
4261 ~~~
4262 vtk_module_export_find_packages(
4263  CMAKE_DESTINATION <directory>
4264  FILE_NAME <filename>
4265  [COMPONENT <component>]
4266  MODULES <module>...)
4267 ~~~
4268 
4269 The file will be named according to the `FILE_NAME` argument will be installed
4270 into `CMAKE_DESTINATION` in the build and install trees with the given
4271 filename. If not provided, the `development` component will be used.
4272 
4273 The `vtk_module_find_package` calls made by the modules listed in `MODULES`
4274 will be exported to this file.
4275 #]==]
4276 function (vtk_module_export_find_packages)
4277  cmake_parse_arguments(_vtk_export
4278  ""
4279  "CMAKE_DESTINATION;FILE_NAME;COMPONENT"
4280  "MODULES"
4281  ${ARGN})
4282 
4283  if (_vtk_export_UNPARSED_ARGUMENTS)
4284  message(FATAL_ERROR
4285  "Unparsed arguments for vtk_module_export_find_packages: "
4286  "${_vtk_export_UNPARSED_ARGUMENTS}")
4287  endif ()
4288 
4289  if (NOT DEFINED _vtk_export_CMAKE_DESTINATION)
4290  message(FATAL_ERROR
4291  "The `CMAKE_DESTINATION` is required.")
4292  endif ()
4293 
4294  if (NOT DEFINED _vtk_export_FILE_NAME)
4295  message(FATAL_ERROR
4296  "The `FILE_NAME` is required.")
4297  endif ()
4298 
4299  if (NOT DEFINED _vtk_export_COMPONENT)
4300  set(_vtk_export_COMPONENT "development")
4301  endif ()
4302 
4303  set(_vtk_export_output_file
4304  "${CMAKE_BINARY_DIR}/${_vtk_export_CMAKE_DESTINATION}/${_vtk_export_FILE_NAME}")
4305  file(WRITE "${_vtk_export_output_file}"
4306 "set(_vtk_module_find_package_quiet)
4307 if (\${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
4308  set(_vtk_module_find_package_quiet QUIET)
4309 endif ()
4310 
4311 set(_vtk_module_find_package_components_checked)
4312 set(_vtk_module_find_package_components_to_check
4313  \${\${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
4314 set(_vtk_module_find_package_components)
4315 set(_vtk_module_find_package_components_required)
4316 while (_vtk_module_find_package_components_to_check)
4317  list(GET _vtk_module_find_package_components_to_check 0 _vtk_module_component)
4318  list(REMOVE_AT _vtk_module_find_package_components_to_check 0)
4319  if (_vtk_module_component IN_LIST _vtk_module_find_package_components_checked)
4320  continue ()
4321  endif ()
4322  list(APPEND _vtk_module_find_package_components_checked
4323  \"\${_vtk_module_component}\")
4324 
4325  list(APPEND _vtk_module_find_package_components
4326  \"\${_vtk_module_component}\")
4327  if (\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_\${_vtk_module_component})
4328  list(APPEND _vtk_module_find_package_components_required
4329  \"\${_vtk_module_component}\")
4330  endif ()
4331 
4332  if (TARGET \"\${CMAKE_FIND_PACKAGE_NAME}::\${_vtk_module_component}\")
4333  set(_vtk_module_find_package_component_target \"\${CMAKE_FIND_PACKAGE_NAME}::\${_vtk_module_component}\")
4334  elseif (TARGET \"\${_vtk_module_component}\")
4335  set(_vtk_module_find_package_component_target \"\${_vtk_module_component}\")
4336  else ()
4337  # No such target for the component; skip.
4338  continue ()
4339  endif ()
4340  get_property(_vtk_module_find_package_depends
4341  TARGET \"\${_vtk_module_find_package_component_target}\"
4342  PROPERTY \"INTERFACE_vtk_module_depends\")
4343  string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depends \"\${_vtk_module_find_package_depends}\")
4344  list(APPEND _vtk_module_find_package_components_to_check
4345  \${_vtk_module_find_package_depends})
4346  get_property(_vtk_module_find_package_depends
4347  TARGET \"\${_vtk_module_find_package_component_target}\"
4348  PROPERTY \"INTERFACE_vtk_module_private_depends\")
4349  string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depends \"\${_vtk_module_find_package_depends}\")
4350  list(APPEND _vtk_module_find_package_components_to_check
4351  \${_vtk_module_find_package_depends})
4352  get_property(_vtk_module_find_package_depends
4353  TARGET \"\${_vtk_module_find_package_component_target}\"
4354  PROPERTY \"INTERFACE_vtk_module_optional_depends\")
4355  foreach (_vtk_module_find_package_depend IN LISTS _vtk_module_find_package_depends)
4356  if (TARGET \"\${_vtk_module_find_package_depend}\")
4357  string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depend \"\${_vtk_module_find_package_depend}\")
4358  list(APPEND _vtk_module_find_package_components_to_check
4359  \"\${_vtk_module_find_package_depend}\")
4360  endif ()
4361  endforeach ()
4362  get_property(_vtk_module_find_package_depends
4363  TARGET \"\${_vtk_module_find_package_component_target}\"
4364  PROPERTY \"INTERFACE_vtk_module_forward_link\")
4365  string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depends \"\${_vtk_module_find_package_depends}\")
4366  list(APPEND _vtk_module_find_package_components_to_check
4367  \${_vtk_module_find_package_depends})
4368 
4369  get_property(_vtk_module_find_package_kit
4370  TARGET \"\${_vtk_module_find_package_component_target}\"
4371  PROPERTY \"INTERFACE_vtk_module_kit\")
4372  if (_vtk_module_find_package_kit)
4373  get_property(_vtk_module_find_package_kit_modules
4374  TARGET \"\${_vtk_module_find_package_kit}\"
4375  PROPERTY \"INTERFACE_vtk_kit_kit_modules\")
4376  string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_kit_modules \"\${_vtk_module_find_package_kit_modules}\")
4377  list(APPEND _vtk_module_find_package_components_to_check
4378  \${_vtk_module_find_package_kit_modules})
4379  endif ()
4380 endwhile ()
4381 unset(_vtk_module_find_package_component_target)
4382 unset(_vtk_module_find_package_components_to_check)
4383 unset(_vtk_module_find_package_components_checked)
4384 unset(_vtk_module_component)
4385 unset(_vtk_module_find_package_depend)
4386 unset(_vtk_module_find_package_depends)
4387 unset(_vtk_module_find_package_kit)
4388 unset(_vtk_module_find_package_kit_modules)
4389 
4390 if (_vtk_module_find_package_components)
4391  list(REMOVE_DUPLICATES _vtk_module_find_package_components)
4392 endif ()
4393 if (_vtk_module_find_package_components_required)
4394  list(REMOVE_DUPLICATES _vtk_module_find_package_components_required)
4395 endif ()\n\n")
4396 
4397  foreach (_vtk_export_module IN LISTS _vtk_export_MODULES)
4398  get_property(_vtk_export_target_name GLOBAL
4399  PROPERTY "_vtk_module_${_vtk_export_module}_target_name")
4400  set(_vtk_export_base "_vtk_module_find_package_${_vtk_export_module}")
4401  get_property(_vtk_export_packages GLOBAL
4402  PROPERTY "${_vtk_export_base}")
4403  if (NOT _vtk_export_packages)
4404  continue ()
4405  endif ()
4406 
4407  file(APPEND "${_vtk_export_output_file}"
4408 "set(_vtk_module_find_package_enabled OFF)
4409 set(_vtk_module_find_package_is_required OFF)
4410 set(_vtk_module_find_package_fail_if_not_found OFF)
4411 if (_vtk_module_find_package_components)
4412  if (\"${_vtk_export_target_name}\" IN_LIST _vtk_module_find_package_components)
4413  set(_vtk_module_find_package_enabled ON)
4414  if (\"${_vtk_export_target_name}\" IN_LIST _vtk_module_find_package_components_required)
4415  set(_vtk_module_find_package_is_required \"\${\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED}\")
4416  set(_vtk_module_find_package_fail_if_not_found ON)
4417  endif ()
4418  endif ()
4419 else ()
4420  set(_vtk_module_find_package_enabled ON)
4421  set(_vtk_module_find_package_is_required \"\${\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED}\")
4422  set(_vtk_module_find_package_fail_if_not_found ON)
4423 endif ()
4424 
4425 if (_vtk_module_find_package_enabled)
4426  set(_vtk_module_find_package_required)
4427  if (_vtk_module_find_package_is_required)
4428  set(_vtk_module_find_package_required REQUIRED)
4429  endif ()\n\n")
4430 
4431  list(REMOVE_DUPLICATES _vtk_export_packages)
4432  foreach (_vtk_export_package IN LISTS _vtk_export_packages)
4433  set(_vtk_export_base_package "${_vtk_export_base}_${_vtk_export_package}")
4434  get_property(_vtk_export_version GLOBAL
4435  PROPERTY "${_vtk_export_base_package}_version")
4436  get_property(_vtk_export_config GLOBAL
4437  PROPERTY "${_vtk_export_base_package}_config")
4438  get_property(_vtk_export_exact GLOBAL
4439  PROPERTY "${_vtk_export_base_package}_exact")
4440  get_property(_vtk_export_components GLOBAL
4441  PROPERTY "${_vtk_export_base_package}_components")
4442  get_property(_vtk_export_optional_components GLOBAL
4443  PROPERTY "${_vtk_export_base_package}_optional_components")
4444  get_property(_vtk_export_optional_components_found GLOBAL
4445  PROPERTY "${_vtk_export_base_package}_optional_components_found")
4446 
4447  # Assume that any found optional components end up being required.
4448  if (${_vtk_export_base_package}_optional_components_found)
4449  list(REMOVE_ITEM _vtk_export_optional_components
4450  ${_vtk_export_optional_components_found})
4451  list(APPEND _vtk_export_components
4452  ${_vtk_export_optional_components_found})
4453  endif ()
4454 
4455  set(_vtk_export_config_arg)
4456  if (_vtk_export_config)
4457  set(_vtk_export_config_arg CONFIG)
4458  endif ()
4459 
4460  set(_vtk_export_exact_arg)
4461  if (_vtk_export_exact)
4462  set(_vtk_export_exact_arg EXACT)
4463  endif ()
4464 
4465  file(APPEND "${_vtk_export_output_file}"
4466 " find_package(${_vtk_export_package}
4467  ${_vtk_export_version}
4468  ${_vtk_export_exact_arg}
4469  ${_vtk_export_config_arg}
4470  \${_vtk_module_find_package_quiet}
4471  \${_vtk_module_find_package_required}
4472  COMPONENTS ${_vtk_export_components}
4473  OPTIONAL_COMPONENTS ${_vtk_export_optional_components})
4474  if (NOT ${_vtk_export_package}_FOUND AND _vtk_module_find_package_fail_if_not_found)
4475  if (NOT \${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
4476  message(STATUS
4477  \"Could not find the \${CMAKE_FIND_PACKAGE_NAME} package due to a \"
4478  \"missing dependency: ${_vtk_export_package}\")
4479  endif ()
4480  set(\"\${CMAKE_FIND_PACKAGE_NAME}_${_vtk_export_target_name}_FOUND\" 0)
4481  list(APPEND \"\${CMAKE_FIND_PACKAGE_NAME}_${_vtk_export_target_name}_NOT_FOUND_MESSAGE\"
4482  \"Failed to find the ${_vtk_export_package} package.\")
4483  endif ()\n")
4484  endforeach ()
4485 
4486  file(APPEND "${_vtk_export_output_file}"
4487 "endif ()
4488 
4489 unset(_vtk_module_find_package_fail_if_not_found)
4490 unset(_vtk_module_find_package_enabled)
4491 unset(_vtk_module_find_package_required)\n\n")
4492 
4493  endforeach ()
4494 
4495  file(APPEND "${_vtk_export_output_file}"
4496  "unset(_vtk_module_find_package_components)
4497 unset(_vtk_module_find_package_components_required)
4498 unset(_vtk_module_find_package_quiet)\n")
4499 
4500  install(
4501  FILES "${CMAKE_BINARY_DIR}/${_vtk_export_CMAKE_DESTINATION}/${_vtk_export_FILE_NAME}"
4502  DESTINATION "${_vtk_export_CMAKE_DESTINATION}"
4503  COMPONENT "${_vtk_export_COMPONENT}")
4504 endfunction ()
4505 
4506 #[==[
4507 @page module-overview
4508 
4509 @ingroup module
4510 @section module-third-party Third party support
4511 
4512 The module system acknowledges that third party support is a pain and offers
4513 APIs to help wrangle them. Sometimes third party code needs a shim introduced
4514 to make it behave better, so an `INTERFACE` library to add that in is very
4515 useful. Other times, third party code is hard to ensure that it exists
4516 everywhere, so it is bundled. When that happens, the ability to select between
4517 the bundled copy and an external copy is useful. All three (and more) of these
4518 are possible.
4519 
4520 The following functions are used to handle third party modules:
4521 
4522  - @ref vtk_module_third_party
4523  - @ref vtk_module_third_party_external
4524  - @ref vtk_module_third_party_internal
4525 #]==]
4526 
4527 #[==[
4528 @ingroup module
4529 @brief Third party module
4530 
4531 When a project has modules which represent third party packages, there are some
4532 convenience functions to help deal with them. First, there is the meta-wrapper:
4533 
4534 ~~~
4535 vtk_module_third_party(
4536  [INTERNAL <internal arguments>...]
4537  [EXTERNAL <external arguments>...])
4538 ~~~
4539 
4540 This offers a cache variable named `VTK_MODULE_USE_EXTERNAL_<module name>` that
4541 may be set to trigger between the internal copy and an externally provided
4542 copy. This is available as a local variable named
4543 `VTK_MODULE_USE_EXTERNAL_<library name>`. See the
4544 @ref vtk_module_third_party_external and @ref vtk_module_third_party_internal
4545 functions for the arguments supported by the `EXTERNAL` and `INTERNAL`
4546 arguments, respectively.
4547 #]==]
4548 function (vtk_module_third_party)
4549  cmake_parse_arguments(_vtk_third_party
4550  ""
4551  ""
4552  "INTERNAL;EXTERNAL"
4553  ${ARGN})
4554 
4555  if (_vtk_third_party_UNPARSED_ARGUMENTS)
4556  message(FATAL_ERROR
4557  "Unparsed arguments for vtk_module_third_party: "
4558  "${_vtk_third_party_UNPARSED_ARGUMENTS}")
4559  endif ()
4560 
4561  string(REPLACE "::" "_" _vtk_build_module_safe "${_vtk_build_module}")
4562  option("VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe}"
4563  "Use externally provided ${_vtk_build_module}"
4564  "${_vtk_build_USE_EXTERNAL}")
4565  mark_as_advanced("VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe}")
4566  get_property(_vtk_third_party_library_name GLOBAL
4567  PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
4568  set("VTK_MODULE_USE_EXTERNAL_${_vtk_third_party_library_name}"
4569  "${VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe}}"
4570  PARENT_SCOPE)
4571 
4572  if (VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe})
4573  # XXX(cmake): https://gitlab.kitware.com/cmake/cmake/issues/16364.
4574  # Unset a variable which CMake doesn't like when switching between real
4575  # libraries (internal) and interface libraries (external).
4576  unset("${_vtk_build_module}_LIB_DEPENDS" CACHE)
4577  vtk_module_third_party_external(${_vtk_third_party_EXTERNAL})
4578 
4579  # Bubble up variables again.
4580  foreach (_vtk_third_party_variable IN LISTS _vtk_third_party_variables)
4581  set("${_vtk_third_party_variable}"
4582  "${${_vtk_third_party_variable}}"
4583  PARENT_SCOPE)
4584  endforeach ()
4585  else ()
4586  set(_vtk_third_party_has_external_support 1)
4587  vtk_module_third_party_internal(${_vtk_third_party_INTERNAL})
4588  endif ()
4589 endfunction ()
4590 
4591 #[==[
4592 @ingroup module-impl
4593 @brief Mark a module as being third party
4594 
4595 Mark a module as being a third party module.
4596 
4597 ~~~
4599 ~~~
4600 #]==]
4602  # TODO: `_vtk_module_set_module_property` instead.
4603  set_target_properties("${target}"
4604  PROPERTIES
4605  "INTERFACE_vtk_module_exclude_wrap" 1
4606  "INTERFACE_vtk_module_third_party" 1)
4607 endfunction ()
4608 
4609 #[==[
4610 @ingroup module
4611 @brief External third party package
4612 
4613 A third party dependency may be expressed as a module using this function.
4614 Third party packages are found using CMake's `find_package` function. It is
4615 highly recommended that imported targets are used to make usage easier. The
4616 module itself will be created as an `INTERFACE` library which exposes the
4617 package.
4618 
4619 ~~~
4620 vtk_module_third_party_external(
4621  PACKAGE <package>
4622  [VERSION <version>]
4623  [COMPONENTS <component>...]
4624  [OPTIONAL_COMPONENTS <component>...]
4625  [INCLUDE_DIRS <path-or-variable>...]
4626  [LIBRARIES <target-or-variable>...]
4627  [DEFINITIONS <variable>...]
4628  [FORWARD_VERSION_REQ <MAJOR|MINOR|PATCH|EXACT>]
4629  [VERSION_VAR <version-spec>]
4630  [USE_VARIABLES <variable>...]
4631  [CONFIG_MODE]
4632  [STANDARD_INCLUDE_DIRS])
4633 ~~~
4634 
4635 Only the `PACKAGE` argument is required. The arguments are as follows:
4636 
4637  * `PACKAGE`: (Required) The name of the package to find.
4638  * `VERSION`: If specified, the minimum version of the dependency that must be
4639  found.
4640  * `COMPONENTS`: The list of components to request from the package.
4641  * `OPTIONAL_COMPONENTS`: The list of optional components to request from the
4642  package.
4643  * `STANDARD_INCLUDE_DIRS`: If present, standard include directories will be
4644  added to the module target. This is usually only required if both internal
4645  and external are supported for a given dependency.
4646  * `INCLUDE_DIRS`: If specified, this is added as a `SYSTEM INTERFACE` include
4647  directory for the target. If a variable name is given, it will be
4648  dereferenced.
4649  * `LIBRARIES`: The libraries to link from the package. If a variable name is
4650  given, it will be dereferenced, however a warning that imported targets are
4651  not being used will be emitted.
4652  * `DEFINITIONS`: If specified, the given variables will be added to the
4653  target compile definitions interface.
4654  * `CONFIG_MODE`: Force `CONFIG` mode.
4655  * `FORWARD_VERSION_REQ` and `VERSION_VAR`: See documentation for
4656  @ref vtk_module_find_package.
4657  * `USE_VARIABLES`: List of variables from the `find_package` to make
4658  available to the caller.
4659 #]==]
4660 function (vtk_module_third_party_external)
4661  cmake_parse_arguments(_vtk_third_party_external
4662  "STANDARD_INCLUDE_DIRS;CONFIG_MODE"
4663  "VERSION;PACKAGE;FORWARD_VERSION_REQ;VERSION_VAR"
4664  "COMPONENTS;OPTIONAL_COMPONENTS;LIBRARIES;INCLUDE_DIRS;DEFINITIONS;TARGETS;USE_VARIABLES"
4665  ${ARGN})
4666 
4667  if (_vtk_third_party_external_UNPARSED_ARGUMENTS)
4668  message(FATAL_ERROR
4669  "Unparsed arguments for vtk_module_third_party_external: "
4670  "${_vtk_third_party_external_UNPARSED_ARGUMENTS}")
4671  endif ()
4672 
4673  get_property(_vtk_third_party_external_is_third_party GLOBAL
4674  PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
4675  if (NOT _vtk_third_party_external_is_third_party)
4676  message(FATAL_ERROR
4677  "The ${_vtk_build_module} has not been declared as a third party "
4678  "module.")
4679  endif ()
4680 
4681  if (NOT DEFINED _vtk_third_party_external_PACKAGE)
4682  message(FATAL_ERROR
4683  "The `PACKAGE` argument is required.")
4684  endif ()
4685 
4686  set(_vtk_third_party_external_args)
4687  if (DEFINED _vtk_third_party_external_FORWARD_VERSION_REQ)
4688  list(APPEND _vtk_third_party_external_args
4689  FORWARD_VERSION_REQ "${_vtk_third_party_external_FORWARD_VERSION_REQ}")
4690  endif ()
4691  if (DEFINED _vtk_third_party_external_VERSION_VAR)
4692  list(APPEND _vtk_third_party_external_args
4693  VERSION_VAR "${_vtk_third_party_external_VERSION_VAR}")
4694  endif ()
4695 
4696  if (_vtk_third_party_external_TARGETS)
4697  set(_vtk_third_party_external_config_mode)
4698  if (_vtk_third_party_external_CONFIG_MODE)
4699  set(_vtk_third_party_external_config_mode "CONFIG_MODE")
4700  endif ()
4701 
4702  # If we have targets, they must be exported to the install as well.
4703  vtk_module_find_package(
4704  PACKAGE "${_vtk_third_party_external_PACKAGE}"
4705  VERSION "${_vtk_third_party_external_VERSION}"
4706  COMPONENTS ${_vtk_third_party_external_COMPONENTS}
4707  OPTIONAL_COMPONENTS ${_vtk_third_party_external_OPTIONAL_COMPONENTS}
4708  ${_vtk_third_party_external_config_mode}
4709  ${_vtk_third_party_external_args})
4710  else ()
4711  set(_vtk_third_party_external_config)
4712  if (_vtk_third_party_external_CONFIG_MODE)
4713  set(_vtk_third_party_external_config "CONFIG")
4714  endif ()
4715 
4716  # If there are no targets, the install uses strings and therefore does not
4717  # need to find the dependency again.
4718  find_package("${_vtk_third_party_external_PACKAGE}"
4719  ${_vtk_third_party_external_VERSION}
4720  ${_vtk_third_party_external_config}
4721  COMPONENTS ${_vtk_third_party_external_COMPONENTS}
4722  OPTIONAL_COMPONENTS ${_vtk_third_party_external_OPTIONAL_COMPONENTS})
4723  endif ()
4724 
4725  get_property(_vtk_third_party_external_target_name GLOBAL
4726  PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
4727 
4728  # Check if an imported target of the same name already exists.
4729  set(_vtk_third_party_external_real_target_name
4730  "${_vtk_third_party_external_target_name}")
4731  set(_vtk_third_party_external_using_mangled_name OFF)
4732  if (TARGET "${_vtk_third_party_external_target_name}")
4733  # Ensure that the target collision comes from an imported target.
4734  get_property(_vtk_third_party_external_is_imported
4735  TARGET "${_vtk_third_party_external_target_name}"
4736  PROPERTY IMPORTED)
4737  if (NOT _vtk_third_party_external_is_imported)
4738  message(FATAL_ERROR
4739  "It appears as though there is a conflicting target named "
4740  "`${_vtk_third_party_external_target_name}` expected to be used by "
4741  "the `${_vtk_build_module}` module already added to the build. This "
4742  "conflicts with the target name expected to be used by an external "
4743  "third party dependency.")
4744  endif ()
4745 
4746  # If it does, we need to have a module name that is not the same as this
4747  # one. Error out if this is detected.
4748  if (_vtk_build_module STREQUAL _vtk_third_party_external_target_name)
4749  message(FATAL_ERROR
4750  "An imported target has the same name used by the module system for "
4751  "the facade of the external dependency for `${_vtk_build_module}`. "
4752  "This module must be either renamed or placed into a namespace.")
4753  endif ()
4754 
4755  # Mangle the internal name. The alias is the expected use case anyways and
4756  # since this is an INTERFACE target, there's nothing to break with respect
4757  # to `make $target` anyways.
4758  string(APPEND _vtk_third_party_external_real_target_name
4759  "_vtk_module_mangle")
4760  set_property(GLOBAL APPEND_STRING
4761  PROPERTY "_vtk_module_${_vtk_build_module}_target_name"
4762  "_vtk_module_mangle")
4763  set(_vtk_third_party_external_using_mangled_name ON)
4764  endif ()
4765 
4766  add_library("${_vtk_third_party_external_real_target_name}" INTERFACE)
4767  if (_vtk_third_party_external_using_mangled_name)
4768  set_property(TARGET "${_vtk_third_party_external_real_target_name}"
4769  PROPERTY
4770  EXPORT_NAME "${_vtk_third_party_external_target_name}")
4771  endif ()
4772  if (NOT _vtk_build_module STREQUAL _vtk_third_party_external_target_name)
4773  add_library("${_vtk_build_module}" ALIAS
4774  "${_vtk_third_party_external_real_target_name}")
4775  endif ()
4776 
4777  if (_vtk_third_party_external_STANDARD_INCLUDE_DIRS)
4778  _vtk_module_standard_includes(TARGET "${_vtk_third_party_external_real_target_name}"
4779  SYSTEM INTERFACE)
4780  endif ()
4781 
4782  # Try to use targets if they're specified and available.
4783  set(_vtk_third_party_external_have_targets FALSE)
4784  set(_vtk_third_party_external_used_targets FALSE)
4785  if (_vtk_third_party_external_TARGETS)
4786  set(_vtk_third_party_external_have_targets TRUE)
4787  set(_vtk_third_party_external_all_targets_okay TRUE)
4788  foreach (_vtk_third_party_external_target IN LISTS _vtk_third_party_external_TARGETS)
4789  if (NOT TARGET "${_vtk_third_party_external_target}")
4790  set(_vtk_third_party_external_all_targets_okay FALSE)
4791  break ()
4792  endif ()
4793  endforeach ()
4794 
4795  if (_vtk_third_party_external_all_targets_okay)
4796  target_link_libraries("${_vtk_third_party_external_real_target_name}"
4797  INTERFACE
4798  ${_vtk_third_party_external_TARGETS})
4799  set(_vtk_third_party_external_used_targets TRUE)
4800  endif ()
4801  endif ()
4802 
4803  if (NOT _vtk_third_party_external_used_targets)
4804  if (NOT _vtk_third_party_external_have_targets)
4805  message(WARNING
4806  "A third party dependency for ${_vtk_build_module} was found externally "
4807  "using paths rather than targets; it is recommended to use imported "
4808  "targets rather than find_library and such.")
4809  endif ()
4810 
4811  set(_vtk_third_party_external_have_includes FALSE)
4812  foreach (_vtk_third_party_external_include_dir IN LISTS _vtk_third_party_external_INCLUDE_DIRS)
4813  if (DEFINED "${_vtk_third_party_external_include_dir}")
4814  if (${_vtk_third_party_external_include_dir})
4815  set(_vtk_third_party_external_have_includes TRUE)
4816  endif ()
4817  target_include_directories("${_vtk_third_party_external_real_target_name}" SYSTEM
4818  INTERFACE "${${_vtk_third_party_external_include_dir}}")
4819  endif ()
4820  endforeach ()
4821 
4822  if (_vtk_third_party_external_have_targets AND
4823  NOT _vtk_third_party_external_have_includes)
4824  message(WARNING
4825  "A third party dependency for ${_vtk_build_module} has external targets "
4826  "which were not found and no `INCLUDE_DIRS` were found either. "
4827  "Including this module may not work.")
4828  endif ()
4829 
4830  foreach (_vtk_third_party_external_define IN LISTS _vtk_third_party_external_DEFINITIONS)
4831  if (DEFINED "${_vtk_third_party_external_define}")
4832  target_compile_definitions("${_vtk_third_party_external_real_target_name}"
4833  INTERFACE "${${_vtk_third_party_external_define}}")
4834  endif ()
4835  endforeach ()
4836 
4837  set(_vtk_third_party_external_have_libraries FALSE)
4838  foreach (_vtk_third_party_external_library IN LISTS _vtk_third_party_external_LIBRARIES)
4839  if (DEFINED "${_vtk_third_party_external_library}")
4840  if (${_vtk_third_party_external_library})
4841  set(_vtk_third_party_external_have_libraries TRUE)
4842  endif ()
4843  target_link_libraries("${_vtk_third_party_external_real_target_name}"
4844  INTERFACE "${${_vtk_third_party_external_library}}")
4845  endif ()
4846  endforeach ()
4847 
4848  if (_vtk_third_party_external_have_targets AND
4849  NOT _vtk_third_party_external_have_libraries)
4850  message(WARNING
4851  "A third party dependency for ${_vtk_build_module} has external targets "
4852  "which were not found and no `LIBRARIES` were found either. Linking to "
4853  "this this module may not work.")
4854  endif ()
4855  endif ()
4856 
4857  if (DEFINED _vtk_third_party_external_USE_VARIABLES)
4858  # If we're called from `vtk_module_third_party`, the variables need bubbled
4859  # up again.
4860  if (DEFINED _vtk_third_party_EXTERNAL)
4861  set(_vtk_third_party_variables
4862  "${_vtk_third_party_external_USE_VARIABLES}"
4863  PARENT_SCOPE)
4864  endif ()
4865 
4866  foreach (_vtk_third_party_external_variable IN LISTS _vtk_third_party_external_USE_VARIABLES)
4867  if (NOT DEFINED "${_vtk_third_party_external_variable}")
4868  message(FATAL_ERROR
4869  "The variable `${_vtk_third_party_external_variable}` was expected "
4870  "to have been available, but was not defined.")
4871  endif ()
4872 
4873  set("${_vtk_third_party_external_variable}"
4874  "${${_vtk_third_party_external_variable}}"
4875  PARENT_SCOPE)
4876  endforeach ()
4877  endif ()
4878 
4879  _vtk_module_mark_third_party("${_vtk_third_party_external_real_target_name}")
4880  _vtk_module_install("${_vtk_third_party_external_real_target_name}")
4881 endfunction ()
4882 
4883 #[==[
4884 @ingroup module
4885 @brief Internal third party package
4886 
4887 Third party modules may also be bundled with the project itself. In this case,
4888 it is an internal third party dependency. The dependency is assumed to be in a
4889 subdirectory that will be used via `add_subdirectory`. Unless it is marked as
4890 `HEADERS_ONLY`, it is assumed that it will create a target with the name of the
4891 module.
4892 
4893 ~~~
4894 vtk_module_third_party_internal(
4895  [SUBDIRECTORY <path>]
4896  [HEADERS_SUBDIR <subdir>]
4897  [LICENSE_FILES <file>...]
4898  [VERSION <version>]
4899  [HEADER_ONLY]
4900  [INTERFACE]
4901  [STANDARD_INCLUDE_DIRS])
4902 ~~~
4903 
4904 All arguments are optional, however warnings are emitted if `LICENSE_FILES` or
4905 `VERSION` is not specified. They are as follows:
4906 
4907  * `SUBDIRECTORY`: (Defaults to the library name of the module) The
4908  subdirectory containing the `CMakeLists.txt` for the dependency.
4909  * `HEADERS_SUBDIR`: If non-empty, the subdirectory to use for installing
4910  headers.
4911  * `LICENSE_FILES`: A list of license files to install for the dependency. If
4912  not given, a warning will be emitted.
4913  * `VERSION`: The version of the library that is included.
4914  * `HEADER_ONLY`: The dependency is header only and will not create a target.
4915  * `INTERFACE`: The dependency is an `INTERFACE` library.
4916  * `STANDARD_INCLUDE_DIRS`: If present, module-standard include directories
4917  will be added to the module target.
4918 #]==]
4919 function (vtk_module_third_party_internal)
4920  # TODO: Support scanning for third-party modules which don't support an
4921  # external copy.
4922 
4923  cmake_parse_arguments(_vtk_third_party_internal
4924  "INTERFACE;HEADER_ONLY;STANDARD_INCLUDE_DIRS"
4925  "SUBDIRECTORY;HEADERS_SUBDIR;VERSION"
4926  "LICENSE_FILES"
4927  ${ARGN})
4928 
4929  if (_vtk_third_party_internal_UNPARSED_ARGUMENTS)
4930  message(FATAL_ERROR
4931  "Unparsed arguments for vtk_module_third_party_internal: "
4932  "${_vtk_third_party_internal_UNPARSED_ARGUMENTS}")
4933  endif ()
4934 
4935  get_property(_vtk_third_party_internal_is_third_party GLOBAL
4936  PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
4937  if (NOT _vtk_third_party_internal_is_third_party)
4938  message(FATAL_ERROR
4939  "The ${_vtk_build_module} has not been declared as a third party "
4940  "module.")
4941  endif ()
4942 
4943  get_property(_vtk_third_party_internal_library_name GLOBAL
4944  PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
4945  if (NOT DEFINED _vtk_third_party_internal_SUBDIRECTORY)
4946  set(_vtk_third_party_internal_SUBDIRECTORY "${_vtk_third_party_internal_library_name}")
4947  endif ()
4948 
4949  if (NOT DEFINED _vtk_third_party_internal_LICENSE_FILES)
4950  message(WARNING
4951  "The ${_vtk_build_module} third party package is embedded, but does not "
4952  "specify any license files.")
4953  endif ()
4954 
4955  if (NOT DEFINED _vtk_third_party_internal_VERSION)
4956  message(WARNING
4957  "The ${_vtk_build_module} third party package is embedded, but does not "
4958  "specify the version it is based on.")
4959  endif ()
4960 
4961  get_property(_vtk_third_party_internal_target_name GLOBAL
4962  PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
4963  set(_vtk_third_party_internal_include_type)
4964  if (_vtk_third_party_internal_INTERFACE)
4965  set(_vtk_third_party_internal_include_type INTERFACE)
4966  elseif (_vtk_third_party_internal_HEADER_ONLY)
4967  add_library("${_vtk_third_party_internal_target_name}" INTERFACE)
4968  if (NOT _vtk_build_module STREQUAL _vtk_third_party_internal_target_name)
4969  add_library("${_vtk_build_module}" ALIAS
4970  "${_vtk_third_party_internal_target_name}")
4971  endif ()
4972  set(_vtk_third_party_internal_include_type INTERFACE)
4973  set(_vtk_third_party_internal_STANDARD_INCLUDE_DIRS 1)
4974  endif ()
4975 
4976  add_subdirectory("${_vtk_third_party_internal_SUBDIRECTORY}")
4977 
4978  if (NOT TARGET "${_vtk_build_module}")
4979  message(FATAL_ERROR
4980  "The ${_vtk_build_module} is being built as an internal third party "
4981  "library, but a matching target was not created.")
4982  endif ()
4983 
4984  if (_vtk_third_party_internal_STANDARD_INCLUDE_DIRS)
4985  _vtk_module_standard_includes(
4986  TARGET "${_vtk_third_party_internal_target_name}"
4987  SYSTEM ${_vtk_third_party_internal_include_type}
4988  HEADERS_DESTINATION "${_vtk_build_HEADERS_DESTINATION}/${_vtk_third_party_internal_HEADERS_SUBDIR}")
4989  endif ()
4990 
4991  _vtk_module_apply_properties("${_vtk_third_party_internal_target_name}")
4992  if (_vtk_third_party_internal_INTERFACE)
4993  # Nothing.
4994  elseif (_vtk_third_party_internal_HEADER_ONLY)
4995  _vtk_module_install("${_vtk_third_party_internal_target_name}")
4996  endif ()
4997 
4998  if (_vtk_third_party_internal_LICENSE_FILES)
4999  install(
5000  FILES ${_vtk_third_party_internal_LICENSE_FILES}
5001  DESTINATION "${_vtk_build_LICENSE_DESTINATION}/${_vtk_third_party_internal_library_name}/"
5002  COMPONENT "license")
5003  endif ()
5004 
5005  _vtk_module_mark_third_party("${_vtk_third_party_internal_target_name}")
5006 endfunction ()
_vtk_module_debug
function _vtk_module_debug(domain, format)
Conditionally output debug statements.
Definition: vtkModule.cmake:57
VTK_MODULE_AUTOINIT
#define VTK_MODULE_AUTOINIT
Definition: vtkAutoInit.h:21
vtk_module_link_options
function vtk_module_link_options(module)
Add link options to a module.
Definition: vtkModule.cmake:1591
_vtk_module_export_properties
function _vtk_module_export_properties()
Export properties on modules and targets.
Definition: vtkModule.cmake:1925
global
Definition: UnstructuredGhostZonesCommon.h:30
vtkX3D::component
@ component
Definition: vtkX3D.h:181
vtk_module_compile_features
function vtk_module_compile_features(module)
Add compile features to a module.
Definition: vtkModule.cmake:1492
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkX3D::data
@ data
Definition: vtkX3D.h:321
vtkX3D::language
@ language
Definition: vtkX3D.h:396
vtkX3D::time
@ time
Definition: vtkX3D.h:503
_vtk_module_real_target
function _vtk_module_real_target(var, module)
The real target for a module.
Definition: vtkModule.cmake:1093
vtkX3D::on
@ on
Definition: vtkX3D.h:445
vtk_module_install_headers
function vtk_module_install_headers()
Install headers.
Definition: vtkModule.cmake:3724
vtkX3D::level
@ level
Definition: vtkX3D.h:401
target
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:965
_vtk_module_set_module_property
function _vtk_module_set_module_property(module)
Set a module property.
Definition: vtkModule.cmake:1693
vtk_module_compile_options
function vtk_module_compile_options(module)
Add compile options to a module.
Definition: vtkModule.cmake:1457
vtk_module_link
function vtk_module_link(module)
Add link libraries to a module.
Definition: vtkModule.cmake:1529
vtk_module_set_property
function vtk_module_set_property(module)
Set a property on a module.
Definition: vtkModule.cmake:1225
vtk_module_definitions
function vtk_module_definitions(module)
Add compile definitions to a module.
Definition: vtkModule.cmake:1422
vtk_module_build
function vtk_module_build()
Build modules and kits.
Definition: vtkModule.cmake:2158
vtk_module_third_party_external
function vtk_module_third_party_external()
External third party package.
Definition: vtkModule.cmake:4660
vtkX3D::enabled
@ enabled
Definition: vtkX3D.h:265
vtkX3D::name
@ name
Definition: vtkX3D.h:225
_vtk_module_real_target_kit
function _vtk_module_real_target_kit(var, kit)
The real target for a kit.
Definition: vtkModule.cmake:1162
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtk_module_get_property
function vtk_module_get_property(module)
Get a property from a module.
Definition: vtkModule.cmake:1286
vtk_module_third_party_internal
function vtk_module_third_party_internal()
Internal third party package.
Definition: vtkModule.cmake:4919
vtk_module_autoinit
function vtk_module_autoinit()
Linking to autoinit-using modules.
Definition: vtkModule.cmake:2832
impl
Definition: TestMotionFXCFGReaderCommon.h:36
vtkX3D::description
@ description
Definition: vtkX3D.h:328
vtk
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
Definition: vtkAtomicTypeConcepts.h:21
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:959
vtk_module_include
function vtk_module_include(module)
Add include directories to a module.
Definition: vtkModule.cmake:1381
_vtk_module_mark_third_party
function _vtk_module_mark_third_party(target)
Mark a module as being third party.
Definition: vtkModule.cmake:4601
_vtk_module_apply_properties
function _vtk_module_apply_properties(target)
Apply properties to a module.
Definition: vtkModule.cmake:3786
vtk_module_add_module
function vtk_module_add_module(name)
Create a module library.
Definition: vtkModule.cmake:3182
vtk_module_scan
function vtk_module_scan()
Scan modules and kits.
Definition: vtkModule.cmake:525