From 7d2b702e015812e81270b1b9bf75ee4183646448 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 18 Dec 2023 10:08:19 -0500 Subject: [PATCH] multiple entry overrides now sets FetchContent for all entries (#494) FetchContent was previously only called for the last entry. Authors: - Robert Maynard (https://github.com/robertmaynard) Approvers: - Bradley Dice (https://github.com/bdice) URL: https://github.com/rapidsai/rapids-cmake/pull/494 --- rapids-cmake/cpm/package_override.cmake | 27 +++++++++---------- testing/cpm/cpm_init-override-multiple.cmake | 19 +++++++++++++ ...package_override-obey-cpm-source-var.cmake | 2 ++ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/rapids-cmake/cpm/package_override.cmake b/rapids-cmake/cpm/package_override.cmake index 2cf87ec5..18113b44 100644 --- a/rapids-cmake/cpm/package_override.cmake +++ b/rapids-cmake/cpm/package_override.cmake @@ -86,22 +86,21 @@ function(rapids_cpm_package_override filepath) string(JSON data GET "${json_data}" packages "${package_name}") set_property(GLOBAL PROPERTY rapids_cpm_${package_name}_override_json "${data}") set_property(GLOBAL PROPERTY rapids_cpm_${package_name}_override_json_file "${filepath}") - 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) - include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake") - rapids_cpm_generate_patch_command(${package_name} ${version} patch_command) + # 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} - GIT_SHALLOW ${shallow} - PATCH_COMMAND ${patch_command} EXCLUDE_FROM_ALL ${exclude}) + include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake") + rapids_cpm_generate_patch_command(${package_name} ${version} patch_command) + FetchContent_Declare(${package_name} + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + GIT_SHALLOW ${shallow} + PATCH_COMMAND ${patch_command} EXCLUDE_FROM_ALL ${exclude}) + endif() + endforeach() endif() endfunction() diff --git a/testing/cpm/cpm_init-override-multiple.cmake b/testing/cpm/cpm_init-override-multiple.cmake index e2007b6b..d6d0578a 100644 --- a/testing/cpm/cpm_init-override-multiple.cmake +++ b/testing/cpm/cpm_init-override-multiple.cmake @@ -15,6 +15,17 @@ #============================================================================= include(${rapids-cmake-dir}/cpm/init.cmake) +function(expect_fetch_content_details project expected) + string(TOLOWER ${project} project) + set(internal_fetch_content_var_name "_FetchContent_${project}_savedDetails") + get_property(exists GLOBAL PROPERTY ${internal_fetch_content_var_name} DEFINED) + if(expected AND NOT exists) + message(FATAL_ERROR "FetchContent expected ${project} doesn't match expected[${exists}!=${expected})") + elseif(NOT expected AND exists) + message(FATAL_ERROR "FetchContent expected ${project} doesn't match expected[${exists}!=${expected})") + endif() +endfunction() + rapids_cpm_init() # Load the default values for nvbench and GTest projects @@ -22,6 +33,10 @@ include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") rapids_cpm_package_details(nvbench nvbench_version nvbench_repository nvbench_tag nvbench_shallow nvbench_exclude) rapids_cpm_package_details(GTest GTest_version GTest_repository GTest_tag GTest_shallow GTest_exclude) +expect_fetch_content_details(nvbench NO) +expect_fetch_content_details(rmm NO) +expect_fetch_content_details(GTest NO) + # Need to write out an override file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json @@ -43,6 +58,10 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json ]=]) rapids_cpm_init(OVERRIDE "${CMAKE_CURRENT_BINARY_DIR}/override.json") +expect_fetch_content_details(nvbench YES) +expect_fetch_content_details(rmm YES) +expect_fetch_content_details(GTest YES) + # Verify that the override works rapids_cpm_package_details(nvbench version repository tag shallow exclude) diff --git a/testing/cpm/cpm_package_override-obey-cpm-source-var.cmake b/testing/cpm/cpm_package_override-obey-cpm-source-var.cmake index ab10e855..88ff69c9 100644 --- a/testing/cpm/cpm_package_override-obey-cpm-source-var.cmake +++ b/testing/cpm/cpm_package_override-obey-cpm-source-var.cmake @@ -29,7 +29,9 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json "exclude_from_all" : "ON" }, "not_in_base" : { + "version" : "1.0", "git_url" : "new_rmm_url", + "git_tag" : "main", "git_shallow" : "OFF", "exclude_from_all" : "ON" }