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