Skip to content

Commit

Permalink
Refactor rapids_export_post_find and rapids_export_find_package_root
Browse files Browse the repository at this point in the history
These commands now offer a syntax that allows termination
based on no export set being given, or a external condition
variable.
  • Loading branch information
robertmaynard committed Oct 3, 2023
1 parent c83904a commit ac69df5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 37 deletions.
12 changes: 4 additions & 8 deletions rapids-cmake/cpm/libcudacxx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions rapids-cmake/cpm/nvcomp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
16 changes: 6 additions & 10 deletions rapids-cmake/cpm/thrust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions rapids-cmake/export/detail/post_find_package_code.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ has ben found successfully.
rapids_export_post_find_package_code((BUILD|INSTALL)
<PackageName>
<code>
<ExportSet>
)
(<ExportSetName> | EXPORT_SET [ExportSetName])
[CONDITION <variableName>]
)
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
Expand All @@ -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 <name>`
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)
Expand Down
29 changes: 26 additions & 3 deletions rapids-cmake/export/find_package_root.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,7 +29,8 @@ needs to be set to the provided path.
rapids_export_find_package_root( (BUILD|INSTALL)
<PackageName>
<directory_path>
<ExportSet>
(<ExportSetName> | EXPORT_SET [ExportSetName])
[CONDITION <variableName>]
)
When constructing complicated export sets, espically ones that
Expand All @@ -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 <name>`
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)
Expand Down
14 changes: 6 additions & 8 deletions rapids-cmake/export/write_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion testing/export/write_dependencies-root-dirs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"]=])
Expand All @@ -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")

Expand Down

0 comments on commit ac69df5

Please sign in to comment.