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..d06457e7 100644 --- a/rapids-cmake/cpm/nvcomp.cmake +++ b/rapids-cmake/cpm/nvcomp.cmake @@ -173,9 +173,8 @@ 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 1300708c..72e0a768 100644 --- a/rapids-cmake/cpm/thrust.cmake +++ b/rapids-cmake/cpm/thrust.cmake @@ -100,24 +100,20 @@ function(rapids_cpm_thrust NAMESPACE namespaces_name) set(post_find_code "if(NOT TARGET ${namespaces_name}::Thrust)" " thrust_create_target(${namespaces_name}::Thrust FROM_OPTIONS)" "endif()") - if(Thrust_SOURCE_DIR AND _RAPIDS_BUILD_EXPORT_SET) + 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_export_find_package_root(BUILD Thrust "${Thrust_SOURCE_DIR}/cmake" EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET}) - rapids_export_post_find_package_code(BUILD Thrust "${post_find_code}" + rapids_export_post_find_package_code(BUILD Thrust "${post_find_code}" EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET}) - endif() - if(Thrust_SOURCE_DIR AND _RAPIDS_INSTALL_EXPORT_SET AND to_install) - 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(INSTALL Thrust [=[${CMAKE_CURRENT_LIST_DIR}/../../rapids/cmake/thrust]=] - ${_RAPIDS_INSTALL_EXPORT_SET}) - rapids_export_post_find_package_code(INSTALL Thrust "${post_find_code}" - ${_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 diff --git a/rapids-cmake/export/detail/post_find_package_code.cmake b/rapids-cmake/export/detail/post_find_package_code.cmake index 3e212027..1f388f90 100644 --- a/rapids-cmake/export/detail/post_find_package_code.cmake +++ b/rapids-cmake/export/detail/post_find_package_code.cmake @@ -29,8 +29,9 @@ has ben found successfully. 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 @@ -47,11 +48,33 @@ instructions to execute in call order. 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 export_set) +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}) + # handle when we are given just an export set name and not `EXPORT_SET ` + if(_RAPIDS_UNPARSED_ARGUMENTS AND NOT _RAPIDS_COMPONENTS_EXPORT_SET) + 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..150901f2 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,33 @@ 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 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_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") + 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) + 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 afb91fd3..6080f481 100644 --- a/rapids-cmake/export/write_dependencies.cmake +++ b/rapids-cmake/export/write_dependencies.cmake @@ -89,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) 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")