Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rapids-cmake dependency tracking now understands COMPONENTS #234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions rapids-cmake/cpm/find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tracking of these dependencies for correct export support.
.. code-block:: cmake

rapids_cpm_find(<PackageName> <version>
[COMPONENTS <components...>]
[GLOBAL_TARGETS <targets...>]
[BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand All @@ -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
Expand Down
20 changes: 18 additions & 2 deletions rapids-cmake/export/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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)
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down
15 changes: 15 additions & 0 deletions rapids-cmake/export/template/build_package_components.cmake.in
Original file line number Diff line number Diff line change
@@ -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()
#=============================================================================
Original file line number Diff line number Diff line change
@@ -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@)
vyasr marked this conversation as resolved.
Show resolved Hide resolved
find_dependency(@name@ COMPONENTS @components@)

if(possible_package_dir)
unset(possible_package_dir)
endif()
#=============================================================================
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_dependency(@name@ COMPONENTS @components@)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
find_package(@name@ @version@ QUIET COMPONENTS @components@)
find_dependency(@name@ COMPONENTS @components@)
16 changes: 15 additions & 1 deletion rapids-cmake/find/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tracking of these dependencies for correct export support.

rapids_find_package(<PackageName>
[ all normal find_package options ]
[COMPONENTS <components...>]
[GLOBAL_TARGETS <targets...>]
[BUILD_EXPORT_SET <name>]
[INSTALL_EXPORT_SET <name>]
Expand All @@ -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.
Expand Down Expand Up @@ -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})
vyasr marked this conversation as resolved.
Show resolved Hide resolved
endif()

find_package(${name} ${_RAPIDS_UNPARSED_ARGUMENTS})

if(_RAPIDS_GLOBAL_TARGETS)
Expand All @@ -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})
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
52 changes: 52 additions & 0 deletions testing/cpm/cpm_find-components/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.23.1)
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()
Original file line number Diff line number Diff line change
@@ -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()
31 changes: 31 additions & 0 deletions testing/cpm/cpm_find-components/fakedependency-config.cmake
Original file line number Diff line number Diff line change
@@ -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. ")
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
endif()
endforeach()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(FakeDependency
REASON_FAILURE_MESSAGE "${_FAIL_REASON}"
HANDLE_COMPONENTS)
5 changes: 5 additions & 0 deletions testing/export/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#=============================================================================
# Copyright (c) 2018-2021, NVIDIA CORPORATION.
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
#
# 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()

Loading