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