Skip to content

Commit

Permalink
multiple entry overrides now sets FetchContent for all entries (#494)
Browse files Browse the repository at this point in the history
FetchContent was previously only called for the last entry.

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #494
  • Loading branch information
robertmaynard authored Dec 18, 2023
1 parent 252150a commit 7d2b702
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
27 changes: 13 additions & 14 deletions rapids-cmake/cpm/package_override.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
19 changes: 19 additions & 0 deletions testing/cpm/cpm_init-override-multiple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,28 @@
#=============================================================================
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
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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions testing/cpm/cpm_package_override-obey-cpm-source-var.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 7d2b702

Please sign in to comment.