From 513c105b92beac2287872dc92708431180b5a93e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 20 Dec 2018 17:04:19 -0500 Subject: [PATCH 001/359] vtkEncodeString: ensure it is running in script mode --- CMake/vtkEncodeString.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMake/vtkEncodeString.cmake b/CMake/vtkEncodeString.cmake index f9c2473ab11..ea012ca679e 100644 --- a/CMake/vtkEncodeString.cmake +++ b/CMake/vtkEncodeString.cmake @@ -135,7 +135,7 @@ function (vtk_encode_string) endif () endfunction () -if (_vtk_encode_string_run) +if (_vtk_encode_string_run AND CMAKE_SCRIPT_MODE_FILE) set(output_header "${binary_dir}/${output_name}.h") set(output_source "${binary_dir}/${output_name}.cxx") -- GitLab From 147a4db819ead8cc934f542c0d1edec0f48e68bb Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 20 Dec 2018 17:04:29 -0500 Subject: [PATCH 002/359] vtkHashSource: ensure it is running in script mode --- CMake/vtkHashSource.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMake/vtkHashSource.cmake b/CMake/vtkHashSource.cmake index 3a516fe0747..b16a35e6e9d 100644 --- a/CMake/vtkHashSource.cmake +++ b/CMake/vtkHashSource.cmake @@ -92,7 +92,7 @@ function (vtk_hash_source) endif () endfunction() -if (_vtk_hash_source_run) +if (_vtk_hash_source_run AND CMAKE_SCRIPT_MODE_FILE) file(${algorithm} "${input_file}" file_hash) file(WRITE "${output_file}" "#ifndef ${output_name}\n #define ${output_name} \"${file_hash}\"\n#endif\n") -- GitLab From bd28b231e079721a3cfde8141ed0a1e180e62e9f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Dec 2018 15:59:37 -0500 Subject: [PATCH 003/359] vtkDataArrayAccessor: hide from wrapping code --- Common/Core/vtkDataArrayAccessor.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Common/Core/vtkDataArrayAccessor.h b/Common/Core/vtkDataArrayAccessor.h index f24ba729dc9..23c80ddd41d 100644 --- a/Common/Core/vtkDataArrayAccessor.h +++ b/Common/Core/vtkDataArrayAccessor.h @@ -96,6 +96,8 @@ #ifndef vtkDataArrayAccessor_h #define vtkDataArrayAccessor_h +#ifndef __VTK_WRAP__ + // Generic form for all (non-bit) vtkDataArray subclasses. template struct vtkDataArrayAccessor @@ -192,5 +194,7 @@ struct vtkDataArrayAccessor } }; +#endif + #endif // vtkDataArrayAccessor_h // VTK-HeaderTest-Exclude: vtkDataArrayAccessor.h -- GitLab From 1e8c0d1eefb2792f77b4097e81d1440a36c8c755 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 27 Dec 2017 11:39:50 -0500 Subject: [PATCH 004/359] vtkModule: add CMake code for the new module system The new module system is target-based rather than variable based. All information is passed between targets using target properties and leveraging CMake where possible such as for things like include directories and linking libraries. Where CMake doesn't handle things automatically, we store properties ourselves. This includes whether a module needs autoinit logic (and a function to handle adding the autoinit logic to a set of targets), which headers to wrap in various languages, etc. --- CMake/vtkModule.cmake | 4045 +++++++++++++++++ CMake/vtkModuleTesting.cmake | 645 +++ ...calSort.cmake => vtkTopologicalSort.cmake} | 6 +- Documentation/dev/git/data.md | 6 +- 4 files changed, 4696 insertions(+), 6 deletions(-) create mode 100644 CMake/vtkModule.cmake create mode 100644 CMake/vtkModuleTesting.cmake rename CMake/{TopologicalSort.cmake => vtkTopologicalSort.cmake} (97%) diff --git a/CMake/vtkModule.cmake b/CMake/vtkModule.cmake new file mode 100644 index 00000000000..29db2277e8e --- /dev/null +++ b/CMake/vtkModule.cmake @@ -0,0 +1,4045 @@ +#[==[.md +# `vtkModule` + +This module includes functions to find and build VTK modules. A module is a set +of related functionality. These are then compiled together into libraries at +the "kit" level. Each module may be enabled or disabled individually and its +dependencies will be built as needed. +#]==] + +#[==[.md INTERNAL +# `vtkModule` internals + +The VTK module system provides some API functions for use by other code which +consumes VTK modules (primarily language wrappers). This file documents these +APIs. They may start with `_vtk_module`, but they are intended for use in cases +of language wrappers or dealing with trickier third party packages. +#]==] + +# TODO: Support finding `vtk.module` and `vtk.kit` contents in the +# `CMakeLists.txt` files for the module via a comment header. + +#[==[.md +## Finding modules and kits + +The first step to building modules involves finding their metadata files. These +are files named `vtk.kit` and `vtk.module` within the source tree next to the +associated `CMakeLists.txt` file for the module (for modules). `vtk.kit` files +are standalone. + +In order to find these files, two functions are available: + +``` +vtk_module_find_kits( [...]) +vtk_module_find_modules( [...]) +``` + +These scan the given directories for the files of the associated name and put +the paths into the output variable. +#]==] + +function (vtk_module_find_kits output) + set(_vtk_find_kits_all) + foreach (_vtk_find_kits_directory IN LISTS ARGN) + file(GLOB_RECURSE _vtk_find_kits_kits + "${_vtk_find_kits_directory}/vtk.kit") + list(APPEND _vtk_find_kits_all + ${_vtk_find_kits_kits}) + endforeach () + set("${output}" ${_vtk_find_kits_all} PARENT_SCOPE) +endfunction () + +function (vtk_module_find_modules output) + set(_vtk_find_modules_all) + foreach (_vtk_find_modules_directory IN LISTS ARGN) + file(GLOB_RECURSE _vtk_find_modules_modules + "${_vtk_find_modules_directory}/vtk.module") + list(APPEND _vtk_find_modules_all + ${_vtk_find_modules_modules}) + endforeach () + set("${output}" ${_vtk_find_modules_all} PARENT_SCOPE) +endfunction () + +#[==[.md INTERNAL +## Splitting a module name + +Module names may include a namespace. This function splits the name into a +namespace and target name part. + +``` +_vtk_module_split_module_name( ) +``` + +The `_NAMESPACE` and `_TARGET_NAME` variables will be set in +the calling scope. +#]==] +function (_vtk_module_split_module_name name prefix) + string(FIND "${name}" "::" namespace_pos) + if (namespace_pos EQUAL -1) + set(namespace "") + set(target_name "${name}") + else () + string(SUBSTRING "${name}" 0 "${namespace_pos}" namespace) + math(EXPR name_pos "${namespace_pos} + 2") + string(SUBSTRING "${name}" "${name_pos}" -1 target_name) + endif () + + set("${prefix}_NAMESPACE" + "${namespace}" + PARENT_SCOPE) + set("${prefix}_TARGET_NAME" + "${target_name}" + PARENT_SCOPE) +endfunction () + +#[==[.md +## Module files + +The `vtk.module` file is parsed and used as arguments to a CMake function which +stores information about the module for use when building it. Note that no +variable expansion is allowed and it is not CMake code, so no control flow is +allowed. Comments are supported and any content after a `#` on a line is +treated as a comment. Due to the breakdown of the content, quotes are not +meaningful within the files. + +Example: + +``` +NAME + VTK::CommonCore +LIBRARY_NAME + vtkCommonCore +DESCRIPTION + The base VTK library. +GROUPS + StandAlone +DEPENDS + vtkkwiml +PRIVATE_DEPENDS + vtksys + vtkutf8 +``` + +All values are optional unless otherwise noted. The following arguments are +supported: + + * `NAME`: (Required) The name of the module. + * `LIBRARY_NAME`: The base name of the library file. It defaults to the + module name, but any namespaces are removed. For example, a `NS::Foo` + module will have a default `LIBRARY_NAME` of `Foo`. + * `DESCRIPTION`: (Recommended) Short text describing what the module is for. + * `KIT`: The name of the kit the module belongs to (see `Kits files` for more + information). + * `IMPLEMENTABLE`: If present, the module contains logic which supports the + autoinit functionality. + * `GROUPS`: Modules may belong to "groups" which is exposed as a build + option. This allows for enabling a set of modules with a single build + option. + * `CONDITION`: Arguments to CMake's `if` command which may be used to hide + the module for certain platforms or other reasons. If the expression is + false, the module is completely ignored. + * `DEPENDS`: A list of modules which are required by this module and modules + using this module. + * `PRIVATE_DEPENDS`: A list of modules which are required by this module, but + not by those using this module. + * `OPTIONAL_DEPENDS`: A list of modules which are used by this module if + enabled; these are treated as `PRIVATE_DEPENDS` if they exist. + * `IMPLEMENTS`: A list of modules for which this module needs to register + with. + * `TEST_DEPENDS`: Modules required by the test suite for this module. + * `TEST_OPTIONAL_DEPENDS`: Modules used by the test suite for this module if + available. + * `TEST_LABELS`: Labels to apply to the tests of this module. By default, the + module name is applied as a label. + * `EXCLUDE_WRAP`: If present, this module should not be wrapped in any + language. + * `THIRD_PARTY`: If present, this module is a third party module. +#]==] + +macro (_vtk_module_parse_module_args name_output) + cmake_parse_arguments("_name" + "" + "NAME" + "" + ${ARGN}) + + if (NOT _name_NAME) + message(FATAL_ERROR + "A VTK module requires a name (from ${_vtk_scan_module_file}).") + endif () + set("${name_output}" "${_name_NAME}") + + cmake_parse_arguments("${_name_NAME}" + "IMPLEMENTABLE;EXCLUDE_WRAP;THIRD_PARTY" + "LIBRARY_NAME;NAME;KIT" + "GROUPS;DEPENDS;PRIVATE_DEPENDS;OPTIONAL_DEPENDS;TEST_DEPENDS;TEST_OPTIONAL_DEPENDS;TEST_LABELS;DESCRIPTION;CONDITION;IMPLEMENTS" + ${ARGN}) + + if (${_name_NAME}_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for ${_name_NAME}: " + "${${_name_NAME}_UNPARSED_ARGUMENTS}") + endif () + + if (NOT ${_name_NAME}_DESCRIPTION AND _vtk_module_warnings) + message(WARNING "The ${_name_NAME} module should have a description") + endif () + string(REPLACE ";" " " "${_name_NAME}_DESCRIPTION" "${${_name_NAME}_DESCRIPTION}") + + _vtk_module_split_module_name("${_name_NAME}" "${_name_NAME}") + + if (NOT DEFINED "${_name_NAME}_LIBRARY_NAME") + set("${_name_NAME}_LIBRARY_NAME" "${${_name_NAME}_TARGET_NAME}") + endif () + + if (NOT ${_name_NAME}_LIBRARY_NAME) + message(FATAL_ERROR "The ${_name_NAME} module must have a non-empty `LIBRARY_NAME`.") + endif () + + list(APPEND "${_name_NAME}_TEST_LABELS" + "${${_name_NAME}_NAME}" + "${${_name_NAME}_LIBRARY_NAME}") +endmacro () + +#[==[.md +## Kit files + +The `vtk.kit` file is parsed similarly to `vtk.module` files. Kits are intended +to bring together related modules into a single library in order to reduce the +number of objects that linkers need to deal with. + +Example: + +``` +NAME + vtkCommonKit +DESCRIPTION + Core utilities for VTK. +``` + +All values are optional unless otherwise noted. The following arguments are +supported: + + * `NAME`: (Required) The name of the kit. + * `LIBRARY_NAME`: The base name of the library file. It defaults to the + module name, but any namespaces are removed. For example, a `NS::Foo` + module will have a default `LIBRARY_NAME` of `Foo`. + * `DESCRIPTION`: (Recommended) Short text describing what the kit contains. +#]==] + +macro (_vtk_module_parse_kit_args name_output) + cmake_parse_arguments("_name" + "" + "NAME" + "" + ${ARGN}) + + if (NOT _name_NAME) + message(FATAL_ERROR + "A VTK kit requires a name (from ${_vtk_scan_kit_file}).") + endif () + set("${name_output}" "${_name_NAME}") + + cmake_parse_arguments("${_name_NAME}" + "" + "NAME;LIBRARY_NAME" + "DESCRIPTION" + ${ARGN}) + + if (${_name_NAME}_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for ${_name_NAME}: " + "${${_name_NAME}_UNPARSED_ARGUMENTS}") + endif () + + _vtk_module_split_module_name("${_name_NAME}" "${_name_NAME}") + + if (NOT DEFINED "${_name_NAME}_LIBRARY_NAME") + set("${_name_NAME}_LIBRARY_NAME" "${${_name_NAME}_TARGET_NAME}") + endif () + + if (NOT ${_name_NAME}_LIBRARY_NAME) + message(FATAL_ERROR "The ${_name_NAME} module must have a non-empty `LIBRARY_NAME`.") + endif () + + if (NOT ${_name_NAME}_DESCRIPTION AND _vtk_module_warnings) + message(WARNING "The ${_name_NAME} kit should have a description") + endif () + string(REPLACE ";" " " "${_name_NAME}_DESCRIPTION" "${${_name_NAME}_DESCRIPTION}") +endmacro () + +#[==[.md +## Enable values + +Modules and groups are enable and disable preferences are specified using a +5-way flag setting: + + - `YES`: The module or group must be built. + - `NO`: The module or group must not be built. + - `WANT`: The module or group should be built if possible. + - `DONT_WANT`: The module or group should only be built if required (e.g., + via a dependency). + - `DEFAULT`: Acts as either `WANT` or `DONT_WANT` based on the group settings + for the module or `WANT_BY_DEFAULT` option to `vtk_module_scan` if no other + preference is specified. This is usually handled via another setting in the + main project. + +If a `YES` module preference requires a module with a `NO` preference, an error +is raised. + +A module with a setting of `DEFAULT` will look for its first non-`DEFAULT` +group setting and only if all of those are set to `DEFAULT` is the +`WANT_BY_DEFAULT` setting used. +#]==] + +function (_vtk_module_verify_enable_value var) + if (NOT (${var} STREQUAL "YES" OR + ${var} STREQUAL "WANT" OR + ${var} STREQUAL "DONT_WANT" OR + ${var} STREQUAL "NO" OR + ${var} STREQUAL "DEFAULT")) + message(FATAL_ERROR + "The `${var}` variable must be one of `YES`, `WANT`, `DONT_WANT`, `NO`, " + "or `DEFAULT`. Found `${${var}}`.") + endif () +endfunction () + +#[==[.md +## Scanning modules and kits + +Once all of the modules and kits have been found, they are scanned to determine +what modules are enabled or required. + +``` +vtk_module_scan( + MODULE_FILES ... + [KIT_FILES ...] + PROVIDES_MODULES + [PROVIDES_KITS ] + [REQUIRES_MODULES ] + [REQUEST_MODULES ...] + [REJECT_MODULES ...] + [UNRECOGNIZED_MODULES ] + [WANT_BY_DEFAULT ] + [HIDE_MODULES_FROM_CACHE ] + [ENABLE_TESTS ]) +``` + +The `MODULE_FILES` and `PROVIDES_MODULES` arguments are required. Modules which +refer to kits must be scanned at the same time as their kits. This is so that +modules may not add themselves to kits declared prior. The arguments are as follows: + + * `MODULE_FILES`: (Required) The list of module files to scan. + * `KIT_FILES`: The list of kit files to scan. + * `PROVIDES_MODULES`: (Required) This variable will contain the list of + modules which are enabled due to this scan. + * `PROVIDES_KITS`: (Required if `KIT_FILES` are provided) This variable will + contain the list of kits which are enabled due to this scan. + * `REQUIRES_MODULES`: This variable will contain the list of modules required + by the enabled modules that were not scanned. + * `REQUEST_MODULES`: The list of modules required by previous scans. + * `REJECT_MODULES`: The list of modules to exclude from the scan. If any of + these modules are required, an error will be raised. + * `UNRECOGNIZED_MODULES`: This variable will contain the list of requested + modules that were not scanned. + * `WANT_BY_DEFAULT`: (Defaults to `OFF`) Whether modules should default to + being built or not. + * `HIDE_MODULES_FROM_CACHE`: (Defaults to `OFF`) Whether or not to hide the + control variables from the cache or not. If enabled, modules will not be + built unless they are required elsewhere. + * `ENABLE_TESTS`: (Defaults to `DEFAULT`) Whether or not modules required by + the tests for the scanned modules should be enabled or not. + - `ON`: Modules listed as `TEST_DEPENDS` will be required. + - `OFF`: Test modules will not be considered. + - `DEFAULT`: Test modules will be enabled if their required dependencies + are satisfied and skipped otherwise. + +### Scanning multiple groups of modules + +When scanning complicated projects, multiple scans may be required to get +defaults set properly. The `REQUIRES_MODULES`, `REQUEST_MODULES`, and +`UNRECOGNIZED_MODULES` arguments are meant to deal with this case. As an +example, imagine a project with its source code, third party dependencies, as +well as some utility modules which should only be built as necessary. Here, the +project would perform three scans, one for each "grouping" of modules: + +```cmake +# Scan our modules first because we need to know what of the other groups we +# need. +vtk_module_find_modules(our_modules "${CMAKE_CURRENT_SOURCE_DIR}/src") +vtk_module_scan( + MODULE_FILES ${our_modules} + PROVIDES_MODULES our_enabled_modules + REQUIRES_MODULES required_modules) + +# Scan the third party modules, requesting only those that are necessary, but +# allowing them to be toggled during the build. +vtk_module_find_modules(third_party_modules "${CMAKE_CURRENT_SOURCE_DIR}/third-party") +vtk_module_scan( + MODULE_FILES ${third_party_modules} + PROVIDES_MODULES third_party_enabled_modules + # These modules were requested by an earlier scan. + REQUEST_MODULES ${required_modules} + REQUIRES_MODULES required_modules + UNRECOGNIZED_MODULES unrecognized_modules) + +# These modules are internal and should only be built if necessary. There's no +# need to support them being enabled independently, so hide them from the +# cache. +vtk_module_find_modules(utility_modules "${CMAKE_CURRENT_SOURCE_DIR}/utilities") +vtk_module_scan( + MODULE_FILES ${utility_modules} + PROVIDES_MODULES utility_enabled_modules + # These modules were either requested or unrecognized by an earlier scan. + REQUEST_MODULES ${required_modules} + ${unrecognized_modules} + REQUIRES_MODULES required_modules + UNRECOGNIZED_MODULES unrecognized_modules + HIDE_MODULES_FROM_CACHE ON) + +if (required_modules OR unrecognized_modules) + # Not all of the modules we required were found. This should probably error out. +endif () +``` +#]==] + +include("${CMAKE_CURRENT_LIST_DIR}/vtkTopologicalSort.cmake") + +function (vtk_module_scan) + cmake_parse_arguments(_vtk_scan + "" + "WANT_BY_DEFAULT;HIDE_MODULES_FROM_CACHE;PROVIDES_MODULES;REQUIRES_MODULES;UNRECOGNIZED_MODULES;ENABLE_TESTS;PROVIDES_KITS" + "MODULE_FILES;KIT_FILES;REQUEST_MODULES;REJECT_MODULES" + ${ARGN}) + + if (_vtk_scan_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_scan: " + "${_vtk_scan_UNPARSED_ARGUMENTS}") + endif () + + if (NOT DEFINED _vtk_scan_WANT_BY_DEFAULT) + set(_vtk_scan_WANT_BY_DEFAULT OFF) + endif () + + if (NOT DEFINED _vtk_scan_HIDE_MODULES_FROM_CACHE) + set(_vtk_scan_HIDE_MODULES_FROM_CACHE OFF) + endif () + + if (NOT DEFINED _vtk_scan_PROVIDES_MODULES) + message(FATAL_ERROR + "The `PROVIDES_MODULES` argument is required.") + endif () + + if (NOT DEFINED _vtk_scan_PROVIDES_KITS AND _vtk_scan_KIT_FILES) + message(FATAL_ERROR + "The `PROVIDES_KITS` argument is required.") + endif () + + if (NOT DEFINED _vtk_scan_ENABLE_TESTS) + set(_vtk_scan_ENABLE_TESTS "DEFAULT") + endif () + + if (NOT (_vtk_scan_ENABLE_TESTS STREQUAL "ON" OR + _vtk_scan_ENABLE_TESTS STREQUAL "OFF" OR + _vtk_scan_ENABLE_TESTS STREQUAL "DEFAULT")) + message(FATAL_ERROR + "The `ENABLE_TESTS` argument must be one of `ON`, `OFF`, or `DEFAULT`. " + "Received `${_vtk_scan_ENABLE_TESTS}`.") + endif () + + if (NOT _vtk_scan_MODULE_FILES) + message(FATAL_ERROR + "No module files given to scan.") + endif () + + set(_vtk_scan_option_default_type STRING) + if (_vtk_scan_HIDE_MODULES_FROM_CACHE) + set(_vtk_scan_option_default_type INTERNAL) + endif () + + set(_vtk_scan_all_kits) + + foreach (_vtk_scan_kit_file IN LISTS _vtk_scan_KIT_FILES) + set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND + PROPERTY + CMAKE_CONFIGURE_DEPENDS "${_vtk_scan_kit_file}") + + file(READ "${_vtk_scan_kit_file}" _vtk_scan_kit_args) + # Replace comments. + string(REGEX REPLACE "#[^\n]*\n" "\n" _vtk_scan_kit_args "${_vtk_scan_kit_args}") + # Use argument splitting. + string(REGEX REPLACE "( |\n)+" ";" _vtk_scan_kit_args "${_vtk_scan_kit_args}") + _vtk_module_parse_kit_args(_vtk_scan_kit_name ${_vtk_scan_kit_args}) + + list(APPEND _vtk_scan_all_kits + "${_vtk_scan_kit_name}") + + # Set properties for building. + set_property(GLOBAL + PROPERTY + "_vtk_kit_${_vtk_scan_kit_name}_namespace" "${${_vtk_scan_kit_name}_NAMESPACE}") + set_property(GLOBAL + PROPERTY + "_vtk_kit_${_vtk_scan_kit_name}_target_name" "${${_vtk_scan_kit_name}_TARGET_NAME}") + set_property(GLOBAL + PROPERTY + "_vtk_kit_${_vtk_scan_kit_name}_library_name" "${${_vtk_scan_kit_name}_LIBRARY_NAME}") + endforeach () + + set(_vtk_scan_all_modules) + set(_vtk_scan_all_groups) + set(_vtk_scan_rejected_modules) + + # Read all of the module files passed in. + foreach (_vtk_scan_module_file IN LISTS _vtk_scan_MODULE_FILES) + set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND + PROPERTY + CMAKE_CONFIGURE_DEPENDS "${_vtk_scan_module_file}") + + file(READ "${_vtk_scan_module_file}" _vtk_scan_module_args) + # Replace comments. + string(REGEX REPLACE "#[^\n]*\n" "\n" _vtk_scan_module_args "${_vtk_scan_module_args}") + # Use argument splitting. + string(REGEX REPLACE "( |\n)+" ";" _vtk_scan_module_args "${_vtk_scan_module_args}") + _vtk_module_parse_module_args(_vtk_scan_module_name ${_vtk_scan_module_args}) + + # Determine whether we should provide a user-visible option for this + # module. + set(_vtk_build_use_option 0) + if (DEFINED _vtk_scan_REQUEST_MODULE) + list(FIND _vtk_scan_REQUEST_MODULE "${_vtk_scan_module_name}" _vtk_scan_idx) + if (_vtk_scan_idx EQUAL -1) + set(_vtk_build_use_option 1) + else () + set("_vtk_scan_enable_${_vtk_scan_module_name}" YES) + endif () + else () + set(_vtk_build_use_option 1) + endif () + if (DEFINED _vtk_scan_REJECT_MODULES) + list(FIND _vtk_scan_REJECT_MODULES "${_vtk_scan_module_name}" _vtk_scan_idx) + if (NOT _vtk_scan_idx EQUAL -1) + if (NOT _vtk_build_use_option) + message(FATAL_ERROR + "The ${_vtk_scan_module_name} module has been requested and rejected.") + endif () + # Rejected modules should not have a build option. + set(_vtk_build_use_option 0) + list(APPEND _vtk_scan_rejected_modules + "${_vtk_scan_module_name}") + endif () + endif () + + # Handle cache entries and determine the enabled state of the module from + # the relevant cache variables. + if (_vtk_build_use_option) + set("VTK_MODULE_ENABLE_${_vtk_scan_module_name}" "DEFAULT" + CACHE STRING "Enable the ${_vtk_scan_module_name} module. ${${_vtk_scan_module_name}_DESCRIPTION}") + mark_as_advanced("VTK_MODULE_ENABLE_${_vtk_scan_module_name}") + set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name}" + PROPERTY + STRINGS "YES;WANT;DONT_WANT;NO;DEFAULT") + _vtk_module_verify_enable_value("VTK_MODULE_ENABLE_${_vtk_scan_module_name}") + + if (NOT VTK_MODULE_ENABLE_${_vtk_scan_module_name} STREQUAL "DEFAULT") + set("_vtk_scan_enable_${_vtk_scan_module_name}" "${VTK_MODULE_ENABLE_${_vtk_scan_module_name}}") + endif () + + # Check the state of any groups the module belongs to. + foreach (_vtk_scan_group IN LISTS "${_vtk_scan_module_name}_GROUPS") + if (NOT DEFINED "VTK_GROUP_ENABLE_${_vtk_scan_group}") + set(_vtk_scan_group_default "DEFAULT") + if (DEFINED "_vtk_module_group_default_${_vtk_scan_group}") + set(_vtk_scan_group_default "${_vtk_module_group_default_${_vtk_scan_group}}") + endif () + set("VTK_GROUP_ENABLE_${_vtk_scan_group}" "${_vtk_scan_group_default}" + CACHE STRING "Enable the ${_vtk_scan_group} group modules.") + set_property(CACHE "VTK_GROUP_ENABLE_${_vtk_scan_group}" + PROPERTY + STRINGS "YES;WANT;DONT_WANT;NO;DEFAULT") + _vtk_module_verify_enable_value("VTK_GROUP_ENABLE_${_vtk_scan_group}") + set_property(CACHE "VTK_GROUP_ENABLE_${_vtk_scan_group}" + PROPERTY + TYPE "${_vtk_scan_option_default_type}") + endif () + + if (NOT VTK_MODULE_ENABLE_${_vtk_scan_module_name} STREQUAL "DEFAULT") + continue () + endif () + + # Determine the state of the group. + if (VTK_GROUP_ENABLE_${_vtk_scan_group} STREQUAL "DEFAULT") + if (_vtk_scan_WANT_BY_DEFAULT) + set(_vtk_scan_group_enable WANT) + else () + set(_vtk_scan_group_enable DONT_WANT) + endif () + else () + set(_vtk_scan_group_enable "${VTK_GROUP_ENABLE_${_vtk_scan_group}}") + endif () + + if (NOT _vtk_scan_group_enable STREQUAL "DEFAULT") + set("_vtk_scan_enable_${_vtk_scan_module_name}" "${_vtk_scan_group_enable}") + endif () + endforeach () + + set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name}" + PROPERTY + TYPE "${_vtk_scan_option_default_type}") + endif () + + # Check if the module is visible. Modules which have a failing condition + # are basically invisible. + if (DEFINED ${_vtk_scan_module_name}_CONDITION) + if (NOT (${${_vtk_scan_module_name}_CONDITION})) + if (DEFINED "VTK_MODULE_ENABLE_${_vtk_scan_module_name}") + set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name}" + PROPERTY + TYPE INTERNAL) + endif () + continue () + endif () + endif () + + list(APPEND _vtk_scan_all_modules + "${_vtk_scan_module_name}") + set("_vtk_scan_${_vtk_scan_module_name}_all_depends" + ${${_vtk_scan_module_name}_DEPENDS} + ${${_vtk_scan_module_name}_PRIVATE_DEPENDS}) + + if (${_vtk_scan_module_name}_THIRD_PARTY) + set("${_vtk_scan_module_name}_EXCLUDE_WRAP" TRUE) + set("${_vtk_scan_module_name}_IMPLEMENTABLE" FALSE) + set("${_vtk_scan_module_name}_IMPLEMENTS") + endif () + + if (${_vtk_scan_module_name}_KIT) + if (${_vtk_scan_module_name}_THIRD_PARTY) + message(FATAL_ERROR + "The third party module ${_vtk_scan_module_name} may not be part of " + "a kit (${${_vtk_scan_module_name}_KIT}).") + endif () + + list(FIND _vtk_scan_all_kits "${${_vtk_scan_module_name}_KIT}" _vtk_scan_idx) + if (_vtk_scan_idx EQUAL -1) + message(FATAL_ERROR + "The ${_vtk_scan_module_name} belongs to the " + "${${_vtk_scan_module_name}_KIT} kit, but it has not been scanned.") + endif () + endif () + + # Set properties for building. + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_file" "${_vtk_scan_module_file}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_namespace" "${${_vtk_scan_module_name}_NAMESPACE}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_target_name" "${${_vtk_scan_module_name}_TARGET_NAME}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_library_name" "${${_vtk_scan_module_name}_LIBRARY_NAME}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_third_party" "${${_vtk_scan_module_name}_THIRD_PARTY}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_exclude_wrap" "${${_vtk_scan_module_name}_EXCLUDE_WRAP}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_kit" "${${_vtk_scan_module_name}_KIT}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_depends" "${${_vtk_scan_module_name}_DEPENDS}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_private_depends" "${${_vtk_scan_module_name}_PRIVATE_DEPENDS}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_optional_depends" "${${_vtk_scan_module_name}_OPTIONAL_DEPENDS}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_test_depends" "${${_vtk_scan_module_name}_TEST_DEPENDS}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_test_optional_depends" "${${_vtk_scan_module_name}_TEST_OPTIONAL_DEPENDS}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_test_labels" "${${_vtk_scan_module_name}_TEST_LABELS}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_implements" "${${_vtk_scan_module_name}_IMPLEMENTS}") + set_property(GLOBAL + PROPERTY + "_vtk_module_${_vtk_scan_module_name}_implementable" "${${_vtk_scan_module_name}_IMPLEMENTABLE}") + endforeach () + + set(_vtk_scan_current_modules "${_vtk_scan_all_modules}") + vtk_topological_sort(_vtk_scan_all_modules "_vtk_scan_" "_all_depends") + + set(_vtk_scan_provided_modules) + set(_vtk_scan_required_modules) + set(_vtk_scan_disabled_modules) + + # Seed the `_vtk_scan_provide_` variables with modules requested and rejected + # as arguments. + foreach (_vtk_scan_request_module IN LISTS _vtk_scan_REQUEST_MODULES) + set("_vtk_scan_provide_${_vtk_scan_request_module}" ON) + endforeach () + foreach (_vtk_scan_reject_module IN LISTS _vtk_scan_REJECT_MODULES) + set("_vtk_scan_provide_${_vtk_scan_reject_module}" OFF) + endforeach () + + # Traverse the graph classifying the quad-state for enabling modules into a + # boolean stored in the `_vtk_scan_provide_` variables. + foreach (_vtk_scan_module IN LISTS _vtk_scan_all_modules) + list(FIND _vtk_scan_current_modules "${_vtk_scan_module}" _vtk_scan_idx) + if (_vtk_scan_idx EQUAL -1) + continue () + endif () + + if (DEFINED "_vtk_scan_provide_${_vtk_scan_module}") + # Already done. + elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "YES") + # Mark enabled modules as to-be-provided. Any errors with requiring a + # disabled module will be dealt with later. + set("_vtk_scan_provide_${_vtk_scan_module}" ON) + elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "WANT") + # Check to see if we can provide this module by checking of any of its + # dependencies have been disabled. + set(_vtk_scan_test_depends) + if (NOT ${_vtk_scan_module}_THIRD_PARTY AND _vtk_scan_ENABLE_TESTS STREQUAL "ON") + # If the tests have to be on, we also need the test dependencies. + set(_vtk_scan_test_depends "${${_vtk_scan_module}_TEST_DEPENDS}") + endif () + + set("_vtk_scan_provide_${_vtk_scan_module}" ON) + foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends) + if (DEFINED "_vtk_scan_provide_${_vtk_scan_module_depend}" AND NOT _vtk_scan_provide_${_vtk_scan_module_depend}) + set("_vtk_scan_provide_${_vtk_scan_module}" OFF) + break () + endif () + endforeach () + elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "DONT_WANT") + # Do nothing. We don't want to provide these modules, but we also don't + # want to disable them. + elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "NO") + # Disable the module. + set("_vtk_scan_provide_${_vtk_scan_module}" OFF) + endif () + + # Collect disabled modules into a list. + if (DEFINED "_vtk_scan_provide_${_vtk_scan_module}" AND NOT _vtk_scan_provide_${_vtk_scan_module}) + list(APPEND _vtk_scan_disabled_modules + "${_vtk_scan_module}") + endif () + endforeach () + + # Scan all modules from the top of tree to the bottom. + list(REVERSE _vtk_scan_all_modules) + foreach (_vtk_scan_module IN LISTS _vtk_scan_all_modules) + list(FIND _vtk_scan_current_modules "${_vtk_scan_module}" _vtk_scan_idx) + if (_vtk_scan_idx EQUAL -1) + continue () + endif () + + # If we're providing this module... + if (_vtk_scan_provide_${_vtk_scan_module}) + list(APPEND _vtk_scan_provided_modules + "${_vtk_scan_module}") + + # Grab any test dependencies that are required. + set(_vtk_scan_test_depends) + if (NOT ${_vtk_scan_module}_THIRD_PARTY) + if (_vtk_scan_ENABLE_TESTS STREQUAL "ON") + set_property(GLOBAL APPEND + PROPERTY + "_vtk_module_test_modules" "${_vtk_scan_module}") + set(_vtk_scan_test_depends "${${_vtk_scan_module}_TEST_DEPENDS}") + elseif (_vtk_scan_ENABLE_TESTS STREQUAL "DEFAULT") + set_property(GLOBAL APPEND + PROPERTY + "_vtk_module_test_modules" "${_vtk_scan_module}") + elseif (_vtk_scan_ENABLE_TESTS STREQUAL "OFF") + # Nothing to do. + else () + message(FATAL_ERROR + "Unrecognized option for ENABLE_TESTS: ${_vtk_module_ENABLE_TESTS}.") + endif () + endif () + + # Add all dependent modules to the list of required or provided modules. + foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends) + # Though we need to error if this would cause a disabled module to be + # provided. + list(FIND _vtk_scan_disabled_modules "${_vtk_scan_module_depend}" _vtk_scan_idx) + if (NOT _vtk_scan_idx EQUAL -1) + message(FATAL_ERROR + "The ${_vtk_scan_module} module requires the disabled module ${_vtk_scan_module_depend}.") + endif () + + set("_vtk_scan_provide_${_vtk_scan_module_depend}" ON) + + list(FIND _vtk_scan_current_modules "${_vtk_scan_module_depend}" _vtk_scan_idx) + if (_vtk_scan_idx EQUAL -1) + list(APPEND _vtk_scan_required_modules + "${_vtk_scan_module_depend}") + else () + list(APPEND _vtk_scan_provided_modules + "${_vtk_scan_module_depend}") + endif () + endforeach () + endif () + endforeach () + + if (_vtk_scan_provided_modules) + list(REMOVE_DUPLICATES _vtk_scan_provided_modules) + endif () + + set(_vtk_scan_provided_kits) + + # Build a list of kits which contain the provided modules. + foreach (_vtk_scan_provided_module IN LISTS _vtk_scan_provided_modules) + if (${_vtk_scan_provided_module}_KIT) + list(APPEND _vtk_scan_provided_kits + "${${_vtk_scan_provided_module}_KIT}") + set_property(GLOBAL APPEND + PROPERTY + "_vtk_kit_${${_vtk_scan_provided_module}_KIT}_kit_modules" "${_vtk_scan_provided_module}") + endif () + endforeach () + + if (_vtk_scan_provided_kits) + list(REMOVE_DUPLICATES _vtk_scan_provided_kits) + endif () + + if (_vtk_scan_required_modules) + list(REMOVE_DUPLICATES _vtk_scan_required_modules) + endif () + + set(_vtk_scan_unrecognized_modules + ${_vtk_scan_REQUEST_MODULES} + ${_vtk_scan_REJECT_MODULES}) + + if (_vtk_scan_unrecognized_modules AND (_vtk_scan_provided_modules OR _vtk_scan_rejected_modules)) + list(REMOVE_ITEM _vtk_scan_unrecognized_modules + ${_vtk_scan_provided_modules} + ${_vtk_scan_rejected_modules}) + endif () + + set("${_vtk_scan_PROVIDES_MODULES}" + ${_vtk_scan_provided_modules} + PARENT_SCOPE) + + if (DEFINED _vtk_scan_REQUIRES_MODULES) + set("${_vtk_scan_REQUIRES_MODULES}" + ${_vtk_scan_required_modules} + PARENT_SCOPE) + endif () + + if (DEFINED _vtk_scan_UNRECOGNIZED_MODULES) + set("${_vtk_scan_UNRECOGNIZED_MODULES}" + ${_vtk_scan_unrecognized_modules} + PARENT_SCOPE) + endif () + + if (DEFINED _vtk_scan_PROVIDES_KITS) + set("${_vtk_scan_PROVIDES_KITS}" + ${_vtk_scan_provided_kits} + PARENT_SCOPE) + endif () +endfunction () + +#[==[.md +## Module-as-target functions + +Due to the nature of VTK modules supporting being built as kits, the module +name might not be usable as a target to CMake's `target_` family of commands. +Instead, there are various wrappers around them which take the module name as +an argument. These handle the forwarding of relevant information to the kit +library as well where necessary. +#]==] + +#[==[.md INTERNAL +## Module target internals + +When manipulating modules as targets, there are a few functions provided for +use in wrapping code to more easily access them. +#]==] + +#[==[.md INTERNAL +### The real target for a module + +Sometimes the actual, core target for a module is required (e.g., setting +CMake-level target properties or install rules). The `_vtk_module_real_target` +function finds the real target for a module. This only works for modules which +are built in the current tree. +#]==] + +function (_vtk_module_real_target var module) + if (ARGN) + message(FATAL_ERROR + "Unparsed arguments for _vtk_module_real_target: ${ARGN}.") + endif () + + get_property(_vtk_real_target_res GLOBAL + PROPERTY "_vtk_module_${module}_target_name") + # Querying during the build. + if (DEFINED _vtk_build_BUILD_WITH_KITS AND _vtk_build_BUILD_WITH_KITS) + get_property(_vtk_real_target_kit GLOBAL + PROPERTY "_vtk_module_${module}_kit") + if (_vtk_real_target_kit) + set(_vtk_real_target_res "${_vtk_real_target_res}-objects") + endif () + # A query for after the module is built. + elseif (TARGET "${_vtk_real_target_res}-objects") + set(_vtk_real_target_res "${_vtk_real_target_res}-objects") + endif () + + if (_vtk_real_target_res STREQUAL "") + message(FATAL_ERROR + "Failed to determine the real target for the ${module} module.") + endif () + + set("${var}" + "${_vtk_real_target_res}" + PARENT_SCOPE) +endfunction () + +#[==[.md +### Properties + +Properties may be set or queried using the `vtk_module_set_property` and +`vtk_module_get_property` functions. + +``` +vtk_module_set_properties( + [ ]...) +``` + +``` +vtk_module_set_property( + [APPEND] [APPEND_STRING] + PROPERTY + VALUE ) +``` + +``` +vtk_module_get_property( + PROPERTY + VARIABLE ) +``` + +The variable name passed to the `VARIABLE` argument will be unset if the +property is not set (rather than the empty string). +#]==] + +function (vtk_module_set_properties module) + _vtk_module_real_target(_vtk_set_properties_target "${module}") + + set_target_properties("${_vtk_set_properties_target}" + PROPERTIES + ${ARGN}) +endfunction () + +function (vtk_module_set_property module) + cmake_parse_arguments(_vtk_property + "APPEND;APPEND_STRING" + "PROPERTY;VALUE" + "" + ${ARGN}) + + if (_vtk_property_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_set_property: " + "${_vtk_property_UNPARSED_ARGUMENTS}.") + endif () + + if (NOT DEFINED _vtk_property_PROPERTY) + message(FATAL_ERROR + "The `PROPERTY` argument is required.") + endif () + + if (NOT DEFINED _vtk_property_VALUE) + message(FATAL_ERROR + "The `VALUE` argument is required.") + endif () + + if (_vtk_property_APPEND AND _vtk_property_APPEND_STRING) + message(FATAL_ERROR + "`APPEND` and `APPEND_STRING` may not be used at the same time.") + endif () + + set(_vtk_property_args) + if (_vtk_property_APPEND) + list(APPEND _vtk_property_args + APPEND) + endif () + if (_vtk_property_APPEND_STRING) + list(APPEND _vtk_property_args + APPEND_STRING) + endif () + + _vtk_module_real_target(_vtk_property_target "${module}") + + set_property(TARGET "${_vtk_property_target}" + ${_vtk_property_args} + PROPERTY + "${_vtk_property_PROPERTY}" "${_vtk_property_VALUE}") +endfunction () + +function (vtk_module_get_property module) + cmake_parse_arguments(_vtk_property + "" + "PROPERTY;VARIABLE" + "" + ${ARGN}) + + if (_vtk_property_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_get_property: " + "${_vtk_property_UNPARSED_ARGUMENTS}.") + endif () + + if (NOT DEFINED _vtk_property_PROPERTY) + message(FATAL_ERROR + "The `PROPERTY` argument is required.") + endif () + + if (NOT DEFINED _vtk_property_VARIABLE) + message(FATAL_ERROR + "The `VARIABLE` argument is required.") + endif () + + _vtk_module_real_target(_vtk_property_target "${module}") + + get_property(_vtk_property_is_set + TARGET "${_vtk_property_target}" + PROPERTY "${_vtk_property_PROPERTY}" + SET) + if (_vtk_property_is_set) + get_property(_vtk_property_value + TARGET "${_vtk_property_target}" + PROPERTY "${_vtk_property_PROPERTY}") + + set("${_vtk_property_VARIABLE}" + "${_vtk_property_value}" + PARENT_SCOPE) + else () + unset("${_vtk_property_VARIABLE}" + PARENT_SCOPE) + endif () +endfunction () + +function (_vtk_module_target_function prefix) + foreach (visibility IN ITEMS INTERFACE PUBLIC PRIVATE) + if (${prefix}_${visibility}) + set("${prefix}_${visibility}_args" + "${visibility}" + ${${prefix}_${visibility}} + PARENT_SCOPE) + endif () + endforeach () +endfunction () + +#[==[.md +### Adding dependencies + +Adds dependencies to a module target. Use instead of CMake's +`add_dependencies`. + +``` +vtk_module_depend( ...) +``` +#]==] +function (vtk_module_depend module) + _vtk_module_real_target(_vtk_depend_target "${module}") + + add_dependencies("${_vtk_depend_target}" + ${ARGN}) +endfunction () + +#[==[.md +### Include directories + +Adds include directories to a module target. Use instead of CMake's +`target_include_directories`. + +``` +vtk_module_include( + [SYSTEM] + [PUBLIC ...] + [PRIVATE ...] + [INTERFACE ...]) +``` +#]==] +function (vtk_module_include module) + cmake_parse_arguments(_vtk_include + "SYSTEM" + "" + "INTERFACE;PUBLIC;PRIVATE" + ${ARGN}) + + if (_vtk_include_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_include: " + "${_vtk_include_UNPARSED_ARGUMENTS}.") + endif () + + _vtk_module_real_target(_vtk_include_target "${module}") + _vtk_module_target_function(_vtk_include) + + set(_vtk_include_system_arg) + if (_vtk_include_SYSTEM) + set(_vtk_include_system_arg SYSTEM) + endif () + + target_include_directories("${_vtk_include_target}" + ${_vtk_include_system_arg} + ${_vtk_include_INTERFACE_args} + ${_vtk_include_PUBLIC_args} + ${_vtk_include_PRIVATE_args}) +endfunction () + +#[==[.md +### Compile definitions + +Adds compile definitions to a module target. Use instead of CMake's +`target_compile_definitions`. + +``` +vtk_module_definitions( + [PUBLIC ...] + [PRIVATE ...] + [INTERFACE ...]) +``` +#]==] +function (vtk_module_definitions module) + cmake_parse_arguments(_vtk_definitions + "" + "" + "INTERFACE;PUBLIC;PRIVATE" + ${ARGN}) + + if (_vtk_definitions_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_definitions: " + "${_vtk_definitions_UNPARSED_ARGUMENTS}.") + endif () + + _vtk_module_real_target(_vtk_definitions_target "${module}") + _vtk_module_target_function(_vtk_definitions) + + target_compile_definitions("${_vtk_definitions_target}" + ${_vtk_definitions_INTERFACE_args} + ${_vtk_definitions_PUBLIC_args} + ${_vtk_definitions_PRIVATE_args}) +endfunction () + +#[==[.md +### Compile options + +Adds compile options to a module target. Use instead of CMake's +`target_compile_options`. + +``` +vtk_module_compile_options( + [PUBLIC ...] + [PRIVATE ...] + [INTERFACE ...]) +``` +#]==] +function (vtk_module_compile_options module) + cmake_parse_arguments(_vtk_compile_options + "" + "" + "INTERFACE;PUBLIC;PRIVATE" + ${ARGN}) + + if (_vtk_compile_options_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_compile_options: " + "${_vtk_compile_options_UNPARSED_ARGUMENTS}.") + endif () + + _vtk_module_real_target(_vtk_compile_options_target "${module}") + _vtk_module_target_function(_vtk_compile_options) + + target_compile_options("${_vtk_compile_options_target}" + ${_vtk_compile_options_INTERFACE_args} + ${_vtk_compile_options_PUBLIC_args} + ${_vtk_compile_options_PRIVATE_args}) +endfunction () + +#[==[.md +### Compile features + +Adds compile features to a module target. Use instead of CMake's +`target_compile_features`. + +``` +vtk_module_compile_features( + [PUBLIC ...] + [PRIVATE ...] + [INTERFACE ...]) +``` +#]==] +function (vtk_module_compile_features module) + cmake_parse_arguments(_vtk_compile_features + "" + "" + "INTERFACE;PUBLIC;PRIVATE" + ${ARGN}) + + if (_vtk_compile_features_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_compile_features: " + "${_vtk_compile_features_UNPARSED_ARGUMENTS}.") + endif () + + _vtk_module_real_target(_vtk_compile_features_target "${module}") + _vtk_module_target_function(_vtk_compile_features) + + target_compile_features("${_vtk_compile_features_target}" + ${_vtk_compile_features_INTERFACE_args} + ${_vtk_compile_features_PUBLIC_args} + ${_vtk_compile_features_PRIVATE_args}) +endfunction () + +#[==[.md +### Linking libraries + +Adds link libraries to a module target. Use instead of CMake's +`target_link_libraries`. + +``` +vtk_module_link( + [PUBLIC ...] + [PRIVATE ...] + [INTERFACE ...]) +``` +#]==] +function (vtk_module_link module) + cmake_parse_arguments(_vtk_link + "" + "" + "INTERFACE;PUBLIC;PRIVATE" + ${ARGN}) + + if (_vtk_link_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_link: " + "${_vtk_link_UNPARSED_ARGUMENTS}.") + endif () + + _vtk_module_real_target(_vtk_link_target "${module}") + _vtk_module_target_function(_vtk_link) + + get_property(_vtk_link_kit GLOBAL + PROPERTY "_vtk_module_${module}_kit") + if (_vtk_link_kit AND NOT CMAKE_VERSION VERSION_LESS "3.12") + foreach (_vtk_link_private IN LISTS _vtk_link_PRIVATE) + if (NOT TARGET "${_vtk_link_private}") + # TODO: Issue a warning. + continue () + endif () + + get_property(_vtk_link_private_imported + TARGET "${_vtk_link_private}" + PROPERTY IMPORTED) + if (_vtk_link_private_imported) + get_property(_vtk_link_private_imported_global + TARGET "${_vtk_link_private}" + PROPERTY IMPORTED_GLOBAL) + if (NOT _vtk_link_private_imported_global) + set_property(TARGET "${_vtk_link_private}" + PROPERTY + IMPORTED_GLOBAL TRUE) + endif () + endif () + endforeach () + set_property(GLOBAL APPEND + PROPERTY + "_vtk_kit_${_vtk_link_kit}_private_links" ${_vtk_link_PRIVATE}) + endif () + + target_link_libraries("${_vtk_link_target}" + ${_vtk_link_INTERFACE_args} + ${_vtk_link_PUBLIC_args} + ${_vtk_link_PRIVATE_args}) +endfunction () + +#[==[.md +### Linking options + +Adds link options to a module target. Use instead of CMake's +`target_link_options`. + +``` +vtk_module_link_options( + [PUBLIC ...] + [PRIVATE ...] + [INTERFACE ...]) +``` +#]==] +function (vtk_module_link_options module) + cmake_parse_arguments(_vtk_link_options + "" + "" + "INTERFACE;PUBLIC;PRIVATE" + ${ARGN}) + + if (_vtk_link_options_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_link_options: " + "${_vtk_link_options_UNPARSED_ARGUMENTS}.") + endif () + + _vtk_module_real_target(_vtk_link_options_target "${module}") + _vtk_module_target_function(_vtk_link_options) + + target_link_options("${_vtk_link_options_target}" + ${_vtk_link_options_INTERFACE_args} + ${_vtk_link_options_PUBLIC_args} + ${_vtk_link_options_PRIVATE_args}) +endfunction () + +#[==[.md INTERNAL +## VTK module properties + +The VTK module system leverages CMake's target propogation and storage. As +such, there are a number of properties added to the targets representing +modules. These properties are intended for use by the module system and +associated functionality. In particular, more properties may be available by +language wrappers. + +### Naming properties + +When creating properties for use with the module system, they should be +prefixed with `INTERFACE_vtk_module_`. The `INTERFACE_` portion is required in +order to work with interface libraries. The `vtk_module_` portion is to avoid +colliding with any other properties. This function assumes this naming scheme +for some of its convenience features as well. + +Properties should be the same in the local build as well as when imported to +ease use. + +### VTK module system properties + +There are a number of properties that are used and expected by the core of the +module system. These are generally module metadata (module dependencies, +wrappability, etc.). The properties all have the `INTERFACE_vtk_module_` prefix +mentioned in the previous section. + + * `third_party`: If set, the module represents a third party + dependency and should be treated specially. Third party modules are very + restricted and generally do not have any other properties set on them. + * `exclude_wrap`: If set, the module should not be wrapped by an external + language. + * `depends`: The list of dependent modules. Language wrappers will generally + require this to satisfy references to parent classes of the classes in the + module. + * `implements`: The list of modules for which this module registers to. This + is used by the autoinit subsystem and generally is not required. + * `implementable`: If set, this module provides registries which may be + populated by dependent modules. It is used to check the `implements` + property to help minimize unnecessary work from the autoinit sybsystem. + * `needs_autoinit`: If set, linking to this module requires the autoinit + subsystem to ensure that registries in modules are fully populated. + * `headers`: Paths to the public headers from the module. These are the + headers which should be handled by language wrappers. + * `hierarchy`: The path to the hierarchy file describing inheritence of the + classes for use in language wrappers. + +In order to add new module properties to a module, the +`_vtk_module_set_module_property` function should be used. This works for +modules built as part of the current project or imported module targets. The +`INTERFACE_vtk_module_` prefix will automatically be added. + +``` +_vtk_module_set_module_property( + [APPEND] [APPEND_STRING] + PROPERTY + VALUE ) +``` + +The `_vtk_module_get_module_property` function should be used to query these. +This works for modules built as part of the current project or imported module +targets. + +``` +_vtk_module_get_module_property( + PROPERTY + VARIABLE ) +``` + +As with `vtk_module_get_property`, the output variable will be unset if the +property is not set. The property name is automatically prepended with +`INTERFACE_vtk_module_`. + +### Exporting properties + +The `_vtk_module_export_properties` function is intended for use in support +functions which leverage the module system, not by general system users. This +function supports exporting properties from the build into dependencies via +target properties which are loaded from a project's config file which is loaded +vial CMake's `find_package` function. + +``` +_vtk_module_export_properties( + MODULE + BUILD_FILE + INSTALL_FILE + [PROPERTIES ...] + [FROM_GLOBAL_PROPERTIES ...] + [SPLIT_INSTALL_PROPERTIES ...]) +``` + +The `MODULE`, `BUILD_FILE`, and `INSTALL_FILE` arguments are required. The +`MODULE` argument holds the name of the module that will have properties +exported. The `BUILD_FILE` and `INSTALL_FILE` paths are *appended to*. As such, +when setting up these files, it should be preceeded with: + +```cmake +file(WRITE "${build_file}") +file(WRITE "${install_file}") +``` + +To avoid accidental usage of the install file from the build tree, it is +recommended to store it under a `CMakeFiles/` directory in the build tree. + +The set of properties exported is computed as follows: + + * `PROPERTIES` queries the module target for the given property and exports + its value as-is to both the build and install files. In addition, these + properties are set on the target directly as the same name. + * `FROM_GLOBAL_PROPERTIES` queries the global + `_vtk_module__` property and exports it to both the build + and install files as `INTERFACE_vtk_module_`. + * `SPLIT_INSTALL_PROPERTIES` queries the target for + `INTERFACE_vtk_module_` and exports its value to the build file + and `INTERFACE_vtk_module__install` to the install file as the + non-install property name. This is generally useful for properties which + change between the build and installation. + +The usage of this function is usually predicated by setting up paths for +writing the properties to. + +There is the associated function `_vtk_module_write_import_prefix` as well. +This function is intended for prepending an import prefix computation to the +install file so that the install root can be discovered from the installed +file's location. This function is called as: + +``` +_vtk_module_write_import_prefix( ) +``` + +The prefix is available as the `_vtk_module_import_prefix` variable and may be +used in property values which require it. +#]==] + +function (_vtk_module_set_module_property module) + cmake_parse_arguments(_vtk_property + "APPEND;APPEND_STRING" + "PROPERTY;VALUE" + "" + ${ARGN}) + + if (_vtk_property_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_set_module_property: " + "${_vtk_property_UNPARSED_ARGUMENTS}.") + endif () + + if (NOT DEFINED _vtk_property_PROPERTY) + message(FATAL_ERROR + "The `PROPERTY` argument is required.") + endif () + + if (NOT DEFINED _vtk_property_VALUE) + message(FATAL_ERROR + "The `VALUE` argument is required.") + endif () + + if (_vtk_property_APPEND AND _vtk_property_APPEND_STRING) + message(FATAL_ERROR + "`APPEND` and `APPEND_STRING` may not be used at the same time.") + endif () + + set(_vtk_property_args) + if (_vtk_property_APPEND) + list(APPEND _vtk_property_args + APPEND) + endif () + if (_vtk_property_APPEND_STRING) + list(APPEND _vtk_property_args + APPEND_STRING) + endif () + + get_property(_vtk_property_is_alias + TARGET "${module}" + PROPERTY ALIASED_TARGET + SET) + if (_vtk_property_is_alias) + _vtk_module_real_target(_vtk_property_target "${module}") + else () + set(_vtk_property_target "${module}") + endif () + + set_property(TARGET "${_vtk_property_target}" + ${_vtk_property_args} + PROPERTY + "INTERFACE_vtk_module_${_vtk_property_PROPERTY}" "${_vtk_property_VALUE}") +endfunction () + +function (_vtk_module_get_module_property module) + cmake_parse_arguments(_vtk_property + "" + "PROPERTY;VARIABLE" + "" + ${ARGN}) + + if (_vtk_property_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_get_module_property: " + "${_vtk_property_UNPARSED_ARGUMENTS}.") + endif () + + if (NOT DEFINED _vtk_property_PROPERTY) + message(FATAL_ERROR + "The `PROPERTY` argument is required.") + endif () + + if (NOT DEFINED _vtk_property_VARIABLE) + message(FATAL_ERROR + "The `VARIABLE` argument is required.") + endif () + + get_property(_vtk_property_is_alias + TARGET "${module}" + PROPERTY ALIASED_TARGET + SET) + if (_vtk_property_is_alias) + _vtk_module_real_target(_vtk_property_target "${module}") + else () + set(_vtk_property_target "${module}") + endif () + + get_property(_vtk_property_is_set + TARGET "${_vtk_property_target}" + PROPERTY "INTERFACE_vtk_module_${_vtk_property_PROPERTY}" + SET) + if (_vtk_property_is_set) + get_property(_vtk_property_value + TARGET "${_vtk_property_target}" + PROPERTY "INTERFACE_vtk_module_${_vtk_property_PROPERTY}") + + set("${_vtk_property_VARIABLE}" + "${_vtk_property_value}" + PARENT_SCOPE) + else () + unset("${_vtk_property_VARIABLE}" + PARENT_SCOPE) + endif () +endfunction () + +function (_vtk_module_write_import_prefix file destination) + file(APPEND "${file}" + "set(_vtk_module_import_prefix \"\${CMAKE_CURRENT_LIST_DIR}\")\n") + while (destination) + get_filename_component(destination "${destination}" DIRECTORY) + file(APPEND "${file}" + "get_filename_component(_vtk_module_import_prefix \"\${_vtk_module_import_prefix}\" DIRECTORY)\n") + endwhile () +endfunction () + +function (_vtk_module_export_properties) + cmake_parse_arguments(_vtk_export_properties + "" + "BUILD_FILE;INSTALL_FILE;MODULE" + "FROM_GLOBAL_PROPERTIES;PROPERTIES;SPLIT_INSTALL_PROPERTIES" + ${ARGN}) + + if (_vtk_export_properties_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for _vtk_export_properties: " + "${_vtk_export_properties_UNPARSED_ARGUMENTS}.") + endif () + + if (NOT _vtk_export_properties_MODULE) + message(FATAL_ERROR + "A module is required to export properties.") + endif () + + if (NOT _vtk_export_properties_BUILD_FILE) + message(FATAL_ERROR + "Exporting properties requires a build file to write to.") + endif () + + if (NOT _vtk_export_properties_INSTALL_FILE) + message(FATAL_ERROR + "Exporting properties requires an install file to write to.") + endif () + + get_property(_vtk_export_properties_target_name GLOBAL + PROPERTY "_vtk_module_${_vtk_export_properties_MODULE}_target_name") + + foreach (_vtk_export_properties_global IN LISTS _vtk_export_properties_FROM_GLOBAL_PROPERTIES) + get_property(_vtk_export_properties_is_set GLOBAL + PROPERTY "_vtk_module_${_vtk_export_properties_MODULE}_${_vtk_export_properties_global}" + SET) + if (NOT _vtk_export_properties_is_set) + continue () + endif () + + get_property(_vtk_export_properties_value GLOBAL + PROPERTY "_vtk_module_${_vtk_export_properties_MODULE}_${_vtk_export_properties_global}") + set(_vtk_export_properties_set_property + "set_property(TARGET \"${_vtk_export_properties_MODULE}\" PROPERTY \"INTERFACE_vtk_module_${_vtk_export_properties_global}\" \"${_vtk_export_properties_value}\")\n") + + set_property(TARGET "${_vtk_export_properties_target_name}" + PROPERTY + "INTERFACE_vtk_module_${_vtk_export_properties_global}" "${_vtk_export_properties_value}") + file(APPEND "${_vtk_export_properties_BUILD_FILE}" + "${_vtk_export_properties_set_property}") + file(APPEND "${_vtk_export_properties_INSTALL_FILE}" + "${_vtk_export_properties_set_property}") + endforeach () + + foreach (_vtk_export_properties_target IN LISTS _vtk_export_properties_PROPERTIES) + get_property(_vtk_export_properties_is_set + TARGET "${_vtk_export_properties_target_name}" + PROPERTY "${_vtk_export_properties_target}" + SET) + if (NOT _vtk_export_properties_is_set) + continue () + endif () + + get_property(_vtk_export_properties_value + TARGET "${_vtk_export_properties_target_name}" + PROPERTY "${_vtk_export_properties_target}") + set(_vtk_export_properties_set_property + "set_property(TARGET \"${_vtk_export_properties_MODULE}\" PROPERTY \"${_vtk_export_properties_target}\" \"${_vtk_export_properties_value}\")\n") + + file(APPEND "${_vtk_export_properties_BUILD_FILE}" + "${_vtk_export_properties_set_property}") + file(APPEND "${_vtk_export_properties_INSTALL_FILE}" + "${_vtk_export_properties_set_property}") + endforeach () + + foreach (_vtk_export_properties_split IN LISTS _vtk_export_properties_SPLIT_INSTALL_PROPERTIES) + get_property(_vtk_export_properties_is_set + TARGET "${_vtk_export_properties_MODULE}" + PROPERTY "INTERFACE_vtk_module_${_vtk_export_properties_split}" + SET) + if (NOT _vtk_export_properties_is_set) + continue () + endif () + + get_property(_vtk_export_properties_value + TARGET "${_vtk_export_properties_target_name}" + PROPERTY "INTERFACE_vtk_module_${_vtk_export_properties_split}") + set(_vtk_export_properties_set_property + "set_property(TARGET \"${_vtk_export_properties_MODULE}\" PROPERTY \"INTERFACE_vtk_module_${_vtk_export_properties_split}\" \"${_vtk_export_properties_value}\")\n") + file(APPEND "${_vtk_export_properties_BUILD_FILE}" + "${_vtk_export_properties_set_property}") + + get_property(_vtk_export_properties_value + TARGET "${_vtk_export_properties_target_name}" + PROPERTY "INTERFACE_vtk_module_${_vtk_export_properties_split}_install") + set(_vtk_export_properties_set_property + "set_property(TARGET \"${_vtk_export_properties_MODULE}\" PROPERTY \"INTERFACE_vtk_module_${_vtk_export_properties_split}\" \"${_vtk_export_properties_value}\")\n") + file(APPEND "${_vtk_export_properties_INSTALL_FILE}" + "${_vtk_export_properties_set_property}") + endforeach () +endfunction () + +include("${CMAKE_CURRENT_LIST_DIR}/vtkModuleTesting.cmake") + +#[==[.md +## Building modules + +Once all of the modules have been scanned, they need to be built. Generally, +there will be just one build necessary for a set of scans, though they may be +built distinctly as well, but generally in reverse order of their scans. + +``` +vtk_module_build( + MODULES ... + [KITS ...] + + [LIBRARY_NAME_SUFFIX ] + [VERSION ] + [SOVERSION ] + + [PACKAGE ] + + [BUILD_WITH_KITS ] + + [USE_EXTERNAL ] + + [INSTALL_HEADERS ] + [HEADERS_COMPONENT ] + + [TARGETS_COMPONENT ] + [INSTALL_EXPORT ] + + [TEST_DATA_TARGET ] + [TEST_INPUT_DATA_DIRECTORY ] + [TEST_OUTPUT_DATA_DIRECTORY ] + [TEST_OUTPUT_DIRECTORY ] + + [ARCHIVE_DESTINATION ] + [HEADERS_DESTINATION ] + [LIBRARY_DESTINATION ] + [RUNTIME_DESTINATION ] + [CMAKE_DESTINATION ] + [LICENSE_DESTINATION ] + [HIERARCHY_DESTINATION ]) +``` + +The only requirement of the function is the list of modules to build, the rest +have reasonable defaults if not specified. + + * `MODULES`: (Required) The list of modules to build. + * `KITS`: (Required if `BUILD_WITH_KITS` is `ON`) The list of kits to build. + * `LIBRARY_NAME_SUFFIX`: (Defaults to `""`) A suffix to add to library names. + If it is not empty, it is prefixed with `-` to separate it from the kit + name. + * `VERSION`: If specified, the `VERSION` property on built libraries will be + set to this value. + * `SOVERSION`: If specified, the `SOVERSION` property on built libraries will + be set to this value. + * `PACKAGE`: (Defaults to `${CMAKE_PROJECT_NAME}`) The name the build is + meant to be found as when using `find_package`. Note that separate builds + will require distinct `PACKAGE` values. + * `USE_EXTERNAL`: (Defaults to `OFF`) Whether third party modules should find + external copies rather than building their own copy. + * `INSTALL_HEADERS`: (Defaults to `ON`) Whether or not to install public headers. + * `HEADERS_COMPONENT`: (Defaults to `development`) The install component to + use for header installation. Note that other SDK-related bits use the same + component (e.g., CMake module files). + * `TARGETS_COMPONENT`: `Defaults to `runtime`) The install component to use + for the libraries built. + * `TARGET_NAMESPACE`: `Defaults to ``) The namespace for installed + targets. All targets must have the same namespace. If set to ``, the + namespace will be detected automatically. + * `INSTALL_EXPORT`: (Defaults to `""`) If non-empty, targets will be added to + the given export. The export will also be installed as part of this build + command. + * `TEST_DATA_TARGET`: (Defaults to `-data`) The target to add + testing data download commands to. + * `TEST_INPUT_DATA_DIRECTORY`: (Defaults to + `${CMAKE_CURRENT_SOURCE_DIR}/Data`) The directory which will contain data + for use by tests. + * `TEST_OUTPUTPUT_DATA_DIRECTORY`: (Defaults to + `${CMAKE_CURRENT_BINARY_DIR}/Data`) The directory which will contain data + for use by tests. + * `TEST_OUTPUT_DIRECTORY`: (Defaults to + `${CMAKE_BINARY_DIR}/Testing/Temporary`) The directory which tests may + write any output files to. + +The remaining arguments control where to install files related to the build. +See CMake documentation for the difference between `ARCHIVE`, `LIBRARY`, and +`RUNTIME`. + + * `ARCHIVE_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) The install + destination for archive files. + * `HEADERS_DESTINATION`: (Defaults to `${CMAKE_INSTALL_INCLUDEDIR}`) The + install destination for header files. + * `LIBRARY_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) The install + destination for library files. + * `RUNTIME_DESTINATION`: (Defaults to `${CMAKE_INSTALL_BINDIR}`) The install + destination for runtime files. + * `CMAKE_DESTINATION`: (Defaults to `/cmake/`) + The install destination for CMake files. + * `LICENSE_DESTINATION`: (Defaults to `${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}`) + The install destination for license files (relevant for third party + packages). + * `HIERARCHY_DESTINATION`: (Defaults to `/vtk/hierarchy/`) The install destination + for hierarchy files (used for language wrapping). +#]==] + +function (vtk_module_build) + set(_vtk_build_install_arguments + # Headers + INSTALL_HEADERS + HEADERS_COMPONENT + + # Targets + INSTALL_EXPORT + TARGETS_COMPONENT + TARGET_NAMESPACE + + # Destinations + ARCHIVE_DESTINATION + HEADERS_DESTINATION + LIBRARY_DESTINATION + RUNTIME_DESTINATION + CMAKE_DESTINATION + LICENSE_DESTINATION + HIERARCHY_DESTINATION) + set(_vtk_build_test_arguments + # Testing + TEST_DATA_TARGET + TEST_INPUT_DATA_DIRECTORY + TEST_OUTPUT_DATA_DIRECTORY + TEST_OUTPUT_DIRECTORY) + + # TODO: Add an option to build statically? Currently, `BUILD_SHARED_LIBS` is + # used. + + cmake_parse_arguments(_vtk_build + "" + "BUILD_WITH_KITS;USE_EXTERNAL;LIBRARY_NAME_SUFFIX;VERSION;SOVERSION;PACKAGE;${_vtk_build_install_arguments};${_vtk_build_test_arguments}" + "MODULES;KITS" + ${ARGN}) + + if (_vtk_build_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_build: " + "${_vtk_build_UNPARSED_ARGUMENTS}") + endif () + + if (NOT DEFINED _vtk_build_USE_EXTERNAL) + set(_vtk_build_USE_EXTERNAL OFF) + endif () + + if (NOT DEFINED _vtk_build_PACKAGE) + set(_vtk_build_PACKAGE "${CMAKE_PROJECT_NAME}") + endif () + get_property(_vtk_build_package_exists GLOBAL + PROPERTY "_vtk_module_package_${_vtk_build_PACKAGE}" + SET) + if (_vtk_build_package_exists) + message(FATAL_ERROR + "A set of modules have already been built using the " + "`${_vtk_build_PACKAGE}` package.") + else () + set_property(GLOBAL + PROPERTY + "_vtk_module_package_${_vtk_build_PACKAGE}" "ON") + endif () + + if (NOT DEFINED _vtk_build_INSTALL_HEADERS) + set(_vtk_build_INSTALL_HEADERS ON) + endif () + + if (NOT DEFINED _vtk_build_TARGET_NAMESPACE) + set(_vtk_build_TARGET_NAMESPACE "") + endif () + + if (NOT DEFINED _vtk_build_BUILD_WITH_KITS) + set(_vtk_build_BUILD_WITH_KITS OFF) + endif () + + if (_vtk_build_BUILD_WITH_KITS AND CMAKE_VERSION VERSION_LESS "3.12") + message(FATAL_ERROR + "Building with kits enabled requires CMake 3.12 which introduced " + "support for OBJECT libraries to have and utilize usage requirements.") + endif () + + if (_vtk_build_BUILD_WITH_KITS AND NOT DEFINED _vtk_build_KITS) + message(FATAL_ERROR + "Building with kits was requested, but no kits were specified.") + endif () + + if (NOT DEFINED _vtk_build_TEST_DATA_TARGET) + set(_vtk_build_TEST_DATA_TARGET "${_vtk_build_PACKAGE}-data") + endif () + + if (NOT DEFINED _vtk_build_TEST_INPUT_DATA_DIRECTORY) + set(_vtk_build_TEST_INPUT_DATA_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Data") + endif () + + if (NOT DEFINED _vtk_build_TEST_OUTPUT_DATA_DIRECTORY) + set(_vtk_build_TEST_OUTPUT_DATA_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Data") + endif () + + if (NOT DEFINED _vtk_build_TEST_OUTPUT_DIRECTORY) + set(_vtk_build_TEST_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Testing/Temporary") + endif () + + if (NOT DEFINED _vtk_build_HEADERS_COMPONENT) + set(_vtk_build_HEADERS_COMPONENT "development") + endif () + + if (NOT DEFINED _vtk_build_ARCHIVE_DESTINATION) + set(_vtk_build_ARCHIVE_DESTINATION "${CMAKE_INSTALL_LIBDIR}") + endif () + + if (NOT DEFINED _vtk_build_HEADERS_DESTINATION) + set(_vtk_build_HEADERS_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + endif () + + if (NOT DEFINED _vtk_build_LIBRARY_DESTINATION) + set(_vtk_build_LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}") + endif () + + if (NOT DEFINED _vtk_build_RUNTIME_DESTINATION) + set(_vtk_build_RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}") + endif () + + if (NOT DEFINED _vtk_build_CMAKE_DESTINATION) + set(_vtk_build_CMAKE_DESTINATION "${_vtk_build_LIBRARY_DESTINATION}/cmake/${_vtk_build_PACKAGE}") + endif () + + if (NOT DEFINED _vtk_build_LICENSE_DESTINATION) + set(_vtk_build_LICENSE_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}") + endif () + + if (NOT DEFINED _vtk_build_HIERARCHY_DESTINATION) + set(_vtk_build_HIERARCHY_DESTINATION "${_vtk_build_LIBRARY_DESTINATION}/vtk/hierarchy/${_vtk_build_PACKAGE}") + endif () + + if (NOT DEFINED _vtk_build_TARGETS_COMPONENT) + set(_vtk_build_TARGETS_COMPONENT "runtime") + endif () + + if (NOT _vtk_build_MODULES) + message(FATAL_ERROR + "No modules given to build.") + endif () + + foreach (_vtk_build_module IN LISTS _vtk_build_MODULES) + get_property("_vtk_build_${_vtk_build_module}_depends" GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_depends") + get_property("_vtk_build_${_vtk_build_module}_private_depends" GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_private_depends") + get_property("_vtk_build_${_vtk_build_module}_optional_depends" GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends") + set("_vtk_build_${_vtk_build_module}_all_depends" + ${_vtk_build_${_vtk_build_module}_depends} + ${_vtk_build_${_vtk_build_module}_private_depends} + ${_vtk_build_${_vtk_build_module}_optional_depends}) + endforeach () + + set(_vtk_build_sorted_modules "${_vtk_build_MODULES}") + vtk_topological_sort(_vtk_build_sorted_modules "_vtk_build_" "_all_depends") + + foreach (_vtk_build_module IN LISTS _vtk_build_sorted_modules) + list(FIND _vtk_build_MODULES "${_vtk_build_module}" _vtk_build_idx) + if (_vtk_build_idx EQUAL "-1") + continue () + endif () + + if (TARGET "${_vtk_build_module}") + get_property(_vtk_build_is_imported + TARGET "${_vtk_build_module}" + PROPERTY IMPORTED) + + # TODO: Is this right? + if (NOT _vtk_build_is_imported) + message(FATAL_ERROR + "The ${_vtk_build_module} module has been requested to be built, but " + "it is already built by this project.") + endif () + + continue () + endif () + + foreach (_vtk_build_depend IN LISTS "_vtk_build_${_vtk_build_module}_depends" "_vtk_build_${_vtk_build_module}_private_depends") + if (NOT TARGET "${_vtk_build_depend}") + message(FATAL_ERROR + "The ${_vtk_build_depend} dependency is missing for ${_vtk_build_module}.") + endif () + endforeach () + + get_property(_vtk_build_module_file GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_file") + if (NOT _vtk_build_module_file) + message(FATAL_ERROR + "The requested ${_vtk_build_module} module is not a VTK module.") + endif () + + get_filename_component(_vtk_build_module_dir "${_vtk_build_module_file}" DIRECTORY) + file(RELATIVE_PATH _vtk_build_module_subdir "${CMAKE_SOURCE_DIR}" "${_vtk_build_module_dir}") + add_subdirectory( + "${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}" + "${CMAKE_BINARY_DIR}/${_vtk_build_module_subdir}") + endforeach () + + if (_vtk_build_BUILD_WITH_KITS) + foreach (_vtk_build_kit IN LISTS _vtk_build_KITS) + get_property(_vtk_build_target_name GLOBAL + PROPERTY "_vtk_kit_${_vtk_build_kit}_target_name") + set(_vtk_kit_source_file + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/vtk_module_kit_${_vtk_build_target_name}.c") + file(GENERATE + OUTPUT "${_vtk_kit_source_file}" + CONTENT "void vtk_module_kit_${_vtk_build_target_name}() {}\n") + add_library("${_vtk_build_target_name}" + "${_vtk_kit_source_file}") + get_property(_vtk_build_namespace GLOBAL + PROPERTY "_vtk_kit_${_vtk_build_kit}_namespace") + if (_vtk_build_TARGET_NAMESPACE STREQUAL "") + set(_vtk_build_TARGET_NAMESPACE "${_vtk_build_namespace}") + endif () + if (NOT _vtk_build_namespace STREQUAL _vtk_build_TARGET_NAMESPACE) + message(FATAL_ERROR + "The `TARGET_NAMESPACE` (${_vtk_build_TARGET_NAMESPACE}) is not the " + "same as the ${_vtk_build_kit} kit namespace " + "(${_vtk_build_namespace}).") + endif () + if (NOT _vtk_build_kit STREQUAL _vtk_build_target_name) + add_library("${_vtk_build_kit}" ALIAS + "${_vtk_build_target_name}") + endif () + _vtk_module_apply_properties("${_vtk_build_target_name}") + _vtk_module_install("${_vtk_build_target_name}") + + set(_vtk_build_kit_modules_object_libraries) + set(_vtk_build_kit_modules_private_depends) + + get_property(_vtk_build_kit_modules GLOBAL + PROPERTY "_vtk_kit_${_vtk_build_kit}_kit_modules") + foreach (_vtk_build_kit_module IN LISTS _vtk_build_kit_modules) + get_property(_vtk_build_kit_module_target_name GLOBAL + PROPERTY "_vtk_module_${_vtk_build_kit_module}_target_name") + list(APPEND _vtk_build_kit_modules_object_libraries + "${_vtk_build_kit_module_target_name}-objects") + + # Since there is no link step for modules, we need to copy the private + # dependencies of the constituent modules into the kit so that their + # private dependencies are actually linked. + get_property(_vtk_build_kit_module_private_depends GLOBAL + PROPERTY "_vtk_module_${_vtk_build_kit_module}_private_depends") + foreach (_vtk_build_kit_module_private_depend IN LISTS _vtk_build_kit_module_private_depends) + # But we don't need to link to modules that are part of the kit we are + # building. + list(FIND _vtk_build_kit_modules "${_vtk_build_kit_module_private_depend}" _vtk_build_idx) + if (_vtk_build_idx EQUAL "-1") + list(APPEND _vtk_build_kit_modules_private_depends + "$") + endif () + endforeach () + endforeach () + + get_property(_vtk_build_kit_private_links GLOBAL + PROPERTY "_vtk_kit_${_vtk_build_kit}_private_links") + + if (_vtk_build_kit_modules_private_depends) + list(REMOVE_DUPLICATES _vtk_build_kit_modules_private_depends) + endif () + if (_vtk_build_kit_modules_private_links) + list(REMOVE_DUPLICATES _vtk_build_kit_modules_private_links) + endif () + + target_link_libraries("${_vtk_build_target_name}" + PRIVATE + ${_vtk_build_kit_modules_object_libraries} + ${_vtk_build_kit_modules_private_depends} + ${_vtk_build_kit_private_links}) + get_property(_vtk_build_kit_library_name GLOBAL + PROPERTY "_vtk_kit_${_vtk_build_kit}_library_name") + if (_vtk_build_LIBRARY_NAME_SUFFIX) + string(APPEND _vtk_build_kit_library_name "-${_vtk_build_LIBRARY_NAME_SUFFIX}") + endif () + set_target_properties("${_vtk_build_target_name}" + PROPERTIES + OUTPUT_NAME "${_vtk_build_kit_library_name}") + endforeach () + endif () + + if (_vtk_build_INSTALL_EXPORT) + set(_vtk_build_properties_filename "${_vtk_build_PACKAGE}-vtk-module-properties.cmake") + set(_vtk_build_properties_install_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_build_properties_filename}.install") + set(_vtk_build_properties_build_file "${CMAKE_BINARY_DIR}/${_vtk_build_CMAKE_DESTINATION}/${_vtk_build_properties_filename}") + + file(WRITE "${_vtk_build_properties_build_file}") + file(WRITE "${_vtk_build_properties_install_file}") + + _vtk_module_write_import_prefix( + "${_vtk_build_properties_install_file}" + "${_vtk_build_CMAKE_DESTINATION}") + + foreach (_vtk_build_module IN LISTS _vtk_build_MODULES) + get_property(_vtk_build_namespace GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_namespace") + if (_vtk_build_TARGET_NAMESPACE STREQUAL "") + set(_vtk_build_TARGET_NAMESPACE "${_vtk_build_namespace}") + endif () + if (NOT _vtk_build_namespace STREQUAL "${_vtk_build_TARGET_NAMESPACE}") + message(FATAL_ERROR + "The `TARGET_NAMESPACE` (${_vtk_build_TARGET_NAMESPACE}) is not the " + "same as the ${_vtk_build_module} module namespace " + "(${_vtk_build_namespace}).") + endif () + + get_property(_vtk_build_is_third_party + TARGET "${_vtk_build_module}" + PROPERTY "INTERFACE_vtk_module_third_party") + if (_vtk_build_is_third_party) + _vtk_module_export_properties( + BUILD_FILE "${_vtk_build_properties_build_file}" + INSTALL_FILE "${_vtk_build_properties_install_file}" + MODULE "${_vtk_build_module}" + FROM_GLOBAL_PROPERTIES + # Export the public dependencies of a module. + depends + # The library name of the module. + library_name + PROPERTIES + # Export whether a module is third party or not. + INTERFACE_vtk_module_third_party + INTERFACE_vtk_module_exclude_wrap) + continue () + endif () + + set(_vtk_build_split_properties) + get_property(_vtk_build_exclude_wrap + TARGET "${_vtk_build_module}" + PROPERTY "INTERFACE_vtk_module_${_vtk_build_module}_exclude_wrap") + if (NOT _vtk_build_exclude_wrap) + list(APPEND _vtk_build_split_properties + headers + hierarchy) + endif () + + _vtk_module_export_properties( + BUILD_FILE "${_vtk_build_properties_build_file}" + INSTALL_FILE "${_vtk_build_properties_install_file}" + MODULE "${_vtk_build_module}" + FROM_GLOBAL_PROPERTIES + # Export whether the module should be excluded from wrapping or not. + exclude_wrap + # Export the public dependencies of a module. + depends + # Export what modules are implemented by the module. + implements + # Export whether the module contains autoinit logic. + implementable + # The library name of the module. + library_name + PROPERTIES + # Export whether the module needs autoinit logic handled. + INTERFACE_vtk_module_needs_autoinit + SPLIT_INSTALL_PROPERTIES + # Set the properties which differ between build and install trees. + ${_vtk_build_split_properties}) + endforeach () + + set(_vtk_build_namespace) + if (DEFINED _vtk_build_TARGET_NAMESPACE) + set(_vtk_build_namespace + NAMESPACE "${_vtk_build_TARGET_NAMESPACE}::") + endif () + + export( + EXPORT "${_vtk_build_INSTALL_EXPORT}" + ${_vtk_build_namespace} + FILE "${_vtk_build_CMAKE_DESTINATION}/${_vtk_build_PACKAGE}-targets.cmake") + + if (_vtk_build_INSTALL_HEADERS) + install( + FILES "${_vtk_build_properties_install_file}" + DESTINATION "${_vtk_build_CMAKE_DESTINATION}" + RENAME "${_vtk_build_properties_filename}" + COMPONENT "${_vtk_build_HEADERS_COMPONENT}") + install( + EXPORT "${_vtk_build_INSTALL_EXPORT}" + DESTINATION "${_vtk_build_CMAKE_DESTINATION}" + ${_vtk_build_namespace} + FILE "${_vtk_build_PACKAGE}-targets.cmake" + COMPONENT "${_vtk_build_HEADERS_COMPONENT}") + endif () + endif () + + get_property(_vtk_build_test_modules GLOBAL + PROPERTY "_vtk_module_test_modules") + set(_vtk_build_tests_handled) + foreach (_vtk_build_test IN LISTS _vtk_build_test_modules) + list(FIND _vtk_build_MODULES "${_vtk_build_test}" _vtk_build_test_idx) + if (_vtk_build_test_idx EQUAL "-1") + continue () + endif () + list(APPEND _vtk_build_tests_handled + "${_vtk_build_test}") + + get_property(_vtk_build_test_depends GLOBAL + PROPERTY "_vtk_module_${_vtk_build_test}_test_depends") + + set(_vtk_build_test_has_depends TRUE) + foreach (_vtk_build_test_depend IN LISTS _vtk_build_test_depends) + if (NOT TARGET "${_vtk_build_test_depend}") + set(_vtk_build_test_has_depends FALSE) + break () + endif () + endforeach () + if (NOT _vtk_build_test_has_depends) + continue () + endif () + + get_property(_vtk_build_module_file GLOBAL + PROPERTY "_vtk_module_${_vtk_build_test}_file") + + get_filename_component(_vtk_build_module_dir "${_vtk_build_module_file}" DIRECTORY) + file(RELATIVE_PATH _vtk_build_module_subdir "${CMAKE_SOURCE_DIR}" "${_vtk_build_module_dir}") + if (EXISTS "${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}/Testing") + get_property(_vtk_build_test_labels GLOBAL + PROPERTY "_vtk_module_${_vtk_build_test}_test_labels") + add_subdirectory( + "${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}/Testing" + "${CMAKE_BINARY_DIR}/${_vtk_build_module_subdir}/Testing") + endif () + endforeach () + + if (_vtk_build_test_modules AND _vtk_build_tests_handled) + list(REMOVE_ITEM _vtk_build_test_modules + ${_vtk_build_tests_handled}) + set_property(GLOBAL + PROPERTY + _vtk_module_test_modules "${_vtk_module_test_modules}") + endif () +endfunction () + +# Add the standard includes for a module to its interface. +function (_vtk_module_standard_includes) + cmake_parse_arguments(_vtk_standard_includes + "SYSTEM;INTERFACE" + "TARGET;HEADERS_DESTINATION" + "" + ${ARGN}) + + if (NOT _vtk_standard_includes_TARGET) + message(FATAL_ERROR + "The `TARGET` argument is required.") + endif () + if (NOT TARGET "${_vtk_standard_includes_TARGET}") + message(FATAL_ERROR + "The `TARGET` argument is not a target.") + endif () + + if (_vtk_standard_includes_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_standard_includes: " + "${_vtk_standard_includes_UNPARSED_ARGUMENTS}") + endif () + + set(_vtk_standard_includes_system) + if (_vtk_standard_includes_SYSTEM) + set(_vtk_standard_includes_system SYSTEM) + endif () + + set(_vtk_standard_includes_visibility PUBLIC) + if (_vtk_standard_includes_INTERFACE) + set(_vtk_standard_includes_visibility INTERFACE) + endif () + + target_include_directories("${_vtk_standard_includes_TARGET}" + ${_vtk_standard_includes_system} + "${_vtk_standard_includes_visibility}" + $ + $) + + if (_vtk_build_INSTALL_HEADERS AND _vtk_standard_includes_HEADERS_DESTINATION) + target_include_directories("${_vtk_standard_includes_TARGET}" + ${_vtk_standard_includes_system} + "${_vtk_standard_includes_visibility}" + $) + endif () +endfunction () + +# Determine the default export macro for a module. +function (_vtk_module_default_export_macro_prefix varname) + get_property(_vtk_module_default_library_name GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_library_name") + string(TOUPPER "${_vtk_module_default_library_name}" _vtk_default_export_macro_upper) + set("${varname}" + "${_vtk_default_export_macro_upper}" + PARENT_SCOPE) +endfunction () + +# TODO: It would be nice to support `USE_LINK_PROPERTIES` instead of listing +# the modules again here. However, the format of the `LINK_LIBRARIES` property +# value may not be easy to handle. + +#[==[.md +## Autoinit + +When a module contains a registry which may be populated by other modules, +these registries need to be populated when the modules are loaded by the +dynamic linker (for shared builds) or program load time (for static builds). To +provide for this, the module system contains an autoinit "subsystem". + +### Linking to autoinit-using modules + +When linking to VTK modules, in order for the autoinit system to work, modules +need to declare their registration. In order to do this, defines may need to be +provided to targets in order to trigger registration. These defines may be +added to targets by using the `vtk_module_autoinit` function. + +``` +vtk_module_autoinit( + TARGETS ... + MODULES ...) +``` + +After this call, the targets given to the `TARGETS` argument will gain the +preprocessor definitions to trigger registrations properly. + +### Leveraging the autoinit subsystem + +The subsystem provides the following hooks for use by projects: + + * In modules which `IMPLEMENTS` other modules, in the generated + `Module.h` header (which provides export symbols as well) will + include the modules which are implemented. + * In modules which are `IMPLEMENTABLE` or `IMPLEMENTS` another module, the + generated `Module.h` file will include the following block: + +```c +#ifdef _AUTOINIT_INCLUDE +#include _AUTOINIT_INCLUDE +#endif +#ifdef _AUTOINIT +#include
+VTK_MODULE_AUTOINIT() +#endif +``` + + The `vtk_module_autoinit` function will generate an include file and + provide its path via the `_AUTOINIT_INCLUDE` define. once it has + been included, if the `_AUTOINIT` symbol is defined, a header is + included which is intended to provide the `VTK_MODULE_AUTOINIT` macro. This + macro is given the module name and should use `_AUTOINIT` to fill + in the registries in the module with those from the `IMPLEMENTS` modules + listed in that symbol. + +The `_AUTOINIT` symbol's value is: + + (,,) + +where `` is the number of modules in the parentheses and each module +listed need to register something to ``. + +The `header` value is fetched from the `_vtk_module_autoinit_include` global +variable. This should be provided by projects using the module system at its +lowest level. Projects not implementing the `VTK_MODULE_AUTOINIT` macro should +have its value provided by `find_package` dependencies. +#]==] +function (vtk_module_autoinit) + cmake_parse_arguments(_vtk_autoinit + "" + "" + "TARGETS;MODULES" + ${ARGN}) + + if (_vtk_autoinit_UNRECOGNIZED_ARGUMENTS) + message(FATAL_ERROR + "Unparsed arguments for vtk_module_autoinit: " + "${_vtk_autoinit_UNRECOGNIZED_ARGUMENTS}.") + endif () + + if (NOT _vtk_autoinit_TARGETS) + message(FATAL_ERROR + "The `TARGETS` argument is required.") + endif () + + set(_vtk_autoinit_module_stack + ${_vtk_autoinit_MODULES}) + + set(_vtk_autoinit_needs_implements) + set(_vtk_autoinit_seen) + while (_vtk_autoinit_module_stack) + list(GET _vtk_autoinit_module_stack 0 _vtk_autoinit_current_module) + list(REMOVE_AT _vtk_autoinit_module_stack 0) + list(FIND _vtk_autoinit_seen "${_vtk_autoinit_current_module}" _vtk_autoinit_idx) + if (NOT _vtk_autoinit_idx EQUAL "-1") + continue () + endif () + list(APPEND _vtk_autoinit_seen + "${_vtk_autoinit_current_module}") + + if (TARGET "${_vtk_autoinit_current_module}") + get_property(_vtk_autoinit_implements + TARGET "${_vtk_autoinit_current_module}" + PROPERTY "INTERFACE_vtk_module_implements") + else () + get_property(_vtk_autoinit_implements + GLOBAL + PROPERTY "_vtk_module_${_vtk_autoinit_current_module}_implements") + endif () + + list(APPEND _vtk_autoinit_needs_implements + ${_vtk_autoinit_implements}) + foreach (_vtk_autoinit_implement IN LISTS _vtk_autoinit_implements) + if (TARGET "${_vtk_autoinit_implements}") + get_property(_vtk_autoinit_implementable + TARGET "${_vtk_autoinit_implement}" + PROPERTY "INTERFACE_vtk_module_implementable") + else () + get_property(_vtk_autoinit_implementable + GLOBAL + PROPERTY "_vtk_module_${_vtk_autoinit_implement}_implementable") + endif () + + if (NOT _vtk_autoinit_implementable) + message(FATAL_ERROR + "The `${_vtk_autoinit_current_module}` module says that it " + "implements the `${_vtk_autoinit_implement}` module, but it is not " + "implementable.") + endif () + + list(APPEND "_vtk_autoinit_implements_${_vtk_autoinit_implement}" + "${_vtk_autoinit_current_module}") + endforeach () + endwhile () + + if (NOT _vtk_autoinit_needs_implements) + return () + endif () + list(REMOVE_DUPLICATES _vtk_autoinit_needs_implements) + list(SORT _vtk_autoinit_needs_implements) + + set(_vtk_autoinit_hash_content) + foreach (_vtk_autoinit_need_implements IN LISTS _vtk_autoinit_needs_implements) + if (NOT _vtk_autoinit_implements_${_vtk_autoinit_need_implements}) + continue () + endif () + list(SORT "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}") + + string(APPEND _vtk_autoinit_hash_content + "${_vtk_autoinit_need_implements}: ${_vtk_autoinit_implements_${_vtk_autoinit_need_implements}}\n") + endforeach () + string(MD5 _vtk_autoinit_header_tag "${_vtk_autoinit_hash_content}") + set(_vtk_autoinit_header + "${CMAKE_BINARY_DIR}/CMakeFiles/vtkModuleAutoInit_${_vtk_autoinit_header_tag}.h") + + get_property(_vtk_autoinit_header_generated GLOBAL + PROPERTY "_vtk_autoinit_generated_${_vtk_autoinit_header_tag}") + + set(_vtk_autoinit_defines) + set(_vtk_autoinit_header_content) + foreach (_vtk_autoinit_need_implements IN LISTS _vtk_autoinit_needs_implements) + if (NOT _vtk_autoinit_implements_${_vtk_autoinit_need_implements}) + continue () + endif () + + get_property(_vtk_autoinit_implements_library_name + TARGET "${_vtk_autoinit_need_implements}" + PROPERTY "INTERFACE_vtk_module_library_name") + + if (NOT _vtk_autoinit_header_generated) + list(LENGTH "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}" + _vtk_autoinit_length) + set(_vtk_autoinit_args) + foreach (_vtk_autoinit_arg IN LISTS "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}") + get_property(_vtk_autoinit_arg_library_name + TARGET "${_vtk_autoinit_arg}" + PROPERTY "INTERFACE_vtk_module_library_name") + list(APPEND _vtk_autoinit_args + "${_vtk_autoinit_arg_library_name}") + endforeach () + string(REPLACE ";" "," _vtk_autoinit_args "${_vtk_autoinit_args}") + string(APPEND _vtk_autoinit_header_content + "#define ${_vtk_autoinit_implements_library_name}_AUTOINIT ${_vtk_autoinit_length}(${_vtk_autoinit_args})\n") + endif () + + list(APPEND _vtk_autoinit_defines + "${_vtk_autoinit_implements_library_name}_AUTOINIT_INCLUDE=\"${_vtk_autoinit_header}\"") + endforeach () + + if (NOT _vtk_autoinit_header_generated) + file(GENERATE + OUTPUT "${_vtk_autoinit_header}" + CONTENT "${_vtk_autoinit_header_content}") + + set_property(GLOBAL + PROPERTY + "_vtk_autoinit_generated_${_vtk_autoinit_header_tag}" TRUE) + endif () + + foreach (_vtk_autoinit_target IN LISTS _vtk_autoinit_TARGETS) + get_property(_vtk_autoinit_target_type + TARGET "${_vtk_autoinit_target}" + PROPERTY TYPE) + if (_vtk_autoinit_target_type STREQUAL "INTERFACE_LIBRARY") + continue () + endif () + + target_compile_definitions("${_vtk_autoinit_target}" + PRIVATE + ${_vtk_autoinit_defines}) + endforeach () +endfunction () + +# Write wrap hierarchy files for a module. This also installs the hierarchy +# file for use by dependent projects. +function (_vtk_module_write_wrap_hierarchy) + get_property(_vtk_hierarchy_exclude_wrap GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_exclude_wrap") + if (_vtk_hierarchy_exclude_wrap) + return () + endif () + + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_HIERARCHY_DESTINATION}") + + get_property(_vtk_hierarchy_library_name GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_library_name") + set(_vtk_hierarchy_filename "${_vtk_hierarchy_library_name}-hierarchy.txt") + set(_vtk_hierarchy_file "${CMAKE_BINARY_DIR}/${_vtk_build_HIERARCHY_DESTINATION}/${_vtk_hierarchy_filename}") + set(_vtk_hierarchy_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.$.args") + set(_vtk_hierarchy_data_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.data") + set(_vtk_hierarchy_depends_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.depends.args") + + set_property(TARGET "${_vtk_add_module_target_name}" + PROPERTY + "INTERFACE_vtk_module_hierarchy" "${_vtk_hierarchy_file}") + + set(_vtk_add_module_target_name_iface "${_vtk_add_module_target_name}") + if (_vtk_add_module_build_with_kit) + set(_vtk_add_module_target_name_iface "${_vtk_add_module_target_name}-objects") + endif () + set(_vtk_hierarchy_genex_compile_definitions + "$") + set(_vtk_hierarchy_genex_include_directories + "$") + file(GENERATE + OUTPUT "${_vtk_hierarchy_args_file}" + CONTENT "$<$:\n-D\"$\">\n +$<$:\n-I\"$\">\n") + + get_property(_vtk_hierarchy_depends_is_global GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_depends" + SET) + if (_vtk_hierarchy_depends_is_global) + get_property(_vtk_hierarchy_depends GLOBAL + PROPERTY "_vtk_module_${_vtk_build_module}_depends") + else () + get_property(_vtk_hierarchy_depends GLOBAL + TARGET "${_vtk_add_module_target_name}" + PROPERTY "INTERFACE_vtk_module_depends") + endif () + + set(_vtk_hierarchy_depends_files) + set(_vtk_hierarchy_depends_targets) + foreach (_vtk_hierarchy_depend IN LISTS _vtk_hierarchy_depends) + _vtk_module_get_module_property("${_vtk_hierarchy_depend}" + PROPERTY "hierarchy" + VARIABLE _vtk_hierarchy_depend_hierarchy) + if (NOT DEFINED _vtk_hierarchy_depend_hierarchy) + continue () + endif () + + list(APPEND _vtk_hierarchy_depends_files + "${_vtk_hierarchy_depend_hierarchy}") + + # Find the hierarchy target of the module. + get_property(_vtk_hierarchy_module_is_alias + TARGET "${_vtk_hierarchy_depend}" + PROPERTY ALIASED_TARGET + SET) + # Non-alias target modules are external and should already have their file + # generated. + if (NOT _vtk_hierarchy_module_is_alias) + continue () + endif () + + get_property(_vtk_hierarchy_depend_target_name GLOBAL + PROPERTY "_vtk_module_${_vtk_hierarchy_depend}_target_name") + if (TARGET "${_vtk_hierarchy_depend_target_name}-hierarchy") + list(APPEND _vtk_hierarchy_depends_targets + "${_vtk_hierarchy_depend_target_name}-hierarchy") + endif () + endforeach () + + set(_vtk_hierarchy_depends_files_arg) + if (_vtk_hierarchy_depends_files) + file(GENERATE + OUTPUT "${_vtk_hierarchy_depends_args_file}" + CONTENT "\"$\"\n") + else () + file(GENERATE + OUTPUT "${_vtk_hierarchy_depends_args_file}" + CONTENT "") + endif () + + get_property(_vtk_hierarchy_headers + TARGET "${_vtk_build_module}" + PROPERTY "INTERFACE_vtk_module_headers") + set(_vtk_hierarchy_data_content "") + foreach (_vtk_hierarchy_header IN LISTS _vtk_hierarchy_headers) + string(APPEND _vtk_hierarchy_data_content + "${_vtk_hierarchy_header};${_vtk_build_module}\n") + endforeach () + file(GENERATE + OUTPUT "${_vtk_hierarchy_data_file}" + CONTENT "${_vtk_hierarchy_data_content}") + + if (CMAKE_GENERATOR MATCHES "Ninja") + set(_vtk_hierarchy_command_depends ${_vtk_hierarchy_depends_files}) + else () + set(_vtk_hierarchy_command_depends ${_vtk_hierarchy_depends_targets}) + endif () + + add_custom_command( + OUTPUT "${_vtk_hierarchy_file}" + COMMAND VTK::WrapHierarchy + "@${_vtk_hierarchy_args_file}" + -o "${_vtk_hierarchy_file}" + "${_vtk_hierarchy_data_file}" + "@${_vtk_hierarchy_depends_args_file}" + COMMENT "Generating the wrap hierarchy for ${_vtk_build_module}" + DEPENDS + ${_vtk_hierarchy_headers} + "${_vtk_hierarchy_args_file}" + "${_vtk_hierarchy_data_file}" + "${_vtk_hierarchy_depends_args_file}" + ${_vtk_hierarchy_command_depends}) + add_custom_target("${_vtk_add_module_target_name}-hierarchy" ALL + DEPENDS + "${_vtk_hierarchy_file}") + set_property(TARGET "${_vtk_add_module_target_name}" + PROPERTY + "INTERFACE_vtk_module_hierarchy" "${_vtk_hierarchy_file}") + + if (_vtk_build_INSTALL_HEADERS) + set_property(TARGET "${_vtk_add_module_target_name}" + PROPERTY + "INTERFACE_vtk_module_hierarchy_install" "\${_vtk_module_import_prefix}/${_vtk_build_HIERARCHY_DESTINATION}/${_vtk_hierarchy_filename}") + install( + FILES "${_vtk_hierarchy_file}" + DESTINATION "${_vtk_build_HIERARCHY_DESTINATION}" + RENAME "${_vtk_hierarchy_filename}" + COMPONENT "${_vtk_build_HEADERS_COMPONENT}") + endif () +endfunction () + +include(GenerateExportHeader) + +#[==[.md +## Building a module + +Create a module library. + +``` +vtk_module_add_module( + [FORCE_STATIC] [HEADER_ONLY] + [EXPORT_MACRO_PREFIX ] + [HEADERS_SUBDIR ] + [LIBRARY_NAME_SUFFIX ] + [CLASSES ...] + [TEMPLATE_CLASSES