Skip to content

Commit

Permalink
Introduce rapids_cpm_libcudacxx
Browse files Browse the repository at this point in the history
Provides an unified version of libcudacxx for all rapids-cmake based projects.

Since the libcudacxx is focused on building the project, we can't rely
on its install rules. Instead we manually produce install rules and a
libcudacxx-config.cmake to allow find_package(libcudacxx).

Like Thrust we also make sure the includes are namespaced and
always marked as user include so that consumers use this version
of libcudacxx instead of the one provided in the system cuda toolkit.

Fixes rapidsai#97
  • Loading branch information
robertmaynard committed Oct 26, 2021
1 parent 2a041d4 commit 8d99c43
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
"INSTALL_EXPORT_SET": 1
}
},
"rapids_cpm_libcudacxx": {
"pargs": {
"nargs": 0
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1
}
},
"rapids_cpm_nvbench": {
"pargs": {
"nargs": 0
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ package uses :ref:`can be found here. <cpm_versions>`
:titlesonly:

/packages/rapids_cpm_gtest
/packages/rapids_cpm_libcudacxx
/packages/rapids_cpm_nvbench
/packages/rapids_cpm_rmm
/packages/rapids_cpm_spdlog
Expand Down
1 change: 1 addition & 0 deletions docs/packages/rapids_cpm_libcudacxx.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/libcudacxx.cmake
2 changes: 1 addition & 1 deletion rapids-cmake/cpm/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ The CPM module will be downloaded based on the state of :cmake:variable:`CPM_SOU
same download of CPM. If those variables aren't set the file will be cached
in the build tree of the calling project
``OVERRIDE``
.. versionadded:: v21.10.00
``OVERRIDE``
Override the `CPM` preset package information for the project. The user provided
json file must follow the `versions.json` format, which is :ref:`documented here<cpm_version_format>`.
Expand Down
143 changes: 143 additions & 0 deletions rapids-cmake/cpm/libcudacxx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#=============================================================================
# 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.
#=============================================================================
include_guard(GLOBAL)

#[=======================================================================[.rst:
rapids_cpm_libcudacxx
------------------
.. versionadded:: v21.12.00
Allow projects to find or build `libcudacxx` via `CPM` with built-in
tracking of these dependencies for correct export support.
Uses the version of libcudacxx :ref:`specified in the version file <cpm_versions>` for consistency
across all RAPIDS projects.
.. code-block:: cmake
rapids_cpm_libcudacxx( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
)
``BUILD_EXPORT_SET``
Record that a :cmake:command:`CPMFindPackage(libcudacxx)` call needs to occur as part of
our build directory export set.
``INSTALL_EXPORT_SET``
Record a :cmake:command:`find_dependency(libcudacxx)` call needs to occur as part of
our install directory export set.
Result Targets
^^^^^^^^^^^^^^
libcudacxx::libcudacxx target will be created
Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`libcudacxx_SOURCE_DIR` is set to the path to the source directory of libcudacxx.
:cmake:variable:`libcudacxx_BINAR_DIR` is set to the path to the build directory of libcudacxx.
:cmake:variable:`libcudacxx_ADDED` is set to a true value if libcudacxx has not been added before.
:cmake:variable:`libcudacxx_VERSION` is set to the version of libcudacxx specified by the versions.json.
#]=======================================================================]
function(rapids_cpm_libcudacxx)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.libcudacxx")

set(install_export FALSE)
if(INSTALL_EXPORT_SET IN_LIST ARGN)
set(install_export TRUE)
endif()

set(build_export FALSE)
if(BUILD_EXPORT_SET IN_LIST ARGN)
set(build_export TRUE)
endif()

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
rapids_cpm_package_details(libcudacxx version repository tag shallow)

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(libcudacxx ${version} ${ARGN}
GLOBAL_TARGETS libcudacxx::libcudacxx
CPM_ARGS
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow}
DOWNLOAD_ONLY TRUE)

# establish the correct libcudacxx namespace aliases
if(libcudacxx_ADDED AND NOT TARGET libcudacxx)
add_library(libcudacxx INTERFACE)
add_library(libcudacxx::libcudacxx ALIAS libcudacxx)

target_include_directories(libcudacxx
INTERFACE $<BUILD_INTERFACE:${libcudacxx_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/rapids/libcudacxx>)

install(TARGETS libcudacxx
DESTINATION ${lib_dir}
EXPORT libcudacxx-targets)


set(code_string [=[
# nvcc automatically adds the CUDA Toolkit system include paths before any
# system include paths that CMake adds. CMake implicitly treats all includes
# on import targets as 'SYSTEM' includes.
#
# To get this cudacxx to be picked up by consumers instead of the version shipped
# with the CUDA Toolkit we need to make sure it is a non-SYSTEM include on the CMake side.
#
add_library(libcudacxx_includes INTERFACE)
target_link_libraries(libcudacxx::libcudacxx INTERFACE libcudacxx_includes)
get_target_property(all_includes libcudacxx::libcudacxx INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(libcudacxx::libcudacxx PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
set_target_properties(libcudacxx_includes PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${all_includes}")
]=])

if(build_export)
include("${rapids-cmake-dir}/export/export.cmake")
rapids_export(BUILD libcudacxx
EXPORT_SET libcudacxx-targets
GLOBAL_TARGETS libcudacxx
VERSION ${version}
NAMESPACE libcudacxx::
FINAL_CODE_BLOCK code_string)
endif()

if(install_export)
include("${rapids-cmake-dir}/cmake/install_lib_dir.cmake")
rapids_cmake_install_lib_dir( lib_dir )
install(DIRECTORY ${libcudacxx_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rapids/libcudacxx)
install(DIRECTORY ${libcudacxx_SOURCE_DIR}/libcxx/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rapids/libcxx/include)

include("${rapids-cmake-dir}/export/export.cmake")
rapids_export(INSTALL libcudacxx
EXPORT_SET libcudacxx-targets
GLOBAL_TARGETS libcudacxx
VERSION ${version}
NAMESPACE libcudacxx::
FINAL_CODE_BLOCK code_string)

endif()
endif()

# Propagate up variables that CPMFindPackage provide
set(libcudacxx_SOURCE_DIR "${libcudacxx_SOURCE_DIR}" PARENT_SCOPE)
set(libcudacxx_BINARY_DIR "${libcudacxx_BINARY_DIR}" PARENT_SCOPE)
set(libcudacxx_ADDED "${libcudacxx_ADDED}" PARENT_SCOPE)
set(libcudacxx_VERSION ${version} PARENT_SCOPE)

endfunction()
5 changes: 5 additions & 0 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"version" : "1.12.0",
"git_url" : "https://github.com/NVIDIA/thrust.git",
"git_tag" : "${version}"
},
"libcudacxx" : {
"version" : "1.4.0",
"git_url" : "https://github.com/NVIDIA/libcudacxx.git",
"git_tag" : "${version}"
}
}
}
3 changes: 3 additions & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ add_cmake_config_test( cpm_package_override-simple.cmake )
add_cmake_config_test( cpm_gtest-export.cmake )
add_cmake_config_test( cpm_gtest-simple.cmake )

add_cmake_config_test( cpm_libcudacxx-export.cmake )
add_cmake_config_test( cpm_libcudacxx-simple.cmake )

add_cmake_config_test( cpm_nvbench-export.cmake )
add_cmake_config_test( cpm_nvbench-simple.cmake )

Expand Down
37 changes: 37 additions & 0 deletions testing/cpm/cpm_libcudacxx-export.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#=============================================================================
# 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.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/libcudacxx.cmake)

rapids_cpm_init()

rapids_cpm_libcudacxx(BUILD_EXPORT_SET frank INSTALL_EXPORT_SET test)
rapids_cpm_libcudacxx(INSTALL_EXPORT_SET test2)

get_target_property(packages rapids_export_install_test PACKAGE_NAMES)
if(NOT libcudacxx IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_libcudacxx failed to record libcudacxx needs to be exported")
endif()

get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES)
if(NOT libcudacxx IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_libcudacxx failed to record libcudacxx needs to be exported")
endif()

get_target_property(packages rapids_export_build_frank PACKAGE_NAMES)
if(NOT libcudacxx IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_libcudacxx failed to record libcudacxx needs to be exported")
endif()
30 changes: 30 additions & 0 deletions testing/cpm/cpm_libcudacxx-simple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#=============================================================================
# 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.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/libcudacxx.cmake)

rapids_cpm_init()

if(TARGET libcudacxx::libcudacxx)
message(FATAL_ERROR "Expected libcudacxx::libcudacxx expected to not exist")
endif()

rapids_cpm_libcudacxx()
if(NOT TARGET libcudacxx::libcudacxx)
message(FATAL_ERROR "Expected libcudacxx::libcudacxx target to exist")
endif()

rapids_cpm_libcudacxx()
2 changes: 2 additions & 0 deletions testing/utils/fill_cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ project(fill_cache LANGUAGES NONE)
include(${rapids-cmake-dir}/cpm/init.cmake)

include(${rapids-cmake-dir}/cpm/gtest.cmake)
include(${rapids-cmake-dir}/cpm/libcudacxx.cmake)
include(${rapids-cmake-dir}/cpm/nvbench.cmake)
include(${rapids-cmake-dir}/cpm/rmm.cmake)
include(${rapids-cmake-dir}/cpm/spdlog.cmake)
Expand All @@ -30,6 +31,7 @@ rapids_cpm_init()
set(CPM_SOURCE_CACHE "${CMAKE_BINARY_DIR}")
set(CPM_DOWNLOAD_ALL "ON")
rapids_cpm_gtest(DOWNLOAD_ONLY ON)
rapids_cpm_libcudacxx(DOWNLOAD_ONLY ON)
rapids_cpm_nvbench(DOWNLOAD_ONLY ON)
rapids_cpm_rmm(DOWNLOAD_ONLY ON)
rapids_cpm_spdlog(DOWNLOAD_ONLY ON)
Expand Down

0 comments on commit 8d99c43

Please sign in to comment.