From 5e356b03e56f63a52f18b36e37e63b681a398fe4 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 4 Nov 2024 16:56:18 -0500 Subject: [PATCH] command line overrides still allow rapids_cmake_override to work when they have no set intersection --- rapids-cmake/cpm/init.cmake | 10 ++- rapids-cmake/cpm/package_override.cmake | 14 ++-- testing/cpm/CMakeLists.txt | 1 + ..._package_override-multiple-cmake-var.cmake | 69 +++++++++++++++++++ 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 testing/cpm/cpm_package_override-multiple-cmake-var.cmake 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 9656335a..00f876c5 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -62,6 +62,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()