From 014aee6e1f2c95c14e91107ad8fb1db055e48486 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 30 Jul 2021 09:22:09 -0400 Subject: [PATCH] rapids_cpm_find is more invariant as one would expect Fixes #49 rapids_cpm_find now looks at the `GLOBAL_TARGETS` entries and wil 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. --- rapids-cmake/cpm/find.cmake | 44 ++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/rapids-cmake/cpm/find.cmake b/rapids-cmake/cpm/find.cmake index e65b47c44..52219c332 100644 --- a/rapids-cmake/cpm/find.cmake +++ b/rapids-cmake/cpm/find.cmake @@ -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. @@ -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( ...)` call needs to occur as part of our build directory export set. @@ -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") @@ -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()