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