Skip to content

Commit

Permalink
command line overrides still allow rapids_cmake_override to work when…
Browse files Browse the repository at this point in the history
… they have no set intersection
  • Loading branch information
robertmaynard committed Nov 5, 2024
1 parent 39ec6f2 commit 0f45eec
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
10 changes: 7 additions & 3 deletions rapids-cmake/cpm/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ in the build tree of the calling project
.. versionadded:: v24.06.00
If the variable :cmake:variable:`RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE` is specified it will be used
in all calls to ``rapids_cpm_init``. Any existing explicit `OVERRIDE` files will be ignored, and
all other calls will be treated as if this file was specified as the override.
in all calls to ``rapids_cpm_init`` no matter the arguments. Any existing
``rapids_cpm_init(OVERRIDE` files will be ignored, and all other calls will be treated as if this file was specified
as the override.
.. versionadded:: v24.04.00
```
Expand Down Expand Up @@ -118,7 +119,10 @@ function(rapids_cpm_init)
rapids_cpm_load_preset_versions()
endif()

if(_RAPIDS_OVERRIDE OR RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE)
if(RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE)
include("${rapids-cmake-dir}/cpm/package_override.cmake")
rapids_cpm_package_override("${RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE}")
elseif(_RAPIDS_OVERRIDE)
include("${rapids-cmake-dir}/cpm/package_override.cmake")
rapids_cpm_package_override("${_RAPIDS_OVERRIDE}")
endif()
Expand Down
14 changes: 4 additions & 10 deletions rapids-cmake/cpm/package_override.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ for that project will occur. This is done to make sure that the requested modifi
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"
and all later calls for that package will be ignored. This "first to record, wins"
approach is used to match FetchContent, and allows parent projects to override child
projects.
.. versionadded:: v24.06.00
If the variable :cmake:variable:`RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE` is specified it will be used
in all calls to ``rapids_cpm_init``. Any existing explicit `OVERRIDE` files will be ignored, and
all other calls will be treated as if this file was specified as the override.
in all calls to ``rapids_cpm_init`` no matter the arguments. Any existing
``rapids_cpm_init(OVERRIDE` files will be ignored, and all other calls will be treated as if this file was specified
as the override.
.. note::
Expand All @@ -72,12 +72,6 @@ all other calls will be treated as if this file was specified as the override.
function(rapids_cpm_package_override _rapids_override_filepath)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rapids_cpm_package_override")

# The `RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE` must be loaded instead of any explicit file path
# when it is set
if(DEFINED RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE)
set(_rapids_override_filepath "${RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE}")
endif()

if(NOT EXISTS "${_rapids_override_filepath}")
message(FATAL_ERROR "rapids_cpm_package_override can't load '${_rapids_override_filepath}', verify it exists"
)
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ add_cmake_config_test( cpm_package_override-defaults-with-different-casing-warni
add_cmake_config_test( cpm_package_override-empty-patches.cmake )
add_cmake_config_test( cpm_package_override-empty.cmake )
add_cmake_config_test( cpm_package_override-env-var-support.cmake )
add_cmake_config_test( cpm_package_override-multiple-cmake-var.cmake )
add_cmake_config_test( cpm_package_override-multiple.cmake )
add_cmake_config_test( cpm_package_override-no-version-value.cmake SHOULD_FAIL "rapids_cmake can't parse")
add_cmake_config_test( cpm_package_override-obey-cpm-source-var.cmake )
Expand Down
69 changes: 69 additions & 0 deletions testing/cpm/cpm_package_override-multiple-cmake-var.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#=============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/package_override.cmake)

# Need to write out an override file
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override1.json
[=[
{
"packages": {
"nvbench": {
"git_tag": "my_tag"
},
"gtest": {
"version": "2.99"
}
}
}
]=])

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override2.json
[=[
{
"packages": {
"rmm": {
"git_tag": "new_rmm_tag"
},
"GTest": {
"version": "3.99"
}
}
}
]=])

set(RAPIDS_CMAKE_CPM_OVERRIDE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/override1.json")
rapids_cpm_init()
rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override2.json)

# Verify that the override works
rapids_cpm_package_details(nvbench version repository tag shallow exclude)
if(NOT tag STREQUAL "my_tag")
message(FATAL_ERROR "custom git_tag field was ignored. ${tag} found instead of my_url")
endif()

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

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

0 comments on commit 0f45eec

Please sign in to comment.