From e73ceffc85f3550560f573650d8a7253b2c4c038 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 18 Aug 2021 16:37:01 -0400 Subject: [PATCH] Introduce rapids_cpm_ (#52) Requires https://github.com/rapidsai/rapids-cmake/pull/48 and https://github.com/rapidsai/rapids-cmake/pull/51 Adds rapids_cpm_ for common packages 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`. Authors: - Robert Maynard (https://github.com/robertmaynard) Approvers: - Dante Gama Dessavre (https://github.com/dantegd) URL: https://github.com/rapidsai/rapids-cmake/pull/52 --- CONTRIBUTING.md | 2 +- cmake-format-rapids-cmake.json | 48 ++++++++++ docs/api.rst | 20 ++++ docs/packages/example.json | 11 +++ docs/packages/rapids_cpm_gtest.rst | 1 + docs/packages/rapids_cpm_nvbench.rst | 1 + docs/packages/rapids_cpm_rmm.rst | 1 + docs/packages/rapids_cpm_spdlog.rst | 1 + docs/packages/rapids_cpm_thrust.rst | 1 + docs/packages/rapids_cpm_versions.rst | 63 ++++++++++++ rapids-cmake/cpm/detail/download.cmake | 65 +++++++++++++ .../cpm/detail/load_preset_versions.cmake | 60 ++++++++++++ rapids-cmake/cpm/detail/package_details.cmake | 58 +++++++++++ rapids-cmake/cpm/find.cmake | 7 +- rapids-cmake/cpm/gtest.cmake | 83 ++++++++++++++++ rapids-cmake/cpm/init.cmake | 30 ++---- rapids-cmake/cpm/nvbench.cmake | 85 +++++++++++++++++ rapids-cmake/cpm/rmm.cmake | 88 +++++++++++++++++ rapids-cmake/cpm/spdlog.cmake | 86 +++++++++++++++++ rapids-cmake/cpm/thrust.cmake | 95 +++++++++++++++++++ rapids-cmake/cpm/versions.json | 30 ++++++ rapids-cmake/export/write_dependencies.cmake | 4 +- testing/cpm/CMakeLists.txt | 15 +++ testing/cpm/cpm_gtest-export.cmake | 34 +++++++ testing/cpm/cpm_gtest-simple.cmake | 39 ++++++++ testing/cpm/cpm_nvbench-export.cmake | 34 +++++++ testing/cpm/cpm_nvbench-simple.cmake | 38 ++++++++ testing/cpm/cpm_rmm-export.cmake | 39 ++++++++ testing/cpm/cpm_rmm-simple.cmake | 32 +++++++ testing/cpm/cpm_spdlog-export.cmake | 39 ++++++++ testing/cpm/cpm_spdlog-simple.cmake | 32 +++++++ testing/cpm/cpm_thrust-export.cmake | 34 +++++++ testing/cpm/cpm_thrust-simple.cmake | 37 ++++++++ testing/cpm/setup_cpm_cache.cmake | 21 ++++ 34 files changed, 1208 insertions(+), 26 deletions(-) create mode 100644 docs/packages/example.json create mode 100644 docs/packages/rapids_cpm_gtest.rst create mode 100644 docs/packages/rapids_cpm_nvbench.rst create mode 100644 docs/packages/rapids_cpm_rmm.rst create mode 100644 docs/packages/rapids_cpm_spdlog.rst create mode 100644 docs/packages/rapids_cpm_thrust.rst create mode 100644 docs/packages/rapids_cpm_versions.rst create mode 100644 rapids-cmake/cpm/detail/download.cmake create mode 100644 rapids-cmake/cpm/detail/load_preset_versions.cmake create mode 100644 rapids-cmake/cpm/detail/package_details.cmake create mode 100644 rapids-cmake/cpm/gtest.cmake create mode 100644 rapids-cmake/cpm/nvbench.cmake create mode 100644 rapids-cmake/cpm/rmm.cmake create mode 100644 rapids-cmake/cpm/spdlog.cmake create mode 100644 rapids-cmake/cpm/thrust.cmake create mode 100644 rapids-cmake/cpm/versions.json create mode 100644 testing/cpm/cpm_gtest-export.cmake create mode 100644 testing/cpm/cpm_gtest-simple.cmake create mode 100644 testing/cpm/cpm_nvbench-export.cmake create mode 100644 testing/cpm/cpm_nvbench-simple.cmake create mode 100644 testing/cpm/cpm_rmm-export.cmake create mode 100644 testing/cpm/cpm_rmm-simple.cmake create mode 100644 testing/cpm/cpm_spdlog-export.cmake create mode 100644 testing/cpm/cpm_spdlog-simple.cmake create mode 100644 testing/cpm/cpm_thrust-export.cmake create mode 100644 testing/cpm/cpm_thrust-simple.cmake create mode 100644 testing/cpm/setup_cpm_cache.cmake diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b81f0742..3655c06a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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..")` - 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 diff --git a/cmake-format-rapids-cmake.json b/cmake-format-rapids-cmake.json index 21ad2abf..0d002ebd 100644 --- a/cmake-format-rapids-cmake.json +++ b/cmake-format-rapids-cmake.json @@ -55,6 +55,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": { diff --git a/docs/api.rst b/docs/api.rst index f1727896..4d3af4f1 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -30,6 +30,26 @@ tracking of these dependencies for correct export support. /command/rapids_cpm_init /command/rapids_cpm_find +CPM Pre-Configured Pacakges +*************************** + +These `rapids_cpm` functions allow projects to easily find or build common +RAPIDS dependencies. + +These allow projects to make sure they use the same version and flags for +dependencies as the rest of RAPIDS. The exact versions that each pre-configured +package uses :ref:`can be found here. ` + +.. toctree:: + :titlesonly: + + /packages/rapids_cpm_gtest + /packages/rapids_cpm_nvbench + /packages/rapids_cpm_rmm + /packages/rapids_cpm_spdlog + /packages/rapids_cpm_thrust + + Find **** diff --git a/docs/packages/example.json b/docs/packages/example.json new file mode 100644 index 00000000..69257615 --- /dev/null +++ b/docs/packages/example.json @@ -0,0 +1,11 @@ + +{ + "packages" : { + "Thrust" : { + "version" : "1.12.0", + "git_url" : "https://github.com/NVIDIA/thrust.git", + "git_tag" : "${version}", + "git_shallow" : true + } + } +} diff --git a/docs/packages/rapids_cpm_gtest.rst b/docs/packages/rapids_cpm_gtest.rst new file mode 100644 index 00000000..0394cfc3 --- /dev/null +++ b/docs/packages/rapids_cpm_gtest.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../rapids-cmake/cpm/gtest.cmake diff --git a/docs/packages/rapids_cpm_nvbench.rst b/docs/packages/rapids_cpm_nvbench.rst new file mode 100644 index 00000000..53bda4b0 --- /dev/null +++ b/docs/packages/rapids_cpm_nvbench.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../rapids-cmake/cpm/nvbench.cmake diff --git a/docs/packages/rapids_cpm_rmm.rst b/docs/packages/rapids_cpm_rmm.rst new file mode 100644 index 00000000..01b12e2f --- /dev/null +++ b/docs/packages/rapids_cpm_rmm.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../rapids-cmake/cpm/rmm.cmake diff --git a/docs/packages/rapids_cpm_spdlog.rst b/docs/packages/rapids_cpm_spdlog.rst new file mode 100644 index 00000000..5ef0f1bb --- /dev/null +++ b/docs/packages/rapids_cpm_spdlog.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../rapids-cmake/cpm/spdlog.cmake diff --git a/docs/packages/rapids_cpm_thrust.rst b/docs/packages/rapids_cpm_thrust.rst new file mode 100644 index 00000000..1e8c52a4 --- /dev/null +++ b/docs/packages/rapids_cpm_thrust.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../rapids-cmake/cpm/thrust.cmake diff --git a/docs/packages/rapids_cpm_versions.rst b/docs/packages/rapids_cpm_versions.rst new file mode 100644 index 00000000..3e2c543e --- /dev/null +++ b/docs/packages/rapids_cpm_versions.rst @@ -0,0 +1,63 @@ +:orphan: + + +rapids-cmake package version format +################################### + + +rapids-cmake uses a JSON file to encode the version of a project and how to download the project. + +The JSON format is a root object that contains the ``packages`` object. + +The ``packages`` object contains a key/value map of all supported +packages where the key is the case senstive name of the project and +the value is a ``project`` object, as seen in this example: + +.. literalinclude:: /packages/example.json + :language: json + + +Project Object Fields +********************* + +Each ``project`` object must contain the following fields so that +rapids-cmake can properly use CPM to find or download the project +as needed. + +``version`` + + A required string representing the version of the project to be used + by :cmake:command:`rapids_cpm_find` when looking for a local installed + copy of the project. + + Supports the following placeholders: + - ``${rapids-cmake-version}`` will be evulated to 'major.minor' of the current rapids-cmake cal-ver value. + +``git_url`` + + A required string representing the git url to be used when cloning the + project locally by the :cmake:command:`rapids_cpm_find` when a locally + installed copy of the project can't be found. + +``git_tag`` + + A required string representing the git tag to be used when cloning the + project locally by the :cmake:command:`rapids_cpm_find` when a locally + installed copy of the project can't be found. + + Supports the following placeholders: + - ``${rapids-cmake-version}`` will be evulated to 'major.minor' of the current rapids-cmake cal-ver value. + - ``${version}`` will be evulated to the contents of the ``version`` field. + +``git_shallow`` + + An optional boolean value that represents if we should do a shallow git clone + or not. If no such field exists the default is `git_shallow : true` + +rapids-cmake package versions +############################# + + +.. _cpm_versions: +.. literalinclude:: /../rapids-cmake/cpm/versions.json + :language: json diff --git a/rapids-cmake/cpm/detail/download.cmake b/rapids-cmake/cpm/detail/download.cmake new file mode 100644 index 00000000..bd0d77dc --- /dev/null +++ b/rapids-cmake/cpm/detail/download.cmake @@ -0,0 +1,65 @@ +#============================================================================= +# 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_download +------------------- + +.. versionadded:: v21.10.00 + +Does the downloading of the `CPM` module + +.. code-block:: cmake + + rapids_cpm_download() + +The CPM module will be downloaded based on the state of :cmake:variable:`CPM_SOURCE_CACHE` and +:cmake:variable:`ENV{CPM_SOURCE_CACHE}`. + +.. note:: + Use `rapids_cpm_init` instead of this function, as this is an implementation detail + required for proper cpm project exporting in build directories + + This function can't call other rapids-cmake functions, due to the + restrictions of `write_dependencies.cmake` + +#]=======================================================================] +function(rapids_cpm_download) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.download") + + set(CPM_DOWNLOAD_VERSION 7644c3a40fc7889f8dee53ce21e85dc390b883dc) # 0.32.1 + + if(CPM_SOURCE_CACHE) + # Expand relative path. This is important if the provided path contains a tilde (~) + cmake_path(ABSOLUTE_PATH CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + endif() + + if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) + message(VERBOSE "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") + file(DOWNLOAD + https://raw.githubusercontent.com/cpm-cmake/CPM.cmake/${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake + ${CPM_DOWNLOAD_LOCATION}) + endif() + + include(${CPM_DOWNLOAD_LOCATION}) + +endfunction() diff --git a/rapids-cmake/cpm/detail/load_preset_versions.cmake b/rapids-cmake/cpm/detail/load_preset_versions.cmake new file mode 100644 index 00000000..8674f51b --- /dev/null +++ b/rapids-cmake/cpm/detail/load_preset_versions.cmake @@ -0,0 +1,60 @@ +#============================================================================= +# 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_load_preset_versions +------------------------------- + +.. versionadded:: v21.10.00 + +Establish the `CPM` preset package information for the project. + +.. code-block:: cmake + + rapids_cpm_load_preset_versions() + +.. note:: + Will be called by the first invocation of :cmake:command:`rapids_cpm_init` or :cmake:command:`rapids_cpm_`. + +#]=======================================================================] +function(rapids_cpm_load_preset_versions) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.load_preset_versions") + + # Check if we have been loaded before, if so early terminate + get_property(already_loaded GLOBAL PROPERTY rapids_cpm_load_presets SET) + if(already_loaded) + return() + endif() + set_property(GLOBAL PROPERTY rapids_cpm_load_presets "ON") + + # Load our json files + file(READ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../versions.json" json_data) + + # Determine all the projects that exist in the json file + string(JSON package_count LENGTH "${json_data}" packages) + math(EXPR package_count "${package_count} - 1") + + # For each project cache the subset of the json for that project in a global property + + # cmake-lint: disable=E1120 + foreach(index RANGE ${package_count}) + string(JSON package_name MEMBER "${json_data}" packages ${index}) + string(JSON data GET "${json_data}" packages "${package_name}") + set_property(GLOBAL PROPERTY rapids_cpm_${package_name}_json "${data}") + endforeach() + +endfunction() diff --git a/rapids-cmake/cpm/detail/package_details.cmake b/rapids-cmake/cpm/detail/package_details.cmake new file mode 100644 index 00000000..94bd79c8 --- /dev/null +++ b/rapids-cmake/cpm/detail/package_details.cmake @@ -0,0 +1,58 @@ +#============================================================================= +# 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_package_details +-------------------------- + +. code-block:: cmake + + rapids_cpm_package_details( ) + +#]=======================================================================] +function(rapids_cpm_package_details package_name version_var url_var tag_var shallow_var) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rapids_cpm_package_details") + + include("${rapids-cmake-dir}/cpm/detail/load_preset_versions.cmake") + rapids_cpm_load_preset_versions() + + get_property(json_data GLOBAL PROPERTY rapids_cpm_${package_name}_json) + + # Parse required fields + string(JSON version GET "${json_data}" version) + string(JSON git_url GET "${json_data}" git_url) + string(JSON git_tag GET "${json_data}" git_tag) + + # Parse optional fields + string(JSON git_shallow ERROR_VARIABLE git_shallow_error GET "${json_data}" git_shallow) + if(git_shallow_error) + set(git_shallow ON) + endif() + + # Evaluate any magic placeholders in the version or tag components including the + # `rapids-cmake-version` value + include("${rapids-cmake-dir}/rapids-version.cmake") + + cmake_language(EVAL CODE "set(version ${version})") + cmake_language(EVAL CODE "set(git_tag ${git_tag})") + + set(${version_var} ${version} PARENT_SCOPE) + set(${url_var} ${git_url} PARENT_SCOPE) + set(${tag_var} ${git_tag} PARENT_SCOPE) + set(${shallow_var} ${git_shallow} PARENT_SCOPE) + +endfunction() diff --git a/rapids-cmake/cpm/find.cmake b/rapids-cmake/cpm/find.cmake index 52219c33..8d672247 100644 --- a/rapids-cmake/cpm/find.cmake +++ b/rapids-cmake/cpm/find.cmake @@ -67,12 +67,17 @@ consistency. List all targets used by your project in `GLOBAL_TARGET`. ``INSTALL_EXPORT_SET`` Record a :cmake:command:`find_dependency( ...)` 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:`_SOURCE_DIR` is set to the path to the source directory of . + :cmake:variable:`_BINAR_DIR` is set to the path to the build directory of . + :cmake:variable:`_ADDED` is set to a true value if has not been added before. .. note:: Adding an export set to :cmake:command:`rapids_cpm_find` has different behavior diff --git a/rapids-cmake/cpm/gtest.cmake b/rapids-cmake/cpm/gtest.cmake new file mode 100644 index 00000000..f7d5a31b --- /dev/null +++ b/rapids-cmake/cpm/gtest.cmake @@ -0,0 +1,83 @@ +#============================================================================= +# 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_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 the version of GTest :ref:`specified in the version file ` for consistency +across all RAPIDS projects. + +.. code-block:: cmake + + rapids_cpm_gtest( [BUILD_EXPORT_SET ] + [INSTALL_EXPORT_SET ] + ) +.. 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. + :cmake:variable:`GTest_VERSION` is set to the version of GTest specified by the versions.json. + +#]=======================================================================] +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/detail/package_details.cmake") + rapids_cpm_package_details(GTest version repository tag shallow) + + include("${rapids-cmake-dir}/cpm/find.cmake") + rapids_cpm_find(GTest ${version} ${ARGN} + GLOBAL_TARGETS GTest::gtest GTest::gmock GTest::gtest_main GTest::gmock_main + CPM_ARGS + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + GIT_SHALLOW ${shallow} + 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) + set(GTest_VERSION ${version} 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() diff --git a/rapids-cmake/cpm/init.cmake b/rapids-cmake/cpm/init.cmake index 88f54222..77fb98a2 100644 --- a/rapids-cmake/cpm/init.cmake +++ b/rapids-cmake/cpm/init.cmake @@ -17,11 +17,11 @@ include_guard(GLOBAL) #[=======================================================================[.rst: rapids_cpm_init -------------------- +--------------- .. versionadded:: v21.06.00 -Establish the `CPM` infrastructure for the project. +Establish the `CPM` and preset package infrastructure for the project. .. code-block:: cmake @@ -38,25 +38,11 @@ in the build tree of the calling project #]=======================================================================] function(rapids_cpm_init) list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.init") - set(CPM_DOWNLOAD_VERSION 7644c3a40fc7889f8dee53ce21e85dc390b883dc) # 0.32.1 - - if(CPM_SOURCE_CACHE) - # Expand relative path. This is important if the provided path contains a tilde (~) - cmake_path(ABSOLUTE_PATH CPM_SOURCE_CACHE) - set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") - elseif(DEFINED ENV{CPM_SOURCE_CACHE}) - set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") - else() - set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") - endif() - - if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) - message(VERBOSE "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") - file(DOWNLOAD - https://raw.githubusercontent.com/cpm-cmake/CPM.cmake/${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake - ${CPM_DOWNLOAD_LOCATION}) - endif() - - include(${CPM_DOWNLOAD_LOCATION}) + + include("${rapids-cmake-dir}/cpm/detail/load_preset_versions.cmake") + rapids_cpm_load_preset_versions() + + include("${rapids-cmake-dir}/cpm/detail/download.cmake") + rapids_cpm_download() endfunction() diff --git a/rapids-cmake/cpm/nvbench.cmake b/rapids-cmake/cpm/nvbench.cmake new file mode 100644 index 00000000..27d0b4b6 --- /dev/null +++ b/rapids-cmake/cpm/nvbench.cmake @@ -0,0 +1,85 @@ +#============================================================================= +# 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_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 the version of nvbench :ref:`specified in the version file ` for consistency +across all RAPIDS projects. + +.. code-block:: cmake + + rapids_cpm_nvbench( [BUILD_EXPORT_SET ] ) + +``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. + :cmake:variable:`nvbench_VERSION` is set to the version of nvbench specified by the versions.json. + +#]=======================================================================] +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/detail/package_details.cmake") + rapids_cpm_package_details(nvbench version repository tag shallow) + + include("${rapids-cmake-dir}/cpm/find.cmake") + rapids_cpm_find(nvbench ${version} ${ARGN} + GLOBAL_TARGETS nvbench::nvbench nvbench::main + CPM_ARGS + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + GIT_SHALLOW ${shallow} + 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) + set(nvbench_VERSION ${version} PARENT_SCOPE) + + # nvbench creates the correct namespace aliases +endfunction() diff --git a/rapids-cmake/cpm/rmm.cmake b/rapids-cmake/cpm/rmm.cmake new file mode 100644 index 00000000..6baed68e --- /dev/null +++ b/rapids-cmake/cpm/rmm.cmake @@ -0,0 +1,88 @@ +#============================================================================= +# 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_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 current rapids-cmake version of RMM `as specified in the version file ` +for consistency across all RAPIDS projects. + +.. code-block:: cmake + + rapids_cpm_rmm( [BUILD_EXPORT_SET ] + [INSTALL_EXPORT_SET ] + ) + +``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 + +Result Variables +^^^^^^^^^^^^^^^^ + :cmake:variable:`rmm_SOURCE_DIR` is set to the path to the source directory of RMM. + :cmake:variable:`rmm_BINAR_DIR` is set to the path to the build directory of RMM. + :cmake:variable:`rmm_ADDED` is set to a true value if RMM has not been added before. + :cmake:variable:`rmm_VERSION` is set to the version of RMM specified by the versions.json. + +#]=======================================================================] +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}/cpm/detail/package_details.cmake") + rapids_cpm_package_details(rmm version repository tag shallow) + + 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 "${version}.0" ${ARGN} + GLOBAL_TARGETS rmm::rmm + CPM_ARGS + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + GIT_SHALLOW ${shallow} + OPTIONS "BUILD_TESTS OFF" "BUILD_BENCHMARKS OFF") + + # Propagate up variables that CPMFindPackage provide + set(rmm_SOURCE_DIR "${rmm_SOURCE_DIR}" PARENT_SCOPE) + set(rmm_BINARY_DIR "${rmm_BINARY_DIR}" PARENT_SCOPE) + set(rmm_ADDED "${rmm_ADDED}" PARENT_SCOPE) + set(rmm_VERSION ${version} PARENT_SCOPE) + + # rmm creates the correct namespace aliases +endfunction() diff --git a/rapids-cmake/cpm/spdlog.cmake b/rapids-cmake/cpm/spdlog.cmake new file mode 100644 index 00000000..4d55844b --- /dev/null +++ b/rapids-cmake/cpm/spdlog.cmake @@ -0,0 +1,86 @@ +#============================================================================= +# 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_spdlog +----------------- + +.. versionadded:: v21.10.00 + +Allow projects to find or build `spdlog` via `CPM` with built-in +tracking of these dependencies for correct export support. + +Uses the version of spdlog :ref:`specified in the version file ` for consistency +across all RAPIDS projects. + +.. code-block:: cmake + + rapids_cpm_spdlog( [BUILD_EXPORT_SET ] + [INSTALL_EXPORT_SET ] + ) + +``BUILD_EXPORT_SET`` + Record that a :cmake:command:`CPMFindPackage( ...)` call needs to occur as part of + our build directory export set. + +``INSTALL_EXPORT_SET`` + Record a :cmake:command:`find_dependency( ...)` call needs to occur as part of + our build directory export set. + +.. note:: + Installation of spdlog will occur if an INSTALL_EXPORT_SET is provided, and spdlog + is added to the project via :cmake:command:`add_subdirectory` by CPM. + +Result Targets +^^^^^^^^^^^^^^ + spdlog::spdlog, spdlog::spdlog_header_only targets will be created + +Result Variables +^^^^^^^^^^^^^^^^ + :cmake:variable:`spdlog_SOURCE_DIR` is set to the path to the source directory of spdlog. + :cmake:variable:`spdlog_BINAR_DIR` is set to the path to the build directory of spdlog. + :cmake:variable:`spdlog_ADDED` is set to a true value if spdlog has not been added before. + :cmake:variable:`spdlog_VERSION` is set to the version of spdlog specified by the versions.json. + +#]=======================================================================] +function(rapids_cpm_spdlog) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.spdlog") + + set(to_install OFF) + if(INSTALL_EXPORT_SET IN_LIST ARGN) + set(to_install ON) + endif() + + include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") + rapids_cpm_package_details(spdlog version repository tag shallow) + + include("${rapids-cmake-dir}/cpm/find.cmake") + rapids_cpm_find(spdlog ${version} ${ARGN} + CPM_ARGS + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + GIT_SHALLOW ${shallow} + OPTIONS "spdlog_INSTALL ${to_install}") + + # Propagate up variables that CPMFindPackage provide + set(spdlog_SOURCE_DIR "${spdlog_SOURCE_DIR}" PARENT_SCOPE) + set(spdlog_BINARY_DIR "${spdlog_BINARY_DIR}" PARENT_SCOPE) + set(spdlog_ADDED "${spdlog_ADDED}" PARENT_SCOPE) + set(spdlog_VERSION ${version} PARENT_SCOPE) + + # spdlog creates the correct namespace aliases +endfunction() diff --git a/rapids-cmake/cpm/thrust.cmake b/rapids-cmake/cpm/thrust.cmake new file mode 100644 index 00000000..e09b029f --- /dev/null +++ b/rapids-cmake/cpm/thrust.cmake @@ -0,0 +1,95 @@ +#============================================================================= +# 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_thrust +----------------- + +.. versionadded:: v21.10.00 + +Allow projects to find or build `Thrust` via `CPM` with built-in +tracking of these dependencies for correct export support. + +Uses the version of Thrust :ref:`specified in the version file ` for consistency +across all RAPIDS projects. + +.. code-block:: cmake + + rapids_cpm_thrust( NAMESPACE + [BUILD_EXPORT_SET ] + [INSTALL_EXPORT_SET ] + ) + +``NAMESPACE`` + The namespace that the Thrust target will be constructed into. + +``BUILD_EXPORT_SET`` + Record that a :cmake:command:`CPMFindPackage( ...)` call needs to occur as part of + our build directory export set. + +``INSTALL_EXPORT_SET`` + Record a :cmake:command:`find_dependency( ...)` call needs to occur as part of + our build directory export set. + +.. note:: + Installation of Thrust will occur if an INSTALL_EXPORT_SET is provided, and Thrust + is added to the project via :cmake:command:`add_subdirectory` by CPM. + + +Result Targets +^^^^^^^^^^^^^^ + ::Thrust target will be created + +Result Variables +^^^^^^^^^^^^^^^^ + :cmake:variable:`Thrust_SOURCE_DIR` is set to the path to the source directory of Thrust. + :cmake:variable:`Thrust_BINAR_DIR` is set to the path to the build directory of Thrust. + :cmake:variable:`Thrust_ADDED` is set to a true value if Thrust has not been added before. + :cmake:variable:`Thrust_VERSION` is set to the version of Thrust specified by the versions.json. + +#]=======================================================================] +function(rapids_cpm_thrust NAMESPACE namespaces_name) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.thrust") + + set(to_install OFF) + if(INSTALL_EXPORT_SET IN_LIST ARGN) + set(to_install ON) + endif() + + include("${rapids-cmake-dir}/cpm/detail/package_details.cmake") + rapids_cpm_package_details(Thrust version repository tag shallow) + + include("${rapids-cmake-dir}/cpm/find.cmake") + rapids_cpm_find(Thrust ${version} ${ARGN} + GLOBAL_TARGETS ${namespaces_name}::Thrust + CPM_ARGS + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + GIT_SHALLOW ${shallow} + OPTIONS "THRUST_INSTALL ${to_install}") + + if(NOT TARGET ${namespaces_name}::Thrust) + thrust_create_target(${namespaces_name}::Thrust FROM_OPTIONS) + endif() + + # Propagate up variables that CPMFindPackage provide + set(Thrust_SOURCE_DIR "${Thrust_SOURCE_DIR}" PARENT_SCOPE) + set(Thrust_BINARY_DIR "${Thrust_BINARY_DIR}" PARENT_SCOPE) + set(Thrust_ADDED "${Thrust_ADDED}" PARENT_SCOPE) + set(Thrust_VERSION ${version} PARENT_SCOPE) + +endfunction() diff --git a/rapids-cmake/cpm/versions.json b/rapids-cmake/cpm/versions.json new file mode 100644 index 00000000..aee5d711 --- /dev/null +++ b/rapids-cmake/cpm/versions.json @@ -0,0 +1,30 @@ + +{ + "packages" : { + "GTest" : { + "version" : "1.10", + "git_url" : "https://github.com/google/googletest.git", + "git_tag" : "release-${version}.0" + }, + "nvbench" : { + "version" : "0.0", + "git_url" : "https://github.com/NVIDIA/nvbench.git", + "git_tag" : "main" + }, + "rmm" : { + "version" : "${rapids-cmake-version}", + "git_url" : "https://github.com/rapidsai/rmm.git", + "git_tag" : "branch-${version}" + }, + "spdlog" : { + "version" : "1.8.5", + "git_url" : "https://github.com/gabime/spdlog.git", + "git_tag" : "v${version}" + }, + "Thrust" : { + "version" : "1.12.0", + "git_url" : "https://github.com/NVIDIA/thrust.git", + "git_tag" : "${version}" + } + } +} diff --git a/rapids-cmake/export/write_dependencies.cmake b/rapids-cmake/export/write_dependencies.cmake index 714c79a9..4f78ff4c 100644 --- a/rapids-cmake/export/write_dependencies.cmake +++ b/rapids-cmake/export/write_dependencies.cmake @@ -73,9 +73,9 @@ function(rapids_export_write_dependencies type export_set file_path) # Do we need a Template header? set(RAPIDS_EXPORT_CONTENTS) if(uses_cpm) - file(READ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../cpm/init.cmake" cpm_logic) + file(READ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../cpm/detail/download.cmake" cpm_logic) string(APPEND RAPIDS_EXPORT_CONTENTS ${cpm_logic}) - string(APPEND RAPIDS_EXPORT_CONTENTS "rapids_cpm_init()\n\n") + string(APPEND RAPIDS_EXPORT_CONTENTS "rapids_cpm_download()\n\n") if(type STREQUAL build) string(APPEND diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 90a86ff9..f703ff19 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -19,3 +19,18 @@ add_cmake_config_test( cpm_find-existing-build-dir ) add_cmake_config_test( cpm_find-existing-target ) add_cmake_config_test( cpm_find-existing-target-to-export-sets ) add_cmake_config_test( cpm_find-options-escaped ) + +add_cmake_config_test( cpm_gtest-export.cmake SERIAL ) +add_cmake_config_test( cpm_gtest-simple.cmake SERIAL ) + +add_cmake_config_test( cpm_nvbench-export.cmake SERIAL ) +add_cmake_config_test( cpm_nvbench-simple.cmake SERIAL ) + +add_cmake_config_test( cpm_rmm-export.cmake SERIAL ) +add_cmake_config_test( cpm_rmm-simple.cmake SERIAL ) + +add_cmake_config_test( cpm_spdlog-export.cmake SERIAL ) +add_cmake_config_test( cpm_spdlog-simple.cmake SERIAL ) + +add_cmake_config_test( cpm_thrust-export.cmake SERIAL ) +add_cmake_config_test( cpm_thrust-simple.cmake SERIAL ) \ No newline at end of file diff --git a/testing/cpm/cpm_gtest-export.cmake b/testing/cpm/cpm_gtest-export.cmake new file mode 100644 index 00000000..54f1e7be --- /dev/null +++ b/testing/cpm/cpm_gtest-export.cmake @@ -0,0 +1,34 @@ +#============================================================================= +# 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/gtest.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +rapids_cpm_gtest(BUILD_EXPORT_SET test) +rapids_cpm_gtest(BUILD_EXPORT_SET test2) + +get_target_property(packages rapids_export_build_test PACKAGE_NAMES) +if(NOT GTest IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_gtest failed to record gtest needs to be exported") +endif() + +get_target_property(packages rapids_export_build_test2 PACKAGE_NAMES) +if(NOT GTest IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_gtest failed to record gtest needs to be exported") +endif() diff --git a/testing/cpm/cpm_gtest-simple.cmake b/testing/cpm/cpm_gtest-simple.cmake new file mode 100644 index 00000000..2b520253 --- /dev/null +++ b/testing/cpm/cpm_gtest-simple.cmake @@ -0,0 +1,39 @@ +#============================================================================= +# 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/gtest.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + + +if(TARGET GTest::gtest) + message(FATAL_ERROR "Expected GTest::gtest expected to not exist") +endif() + +rapids_cpm_gtest() + +set(targets_made GTest::gtest GTest::gmock GTest::gtest_main GTest::gmock_main) + +foreach(t IN LISTS targets_made) + if(NOT TARGET ${t}) + message(FATAL_ERROR "Expected ${t} target to exist") + endif() +endforeach() + +# Make sure we can be called multiple times +rapids_cpm_gtest() diff --git a/testing/cpm/cpm_nvbench-export.cmake b/testing/cpm/cpm_nvbench-export.cmake new file mode 100644 index 00000000..d9ee168e --- /dev/null +++ b/testing/cpm/cpm_nvbench-export.cmake @@ -0,0 +1,34 @@ +#============================================================================= +# 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/nvbench.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +rapids_cpm_nvbench(BUILD_EXPORT_SET test) +rapids_cpm_nvbench(BUILD_EXPORT_SET test2) + +get_target_property(packages rapids_export_build_test PACKAGE_NAMES) +if(NOT nvbench IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_nvbench failed to record nvbench needs to be exported") +endif() + +get_target_property(packages rapids_export_build_test2 PACKAGE_NAMES) +if(NOT nvbench IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_nvbench failed to record nvbench needs to be exported") +endif() diff --git a/testing/cpm/cpm_nvbench-simple.cmake b/testing/cpm/cpm_nvbench-simple.cmake new file mode 100644 index 00000000..f4692d9b --- /dev/null +++ b/testing/cpm/cpm_nvbench-simple.cmake @@ -0,0 +1,38 @@ +#============================================================================= +# 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/nvbench.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +if(TARGET nvbench::nvbench) + message(FATAL_ERROR "Expected nvbench::nvbench expected to not exist") +endif() + +rapids_cpm_nvbench() + +set(targets_made nvbench::nvbench nvbench::main) + +foreach(t IN LISTS targets_made) + if(NOT TARGET ${t}) + message(FATAL_ERROR "Expected ${t} target to exist") + endif() +endforeach() + +# Make sure we can be called multiple times +rapids_cpm_nvbench() diff --git a/testing/cpm/cpm_rmm-export.cmake b/testing/cpm/cpm_rmm-export.cmake new file mode 100644 index 00000000..21a14877 --- /dev/null +++ b/testing/cpm/cpm_rmm-export.cmake @@ -0,0 +1,39 @@ +#============================================================================= +# 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/rmm.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +rapids_cpm_rmm(BUILD_EXPORT_SET frank INSTALL_EXPORT_SET test) +rapids_cpm_rmm(INSTALL_EXPORT_SET test2) + +get_target_property(packages rapids_export_install_test PACKAGE_NAMES) +if(NOT rmm IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_rmm failed to record rmm needs to be exported") +endif() + +get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES) +if(NOT rmm IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_rmm failed to record rmm needs to be exported") +endif() + +get_target_property(packages rapids_export_build_frank PACKAGE_NAMES) +if(NOT rmm IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_rmm failed to record rmm needs to be exported") +endif() diff --git a/testing/cpm/cpm_rmm-simple.cmake b/testing/cpm/cpm_rmm-simple.cmake new file mode 100644 index 00000000..a5f9abde --- /dev/null +++ b/testing/cpm/cpm_rmm-simple.cmake @@ -0,0 +1,32 @@ +#============================================================================= +# 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/rmm.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +if(TARGET rmm::rmm) + message(FATAL_ERROR "Expected rmm::rmm expected to not exist") +endif() + +rapids_cpm_rmm() +if(NOT TARGET rmm::rmm) + message(FATAL_ERROR "Expected rmm::rmm target to exist") +endif() + +rapids_cpm_rmm() diff --git a/testing/cpm/cpm_spdlog-export.cmake b/testing/cpm/cpm_spdlog-export.cmake new file mode 100644 index 00000000..610ae43c --- /dev/null +++ b/testing/cpm/cpm_spdlog-export.cmake @@ -0,0 +1,39 @@ +#============================================================================= +# 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/spdlog.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +rapids_cpm_spdlog(BUILD_EXPORT_SET frank INSTALL_EXPORT_SET test) +rapids_cpm_spdlog(INSTALL_EXPORT_SET test2) + +get_target_property(packages rapids_export_install_test PACKAGE_NAMES) +if(NOT spdlog IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_spdlog failed to record spdlog needs to be exported") +endif() + +get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES) +if(NOT spdlog IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_spdlog failed to record spdlog needs to be exported") +endif() + +get_target_property(packages rapids_export_build_frank PACKAGE_NAMES) +if(NOT spdlog IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_spdlog failed to record spdlog needs to be exported") +endif() diff --git a/testing/cpm/cpm_spdlog-simple.cmake b/testing/cpm/cpm_spdlog-simple.cmake new file mode 100644 index 00000000..9cd0d1df --- /dev/null +++ b/testing/cpm/cpm_spdlog-simple.cmake @@ -0,0 +1,32 @@ +#============================================================================= +# 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/spdlog.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +if(TARGET spdlog::spdlog_header_only) + message(FATAL_ERROR "Expected spdlog::spdlog_header_only expected to not exist") +endif() + +rapids_cpm_spdlog() +if(NOT TARGET spdlog::spdlog_header_only) + message(FATAL_ERROR "Expected spdlog::spdlog_header_only target to exist") +endif() + +rapids_cpm_spdlog() diff --git a/testing/cpm/cpm_thrust-export.cmake b/testing/cpm/cpm_thrust-export.cmake new file mode 100644 index 00000000..0ceddcc9 --- /dev/null +++ b/testing/cpm/cpm_thrust-export.cmake @@ -0,0 +1,34 @@ +#============================================================================= +# 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/thrust.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +rapids_cpm_thrust(NAMESPACE A BUILD_EXPORT_SET test) +rapids_cpm_thrust(NAMESPACE B BUILD_EXPORT_SET test2) + +get_target_property(packages rapids_export_build_test PACKAGE_NAMES) +if(NOT Thrust IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_thrust failed to record thrust needs to be exported") +endif() + +get_target_property(packages rapids_export_build_test2 PACKAGE_NAMES) +if(NOT Thrust IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_thrust failed to record thrust needs to be exported") +endif() diff --git a/testing/cpm/cpm_thrust-simple.cmake b/testing/cpm/cpm_thrust-simple.cmake new file mode 100644 index 00000000..4615f3df --- /dev/null +++ b/testing/cpm/cpm_thrust-simple.cmake @@ -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/thrust.cmake) + +include("${rapids-cmake-testing-dir}/cpm/setup_cpm_cache.cmake") +setup_cpm_cache() +rapids_cpm_init() + +if(TARGET test::Thrust) + message(FATAL_ERROR "Expected test::Thrust expected to not exist") +endif() + +rapids_cpm_thrust(NAMESPACE test) +if(NOT TARGET test::Thrust) + message(FATAL_ERROR "Expected test::Thrust target to exist") +endif() + +rapids_cpm_thrust(NAMESPACE test) + +rapids_cpm_thrust(NAMESPACE test2) +if(NOT TARGET test2::Thrust) + message(FATAL_ERROR "Expected test2::Thrust target to exist") +endif() diff --git a/testing/cpm/setup_cpm_cache.cmake b/testing/cpm/setup_cpm_cache.cmake new file mode 100644 index 00000000..01e23928 --- /dev/null +++ b/testing/cpm/setup_cpm_cache.cmake @@ -0,0 +1,21 @@ +#============================================================================= +# 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. +#============================================================================= + +function(setup_cpm_cache ) + cmake_path(GET CMAKE_BINARY_DIR PARENT_PATH CPM_SOURCE_CACHE) + cmake_path(APPEND_STRING CPM_SOURCE_CACHE "/cache") + set(CPM_SOURCE_CACHE "${CPM_SOURCE_CACHE}" PARENT_SCOPE) +endfunction()