Skip to content

Commit

Permalink
rapids_cpm_find is more invariant as one would expect
Browse files Browse the repository at this point in the history
Fixes rapidsai#49

rapids_cpm_find now looks at the `GLOBAL_TARGETS` entries and
will not call CPMFindPackage if any of them already exist.

This makes it safe to call `rapids_cpm_find` no matter what
existing targets already exist. therefore users of rapids-cmake
don't need to do manual `if(TARGET ...)` checks, resulting
in missing packages in the export set.
  • Loading branch information
robertmaynard committed Jul 30, 2021
1 parent 89b8630 commit f5eb8d0
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions rapids-cmake/cpm/find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ consistency. List all targets used by your project in `GLOBAL_TARGET`.
.. note::
Requires :cmake:command:`rapids_cpm_init` to be called before usage
.. note::
Adding an export set to :cmake:command:`rapids_cpm_find` has different behavior
for build and install. Build exports a respective CPM call, since
we presume other CPM packages don't generate a correct build directory
config module. While install exports a `find_dependency` call as
we expect projects to have a valid install setup.
If you need different behavior you will need to use :cmake:command:`rapids_export_package()`
or :cmake:command:`rapids_export_cpm()`.
``PackageName``
Name of the package to find.
Expand All @@ -64,6 +54,13 @@ consistency. List all targets used by your project in `GLOBAL_TARGET`.
Which targets from this package should be made global. This information
will be propagated to any associated export set.
.. versionchanged:: v21.10.00
If any targets listed in `GLOBAL_TARGET` exist when :cmake:command:`rapids_cpm_find` is called
no calls to `CPM` will be executed. This is done for the following reasons:
- Removes the need for the calling code to do the conditional checks
- Allows `BUILD_EXPORT_SET` and `INSTALL_EXPORT_SET` tracking to happen correctly when targets had already been brought it by non-CPM means.
``BUILD_EXPORT_SET``
Record that a :cmake:command:`CPMFindPackage(<PackageName> ...)` call needs to occur as part of
our build directory export set.
Expand All @@ -77,6 +74,16 @@ consistency. List all targets used by your project in `GLOBAL_TARGET`.
be passed down to :cmake:command:`CPMFindPackage`.
.. note::
Adding an export set to :cmake:command:`rapids_cpm_find` has different behavior
for build and install. Build exports a respective CPM call, since
we presume other CPM packages don't generate a correct build directory
config module. While install exports a `find_dependency` call as
we expect projects to have a valid install setup.
If you need different behavior you will need to use :cmake:command:`rapids_export_package()`
or :cmake:command:`rapids_export_cpm()`.
#]=======================================================================]
function(rapids_cpm_find name version)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.find")
Expand All @@ -89,14 +96,25 @@ function(rapids_cpm_find name version)
message(FATAL_ERROR "rapids_cpm_find requires you to specify CPM_ARGS before any CPM arguments")
endif()

CPMFindPackage(NAME ${name} VERSION ${version} ${RAPIDS_UNPARSED_ARGUMENTS})
set(package_needs_to_be_added TRUE)
if(RAPIDS_GLOBAL_TARGETS)
include("${rapids-cmake-dir}/cmake/make_global.cmake")
rapids_cmake_make_global(RAPIDS_GLOBAL_TARGETS)
foreach(target IN LISTS RAPIDS_GLOBAL_TARGETS)
if(TARGET ${target})
set(package_needs_to_be_added FALSE)
break()
endif()
endforeach()
endif()

if(package_needs_to_be_added)
CPMFindPackage(NAME ${name} VERSION ${version} ${RAPIDS_UNPARSED_ARGUMENTS})
endif()

set(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})
endif()
Expand Down

0 comments on commit f5eb8d0

Please sign in to comment.