-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend rapids_export to support the concept of optional COMPONENTS
rapids_export via the COMPONENTS and COMPONENTS_EXPORT_SET commands can now generate find modules that have optional components.
- Loading branch information
1 parent
05e915d
commit 8a158d8
Showing
11 changed files
with
651 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#============================================================================= | ||
# Copyright (c) 2022-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_component | ||
----------------------- | ||
|
||
.. versionadded:: v22.04.00 | ||
|
||
.. code-block:: cmake | ||
|
||
Generate the necessary -Config.cmake modules needed for an optional component | ||
of a rapids export package. | ||
|
||
rapids_export_component( (BUILD|INSTALL) <project_name> <component_name> <export_set> <unique_name> <namespace>) | ||
|
||
The :cmake:command:`rapids_export_component` function generates | ||
the `<proj>-<unique_name>-targets.cmake` and `<proj>-<unique_name>-dependencies.cmake` | ||
files necessary for :cmake:command:`rapids_export` to support optional | ||
components. | ||
|
||
.. note:: | ||
It is an anti-pattern to use this function directly. The vast majority of projects | ||
would use :cmake:command:`rapids_export` | ||
|
||
|
||
#]=======================================================================] | ||
# cmake-lint: disable=W0105,R0913 | ||
function(rapids_export_component type project_name component_name export_set unique_name namespace) | ||
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.export.rapids_export_component") | ||
|
||
string(TOLOWER ${type} type) | ||
|
||
set(deps_destination) | ||
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(deps_destination | ||
"${PROJECT_BINARY_DIR}/rapids-cmake/${project_name}/export/${component_name}/") | ||
file(MAKE_DIRECTORY "${deps_destination}") | ||
install(DIRECTORY "${deps_destination}" DESTINATION "${install_location}" | ||
COMPONENT ${component_name}) | ||
install(EXPORT ${export_set} | ||
FILE ${project_name}-${unique_name}-targets.cmake | ||
NAMESPACE ${namespace} | ||
DESTINATION "${install_location}" | ||
COMPONENT ${component_name}) | ||
|
||
else() | ||
set(install_location "${PROJECT_BINARY_DIR}") | ||
set(deps_destination "${install_location}/") | ||
|
||
export(EXPORT ${export_set} NAMESPACE ${namespace} | ||
FILE "${install_location}/${project_name}-${unique_name}-targets.cmake") | ||
|
||
endif() | ||
|
||
if(TARGET rapids_export_${type}_${export_set}) | ||
include("${rapids-cmake-dir}/export/write_dependencies.cmake") | ||
rapids_export_write_dependencies( | ||
${type} ${export_set} "${deps_destination}/${project_name}-${unique_name}-dependencies.cmake") | ||
endif() | ||
|
||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,17 +40,29 @@ foreach(lang IN LISTS rapids_global_languages) | |
endforeach() | ||
unset(rapids_global_languages) | ||
|
||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
endif() | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]" OPTIONAL) | ||
|
||
# The same component can be listed multiple times in `rapids_comp_names` so that we | ||
# can support multiple export sets being mapped to the same component | ||
set(rapids_comp_names @_RAPIDS_COMPONENTS@) | ||
set(rapids_comp_unique_ids @_RAPIDS_COMPONENTS_EXPORT_SET_NICE_NAMES@) | ||
foreach(comp unique_name IN ZIP_LISTS rapids_comp_names rapids_comp_unique_ids) | ||
# 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@-${unique_name}-dependencies.cmake" OPTIONAL) | ||
endif() | ||
endforeach() | ||
|
||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
endif() | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]" OPTIONAL) | ||
foreach(comp unique_name IN ZIP_LISTS rapids_comp_names rapids_comp_unique_ids) | ||
if(${comp} IN_LIST @project_name@_FIND_COMPONENTS) | ||
include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-${unique_name}-targets.cmake" OPTIONAL) | ||
set(@project_name@_${comp}_FOUND TRUE) | ||
endif() | ||
endforeach() | ||
|
||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
endif() | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]" OPTIONAL) | ||
|
||
# Set our version variables | ||
set(@project_name_uppercase@_VERSION_MAJOR @rapids_orig_major_version@) | ||
|
@@ -62,7 +74,7 @@ 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@ ) | ||
list(TRANSFORM rapids_namespaced_global_targets PREPEND @_RAPIDS_PROJECT_NAMESPACE@ ) | ||
endif() | ||
|
||
foreach(target IN LISTS rapids_namespaced_global_targets) | ||
|
@@ -91,6 +103,8 @@ if("rapids_config_@type@" STREQUAL "rapids_config_build") | |
endforeach() | ||
endif() | ||
|
||
unset(rapids_comp_names) | ||
unset(rapids_comp_unique_ids) | ||
unset(rapids_global_targets) | ||
unset(rapids_namespaced_global_targets) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
testing/export/export-verify-build-components-dependencies/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#============================================================================= | ||
# 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/export.cmake) | ||
|
||
cmake_minimum_required(VERSION 3.20) | ||
project(FakEProJecT LANGUAGES CXX VERSION 3.1.4) | ||
|
||
add_library(fakeLib INTERFACE) | ||
install(TARGETS fakeLib EXPORT fake_set) | ||
|
||
add_library(fakeLib_c1 INTERFACE) | ||
install(TARGETS fakeLib_c1 EXPORT fake_set_c1_export) | ||
|
||
include(${rapids-cmake-dir}/export/package.cmake) | ||
rapids_export_package( build CUDAToolkit fake_set_c1_export) | ||
|
||
rapids_export(BUILD FakEProJecT | ||
EXPORT_SET fake_set | ||
COMPONENTS c1 | ||
COMPONENTS_EXPORT_SET fake_set_c1_export | ||
LANGUAGES CXX | ||
NAMESPACE test:: | ||
) | ||
|
||
# Add a custom command that generates a second project | ||
# that verifies our component targetd are exported correctly | ||
file(WRITE "${CMAKE_BINARY_DIR}/verify-1/CMakeLists.txt" [=[ | ||
cmake_minimum_required(VERSION 3.20) | ||
project(verify_build_targets LANGUAGES CXX) | ||
|
||
set(components c1) | ||
set(export_sets fake_set_c1) | ||
foreach(comp exp_set IN ZIP_LISTS components export_sets) | ||
message(STATUS "${CMAKE_CURRENT_LIST_DIR}/../fakeproject-${exp_set}-dependencies.cmake") | ||
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../fakeproject-${exp_set}-dependencies.cmake") | ||
message(FATAL_ERROR "rapids_export failed to generate correct component dependencies file name[fakeproject-${exp_set}-dependencies.cmake]") | ||
endif() | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/../fakeproject-${exp_set}-dependencies.cmake") | ||
if(NOT TARGET CUDA::toolkit) | ||
message(FATAL_ERROR "rapids_export failed to generate correct dependencies imports[fakeproject-${exp_set}-dependencies.cmake]") | ||
endif() | ||
endforeach() | ||
]=]) | ||
|
||
add_custom_target(verify_target_dependencies_files ALL | ||
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/verify-1/build" | ||
COMMAND ${CMAKE_COMMAND} -S="${CMAKE_BINARY_DIR}/verify-1" -B="${CMAKE_BINARY_DIR}/verify-1/build" | ||
) | ||
|
||
# Add a custom command that generates a second project | ||
# that verifies our component targetd are exported correctly | ||
file(WRITE "${CMAKE_BINARY_DIR}/verify-2/CMakeLists.txt" [=[ | ||
cmake_minimum_required(VERSION 3.20) | ||
project(verify_build_targets LANGUAGES CXX) | ||
|
||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../) | ||
find_package(fakeproject COMPONENTS c1 REQUIRED) | ||
if(NOT TARGET CUDA::toolkit) | ||
message(FATAL_ERROR "rapids_export failed to generate correct dependencies imports") | ||
endif() | ||
]=]) | ||
|
||
add_custom_target(verify_target_dependencies_find ALL | ||
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/verify-2/build" | ||
COMMAND ${CMAKE_COMMAND} -S="${CMAKE_BINARY_DIR}/verify-2" -B="${CMAKE_BINARY_DIR}/verify-2/build" | ||
) |
Oops, something went wrong.