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
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.
  • Loading branch information
robertmaynard committed Jul 30, 2021
1 parent 8cdc275 commit 2f21a62
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions rapids-cmake/cpm/find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,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 2f21a62

Please sign in to comment.