diff --git a/rapids-cmake/cpm/init.cmake b/rapids-cmake/cpm/init.cmake index ead56cf9..7cd99f89 100644 --- a/rapids-cmake/cpm/init.cmake +++ b/rapids-cmake/cpm/init.cmake @@ -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 ``` @@ -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() diff --git a/rapids-cmake/cpm/package_override.cmake b/rapids-cmake/cpm/package_override.cmake index 4ccf8ce5..967c5be4 100644 --- a/rapids-cmake/cpm/package_override.cmake +++ b/rapids-cmake/cpm/package_override.cmake @@ -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:: @@ -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" ) diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 7b770a42..75441786 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -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 ) diff --git a/testing/cpm/cpm_package_override-multiple-cmake-var.cmake b/testing/cpm/cpm_package_override-multiple-cmake-var.cmake new file mode 100644 index 00000000..6c70e3d7 --- /dev/null +++ b/testing/cpm/cpm_package_override-multiple-cmake-var.cmake @@ -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()