Skip to content

Commit

Permalink
Resolve long standing bug where rapids-cmake overrides kept applying
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Nov 4, 2024
1 parent 03ec7ef commit 89019b6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
52 changes: 27 additions & 25 deletions rapids-cmake/cpm/package_override.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,34 @@ function(rapids_cpm_package_override _rapids_override_filepath)
# cmake-lint: disable=E1120
foreach(index RANGE ${package_count})
string(JSON package_name MEMBER "${json_data}" packages ${index})
get_property(override_exists GLOBAL PROPERTY rapids_cpm_${package_name}_override_json DEFINED)
if(NOT (override_exists OR DEFINED CPM_${package_name}_SOURCE))
# only add the first override for a project we encounter
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
"${_rapids_override_filepath}")

# 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)

unset(exclude_from_all)
if(exclude AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.28.0)
set(exclude_from_all EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(${package_name}
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow}
${patch_command} ${exclude_from_all})
get_property(override_exists GLOBAL PROPERTY rapids_cpm_${package_name}_override_json SET)
if(override_exists OR DEFINED CPM_${package_name}_SOURCE)
continue()
endif()

# only add the first override for a project we encounter
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
"${_rapids_override_filepath}")

# 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)

unset(exclude_from_all)
if(exclude AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.28.0)
set(exclude_from_all EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(${package_name}
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow}
${patch_command} ${exclude_from_all})
endforeach()
endif()
endfunction()
2 changes: 1 addition & 1 deletion testing/cpm/cpm_init-override-multiple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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)
get_property(exists GLOBAL PROPERTY ${internal_fetch_content_var_name} SET)
if(expected AND NOT exists)
message(FATAL_ERROR "FetchContent expected ${project} doesn't match expected[${exists}!=${expected})")
elseif(NOT expected AND exists)
Expand Down
4 changes: 2 additions & 2 deletions testing/cpm/cpm_package_override-multiple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ if(NOT tag STREQUAL "my_tag")
endif()

rapids_cpm_package_details(GTest version repository tag shallow exclude)
if(NOT version STREQUAL "3.99")
if(NOT version STREQUAL "2.99")
message(FATAL_ERROR "custom version field was removed. ${version} was found instead")
endif()
if(NOT tag MATCHES "3.99")
if(NOT tag MATCHES "2.99")
message(FATAL_ERROR "custom version field not used when computing git_tag value. ${tag} was found instead")
endif()

Expand Down

0 comments on commit 89019b6

Please sign in to comment.