From b517a73f8f0f3fcd2e09b96e9f226e0560b98e89 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 1 Aug 2022 13:39:13 -0400 Subject: [PATCH 1/4] rapids_export_package understands components --- rapids-cmake/export/package.cmake | 20 +++++++++- .../build_package_components.cmake.in | 15 +++++++ ...uild_package_components_versioned.cmake.in | 16 ++++++++ .../install_package_components.cmake.in | 1 + ...tall_package_components_versioned.cmake.in | 2 + testing/export/CMakeLists.txt | 5 +++ ...ge-build-with-components-and-version.cmake | 40 +++++++++++++++++++ ...export_package-build-with-components.cmake | 33 +++++++++++++++ ..._package-build-with-empty-components.cmake | 33 +++++++++++++++ ...-install-with-components-and-version.cmake | 39 ++++++++++++++++++ ...port_package-install-with-components.cmake | 32 +++++++++++++++ .../export_package-install-with-version.cmake | 8 ++-- 12 files changed, 238 insertions(+), 6 deletions(-) create mode 100644 rapids-cmake/export/template/build_package_components.cmake.in create mode 100644 rapids-cmake/export/template/build_package_components_versioned.cmake.in create mode 100644 rapids-cmake/export/template/install_package_components.cmake.in create mode 100644 rapids-cmake/export/template/install_package_components_versioned.cmake.in create mode 100644 testing/export/export_package-build-with-components-and-version.cmake create mode 100644 testing/export/export_package-build-with-components.cmake create mode 100644 testing/export/export_package-build-with-empty-components.cmake create mode 100644 testing/export/export_package-install-with-components-and-version.cmake create mode 100644 testing/export/export_package-install-with-components.cmake diff --git a/rapids-cmake/export/package.cmake b/rapids-cmake/export/package.cmake index 20beba9f..8d16854a 100644 --- a/rapids-cmake/export/package.cmake +++ b/rapids-cmake/export/package.cmake @@ -49,6 +49,11 @@ generated information will include a :cmake:command:`find_dependency` call for < Record which `major.minor` version of the package is required for consumers. +``COMPONENTS`` + .. versionadded:: v22.10.00 + + Record which components of the package are required for consumers. + ``GLOBAL_TARGETS`` Which targets from this package should be made global when the package is imported in. @@ -62,7 +67,7 @@ function(rapids_export_package type name export_set) set(options "") set(one_value EXPORT_SET VERSION) - set(multi_value GLOBAL_TARGETS) + set(multi_value GLOBAL_TARGETS COMPONENTS) cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) if(type STREQUAL build) @@ -72,7 +77,18 @@ function(rapids_export_package type name export_set) endif() endif() - if(_RAPIDS_VERSION) + if(_RAPIDS_COMPONENTS AND _RAPIDS_VERSION) + set(version ${_RAPIDS_VERSION}) + set(components ${_RAPIDS_COMPONENTS}) + configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/${type}_package_components_versioned.cmake.in" + "${CMAKE_BINARY_DIR}/rapids-cmake/${export_set}/${type}/package_${name}.cmake" + @ONLY) + elseif(_RAPIDS_COMPONENTS) + set(components ${_RAPIDS_COMPONENTS}) + configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/${type}_package_components.cmake.in" + "${CMAKE_BINARY_DIR}/rapids-cmake/${export_set}/${type}/package_${name}.cmake" + @ONLY) + elseif(_RAPIDS_VERSION) set(version ${_RAPIDS_VERSION}) configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/${type}_package_versioned.cmake.in" "${CMAKE_BINARY_DIR}/rapids-cmake/${export_set}/${type}/package_${name}.cmake" diff --git a/rapids-cmake/export/template/build_package_components.cmake.in b/rapids-cmake/export/template/build_package_components.cmake.in new file mode 100644 index 00000000..9faac7b2 --- /dev/null +++ b/rapids-cmake/export/template/build_package_components.cmake.in @@ -0,0 +1,15 @@ +#============================================================================= +# find_dependency Search for @name@ +# +# Make sure we search for a build-dir config module for the project +set(possible_package_dir "@possible_dir@") +if(possible_package_dir AND NOT DEFINED @name@_DIR) + set(@name@_DIR "${possible_package_dir}") +endif() + +find_dependency(@name@ COMPONENTS @components@) + +if(possible_package_dir) + unset(possible_package_dir) +endif() +#============================================================================= diff --git a/rapids-cmake/export/template/build_package_components_versioned.cmake.in b/rapids-cmake/export/template/build_package_components_versioned.cmake.in new file mode 100644 index 00000000..da5dc940 --- /dev/null +++ b/rapids-cmake/export/template/build_package_components_versioned.cmake.in @@ -0,0 +1,16 @@ +#============================================================================= +# find_dependency Search for @name@ +# +# Make sure we search for a build-dir config module for the project +set(possible_package_dir "@possible_dir@") +if(possible_package_dir AND NOT DEFINED @name@_DIR) + set(@name@_DIR "${possible_package_dir}") +endif() + +find_package(@name@ @version@ QUIET COMPONENTS @components@) +find_dependency(@name@ COMPONENTS @components@) + +if(possible_package_dir) + unset(possible_package_dir) +endif() +#============================================================================= diff --git a/rapids-cmake/export/template/install_package_components.cmake.in b/rapids-cmake/export/template/install_package_components.cmake.in new file mode 100644 index 00000000..1aca3ee2 --- /dev/null +++ b/rapids-cmake/export/template/install_package_components.cmake.in @@ -0,0 +1 @@ +find_dependency(@name@ COMPONENTS @components@) diff --git a/rapids-cmake/export/template/install_package_components_versioned.cmake.in b/rapids-cmake/export/template/install_package_components_versioned.cmake.in new file mode 100644 index 00000000..1f07e44f --- /dev/null +++ b/rapids-cmake/export/template/install_package_components_versioned.cmake.in @@ -0,0 +1,2 @@ +find_package(@name@ @version@ QUIET COMPONENTS @components@) +find_dependency(@name@ COMPONENTS @components@) diff --git a/testing/export/CMakeLists.txt b/testing/export/CMakeLists.txt index 34697db9..3cb5a6ca 100644 --- a/testing/export/CMakeLists.txt +++ b/testing/export/CMakeLists.txt @@ -39,10 +39,15 @@ add_cmake_config_test( export-verify-implicit-major-version-only-matching.cmake add_cmake_config_test( export-verify-version.cmake ) add_cmake_config_test( export_package-build-possible-dir.cmake ) +add_cmake_config_test( export_package-build-with-components.cmake ) +add_cmake_config_test( export_package-build-with-components-and-version.cmake ) +add_cmake_config_test( export_package-build-with-empty-components.cmake ) add_cmake_config_test( export_package-build-with-version.cmake ) add_cmake_config_test( export_package-build.cmake ) add_cmake_config_test( export_package-install-possible-dir.cmake ) add_cmake_config_test( export_package-install.cmake ) +add_cmake_config_test( export_package-install-with-components.cmake ) +add_cmake_config_test( export_package-install-with-components-and-version.cmake ) add_cmake_config_test( export_package-install-with-version.cmake ) add_cmake_config_test( export_package-multiple-export_sets.cmake ) diff --git a/testing/export/export_package-build-with-components-and-version.cmake b/testing/export/export_package-build-with-components-and-version.cmake new file mode 100644 index 00000000..51763f3b --- /dev/null +++ b/testing/export/export_package-build-with-components-and-version.cmake @@ -0,0 +1,40 @@ +#============================================================================= +# Copyright (c) 2018-2021, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/export/package.cmake) + +rapids_export_package( build FAKE_PACKAGE test_export_set VERSION 22.08 COMPONENTS comp1) + +# Verify that package configuration files exist +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FAKE_PACKAGE.cmake") +if(NOT EXISTS "${path}") + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration") +endif() + +# verify that the expected version is in FAKE_PACKAGE.cmake +set(to_match_string [=[22.08 QUIET]=]) +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with version") +endif() + +# verify that the expected components is in FAKE_PACKAGE.cmake +set(to_match_string [=[COMPONENTS comp1)]=]) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with COMPONENTS") +endif() + diff --git a/testing/export/export_package-build-with-components.cmake b/testing/export/export_package-build-with-components.cmake new file mode 100644 index 00000000..d7427f4d --- /dev/null +++ b/testing/export/export_package-build-with-components.cmake @@ -0,0 +1,33 @@ +#============================================================================= +# Copyright (c) 2018-2021, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/export/package.cmake) + +rapids_export_package( build FAKE_PACKAGE test_export_set COMPONENTS comp1 comp2 comp3) + +# Verify that package configuration files exist +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FAKE_PACKAGE.cmake") +if(NOT EXISTS "${path}") + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration") +endif() + +# verify that the expected components is in FAKE_PACKAGE.cmake +set(to_match_string [=[COMPONENTS comp1;comp2;comp3)]=]) +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with COMPONENTS") +endif() + diff --git a/testing/export/export_package-build-with-empty-components.cmake b/testing/export/export_package-build-with-empty-components.cmake new file mode 100644 index 00000000..8b48fa81 --- /dev/null +++ b/testing/export/export_package-build-with-empty-components.cmake @@ -0,0 +1,33 @@ +#============================================================================= +# Copyright (c) 2018-2021, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/export/package.cmake) + +rapids_export_package( build FAKE_PACKAGE test_export_set COMPONENTS) + +# Verify that package configuration files exist +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FAKE_PACKAGE.cmake") +if(NOT EXISTS "${path}") + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration") +endif() + +# verify that `COMPONENTS` isn't in FAKE_PACKAGE.cmake +set(to_match_string [=[COMPONENTS)]=]) +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(NOT is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_package generated a find_package configuration with COMPONENTS") +endif() + diff --git a/testing/export/export_package-install-with-components-and-version.cmake b/testing/export/export_package-install-with-components-and-version.cmake new file mode 100644 index 00000000..8d8cae98 --- /dev/null +++ b/testing/export/export_package-install-with-components-and-version.cmake @@ -0,0 +1,39 @@ +#============================================================================= +# Copyright (c) 2018-2021, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/export/package.cmake) + +rapids_export_package( build FAKE_PACKAGE test_export_set VERSION 14.7.2 COMPONENTS abc def) + +# Verify that package configuration files exist +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FAKE_PACKAGE.cmake") +if(NOT EXISTS "${path}") + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration") +endif() + +# verify that the expected version exists in FAKE_PACKAGE.cmake +set(to_match_string [=[14.7.2 QUIET]=]) +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with version") +endif() + +# verify that the expected components is in FAKE_PACKAGE.cmake +set(to_match_string [=[COMPONENTS abc;def)]=]) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with COMPONENTS") +endif() diff --git a/testing/export/export_package-install-with-components.cmake b/testing/export/export_package-install-with-components.cmake new file mode 100644 index 00000000..1ec49084 --- /dev/null +++ b/testing/export/export_package-install-with-components.cmake @@ -0,0 +1,32 @@ +#============================================================================= +# Copyright (c) 2018-2021, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/export/package.cmake) + +rapids_export_package( build FAKE_PACKAGE test_export_set VERSION 14.7.2) + +# Verify that package configuration files exist +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FAKE_PACKAGE.cmake") +if(NOT EXISTS "${path}") + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration") +endif() + +# verify that the expected version exists in FAKE_PACKAGE.cmake +set(to_match_string [=[14.7.2 QUIET)]=]) +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with version") +endif() diff --git a/testing/export/export_package-install-with-version.cmake b/testing/export/export_package-install-with-version.cmake index 1ec49084..69e871ef 100644 --- a/testing/export/export_package-install-with-version.cmake +++ b/testing/export/export_package-install-with-version.cmake @@ -15,7 +15,7 @@ #============================================================================= include(${rapids-cmake-dir}/export/package.cmake) -rapids_export_package( build FAKE_PACKAGE test_export_set VERSION 14.7.2) +rapids_export_package( build FAKE_PACKAGE test_export_set COMPONENTS 14.7.2) # Verify that package configuration files exist set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FAKE_PACKAGE.cmake") @@ -23,10 +23,10 @@ if(NOT EXISTS "${path}") message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration") endif() -# verify that the expected version exists in FAKE_PACKAGE.cmake -set(to_match_string [=[14.7.2 QUIET)]=]) +# verify that the expected COMPONENTS exists in FAKE_PACKAGE.cmake +set(to_match_string [=[COMPONENTS 14.7.2)]=]) file(READ "${path}" contents) string(FIND "${contents}" "${to_match_string}" is_found) if(is_found EQUAL -1) - message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with version") + message(FATAL_ERROR "rapids_export_package failed to generate a find_package configuration with COMPONENTS") endif() From 649dc1739fe709083b7a10ea08cf5188ccc68b4d Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 1 Aug 2022 16:46:10 -0400 Subject: [PATCH 2/4] rapids_find_package understands components --- rapids-cmake/find/package.cmake | 16 +++++- testing/find/CMakeLists.txt | 3 ++ .../find/find_package-components-failed.cmake | 31 ++++++++++++ .../find_package-components/CMakeLists.txt | 50 +++++++++++++++++++ .../fakedependency-config-version.cmake | 27 ++++++++++ .../fakedependency-config.cmake | 30 +++++++++++ .../find/find_package-optional-failed.cmake | 19 +------ 7 files changed, 157 insertions(+), 19 deletions(-) create mode 100644 testing/find/find_package-components-failed.cmake create mode 100644 testing/find/find_package-components/CMakeLists.txt create mode 100644 testing/find/find_package-components/fakedependency-config-version.cmake create mode 100644 testing/find/find_package-components/fakedependency-config.cmake diff --git a/rapids-cmake/find/package.cmake b/rapids-cmake/find/package.cmake index 03dd183e..50ce10e7 100644 --- a/rapids-cmake/find/package.cmake +++ b/rapids-cmake/find/package.cmake @@ -28,6 +28,7 @@ tracking of these dependencies for correct export support. rapids_find_package( [ all normal find_package options ] + [COMPONENTS ] [GLOBAL_TARGETS ] [BUILD_EXPORT_SET ] [INSTALL_EXPORT_SET ] @@ -48,6 +49,12 @@ in `GLOBAL_TARGETS`. ``PackageName`` Name of the package to find. +``COMPONENTS`` + .. versionadded:: v22.10.00 + + A list of required components that are required to be found for this + package to be considered valid. + ``GLOBAL_TARGETS`` Which targets from this package should be made global. This information will be propagated to any associated export set. @@ -107,10 +114,14 @@ macro(rapids_find_package name) list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.find.package") set(_rapids_options FIND_ARGS) set(_rapids_one_value BUILD_EXPORT_SET INSTALL_EXPORT_SET) - set(_rapids_multi_value GLOBAL_TARGETS) + set(_rapids_multi_value COMPONENTS GLOBAL_TARGETS) cmake_parse_arguments(_RAPIDS "${_rapids_options}" "${_rapids_one_value}" "${_rapids_multi_value}" ${ARGN}) + if(_RAPIDS_COMPONENTS) + list(APPEND _RAPIDS_UNPARSED_ARGUMENTS COMPONENTS ${_RAPIDS_COMPONENTS}) + endif() + find_package(${name} ${_RAPIDS_UNPARSED_ARGUMENTS}) if(_RAPIDS_GLOBAL_TARGETS) @@ -126,6 +137,9 @@ macro(rapids_find_package name) if(_RAPIDS_GLOBAL_TARGETS) list(APPEND _rapids_extra_info "GLOBAL_TARGETS" ${_RAPIDS_GLOBAL_TARGETS}) endif() + if(_RAPIDS_COMPONENTS) + list(APPEND _rapids_extra_info "COMPONENTS" ${_RAPIDS_COMPONENTS}) + endif() # Record the version we found to be what consumers need to find as well set(possible_version ${ARGV1}) diff --git a/testing/find/CMakeLists.txt b/testing/find/CMakeLists.txt index 635884b1..201f6974 100644 --- a/testing/find/CMakeLists.txt +++ b/testing/find/CMakeLists.txt @@ -17,6 +17,9 @@ add_cmake_config_test( rapids-find.cmake ) add_cmake_config_test( find_package-no-variable-leak.cmake ) +add_cmake_config_test( find_package-components ) +add_cmake_config_test( find_package-components-failed.cmake ) + add_cmake_config_test( find_package-build.cmake ) add_cmake_config_test( find_package-install.cmake ) diff --git a/testing/find/find_package-components-failed.cmake b/testing/find/find_package-components-failed.cmake new file mode 100644 index 00000000..41fa99eb --- /dev/null +++ b/testing/find/find_package-components-failed.cmake @@ -0,0 +1,31 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/find/package.cmake) + +set(CMAKE_PREFIX_PATH "${rapids-cmake-testing-dir}/find/find_package-components/") + +rapids_find_package(FakeDependency 11 COMPONENTS AAAAA + BUILD_EXPORT_SET test_export_set + ) + +if(FakeDependency_FOUND) + message(FATAL_ERROR "rapids_find_package recorded incorrect FOUND state for a failed find_package request") +endif() + +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FakeDependency.cmake") +if(EXISTS "${path}") + message(FATAL_ERROR "rapids_find_package(BUILD) recorded a failed find_package request") +endif() diff --git a/testing/find/find_package-components/CMakeLists.txt b/testing/find/find_package-components/CMakeLists.txt new file mode 100644 index 00000000..74d348af --- /dev/null +++ b/testing/find/find_package-components/CMakeLists.txt @@ -0,0 +1,50 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/find/package.cmake) + +cmake_minimum_required(VERSION 3.20) +project(rapids-test-project LANGUAGES CXX) + +set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}") + +rapids_find_package(FakeDependency 11 REQUIRED + COMPONENTS A B C + INSTALL_EXPORT_SET test_export_set + BUILD_EXPORT_SET test_export_set + ) + +if(NOT (DEFINED FakeDependency_A_FOUND AND + DEFINED FakeDependency_B_FOUND AND + DEFINED FakeDependency_C_FOUND) ) + message(FATAL_ERROR "rapids_find_package() failed to propagate COMPONENT A B C") +endif() + + +set(to_match_string "find_package(FakeDependency 11 QUIET COMPONENTS A;B;C)") + +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/package_FakeDependency.cmake") +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_find_package(BUILD) failed to perserve version information in exported file") +endif() + +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/install/package_FakeDependency.cmake") +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_find_package(INSTALL) failed to perserve version information in exported file") +endif() diff --git a/testing/find/find_package-components/fakedependency-config-version.cmake b/testing/find/find_package-components/fakedependency-config-version.cmake new file mode 100644 index 00000000..76d2087a --- /dev/null +++ b/testing/find/find_package-components/fakedependency-config-version.cmake @@ -0,0 +1,27 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +set(PACKAGE_VERSION "11") + +if(PACKAGE_FIND_VERSION_MAJOR STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_COMPATIBLE TRUE) +else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) +endif() + +if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) +endif() diff --git a/testing/find/find_package-components/fakedependency-config.cmake b/testing/find/find_package-components/fakedependency-config.cmake new file mode 100644 index 00000000..5595172c --- /dev/null +++ b/testing/find/find_package-components/fakedependency-config.cmake @@ -0,0 +1,30 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +cmake_minimum_required(VERSION 3.21) +set(allowed_components A B C) +foreach(comp IN LISTS FakeDependency_FIND_COMPONENTS) + if(${comp} IN_LIST allowed_components) + set(FakeDependency_${comp}_FOUND ON) + else() + string(APPEND _FAIL_REASON "component '${comp}' was requested, but not found. ") + endif() +endforeach() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(FakeDependency + REASON_FAILURE_MESSAGE "${_FAIL_REASON}" + HANDLE_COMPONENTS) diff --git a/testing/find/find_package-optional-failed.cmake b/testing/find/find_package-optional-failed.cmake index 0ce0232b..45bd1598 100644 --- a/testing/find/find_package-optional-failed.cmake +++ b/testing/find/find_package-optional-failed.cmake @@ -1,22 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#============================================================================= -include(${rapids-cmake-dir}/find/package.cmake) - -#============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 5cada075041b15b7880e5161d10d4c72137b610a Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 1 Aug 2022 16:46:29 -0400 Subject: [PATCH 3/4] rapids_cpm_find understands components --- rapids-cmake/cpm/find.cmake | 30 ++++++++--- testing/cpm/CMakeLists.txt | 1 + .../cpm/cpm_find-components/CMakeLists.txt | 52 +++++++++++++++++++ .../fakedependency-config-version.cmake | 27 ++++++++++ .../fakedependency-config.cmake | 31 +++++++++++ 5 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 testing/cpm/cpm_find-components/CMakeLists.txt create mode 100644 testing/cpm/cpm_find-components/fakedependency-config-version.cmake create mode 100644 testing/cpm/cpm_find-components/fakedependency-config.cmake diff --git a/rapids-cmake/cpm/find.cmake b/rapids-cmake/cpm/find.cmake index e0239c16..d98232cd 100644 --- a/rapids-cmake/cpm/find.cmake +++ b/rapids-cmake/cpm/find.cmake @@ -27,6 +27,7 @@ tracking of these dependencies for correct export support. .. code-block:: cmake rapids_cpm_find( + [COMPONENTS ] [GLOBAL_TARGETS ] [BUILD_EXPORT_SET ] [INSTALL_EXPORT_SET ] @@ -50,6 +51,12 @@ consistency. List all targets used by your project in `GLOBAL_TARGET`. ``version`` Version of the package you would like CPM to find. +``COMPONENTS`` + .. versionadded:: v22.10.00 + + A list of required components that are required to be found for this + package to be considered valid when doing a local search. + ``GLOBAL_TARGETS`` Which targets from this package should be made global. This information will be propagated to any associated export set. @@ -124,11 +131,12 @@ Example on how to use :cmake:command:`rapids_cpm_find` to include common project #]=======================================================================] +# cmake-lint: disable=R0912,R0915 function(rapids_cpm_find name version) list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.find") set(options CPM_ARGS) set(one_value BUILD_EXPORT_SET INSTALL_EXPORT_SET) - set(multi_value GLOBAL_TARGETS) + set(multi_value COMPONENTS GLOBAL_TARGETS) cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) if(NOT DEFINED _RAPIDS_CPM_ARGS) @@ -145,6 +153,13 @@ function(rapids_cpm_find name version) endforeach() endif() + if(_RAPIDS_COMPONENTS) + # We need to pass the set of components as a space separated string and not a list + string(REPLACE ";" " " _RAPIDS_COMPONENTS "${_RAPIDS_COMPONENTS}") + list(APPEND _RAPIDS_UNPARSED_ARGUMENTS "FIND_PACKAGE_ARGUMENTS" + "COMPONENTS ${_RAPIDS_COMPONENTS}") + endif() + if(package_needs_to_be_added) if(CPM_${name}_SOURCE) CPMAddPackage(NAME ${name} VERSION ${version} ${_RAPIDS_UNPARSED_ARGUMENTS}) @@ -159,26 +174,29 @@ function(rapids_cpm_find name version) endif() endif() - set(extra_info) + set(_rapids_extra_info) if(_RAPIDS_GLOBAL_TARGETS) include("${rapids-cmake-dir}/cmake/make_global.cmake") rapids_cmake_make_global(_RAPIDS_GLOBAL_TARGETS) - set(extra_info "GLOBAL_TARGETS") - list(APPEND extra_info ${_RAPIDS_GLOBAL_TARGETS}) + list(APPEND _rapids_extra_info "GLOBAL_TARGETS" ${_RAPIDS_GLOBAL_TARGETS}) endif() if(_RAPIDS_BUILD_EXPORT_SET) include("${rapids-cmake-dir}/export/cpm.cmake") rapids_export_cpm(BUILD ${name} ${_RAPIDS_BUILD_EXPORT_SET} CPM_ARGS NAME ${name} VERSION ${version} ${_RAPIDS_UNPARSED_ARGUMENTS} - ${extra_info}) + ${_rapids_extra_info}) endif() if(_RAPIDS_INSTALL_EXPORT_SET) include("${rapids-cmake-dir}/export/package.cmake") + + if(_RAPIDS_COMPONENTS) + list(APPEND _rapids_extra_info "COMPONENTS" ${_RAPIDS_COMPONENTS}) + endif() rapids_export_package(INSTALL ${name} ${_RAPIDS_INSTALL_EXPORT_SET} VERSION ${version} - ${extra_info}) + ${_rapids_extra_info}) endif() # Propagate up variables that CPMFindPackage provide diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 8a1e16d1..ea1612ee 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -17,6 +17,7 @@ add_cmake_config_test( rapids-cpm.cmake ) add_cmake_config_test( cpm_find-add-pkg-source ) add_cmake_config_test( cpm_find-and-find_package ) +add_cmake_config_test( cpm_find-components ) add_cmake_config_test( cpm_find-existing-build-dir ) add_cmake_config_test( cpm_find-existing-target ) add_cmake_config_test( cpm_find-existing-target-to-export-sets ) diff --git a/testing/cpm/cpm_find-components/CMakeLists.txt b/testing/cpm/cpm_find-components/CMakeLists.txt new file mode 100644 index 00000000..c2591393 --- /dev/null +++ b/testing/cpm/cpm_find-components/CMakeLists.txt @@ -0,0 +1,52 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/find.cmake) + +cmake_minimum_required(VERSION 3.20) +project(rapids-test-project LANGUAGES CXX) + +set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}") + +rapids_cpm_init() +rapids_cpm_find(FakeDependency 11 REQUIRED + COMPONENTS A B C + INSTALL_EXPORT_SET test_export_set + BUILD_EXPORT_SET test_export_set + ) + +if(NOT (TARGET FakeDependency::A AND + TARGET FakeDependency::B AND + TARGET FakeDependency::C) ) + message(FATAL_ERROR "rapids_cpm_find() failed to propagate COMPONENT A B C") +endif() + + +set(to_match_string "COMPONENTS A B C") + +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/build/cpm_FakeDependency.cmake") +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_cpm_find(BUILD) failed to perserve version information in exported file") +endif() + +set(path "${CMAKE_BINARY_DIR}/rapids-cmake/test_export_set/install/package_FakeDependency.cmake") +file(READ "${path}" contents) +string(FIND "${contents}" "${to_match_string}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_cpm_find(INSTALL) failed to perserve version information in exported file") +endif() diff --git a/testing/cpm/cpm_find-components/fakedependency-config-version.cmake b/testing/cpm/cpm_find-components/fakedependency-config-version.cmake new file mode 100644 index 00000000..76d2087a --- /dev/null +++ b/testing/cpm/cpm_find-components/fakedependency-config-version.cmake @@ -0,0 +1,27 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +set(PACKAGE_VERSION "11") + +if(PACKAGE_FIND_VERSION_MAJOR STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_COMPATIBLE TRUE) +else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) +endif() + +if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) +endif() diff --git a/testing/cpm/cpm_find-components/fakedependency-config.cmake b/testing/cpm/cpm_find-components/fakedependency-config.cmake new file mode 100644 index 00000000..0081994e --- /dev/null +++ b/testing/cpm/cpm_find-components/fakedependency-config.cmake @@ -0,0 +1,31 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +cmake_minimum_required(VERSION 3.21) +set(allowed_components A B C) +foreach(comp IN LISTS FakeDependency_FIND_COMPONENTS) + if(${comp} IN_LIST allowed_components) + set(FakeDependency_${comp}_FOUND ON) + add_library(FakeDependency::${comp} INTERFACE IMPORTED) + else() + string(APPEND _FAIL_REASON "component '${comp}' was requested, but not found. ") + endif() +endforeach() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(FakeDependency + REASON_FAILURE_MESSAGE "${_FAIL_REASON}" + HANDLE_COMPONENTS) From 0839ba4a5eb9141f88514038225491421bd76ada Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 29 Aug 2022 12:55:36 -0400 Subject: [PATCH 4/4] Update tests to 3.23.1 minimum CMake version --- testing/cpm/cpm_find-components/CMakeLists.txt | 2 +- testing/find/find_package-components/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/cpm/cpm_find-components/CMakeLists.txt b/testing/cpm/cpm_find-components/CMakeLists.txt index c2591393..0cef1b01 100644 --- a/testing/cpm/cpm_find-components/CMakeLists.txt +++ b/testing/cpm/cpm_find-components/CMakeLists.txt @@ -16,7 +16,7 @@ include(${rapids-cmake-dir}/cpm/init.cmake) include(${rapids-cmake-dir}/cpm/find.cmake) -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.23.1) project(rapids-test-project LANGUAGES CXX) set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/testing/find/find_package-components/CMakeLists.txt b/testing/find/find_package-components/CMakeLists.txt index 74d348af..c559fea4 100644 --- a/testing/find/find_package-components/CMakeLists.txt +++ b/testing/find/find_package-components/CMakeLists.txt @@ -15,7 +15,7 @@ #============================================================================= include(${rapids-cmake-dir}/find/package.cmake) -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.23.1) project(rapids-test-project LANGUAGES CXX) set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}")