-
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 (#154
) rapids_export via the COMPONENTS and COMPONENTS_EXPORT_SET commands can now generate find modules that have optional components. Authors: - Robert Maynard (https://github.com/robertmaynard) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) URL: #154
- Loading branch information
1 parent
5cc9f72
commit 87d72fb
Showing
11 changed files
with
649 additions
and
17 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,75 @@ | ||
#============================================================================= | ||
# 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_component | ||
----------------------- | ||
|
||
.. versionadded:: v23.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. | ||
|
||
#]=======================================================================] | ||
# 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,36 @@ 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) | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]" OPTIONAL) | ||
|
||
if(@_RAPIDS_HAS_COMPONENTS@) | ||
set(@project_name@_comp_names @_RAPIDS_COMPONENTS@) | ||
# find dependencies before creating targets that use them | ||
# this way if a dependency can't be found we fail | ||
foreach(comp IN LISTS @project_name@_FIND_COMPONENTS) | ||
if(${comp} IN_LIST @project_name@_comp_names) | ||
file(GLOB @project_name@_component_dep_files LIST_DIRECTORIES FALSE | ||
"${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}*-dependencies.cmake") | ||
foreach(f IN LISTS @project_name@_component_dep_files) | ||
include("${f}") | ||
endforeach() | ||
endif() | ||
endforeach() | ||
|
||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
foreach(comp IN LISTS @project_name@_FIND_COMPONENTS) | ||
if(${comp} IN_LIST @project_name@_comp_names) | ||
file(GLOB @project_name@_component_target_files LIST_DIRECTORIES FALSE | ||
"${CMAKE_CURRENT_LIST_DIR}/@project_name@-${comp}*-targets.cmake") | ||
foreach(f IN LISTS @project_name@_component_target_files) | ||
include("${f}") | ||
endforeach() | ||
set(@project_name@_${comp}_FOUND TRUE) | ||
endif() | ||
endforeach() | ||
endif() | ||
|
||
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 +81,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 +110,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
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
#============================================================================= | ||
# 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 targets 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(nice_names c1-fake_set) | ||
foreach(nice_name IN ZIP_LISTS components export_sets) | ||
include("${CMAKE_CURRENT_LIST_DIR}/../fakeproject-${nice_names}-dependencies.cmake") | ||
if(NOT TARGET CUDA::toolkit) | ||
message(FATAL_ERROR "rapids_export failed to generate correct dependencies imports[fakeproject-${nice_names}-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 targets 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.