From f87323c30c7fa37b53707e98a8007cc422d5bd5e Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 18 Jan 2023 14:54:11 -0500 Subject: [PATCH] Use rapids-cmake new COMPONENT exporting feature --- cpp/CMakeLists.txt | 68 +++---- cpp/cmake/modules/config.cmake.in | 123 ------------- cpp/cmake/modules/raft_export.cmake | 265 ---------------------------- fetch_rapids.cmake | 3 + 4 files changed, 26 insertions(+), 433 deletions(-) delete mode 100644 cpp/cmake/modules/config.cmake.in delete mode 100644 cpp/cmake/modules/raft_export.cmake diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 784bbbb935..603749eec7 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -555,45 +555,6 @@ install( DESTINATION include/raft ) -# ################################################################################################## -# * export/install optional components -------------------------------------- - -include("${rapids-cmake-dir}/export/write_dependencies.cmake") - -set(raft_components distance nn distributed) -set(raft_install_comp raft raft raft) -if(TARGET raft_distance_lib) - list(APPEND raft_components distance-lib) - list(APPEND raft_install_comp distance) -endif() -if(TARGET raft_nn_lib) - list(APPEND raft_components nn-lib) - list(APPEND raft_install_comp nn) -endif() - -foreach(comp install_comp IN ZIP_LISTS raft_components raft_install_comp) - install( - EXPORT raft-${comp}-exports - FILE raft-${comp}-targets.cmake - NAMESPACE raft:: - DESTINATION "${lib_dir}/cmake/raft" - COMPONENT ${install_comp} - ) - export( - EXPORT raft-${comp}-exports - FILE ${RAFT_BINARY_DIR}/raft-${comp}-targets.cmake - NAMESPACE raft:: - ) - rapids_export_write_dependencies( - BUILD raft-${comp}-exports "${PROJECT_BINARY_DIR}/raft-${comp}-dependencies.cmake" - ) - rapids_export_write_dependencies( - INSTALL raft-${comp}-exports - "${PROJECT_BINARY_DIR}/rapids-cmake/raft/export/${install_comp}/raft-${comp}-dependencies.cmake" - ) - -endforeach() - # ################################################################################################## # * install export ----------------------------------------------------------- set(doc_string @@ -651,17 +612,34 @@ endif() ]=] ) -# Use `rapids_export` for 22.04 as it will have COMPONENT support -include(cmake/modules/raft_export.cmake) -raft_export( - INSTALL raft COMPONENTS nn distance distributed EXPORT_SET raft-exports GLOBAL_TARGETS raft nn +set(raft_components distance nn distributed) +set(raft_export_sets raft-distance-exports raft-nn-exports raft-distributed-exports) +if(TARGET raft_distance_lib) + list(APPEND raft_components distance) + list(APPEND raft_export_sets raft-distance-lib-exports) +endif() +if(TARGET raft_nn_lib) + list(APPEND raft_components nn) + list(APPEND raft_export_sets raft-nn-lib-exports) +endif() + +rapids_export( + INSTALL raft + EXPORT_SET raft-exports + COMPONENTS ${raft_components} + COMPONENTS_EXPORT_SET ${raft_export_sets} + GLOBAL_TARGETS raft nn distance distributed NAMESPACE raft:: DOCUMENTATION doc_string FINAL_CODE_BLOCK code_string ) # ################################################################################################## # * build export ------------------------------------------------------------- -raft_export( - BUILD raft EXPORT_SET raft-exports COMPONENTS nn distance distributed GLOBAL_TARGETS raft +rapids_export( + BUILD raft + EXPORT_SET raft-exports + COMPONENTS ${raft_components} + COMPONENTS_EXPORT_SET ${raft_export_sets} + GLOBAL_TARGETS raft distance distributed nn DOCUMENTATION doc_string NAMESPACE raft:: FINAL_CODE_BLOCK code_string ) diff --git a/cpp/cmake/modules/config.cmake.in b/cpp/cmake/modules/config.cmake.in deleted file mode 100644 index 4895a3baac..0000000000 --- a/cpp/cmake/modules/config.cmake.in +++ /dev/null @@ -1,123 +0,0 @@ -#============================================================================= -# Copyright (c) 2021, 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. -#============================================================================= - -#[=======================================================================[ - -@RAPIDS_PROJECT_DOCUMENTATION@ - -Result Variables -^^^^^^^^^^^^^^^^ - -This module will set the following variables:: - - @project_name_uppercase@_FOUND - @project_name_uppercase@_VERSION - @project_name_uppercase@_VERSION_MAJOR - @project_name_uppercase@_VERSION_MINOR - -#]=======================================================================] - -@PACKAGE_INIT@ - -cmake_minimum_required(VERSION @CMAKE_MINIMUM_REQUIRED_VERSION@) - -set(rapids_global_languages @RAPIDS_LANGUAGES@) -foreach(lang IN LISTS rapids_global_languages) - include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-${lang}-language.cmake") -endforeach() -unset(rapids_global_languages) - -set(rapids_base_components @RAPIDS_COMPONENTS@) -set(rapids_allowed_components ${rapids_base_components}) - -if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@project_name@-dependencies.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-dependencies.cmake") -endif() -foreach(comp IN LISTS rapids_allowed_components) - # find dependencies before creating targets that use them - # this way if a dependency can't be found we fail - if(${comp} IN_LIST @project_name@_FIND_COMPONENTS) - include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}-dependencies.cmake" OPTIONAL) - include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}-lib-dependencies.cmake" OPTIONAL) - endif() -endforeach() - -include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-targets.cmake" OPTIONAL) - -foreach(comp IN LISTS rapids_allowed_components) - if(${comp} IN_LIST @project_name@_FIND_COMPONENTS) - include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}-targets.cmake" OPTIONAL) - include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}-lib-targets.cmake" OPTIONAL) - set(@project_name@_${comp}_FOUND TRUE) - endif() -endforeach() - -unset(rapids_allowed_components) - -if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@project_name@-config-version.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-config-version.cmake") -endif() - -# Set our version variables -set(@project_name_uppercase@_VERSION_MAJOR @rapids_orig_major_version@) -set(@project_name_uppercase@_VERSION_MINOR @rapids_orig_minor_version@) -set(@project_name_uppercase@_VERSION_PATCH @rapids_orig_patch_version@) -set(@project_name_uppercase@_VERSION @rapids_orig_version@) - - -set(rapids_global_targets @RAPIDS_GLOBAL_TARGETS@) -set(rapids_namespaced_global_targets @RAPIDS_GLOBAL_TARGETS@) -if(rapids_namespaced_global_targets) - list(TRANSFORM rapids_namespaced_global_targets PREPEND @RAPIDS_NAMESPACE@ ) -endif() - -foreach(target IN LISTS rapids_namespaced_global_targets) - if(TARGET ${target}) - get_target_property(_is_imported ${target} IMPORTED) - get_target_property(_already_global ${target} IMPORTED_GLOBAL) - if(_is_imported AND NOT _already_global) - set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE) - endif() - endif() -endforeach() - -# For backwards compat -if("rapids_config_@type@" STREQUAL "rapids_config_build") - foreach(target IN LISTS rapids_global_targets) - if(TARGET ${target}) - get_target_property(_is_imported ${target} IMPORTED) - get_target_property(_already_global ${target} IMPORTED_GLOBAL) - if(_is_imported AND NOT _already_global) - set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL TRUE) - endif() - if(NOT TARGET @RAPIDS_NAMESPACE@${target}) - add_library(@RAPIDS_NAMESPACE@${target} ALIAS ${target}) - endif() - endif() - endforeach() -endif() - -unset(rapids_global_targets) -unset(rapids_namespaced_global_targets) - -check_required_components(@project_name@) - -set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}") - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE HANDLE_COMPONENTS) - -@RAPIDS_PROJECT_FINAL_CODE_BLOCK@ diff --git a/cpp/cmake/modules/raft_export.cmake b/cpp/cmake/modules/raft_export.cmake deleted file mode 100644 index bcc3578bf8..0000000000 --- a/cpp/cmake/modules/raft_export.cmake +++ /dev/null @@ -1,265 +0,0 @@ -# ============================================================================= -# Copyright (c) 2021-2022, 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: -raft_export ---------------------- - -Generate a projects -Config.cmake module and all related information - -.. code-block:: cmake - - raft_export( (BUILD|INSTALL) - EXPORT_SET - [ COMPONENTS ] - [ GLOBAL_TARGETS ] - [ VERSION ] - [ NAMESPACE ] - [ DOCUMENTATION ] - [ FINAL_CODE_BLOCK ] - [ LANGUAGES ] - ) - -The :cmake:command:`raft_export` function allow projects to easily generate a fully -correct build and install tree `Project-Config.cmake` module including any necessary -calls to :cmake:command:`find_dependency`, or :cmake:command:`CPMFindPackage`. - -.. note:: - :cmake:command:`raft_export` always installs to `lib` and doesn't use GNUInstallDirs - - The files generated by :cmake:command:`raft_export` are completely standalone - and don't require the consuming package to use `rapids-cmake` - -``project_name`` - Name of the project, to be used by consumers when using `find_package` - -``GLOBAL_TARGETS`` - Explicitly list what targets should be made globally visible to - the consuming project. - -``VERSION`` - Explicitly list the version of the package being exported. By - default :cmake:command:`raft_export` uses the version specified by the - root level :cmake:command:`project` call. If no version has been specified - either way or `OFF` is provided as the `VERSION` value, no version compatibility - checks will be generated. - - Depending on the version string different compatibility modes will be used. - - +------------------+---------------------+ - | Version String | Compatibility Type | - +==================+=====================+ - | None | No checks performed | - +------------------+---------------------+ - | X | SameMajorVersion | - +------------------+---------------------+ - | X.Y | SameMinorVersion | - +------------------+---------------------+ - | X.Y.Z | SameMinorVersion | - +------------------+---------------------+ - -.. note:: - It can be useful to explicitly specify a version string when generating - export rules for a sub-component of alarger project, or an external - project that doesn't have export rules. - -``NAMESPACE`` - Optional value to specify what namespace all targets from the - EXPORT_SET will be placed into. When provided must match the pattern - of `::`. - If not provided all targets will be placed in the `::` - namespace - - Note: When exporting with `BUILD` type, only `GLOBAL_TARGETS` will - be placed in the namespace. - -``DOCUMENTATION`` - Optional value of the variable that holds the documentation - for this config file. - - Note: This requires the documentation variable instead of the contents - so we can handle having CMake code inside the documentation - -``FINAL_CODE_BLOCK`` - Optional value of the variable that holds a string of code that will - be executed at the last step of this config file. - - Note: This requires the code block variable instead of the contents - so that we can properly insert CMake code - -``LANGUAGES`` - Non default languages, such as CUDA that are required by consumers - of your package. This makes sure all consumers properly setup these - languages correctly. - - This is required as CMake's :cmake:command:`enable_language` only supports - enabling languages for the current directory scope, and doesn't support - being called from within functions. Marking languages here overcomes - these limitations and makes it possible for packages included via - `CPM` to enable languages. - - -#]=======================================================================] -# cmake-lint: disable=R0912,R0915,W0105 -function(raft_export type project_name) - include(CMakePackageConfigHelpers) - - list(APPEND CMAKE_MESSAGE_CONTEXT "raft.export") - string(TOLOWER ${type} type) - - set(options "") - set(one_value EXPORT_SET VERSION NAMESPACE DOCUMENTATION FINAL_CODE_BLOCK) - set(multi_value COMPONENTS GLOBAL_TARGETS LANGUAGES) - cmake_parse_arguments(RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN}) - - set(rapids_version_set ON) - if(DEFINED RAPIDS_VERSION AND NOT RAPIDS_VERSION) - # We need to capture `VERSION OFF` so we need to make sure it has an off value, and not just - # undefined - set(rapids_version_set OFF) - unset(RAPIDS_VERSION) # unset this so we don't export a version value of `OFF` - elseif(NOT DEFINED RAPIDS_VERSION AND NOT DEFINED PROJECT_VERSION) - set(rapids_version_set OFF) - elseif(DEFINED PROJECT_VERSION AND NOT DEFINED RAPIDS_VERSION) - # Choose the project version when an explicit version isn't provided - set(RAPIDS_VERSION "${PROJECT_VERSION}") - endif() - - if(rapids_version_set) - include("${rapids-cmake-dir}/export/detail/parse_version.cmake") - rapids_export_parse_version(${RAPIDS_VERSION} rapids_orig rapids_project_version) - endif() - - set(RAPIDS_PROJECT_VERSION "${project_name}::") - if(DEFINED RAPIDS_NAMESPACE) - set(RAPIDS_PROJECT_VERSION ${RAPIDS_NAMESPACE}) - endif() - - set(RAPIDS_PROJECT_DOCUMENTATION "Generated ${project_name}-config module") - if(DEFINED RAPIDS_DOCUMENTATION) - if(NOT DEFINED ${RAPIDS_DOCUMENTATION}) - message(FATAL_ERROR "DOCUMENTATION variable `${RAPIDS_DOCUMENTATION}` doesn't exist") - endif() - set(RAPIDS_PROJECT_DOCUMENTATION "${${RAPIDS_DOCUMENTATION}}") - endif() - - if(DEFINED RAPIDS_FINAL_CODE_BLOCK) - if(NOT DEFINED ${RAPIDS_FINAL_CODE_BLOCK}) - message(FATAL_ERROR "FINAL_CODE_BLOCK variable `${RAPIDS_FINAL_CODE_BLOCK}` doesn't exist") - endif() - set(RAPIDS_PROJECT_FINAL_CODE_BLOCK "${${RAPIDS_FINAL_CODE_BLOCK}}") - endif() - - # Write configuration and version files - string(TOLOWER ${project_name} project_name) - string(TOUPPER ${project_name} project_name_uppercase) - if(type STREQUAL "install") - include("${rapids-cmake-dir}/cmake/install_lib_dir.cmake") - rapids_cmake_install_lib_dir(install_location) - set(install_location "${install_location}/cmake/${project_name}") - - set(scratch_dir "${PROJECT_BINARY_DIR}/rapids-cmake/${project_name}/export/raft/") - - configure_package_config_file( - "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/config.cmake.in" - "${scratch_dir}/${project_name}-config.cmake" INSTALL_DESTINATION "${install_location}" - ) - - if(rapids_version_set) - write_basic_package_version_file( - "${scratch_dir}/${project_name}-config-version.cmake" - VERSION ${rapids_project_version} - COMPATIBILITY ${rapids_project_version_compat} - ) - endif() - - install( - EXPORT ${RAPIDS_EXPORT_SET} - FILE ${project_name}-targets.cmake - NAMESPACE ${RAPIDS_PROJECT_VERSION} - DESTINATION "${install_location}" - COMPONENT raft - ) - - if(TARGET rapids_export_install_${RAPIDS_EXPORT_SET}) - include("${rapids-cmake-dir}/export/write_dependencies.cmake") - set(destination "${scratch_dir}/${project_name}-dependencies.cmake") - rapids_export_write_dependencies(INSTALL ${RAPIDS_EXPORT_SET} "${destination}") - endif() - - if(DEFINED RAPIDS_LANGUAGES) - include("${rapids-cmake-dir}/export/write_language.cmake") - foreach(lang IN LISTS RAPIDS_LANGUAGES) - set(destination "${scratch_dir}/${project_name}-${lang}-language.cmake") - rapids_export_write_language(INSTALL ${lang} "${destination}") - endforeach() - endif() - - # Install everything we have generated - install( - DIRECTORY "${scratch_dir}/" - DESTINATION "${install_location}" - COMPONENT raft - ) - foreach(comp nn distance) - set(scratch_dir "${PROJECT_BINARY_DIR}/rapids-cmake/${project_name}/export/${comp}/") - file(MAKE_DIRECTORY "${scratch_dir}") - install( - DIRECTORY "${scratch_dir}" - DESTINATION "${install_location}" - COMPONENT ${comp} - ) - endforeach() - - else() - set(install_location "${PROJECT_BINARY_DIR}") - configure_package_config_file( - "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/config.cmake.in" - "${install_location}/${project_name}-config.cmake" INSTALL_DESTINATION "${install_location}" - ) - - if(rapids_version_set) - write_basic_package_version_file( - "${install_location}/${project_name}-config-version.cmake" - VERSION ${rapids_project_version} - COMPATIBILITY ${rapids_project_version_compat} - ) - endif() - - export( - EXPORT ${RAPIDS_EXPORT_SET} - NAMESPACE ${RAPIDS_PROJECT_VERSION} - FILE "${install_location}/${project_name}-targets.cmake" - ) - - if(TARGET rapids_export_build_${RAPIDS_EXPORT_SET}) - include("${rapids-cmake-dir}/export/write_dependencies.cmake") - rapids_export_write_dependencies( - BUILD ${RAPIDS_EXPORT_SET} "${install_location}/${project_name}-dependencies.cmake" - ) - endif() - - if(DEFINED RAPIDS_LANGUAGES) - include("${rapids-cmake-dir}/export/write_language.cmake") - foreach(lang IN LISTS RAPIDS_LANGUAGES) - rapids_export_write_language( - BUILD ${lang} "${install_location}/${project_name}-${lang}-language.cmake" - ) - endforeach() - endif() - - endif() - -endfunction() diff --git a/fetch_rapids.cmake b/fetch_rapids.cmake index 248f5784c0..6b5acbc070 100644 --- a/fetch_rapids.cmake +++ b/fetch_rapids.cmake @@ -16,4 +16,7 @@ if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/RAFT_RAPIDS.cmake) ${CMAKE_CURRENT_BINARY_DIR}/RAFT_RAPIDS.cmake ) endif() + +set(rapids-cmake-branch fea/export-components) +set(rapids-cmake-repo robertmaynard/rapids-cmake) include(${CMAKE_CURRENT_BINARY_DIR}/RAFT_RAPIDS.cmake)