vcpkg/ports/vtk/10945.diff

196 lines
8.8 KiB
Diff
Raw Normal View History

diff --git a/CMake/vtkModule.cmake b/CMake/vtkModule.cmake
index d8282ff98f79548e66a1794c7daf9cd253f0a9e5..7163c690b069c3176a9c921d7799b105bb4b1825 100644
--- a/CMake/vtkModule.cmake
+++ b/CMake/vtkModule.cmake
@@ -129,6 +129,73 @@ function (_vtk_module_split_module_name name prefix)
PARENT_SCOPE)
endfunction ()
+#[==[.rst:
+.. cmake:command:: _vtk_module_optional_dependency_exists
+
+ Detect whether an optional dependency exists or not.
+ |module-internal|
+
+ Optional dependencies need to be detected
+ namespace and target name part.
+
+ .. code-block:: cmake
+
+ _vtk_module_split_module_name(<dependency>
+ SATISFIED_VAR <var>
+ [PACKAGE <package>])
+
+ The result will be returned in the variable specified by ``SATISFIED_VAR``. If
+ ``PACKAGE`` is not given, ``_vtk_build_PACKAGE`` will be used if defined,
+ otherwise an error will be raised.
+#]==]
+function (_vtk_module_optional_dependency_exists dependency)
+ cmake_parse_arguments(_vtk_optional_dep
+ ""
+ "SATISFIED_VAR;PACKAGE"
+ ""
+ ${ARGN})
+
+ if (_vtk_optional_dep_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR
+ "Unparsed arguments for `_vtk_module_optional_dependency_exists`: "
+ "${_vtk_optional_dep_UNPARSED_ARGUMENTS}")
+ endif ()
+
+ if (NOT _vtk_optional_dep_PACKAGE)
+ if (NOT DEFINED _vtk_build_PACKAGE)
+ message(FATAL_ERROR
+ "The `PACKAGE` argument is required outside of `vtk_module_build` "
+ "usage.")
+ endif ()
+ set(_vtk_optional_dep_PACKAGE
+ "${_vtk_build_PACKAGE}")
+ endif ()
+
+ if (NOT _vtk_optional_dep_SATISFIED_VAR)
+ message(FATAL_ERROR
+ "The `SATISFIED_VAR` argument is required.")
+ endif ()
+
+ set(_vtk_optional_dep_satisfied 0)
+ if (TARGET "${dependency}")
+ _vtk_module_split_module_name("${dependency}" _vtk_optional_dep_parse)
+ if (_vtk_optional_dep_PACKAGE STREQUAL _vtk_optional_dep_parse_NAMESPACE)
+ set(_vtk_optional_dep_satisfied 1)
+ else ()
+ set(_vtk_optional_dep_found_var
+ "${_vtk_optional_dep_parse_NAMESPACE}_${_vtk_optional_dep_parse_TARGET_NAME}_FOUND")
+ if (DEFINED "${_vtk_optional_dep_found_var}" AND
+ ${_vtk_optional_dep_found_var})
+ set(_vtk_optional_dep_satisfied 1)
+ endif ()
+ endif ()
+ endif ()
+
+ set("${_vtk_optional_dep_SATISFIED_VAR}"
+ "${_vtk_optional_dep_satisfied}"
+ PARENT_SCOPE)
+endfunction ()
+
#[==[.rst:
.. _module-parse-module:
@@ -2827,8 +2894,12 @@ function (vtk_module_build)
get_property(_vtk_build_kit_module_optional_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_kit_module}_optional_depends")
foreach (_vtk_build_kit_module_private_depend IN LISTS _vtk_build_kit_module_private_depends _vtk_build_kit_module_optional_depends)
- if (NOT TARGET "${_vtk_build_kit_module_private_depend}")
- continue ()
+ if (_vtk_build_kit_module_private_depend IN_LIST _vtk_build_kit_module_optional_depends)
+ _vtk_module_optional_dependency_exists("${_vtk_build_kit_module_private_depend}"
+ SATISFIED_VAR _vtk_build_kit_module_has_optional_dep)
+ if (NOT _vtk_build_kit_module_has_optional_dep)
+ continue ()
+ endif ()
endif ()
# But we don't need to link to modules that are part of the kit we are
@@ -4124,7 +4195,9 @@ function (vtk_module_add_module name)
get_property(_vtk_add_module_optional_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
foreach (_vtk_add_module_optional_depend IN LISTS _vtk_add_module_optional_depends)
- if (TARGET "${_vtk_add_module_optional_depend}")
+ _vtk_module_optional_dependency_exists("${_vtk_add_module_optional_depend}"
+ SATISFIED_VAR _vtk_add_module_optional_depend_exists)
+ if (_vtk_add_module_optional_depend_exists)
set(_vtk_add_module_optional_depend_link "${_vtk_add_module_optional_depend}")
if (_vtk_add_module_build_with_kit)
get_property(_vtk_add_module_optional_depend_kit GLOBAL
@@ -4149,7 +4222,7 @@ function (vtk_module_add_module name)
string(REPLACE "::" "_" _vtk_add_module_optional_depend_safe "${_vtk_add_module_optional_depend}")
target_compile_definitions("${_vtk_add_module_real_target}"
PRIVATE
- "VTK_MODULE_ENABLE_${_vtk_add_module_optional_depend_safe}=$<TARGET_EXISTS:${_vtk_add_module_optional_depend}>")
+ "VTK_MODULE_ENABLE_${_vtk_add_module_optional_depend_safe}=$<BOOL:${_vtk_add_module_optional_depend_exists}>")
endforeach ()
if (_vtk_add_module_private_depends_forward_link)
@@ -4801,10 +4874,12 @@ function (vtk_module_add_executable name)
get_property(_vtk_add_executable_optional_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
foreach (_vtk_add_executable_optional_depend IN LISTS _vtk_add_executable_optional_depends)
+ _vtk_module_optional_dependency_exists("${_vtk_add_executable_optional_depend}"
+ SATISFIED_VAR _vtk_add_executable_optional_depend_exists)
string(REPLACE "::" "_" _vtk_add_executable_optional_depend_safe "${_vtk_add_executable_optional_depend}")
target_compile_definitions("${_vtk_add_executable_target_name}"
PRIVATE
- "VTK_MODULE_ENABLE_${_vtk_add_executable_optional_depend_safe}=$<TARGET_EXISTS:{_vtk_add_executable_optional_depend}>")
+ "VTK_MODULE_ENABLE_${_vtk_add_executable_optional_depend_safe}=$<BOOL:{_vtk_add_executable_optional_depend_exists}>")
endforeach ()
if (_vtk_module_warnings)
@@ -5135,6 +5210,12 @@ while (_vtk_module_find_package_components_to_check)
list(APPEND _vtk_module_find_package_components_checked
\"\${_vtk_module_component}\")
+ # Any 'components' with `::` are not from our package and must have been
+ # provided/satisfied elsewhere.
+ if (_vtk_module_find_package_components MATCHES \"::\")
+ continue ()
+ endif ()
+
list(APPEND _vtk_module_find_package_components
\"\${_vtk_module_component}\")
if (\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_\${_vtk_module_component})
diff --git a/CMake/vtkModuleTesting.cmake b/CMake/vtkModuleTesting.cmake
index 4d91c569e63e1d7c7747fa25da30903645cb9b84..55ebd2651e9c329b05d8b12a9cfad6ea87e74b26 100644
--- a/CMake/vtkModuleTesting.cmake
+++ b/CMake/vtkModuleTesting.cmake
@@ -79,13 +79,15 @@ function (vtk_module_test_executable name)
PROPERTY "_vtk_module_${_vtk_build_test}_test_optional_depends")
set(optional_depends_flags)
foreach (test_optional_depend IN LISTS test_optional_depends)
- if (TARGET "${test_optional_depend}")
+ _vtk_module_optional_dependency_exists("${test_optional_depend}"
+ SATISFIED_VAR test_optional_depend_exists)
+ if (test_optional_depend_exists)
list(APPEND test_depends
"${test_optional_depend}")
endif ()
string(REPLACE "::" "_" safe_test_optional_depend "${test_optional_depend}")
list(APPEND optional_depends_flags
- "VTK_MODULE_ENABLE_${safe_test_optional_depend}=$<TARGET_EXISTS:${test_optional_depend}>")
+ "VTK_MODULE_ENABLE_${safe_test_optional_depend}=$<BOOL:${test_optional_depend_exists}>")
endforeach ()
if (_vtk_build_UTILITY_TARGET)
diff --git a/Documentation/release/dev/better-optional-deps-checks.md b/Documentation/release/dev/better-optional-deps-checks.md
new file mode 100644
index 0000000000000000000000000000000000000000..2ce1e98d95dc247a8912dc1b976f592548a83d49
--- /dev/null
+++ b/Documentation/release/dev/better-optional-deps-checks.md
@@ -0,0 +1,3 @@
+## better-optional-deps-checks
+
+Optional dependencies now have better logic for detecting the usability of external optional dependencies.
diff --git a/Testing/External/CMakeLists.txt b/Testing/External/CMakeLists.txt
index 8d2de9844d979c3298b8fe337f428dbe12b86191..510620f7616f9152f4dfb8f364579a1c3bf1bcdb 100644
--- a/Testing/External/CMakeLists.txt
+++ b/Testing/External/CMakeLists.txt
@@ -53,6 +53,7 @@ vtk_module_scan(
# Input information for test build files.
option(VTK_USE_LARGE_DATA "Enable tests requiring \"large\" data" OFF)
+set(_vtk_build_PACKAGE "VTK")
set(_vtk_build_TEST_DATA_TARGET "VTKData")
set(_vtk_build_TEST_INPUT_DATA_DIRECTORY "${VTK_TOP_DIR}/Testing")
set(_vtk_build_TEST_OUTPUT_DATA_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ExternalData/Testing")
diff --git a/Testing/ExternalWheel/CMakeLists.txt b/Testing/ExternalWheel/CMakeLists.txt
index 518380d5370a9b0b61e0d0f48ae751a81b595098..c9c984578b682f1a6a605b3546e826b63f9c88ea 100644
--- a/Testing/ExternalWheel/CMakeLists.txt
+++ b/Testing/ExternalWheel/CMakeLists.txt
@@ -82,6 +82,7 @@ endforeach ()
# Input information for test build files.
option(VTK_USE_LARGE_DATA "Enable tests requiring \"large\" data" OFF)
+set(_vtk_build_PACKAGE "VTK")
set(_vtk_build_TEST_DATA_TARGET "VTKData")
set(_vtk_build_TEST_INPUT_DATA_DIRECTORY "${VTK_TOP_DIR}/Testing")
set(_vtk_build_TEST_OUTPUT_DATA_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ExternalData/Testing")