From 8d54e6e583b03d3e06c6ce9c077d075b04608544 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 16 Mar 2022 12:47:56 -0400 Subject: [PATCH 1/2] rapids_cpm_package_override now hooks into FetchContent This means that overrides for packages like thrust still work when the caller uses `FetchContent`, `CPMAddPackage`, or `rapids_cpm_find` instead of `rapids_cpm_`. Fixes #152 --- rapids-cmake/cpm/package_override.cmake | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/rapids-cmake/cpm/package_override.cmake b/rapids-cmake/cpm/package_override.cmake index 6ad5531f..936dd069 100644 --- a/rapids-cmake/cpm/package_override.cmake +++ b/rapids-cmake/cpm/package_override.cmake @@ -41,6 +41,11 @@ By default when an override for a project is provided no local search for that project will occur. This is done to make sure that the requested modified version is used. +If a project is listed in multiple override files, the first file values will be used, +and all later calls for that packaged will be ignored. This "first to record, wins" +approach is used to match FetchContent, and allows parent projects to override child +projects. + .. note:: If the override file doesn't specify a value or package entry the default @@ -63,12 +68,27 @@ function(rapids_cpm_package_override filepath) math(EXPR package_count "${package_count} - 1") # For each project cache the subset of the json for that project in a global property + # so that packasge_details.cmake can fetch that information if(package_count GREATER_EQUAL 0) # cmake-lint: disable=E1120 foreach(index RANGE ${package_count}) string(JSON package_name MEMBER "${json_data}" packages ${index}) string(JSON data GET "${json_data}" packages "${package_name}") - set_property(GLOBAL PROPERTY rapids_cpm_${package_name}_override_json "${data}") + get_property(override_exists GLOBAL PROPERTY rapids_cpm_${package_name}_override_json DEFINED) + if(NOT override_exists) + #only add the first override for a project we encounter + set_property(GLOBAL PROPERTY rapids_cpm_${package_name}_override_json "${data}") + endif() endforeach() + + # establish the fetch content + include(FetchContent) + include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") + rapids_cpm_package_details(${package_name} version repository tag shallow exclude) + FetchContent_Declare(${package_name} + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + ) + endif() endfunction() From ba1122d362abaf6eebfc7ec9a7ac1cefd2bf9ce9 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 16 Mar 2022 13:23:02 -0400 Subject: [PATCH 2/2] Correct style issues found by CI --- rapids-cmake/cpm/package_override.cmake | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/rapids-cmake/cpm/package_override.cmake b/rapids-cmake/cpm/package_override.cmake index 936dd069..51ff9752 100644 --- a/rapids-cmake/cpm/package_override.cmake +++ b/rapids-cmake/cpm/package_override.cmake @@ -67,8 +67,8 @@ function(rapids_cpm_package_override filepath) string(JSON package_count LENGTH "${json_data}" packages) math(EXPR package_count "${package_count} - 1") - # For each project cache the subset of the json for that project in a global property - # so that packasge_details.cmake can fetch that information + # For each project cache the subset of the json for that project in a global property so that + # packasge_details.cmake can fetch that information if(package_count GREATER_EQUAL 0) # cmake-lint: disable=E1120 foreach(index RANGE ${package_count}) @@ -76,7 +76,7 @@ function(rapids_cpm_package_override filepath) string(JSON data GET "${json_data}" packages "${package_name}") get_property(override_exists GLOBAL PROPERTY rapids_cpm_${package_name}_override_json DEFINED) if(NOT override_exists) - #only add the first override for a project we encounter + # only add the first override for a project we encounter set_property(GLOBAL PROPERTY rapids_cpm_${package_name}_override_json "${data}") endif() endforeach() @@ -85,10 +85,7 @@ function(rapids_cpm_package_override filepath) include(FetchContent) include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") rapids_cpm_package_details(${package_name} version repository tag shallow exclude) - FetchContent_Declare(${package_name} - GIT_REPOSITORY ${repository} - GIT_TAG ${tag} - ) + FetchContent_Declare(${package_name} GIT_REPOSITORY ${repository} GIT_TAG ${tag}) endif() endfunction()