Skip to content

Commit

Permalink
rapids-cmake add rapids_cpm_<PackageName> for common packages
Browse files Browse the repository at this point in the history
Fixes #32

The following packages are now are easier to user for RAPIDS projects
as rapids-cmake offers a pre-configured setup for each project.

  GTest
  NVBench
  RMM
  SpdLog
  Thrust

On top of providing a consistent version of these packages to
all RAPIDS projects, rapids-cmake now is able to deduce when these
projects should also be installed.

```cmake

rapids_cpm_gtest(BUILD_EXPORT_SET myproject)
rapdis_cpm_rmm(BUILD_EXPORT_SET myproject
               INSTALL_EXPORT_SET myproject)
```
Given the above snippet when RMM is built as a subcomponent of
`myproject` it will be installed as well. This is done since
RMM is part of the INSTALL export set, and therefore must
be available from an installed version of `myproject`.
  • Loading branch information
robertmaynard committed Aug 2, 2021
1 parent f367fe6 commit 6af51f9
Show file tree
Hide file tree
Showing 26 changed files with 833 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Please ensure that when you are creating new features you follow the following g
- Each user facing `.cmake` file should have include guards (`include_guard(GLOBAL)`)
- Each user facing `.cmake` file should be documented following the rst structure
- Each user facing function should be added to the `cmake-format.json` document
- Run `cmake-annotate --json` on the `.cmake` file as a starting point
- Run `cmake-genparsers -f json` on the `.cmake` file as a starting point
- Each function first line should be `list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.<component>.<function>")`
- A file should not modify any state simply by being included. State modification should
only occur inside functions unless absolutely neccessary due to restrctions of the CMake
Expand Down
48 changes: 48 additions & 0 deletions cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,54 @@
"nargs": 0
}
},
"rapids_cpm_gtest": {
"pargs": {
"nargs": 0
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1
}
},

"rapids_cpm_nvbench": {
"pargs": {
"nargs": 0
},
"kwargs": {
"BUILD_EXPORT_SET": 1
}
},

"rapids_cpm_rmm": {
"pargs": {
"nargs": 0
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1
}
},

"rapids_cpm_spdlog": {
"pargs": {
"nargs": 0
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1
}
},

"rapids_cpm_thrust": {
"pargs": {
"nargs": 2
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1
}
},

"rapids_cuda_init_architectures": {
"pargs": {
Expand Down
5 changes: 5 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ tracking of these dependencies for correct export support.

/command/rapids_cpm_init
/command/rapids_cpm_find
/command/rapids_cpm_gtest
/command/rapids_cpm_nvbench
/command/rapids_cpm_rmm
/command/rapids_cpm_spdlog
/command/rapids_cpm_thrust

Find
****
Expand Down
1 change: 1 addition & 0 deletions docs/command/rapids_cpm_gtest.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/gtest.cmake
1 change: 1 addition & 0 deletions docs/command/rapids_cpm_nvbench.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/nvbench.cmake
1 change: 1 addition & 0 deletions docs/command/rapids_cpm_rmm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/rmm.cmake
1 change: 1 addition & 0 deletions docs/command/rapids_cpm_spdlog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/spdlog.cmake
1 change: 1 addition & 0 deletions docs/command/rapids_cpm_thrust.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/thrust.cmake
7 changes: 6 additions & 1 deletion rapids-cmake/cpm/find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ consistency. List all targets used by your project in `GLOBAL_TARGET`.

``INSTALL_EXPORT_SET``
Record a :cmake:command:`find_dependency(<PackageName> ...)` call needs to occur as part of
our build directory export set.
our install directory export set.

``CPM_ARGS``
Required placeholder to be provied before any extra arguments that need to
be passed down to :cmake:command:`CPMFindPackage`.

Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`<PackageName>_SOURCE_DIR` is set to the path to the source directory of <PackageName>.
:cmake:variable:`<PackageName>_BINAR_DIR` is set to the path to the build directory of <PackageName>.
:cmake:variable:`<PackageName>_ADDED` is set to a true value if <PackageName> has not been added before.

.. note::
Adding an export set to :cmake:command:`rapids_cpm_find` has different behavior
Expand Down
77 changes: 77 additions & 0 deletions rapids-cmake/cpm/gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#=============================================================================
# Copyright (c) 2020-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_gtest
----------------

.. versionadded:: v21.10.00

Allow projects to find or build `Google Test` via `CPM` with built-in
tracking of these dependencies for correct export support.

Uses version 1.10.0 of Google Test for consistency across all RAPIDS projects

.. code-block:: cmake

rapids_cpm_gtest( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
)
.. note::
Installation of GTest will occur if an INSTALL_EXPORT_SET is provided, and GTest
is added to the project via :cmake:command:`add_subdirectory` by CPM.

Result Targets
^^^^^^^^^^^^^^
GTest::gtest, GTest::gmock, GTest::gtest_main, GTest::gmock_main targets will be created

Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`GTest_SOURCE_DIR` is set to the path to the source directory of GTest.
:cmake:variable:`GTest_BINAR_DIR` is set to the path to the build directory of GTest.
:cmake:variable:`GTest_ADDED` is set to a true value if GTest has not been added before.

#]=======================================================================]
function(rapids_cpm_gtest)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.gtest")

set(to_install OFF)
if(INSTALL_EXPORT_SET IN_LIST ARGN)
set(to_install ON)
endif()

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(GTest 1.10 ${ARGN}
GLOBAL_TARGETS GTest::gtest GTest::gmock GTest::gtest_main GTest::gmock_main
CPM_ARGS
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
GIT_SHALLOW TRUE
OPTIONS "INSTALL_GTEST ${to_install}")

# Propagate up variables that CPMFindPackage provide
set(GTest_SOURCE_DIR "${GTest_SOURCE_DIR}" PARENT_SCOPE)
set(GTest_BINARY_DIR "${GTest_BINARY_DIR}" PARENT_SCOPE)
set(GTest_ADDED "${GTest_ADDED}" PARENT_SCOPE)

if(NOT TARGET GTest::gtest)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gtest_main ALIAS gtest_main)
add_library(GTest::gmock_main ALIAS gmock_main)
endif()
endfunction()
79 changes: 79 additions & 0 deletions rapids-cmake/cpm/nvbench.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#=============================================================================
# Copyright (c) 2020-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_nvbench
------------------

.. versionadded:: v21.10.00

Allow projects to find or build `nvbench` via `CPM` with built-in
tracking of these dependencies for correct export support.

Uses latest version of nvbench for consistency across all RAPIDS projects

.. code-block:: cmake

rapids_cpm_nvbench( [BUILD_EXPORT_SET <export-name>] )

``BUILD_EXPORT_SET``
Record that a :cmake:command:`CPMFindPackage(nvbench)` call needs to occur as part of
our build directory export set.

.. note::

RAPIDS-cmake will error out if an INSTALL_EXPORT_SET is provided, as nvbench
doesn't provide any support for installation.

Result Targets
^^^^^^^^^^^^^^
nvbench::nvbench target will be created

nvbench::main target will be created

Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`nvbench_SOURCE_DIR` is set to the path to the source directory of nvbench.
:cmake:variable:`nvbench_BINAR_DIR` is set to the path to the build directory of nvbench.
:cmake:variable:`nvbench_ADDED` is set to a true value if nvbench has not been added before.

#]=======================================================================]
function(rapids_cpm_nvbench)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.nvbench")

set(to_install FALSE)
if(INSTALL_EXPORT_SET IN_LIST ARGN)
message(FATAL_ERROR "nvbench doesn't provide install rules.
It can't be part of an INSTALL_EXPORT_SET")
endif()

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(nvbench 0.0 ${ARGN}
GLOBAL_TARGETS nvbench::nvbench nvbench::main
CPM_ARGS
GIT_REPOSITORY https://github.com/NVIDIA/nvbench.git
GIT_TAG main
GIT_SHALLOW TRUE
OPTIONS "NVBench_ENABLE_EXAMPLES OFF" "NVBench_ENABLE_TESTING OFF")

# Propagate up variables that CPMFindPackage provide
set(nvbench_SOURCE_DIR "${nvbench_SOURCE_DIR}" PARENT_SCOPE)
set(nvbench_BINARY_DIR "${nvbench_BINARY_DIR}" PARENT_SCOPE)
set(nvbench_ADDED "${nvbench_ADDED}" PARENT_SCOPE)

# nvbench creates the correct namespace aliases
endfunction()
72 changes: 72 additions & 0 deletions rapids-cmake/cpm/rmm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#=============================================================================
# Copyright (c) 2020-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_rmm
--------------

.. versionadded:: v21.10.00

Allow projects to find or build `rmm` via `CPM` with built-in
tracking of these dependencies for correct export support.

Uses the associated cal-version of rmm for consistency across all RAPIDS projects

.. code-block:: cmake

rapids_cpm_rmm( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
)

``BUILD_EXPORT_SET``
Record that a :cmake:command:`CPMFindPackage(rmm)` call needs to occur as part of
our build directory export set.

``INSTALL_EXPORT_SET``
Record a :cmake:command:`find_dependency(rmm)` call needs to occur as part of
our install directory export set.

.. note::
Installation of rmm will always occur when it is built as a subcomponent of the
calling project.

Result Targets
^^^^^^^^^^^^^^
rmm::rmm target will be created

#]=======================================================================]
function(rapids_cpm_rmm)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rmm")

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

include("${rapids-cmake-dir}/rapids-version.cmake")
include("${rapids-cmake-dir}/cpm/find.cmake")
# Once we can require CMake 3.22 this can use `only_major_minor` for version searches
rapids_cpm_find(rmm "${rapids-cmake-version}.0" ${ARGN}
GLOBAL_TARGETS rmm::rmm
CPM_ARGS
GIT_REPOSITORY https://github.com/rapidsai/rmm.git
GIT_TAG branch-${rapids-cmake-version}
GIT_SHALLOW TRUE
OPTIONS "BUILD_TESTS OFF" "BUILD_BENCHMARKS OFF")

# rmm creates the correct namespace aliases
endfunction()
Loading

0 comments on commit 6af51f9

Please sign in to comment.