diff --git a/cmake-format-rapids-cmake.json b/cmake-format-rapids-cmake.json index d57f9fa2..a508e44f 100644 --- a/cmake-format-rapids-cmake.json +++ b/cmake-format-rapids-cmake.json @@ -230,14 +230,22 @@ }, "rapids_export_find_package_file": { "pargs": { - "nargs": 3, + "nargs": "3+", "flags": ["INSTALL", "BUILD"] + }, + "kwargs": { + "EXPORT_SET": 1, + "CONDITION": 1 } }, "rapids_export_find_package_root": { "pargs": { - "nargs": 4, + "nargs": "3+", "flags": ["INSTALL", "BUILD"] + }, + "kwargs": { + "EXPORT_SET": 1, + "CONDITION": 1 } }, "rapids_export_package": { diff --git a/rapids-cmake/cpm/libcudacxx.cmake b/rapids-cmake/cpm/libcudacxx.cmake index 6279adf8..3b775d28 100644 --- a/rapids-cmake/cpm/libcudacxx.cmake +++ b/rapids-cmake/cpm/libcudacxx.cmake @@ -101,18 +101,14 @@ function(rapids_cpm_libcudacxx) set(multi_value) cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) - if(libcudacxx_SOURCE_DIR AND _RAPIDS_BUILD_EXPORT_SET) + if(libcudacxx_SOURCE_DIR) # Store where CMake can find our custom libcudacxx include("${rapids-cmake-dir}/export/find_package_root.cmake") - rapids_export_find_package_root(BUILD libcudacxx "${libcudacxx_SOURCE_DIR}/lib/cmake" - ${_RAPIDS_BUILD_EXPORT_SET}) - endif() - - if(libcudacxx_SOURCE_DIR AND to_install) - include("${rapids-cmake-dir}/export/find_package_root.cmake") + rapids_export_find_package_root(BUILD libcudacxx "${libcudacxx_SOURCE_DIR}/lib/cmake" FOR + EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET}) rapids_export_find_package_root(INSTALL libcudacxx [=[${CMAKE_CURRENT_LIST_DIR}/../../rapids/cmake/libcudacxx]=] - ${_RAPIDS_INSTALL_EXPORT_SET}) + EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET} CONDITION to_install) endif() # Propagate up variables that CPMFindPackage provide diff --git a/rapids-cmake/cpm/nvcomp.cmake b/rapids-cmake/cpm/nvcomp.cmake index eea96038..4f8c669b 100644 --- a/rapids-cmake/cpm/nvcomp.cmake +++ b/rapids-cmake/cpm/nvcomp.cmake @@ -173,9 +173,9 @@ function(rapids_cpm_nvcomp) install(FILES "${nvcomp_ROOT}/LICENSE" DESTINATION info/ RENAME NVCOMP_LICENSE) endif() - if(_RAPIDS_BUILD_EXPORT_SET AND nvcomp_proprietary_binary) - # point our consumers to where they can find the pre-built version - rapids_export_find_package_root(BUILD nvcomp "${nvcomp_ROOT}" ${_RAPIDS_BUILD_EXPORT_SET}) - endif() + # point our consumers to where they can find the pre-built version + rapids_export_find_package_root(BUILD nvcomp "${nvcomp_ROOT}" + EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET} + CONDITION nvcomp_proprietary_binary) endfunction() diff --git a/rapids-cmake/cpm/thrust.cmake b/rapids-cmake/cpm/thrust.cmake index 7e9f923c..04d453b1 100644 --- a/rapids-cmake/cpm/thrust.cmake +++ b/rapids-cmake/cpm/thrust.cmake @@ -40,6 +40,13 @@ across all RAPIDS projects. .. |PKG_NAME| replace:: Thrust .. include:: common_package_args.txt +.. versionadded:: v23.12.00 + When `BUILD_EXPORT_SET` is specified the generated build export set dependency + file will automatically call `thrust_create_target(::Thrust FROM_OPTIONS)`. + + When `INSTALL_EXPORT_SET` is specified the generated install export set dependency + file will automatically call `thrust_create_target(::Thrust FROM_OPTIONS)`. + Result Targets ^^^^^^^^^^^^^^ ::Thrust target will be created @@ -90,18 +97,23 @@ function(rapids_cpm_thrust NAMESPACE namespaces_name) set(multi_value) cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) - if(Thrust_SOURCE_DIR AND _RAPIDS_BUILD_EXPORT_SET) + set(post_find_code "if(NOT TARGET ${namespaces_name}::Thrust)" + " thrust_create_target(${namespaces_name}::Thrust FROM_OPTIONS)" "endif()") + + if(Thrust_SOURCE_DIR) # Store where CMake can find the Thrust-config.cmake that comes part of Thrust source code include("${rapids-cmake-dir}/export/find_package_root.cmake") + include("${rapids-cmake-dir}/export/detail/post_find_package_code.cmake") rapids_export_find_package_root(BUILD Thrust "${Thrust_SOURCE_DIR}/cmake" - ${_RAPIDS_BUILD_EXPORT_SET}) - endif() + EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET}) + rapids_export_post_find_package_code(BUILD Thrust "${post_find_code}" EXPORT_SET + ${_RAPIDS_BUILD_EXPORT_SET}) - if(Thrust_SOURCE_DIR AND _RAPIDS_INSTALL_EXPORT_SET AND to_install) - include("${rapids-cmake-dir}/export/find_package_root.cmake") rapids_export_find_package_root(INSTALL Thrust [=[${CMAKE_CURRENT_LIST_DIR}/../../rapids/cmake/thrust]=] - ${_RAPIDS_INSTALL_EXPORT_SET}) + EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET} CONDITION to_install) + rapids_export_post_find_package_code(INSTALL Thrust "${post_find_code}" EXPORT_SET + ${_RAPIDS_INSTALL_EXPORT_SET} CONDITION to_install) endif() # Check for the existence of thrust_create_target so we support fetching Thrust with DOWNLOAD_ONLY @@ -113,26 +125,6 @@ function(rapids_cpm_thrust NAMESPACE namespaces_name) endif() endif() - # Since `GLOBAL_TARGET ${namespaces_name}::Thrust` will list the target to be promoted to global - # by `rapids_export` this will break consumers as the target doesn't exist when generating the - # dependencies.cmake file, but requires a call to `thrust_create_target` - # - # So determine what `BUILD_EXPORT_SET` and `INSTALL_EXPORT_SET` this was added to and remove - # ${namespaces_name}::Thrust - if(_RAPIDS_BUILD_EXPORT_SET) - set(target_name rapids_export_build_${_RAPIDS_BUILD_EXPORT_SET}) - get_target_property(global_targets ${target_name} GLOBAL_TARGETS) - list(REMOVE_ITEM global_targets "${namespaces_name}::Thrust") - set_target_properties(${target_name} PROPERTIES GLOBAL_TARGETS "${global_targets}") - endif() - - if(_RAPIDS_INSTALL_EXPORT_SET) - set(target_name rapids_export_install_${_RAPIDS_INSTALL_EXPORT_SET}) - get_target_property(global_targets ${target_name} GLOBAL_TARGETS) - list(REMOVE_ITEM global_targets "${namespaces_name}::Thrust") - set_target_properties(${target_name} PROPERTIES GLOBAL_TARGETS "${global_targets}") - endif() - # Propagate up variables that CPMFindPackage provide set(Thrust_SOURCE_DIR "${Thrust_SOURCE_DIR}" PARENT_SCOPE) set(Thrust_BINARY_DIR "${Thrust_BINARY_DIR}" PARENT_SCOPE) diff --git a/rapids-cmake/export/detail/post_find_package_code.cmake b/rapids-cmake/export/detail/post_find_package_code.cmake new file mode 100644 index 00000000..dc44630a --- /dev/null +++ b/rapids-cmake/export/detail/post_find_package_code.cmake @@ -0,0 +1,84 @@ +#============================================================================= +# Copyright (c) 2023, 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_guard(GLOBAL) + +#[=======================================================================[.rst: +rapids_export_post_find_package_code +------------------------------------ + +.. versionadded:: v23.12.00 + +Record for a set of CMake instructions to be executed after the package +has been found successfully. + +.. code-block:: cmake + + rapids_export_post_find_package_code((BUILD|INSTALL) + + + EXPORT_SET [ExportSetName] + [CONDITION ] + ) + +When using complicated find modules like `Thrust` you might need to run some code after +execution. Multiple calls to :cmake:command:`rapids_export_post_find_package_code` will append the +instructions to execute in call order. + +.. note: + The code will only be run if the package was found + +``BUILD`` + Record code to be executed immediately after `PackageName` has been found + for our our build directory export set. + +``INSTALL`` + Record code to be executed immediately after `PackageName` has been found + for our our install directory export set. + +``EXPORT_SET`` + List the export set name that this code should be attached too. If + no name is given the associated call will be ignored. + +``CONDITION`` + A boolean variable name, that when evaluates to undefined or a false value + will cause the associated call to be ignored. + +#]=======================================================================] +function(rapids_export_post_find_package_code type name code) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.export.post_find_package_code") + + set(options "") + set(one_value EXPORT_SET CONDITION) + set(multi_value "") + cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) + # Early terminate conditions + if(NOT _RAPIDS_EXPORT_SET OR NOT ${_RAPIDS_CONDITION}) + return() + endif() + + string(TOLOWER ${type} type) + set(export_set ${_RAPIDS_EXPORT_SET}) + + if(NOT TARGET rapids_export_${type}_${export_set}) + add_library(rapids_export_${type}_${export_set} INTERFACE) + endif() + + # if the code coming in is a list of string we will have `;`, so transform those to "\n" so we + # have a single string + string(REPLACE ";" "\n" code "${code}") + set_property(TARGET rapids_export_${type}_${export_set} APPEND_STRING + PROPERTY "${name}_POST_FIND_CODE" "${code}\n") +endfunction() diff --git a/rapids-cmake/export/find_package_file.cmake b/rapids-cmake/export/find_package_file.cmake index ed997885..c4b93257 100644 --- a/rapids-cmake/export/find_package_file.cmake +++ b/rapids-cmake/export/find_package_file.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,7 +28,8 @@ the associated export set. rapids_export_find_package_file( (BUILD|INSTALL) - + ( | EXPORT_SET [ExportSetName]) + [CONDITION ] ) When constructing export sets, espically installed ones it is @@ -50,11 +51,38 @@ rapids-cmake to ensure it is installed correct and added to of our install export set. This means that it will be installed as part of our packages CMake export set infrastructure +``EXPORT_SET`` + List the export set name that this code should be attached too. If + no name is given the associated call will be ignored. + +``CONDITION`` + A boolean variable name, that when evaluates to undefined or a false value + will cause the associated call to be ignored. + #]=======================================================================] -function(rapids_export_find_package_file type file_path export_set) +function(rapids_export_find_package_file type file_path) list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.export.find_package_file") + include("${rapids-cmake-dir}/cmake/detail/policy.cmake") + + set(options "") + set(one_value EXPORT_SET CONDITION) + set(multi_value "") + cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) + # handle when we are given just an export set name and not `EXPORT_SET ` + if(_RAPIDS_UNPARSED_ARGUMENTS AND NOT _RAPIDS_COMPONENTS_EXPORT_SET) + rapids_cmake_policy(DEPRECATED_IN 23.12 + REMOVED_IN 24.02 + MESSAGE [=[Usage of `rapids_export_find_package_file` without an explicit `EXPORT_SET` key has been deprecated.]=] + ) + set(_RAPIDS_EXPORT_SET ${_RAPIDS_UNPARSED_ARGUMENTS}) + endif() + # Early terminate conditions + if(NOT _RAPIDS_EXPORT_SET OR NOT ${_RAPIDS_CONDITION}) + return() + endif() string(TOLOWER ${type} type) + set(export_set ${_RAPIDS_EXPORT_SET}) if(NOT TARGET rapids_export_${type}_${export_set}) add_library(rapids_export_${type}_${export_set} INTERFACE) diff --git a/rapids-cmake/export/find_package_root.cmake b/rapids-cmake/export/find_package_root.cmake index e924084b..71deffa3 100644 --- a/rapids-cmake/export/find_package_root.cmake +++ b/rapids-cmake/export/find_package_root.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,7 +29,8 @@ needs to be set to the provided path. rapids_export_find_package_root( (BUILD|INSTALL) - + ( | EXPORT_SET [ExportSetName]) + [CONDITION ] ) When constructing complicated export sets, espically ones that @@ -47,11 +48,38 @@ will find the packaged dependency. before any find_dependency calls for `PackageName` for our install directory export set. +``EXPORT_SET`` + List the export set name that the `directory_path` should be attached too. If + no name is given the associated call will be ignored. + +``CONDITION`` + A boolean variable name, that when evaluates to undefined or a false value + will cause the associated call to be ignored. + #]=======================================================================] -function(rapids_export_find_package_root type name dir_path export_set) +function(rapids_export_find_package_root type name dir_path) list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.export.find_package_root_dir") + include("${rapids-cmake-dir}/cmake/detail/policy.cmake") + + set(options "") + set(one_value EXPORT_SET CONDITION) + set(multi_value "") + cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) + # handle when we are given just an export set name and not `EXPORT_SET ` + if(_RAPIDS_UNPARSED_ARGUMENTS AND NOT _RAPIDS_COMPONENTS_EXPORT_SET) + rapids_cmake_policy(DEPRECATED_IN 23.12 + REMOVED_IN 24.02 + MESSAGE [=[Usage of `rapids_export_find_package_root` without an explicit `EXPORT_SET` key has been deprecated.]=] + ) + set(_RAPIDS_EXPORT_SET ${_RAPIDS_UNPARSED_ARGUMENTS}) + endif() + # Early terminate conditions + if(NOT _RAPIDS_EXPORT_SET OR NOT ${_RAPIDS_CONDITION}) + return() + endif() string(TOLOWER ${type} type) + set(export_set ${_RAPIDS_EXPORT_SET}) if(NOT TARGET rapids_export_${type}_${export_set}) add_library(rapids_export_${type}_${export_set} INTERFACE) diff --git a/rapids-cmake/export/write_dependencies.cmake b/rapids-cmake/export/write_dependencies.cmake index 4f90b2d7..6080f481 100644 --- a/rapids-cmake/export/write_dependencies.cmake +++ b/rapids-cmake/export/write_dependencies.cmake @@ -42,6 +42,7 @@ a given export_set for the requested mode. CMake config module. #]=======================================================================] +# cmake-lint: disable=R0915 function(rapids_export_write_dependencies type export_set file_path) list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.export.write_dependencies") @@ -88,14 +89,12 @@ endif()\n") endif() endif() - if(find_root_dirs) - foreach(package IN LISTS find_root_dirs) - get_property(root_dir_path TARGET rapids_export_${type}_${export_set} - PROPERTY "FIND_ROOT_FOR_${package}") - set(dep_content "set(${package}_ROOT \"${root_dir_path}\")") - string(APPEND _RAPIDS_EXPORT_CONTENTS "${dep_content}\n") - endforeach() - endif() + foreach(package IN LISTS find_root_dirs) + get_property(root_dir_path TARGET rapids_export_${type}_${export_set} + PROPERTY "FIND_ROOT_FOR_${package}") + set(dep_content "set(${package}_ROOT \"${root_dir_path}\")") + string(APPEND _RAPIDS_EXPORT_CONTENTS "${dep_content}\n") + endforeach() if(find_modules) cmake_path(GET file_path PARENT_PATH find_module_dest) @@ -116,6 +115,12 @@ endif()\n") file(READ "${dep_dir}/package_${dep}.cmake" dep_content) endif() string(APPEND _RAPIDS_EXPORT_CONTENTS "${dep_content}\n") + + get_property(post_find_code TARGET rapids_export_${type}_${export_set} + PROPERTY "${dep}_POST_FIND_CODE") + if(post_find_code) + string(APPEND _RAPIDS_EXPORT_CONTENTS "if(${dep}_FOUND)\n${post_find_code}\nendif()\n") + endif() endforeach() string(APPEND _RAPIDS_EXPORT_CONTENTS "\n") diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index c570d5c1..fd5112f8 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -88,3 +88,4 @@ add_cmake_config_test( cpm_spdlog-simple.cmake ) add_cmake_config_test( cpm_thrust-export.cmake ) add_cmake_config_test( cpm_thrust-simple.cmake ) +add_cmake_build_test( cpm_thrust-verify-post-find-code ) diff --git a/testing/cpm/cpm_thrust-export.cmake b/testing/cpm/cpm_thrust-export.cmake index 1727b374..5a7dae77 100644 --- a/testing/cpm/cpm_thrust-export.cmake +++ b/testing/cpm/cpm_thrust-export.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,13 +30,3 @@ get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES) if(NOT Thrust IN_LIST packages) message(FATAL_ERROR "rapids_cpm_thrust failed to record thrust needs to be exported") endif() - -get_target_property(packages rapids_export_build_test GLOBAL_TARGETS) -if(A::Thrust IN_LIST packages) - message(FATAL_ERROR "rapids_cpm_thrust incorrectly added A::Thrust to build GLOBAL_TARGETS") -endif() - -get_target_property(packages rapids_export_install_test2 GLOBAL_TARGETS) -if(B::Thrust IN_LIST packages) - message(FATAL_ERROR "rapids_cpm_thrust incorrectly added B::Thrust to install GLOBAL_TARGETS") -endif() diff --git a/testing/cpm/cpm_thrust-verify-post-find-code/CMakeLists.txt b/testing/cpm/cpm_thrust-verify-post-find-code/CMakeLists.txt new file mode 100644 index 00000000..50451a4a --- /dev/null +++ b/testing/cpm/cpm_thrust-verify-post-find-code/CMakeLists.txt @@ -0,0 +1,63 @@ +#============================================================================= +# Copyright (c) 2023, 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. +#============================================================================= +cmake_minimum_required(VERSION 3.23.1) +project(rapids-test-project LANGUAGES CXX) + +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/thrust.cmake) +include(${rapids-cmake-dir}/export/export.cmake) + +set(CMAKE_INSTALL_LIBDIR "lib") + +rapids_cpm_init() + +rapids_cpm_thrust(NAMESPACE RapidsTest + GLOBAL_TARGETS RapidsTest::Thrust + INSTALL_EXPORT_SET example_export_set) + +add_library(fakeLib INTERFACE) +install(TARGETS fakeLib EXPORT example_export_set) +target_link_libraries(fakeLib INTERFACE RapidsTest::Thrust) + +rapids_export(INSTALL fake + EXPORT_SET example_export_set + NAMESPACE test:: + ) + +# Install our project so we can verify `thrust_create_target` is called +# automatically in the export-set +add_custom_target(install_project ALL + COMMAND ${CMAKE_COMMAND} --install "${CMAKE_BINARY_DIR}" --prefix install/fake/ + ) + +# Add a custom command that verifies that the expect files have +# been installed for each component +file(WRITE "${CMAKE_BINARY_DIR}/install/CMakeLists.txt" [=[ +cmake_minimum_required(VERSION 3.20) +project(verify_install_targets LANGUAGES CXX) + +set(computed_path "${CMAKE_CURRENT_SOURCE_DIR}/fake/lib/cmake/fake/") +find_package(fake REQUIRED NO_DEFAULT_PATH HINTS ${computed_path}) +if(NOT TARGET RapidsTest::Thrust) + message(FATAL_ERROR "Failed to construct RapidsTest::Thrust target") +endif() +]=]) + +add_custom_target(verify_install_thrust_works ALL + COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/install/build" + COMMAND ${CMAKE_COMMAND} -S="${CMAKE_BINARY_DIR}/install" -B="${CMAKE_BINARY_DIR}/install/build" +) +add_dependencies(verify_install_thrust_works install_project) diff --git a/testing/export/CMakeLists.txt b/testing/export/CMakeLists.txt index 78d48dc0..4f36b3ae 100644 --- a/testing/export/CMakeLists.txt +++ b/testing/export/CMakeLists.txt @@ -48,16 +48,18 @@ add_cmake_config_test( export-verify-version.cmake ) add_cmake_config_test( export_component-build ) add_cmake_config_test( export_package-build-possible-dir.cmake ) -add_cmake_config_test( export_package-build-with-components.cmake ) +add_cmake_config_test( export_package-build-post-find-code.cmake ) add_cmake_config_test( export_package-build-with-components-and-version.cmake ) +add_cmake_config_test( export_package-build-with-components.cmake ) add_cmake_config_test( export_package-build-with-empty-components.cmake ) add_cmake_config_test( export_package-build-with-version.cmake ) add_cmake_config_test( export_package-build.cmake ) add_cmake_config_test( export_package-install-possible-dir.cmake ) -add_cmake_config_test( export_package-install.cmake ) -add_cmake_config_test( export_package-install-with-components.cmake ) +add_cmake_config_test( export_package-install-post-find-code.cmake ) add_cmake_config_test( export_package-install-with-components-and-version.cmake ) +add_cmake_config_test( export_package-install-with-components.cmake ) add_cmake_config_test( export_package-install-with-version.cmake ) +add_cmake_config_test( export_package-install.cmake ) add_cmake_config_test( export_package-multiple-export_sets.cmake ) add_cmake_config_test( write_dependencies-cpm-preserve-options.cmake ) @@ -69,3 +71,7 @@ add_cmake_config_test( write_dependencies-root-dirs.cmake ) add_cmake_build_test( write_language-multiple-nested-enables ) add_cmake_build_test( write_language-nested-dirs ) + +set(deprecated_message [=[rapids-cmake policy [deprecated=23.12 removed=24.02]: Usage of ]=]) +add_cmake_config_test( find_package_file-deprecated.cmake SHOULD_FAIL "${deprecated_message}") +add_cmake_config_test( find_package_root-deprecated.cmake SHOULD_FAIL "${deprecated_message}") diff --git a/testing/export/export_package-build-post-find-code.cmake b/testing/export/export_package-build-post-find-code.cmake new file mode 100644 index 00000000..0d88e964 --- /dev/null +++ b/testing/export/export_package-build-post-find-code.cmake @@ -0,0 +1,38 @@ +#============================================================================= +# Copyright (c) 2023, 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}/export/package.cmake) +include(${rapids-cmake-dir}/export/detail/post_find_package_code.cmake) + +rapids_export_package( BUILD FAKE_PACKAGE test_export_set VERSION 22.08) +rapids_export_post_find_package_code( BUILD FAKE_PACKAGE "set(a ON)" EXPORT_SET test_export_set) +rapids_export_post_find_package_code( bUILd FAKE_PACKAGE +[=[ +set(b ON) +set(c ON)]=] EXPORT_SET test_export_set) +rapids_export_post_find_package_code(build FAKE_PACKAGE "set(d ON);set(e ON)" EXPORT_SET test_export_set) + +include(${rapids-cmake-dir}/export/write_dependencies.cmake) +rapids_export_write_dependencies(BUILD test_export_set "${CMAKE_CURRENT_BINARY_DIR}/install_export_set.cmake") + +set(to_match [=[if(FAKE_PACKAGE_FOUND)_set(a ON)_set(b ON)_set(c ON)_set(d ON)_set(e ON)__endif()]=]) + +file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/install_export_set.cmake" contents NEWLINE_CONSUME) +string(REPLACE "\n" "_" contents "${contents}") + +string(FIND "${contents}" "${to_match}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_write_dependencies(BUILD) failed to record rapids_export_post_find_package_code") +endif() diff --git a/testing/export/export_package-install-post-find-code.cmake b/testing/export/export_package-install-post-find-code.cmake new file mode 100644 index 00000000..094c7b7f --- /dev/null +++ b/testing/export/export_package-install-post-find-code.cmake @@ -0,0 +1,39 @@ +#============================================================================= +# Copyright (c) 2023, 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}/export/package.cmake) +include(${rapids-cmake-dir}/export/detail/post_find_package_code.cmake) + +rapids_export_package(INSTALL FAKE_PACKAGE test_export_set VERSION 22.08) +rapids_export_post_find_package_code(INSTALL FAKE_PACKAGE "set(a ON)" EXPORT_SET test_export_set) + +get_target_property(install_code rapids_export_install_test_export_set FAKE_PACKAGE_POST_FIND_CODE) +cmake_language(EVAL CODE "${install_code}") +if(NOT a) + message(FATAL_ERROR "rapids_export_post_find_package_code failed to record first call") +endif() + +include(${rapids-cmake-dir}/export/write_dependencies.cmake) +rapids_export_write_dependencies(INSTALL test_export_set "${CMAKE_CURRENT_BINARY_DIR}/install_export_set.cmake") + +set(to_match [=[if(FAKE_PACKAGE_FOUND)_set(a ON)__endif()]=]) + +file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/install_export_set.cmake" contents NEWLINE_CONSUME) +string(REPLACE "\n" "_" contents "${contents}") + +string(FIND "${contents}" "${to_match}" is_found) +if(is_found EQUAL -1) + message(FATAL_ERROR "rapids_export_write_dependencies(INSTALL) failed to record rapids_export_post_find_package_code") +endif() diff --git a/testing/export/find_package_file-deprecated.cmake b/testing/export/find_package_file-deprecated.cmake new file mode 100644 index 00000000..64da1dd5 --- /dev/null +++ b/testing/export/find_package_file-deprecated.cmake @@ -0,0 +1,20 @@ +#============================================================================= +# Copyright (c) 2023, 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}/export/find_package_file.cmake) + +project(rapids-project LANGUAGES CUDA) +set(CMAKE_ERROR_DEPRECATED ON) +rapids_export_find_package_file(BUILD [=[${CMAKE_CURRENT_LIST_DIR}/fake/build/path]=] test_set) diff --git a/testing/export/find_package_root-deprecated.cmake b/testing/export/find_package_root-deprecated.cmake new file mode 100644 index 00000000..8e635fa1 --- /dev/null +++ b/testing/export/find_package_root-deprecated.cmake @@ -0,0 +1,20 @@ +#============================================================================= +# Copyright (c) 2023, 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}/export/find_package_root.cmake) + +project(rapids-project LANGUAGES CUDA) +set(CMAKE_ERROR_DEPRECATED ON) +rapids_export_find_package_root(BUILD RMM [=[${CMAKE_CURRENT_LIST_DIR}/fake/build/path]=] test_set) diff --git a/testing/export/write_dependencies-root-dirs.cmake b/testing/export/write_dependencies-root-dirs.cmake index a3f5ea36..80655203 100644 --- a/testing/export/write_dependencies-root-dirs.cmake +++ b/testing/export/write_dependencies-root-dirs.cmake @@ -19,6 +19,9 @@ include(${rapids-cmake-dir}/export/write_dependencies.cmake) rapids_export_find_package_root(BUILD RMM [=[${CMAKE_CURRENT_LIST_DIR}/fake/build/path]=] test_set) rapids_export_write_dependencies(build test_set "${CMAKE_CURRENT_BINARY_DIR}/build_export_set.cmake") +rapids_export_find_package_root(BUILD RMM "/bad/install/path" EXPORT_SET ${unknown_var}) #ignored +rapids_export_find_package_root(BUILD RMM "/bad/install/path2" EXPORT_SET test_set CONDITION unknown_var) #ignored + # Parse the `build_export_set.cmake` file for correct escaped args # to `rapids_export_find_package_root` calls set(build_to_match_string [=[set(RMM_ROOT "${CMAKE_CURRENT_LIST_DIR}/fake/build/path"]=]) @@ -28,8 +31,11 @@ if(is_found EQUAL -1) message(FATAL_ERROR "rapids_export_write_dependencies(BUILD) failed to preserve variables in the directory path to rapids_export_find_package_root") endif() -rapids_export_find_package_root(install RMM "/first/install/path" test_set) +rapids_export_find_package_root(install RMM "/first/install/path" EXPORT_SET test_set) rapids_export_find_package_root(INSTALL RMM "/second/install/path" test_set) +set(to_install FALSE) +rapids_export_find_package_root(INSTALL RMM "/bad/install/path" EXPORT_SET test_set CONDITION to_install) #ignored + rapids_export_find_package_root(install PKG2 "/pkg2/install/path" test_set) rapids_export_write_dependencies(INSTALL test_set "${CMAKE_CURRENT_BINARY_DIR}/install_export_set.cmake")