diff --git a/cmake-format-rapids-cmake.json b/cmake-format-rapids-cmake.json index ad18bbbd..0d3f803f 100644 --- a/cmake-format-rapids-cmake.json +++ b/cmake-format-rapids-cmake.json @@ -97,6 +97,15 @@ "INSTALL_EXPORT_SET": 1 } }, + "rapids_cpm_fmt": { + "pargs": { + "nargs": 0 + }, + "kwargs": { + "BUILD_EXPORT_SET": 1, + "INSTALL_EXPORT_SET": 1 + } + }, "rapids_cpm_gbench": { "pargs": { "nargs": 0 diff --git a/docs/api.rst b/docs/api.rst index 9e5013a5..1543157c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -45,6 +45,7 @@ package uses :ref:`can be found here. ` :titlesonly: /packages/rapids_cpm_cuco + /packages/rapids_cpm_fmt /packages/rapids_cpm_gbench /packages/rapids_cpm_gtest /packages/rapids_cpm_libcudacxx diff --git a/docs/packages/rapids_cpm_fmt.rst b/docs/packages/rapids_cpm_fmt.rst new file mode 100644 index 00000000..9a146a5e --- /dev/null +++ b/docs/packages/rapids_cpm_fmt.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../rapids-cmake/cpm/fmt.cmake diff --git a/rapids-cmake/cpm/fmt.cmake b/rapids-cmake/cpm/fmt.cmake new file mode 100644 index 00000000..51fcc172 --- /dev/null +++ b/rapids-cmake/cpm/fmt.cmake @@ -0,0 +1,86 @@ +#============================================================================= +# 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_cpm_fmt +----------------- + +.. versionadded:: v23.04.00 + +Allow projects to find or build `fmt` via `CPM` with built-in +tracking of these dependencies for correct export support. + +Uses the version of fmt :ref:`specified in the version file ` for consistency +across all RAPIDS projects. + +.. code-block:: cmake + + rapids_cpm_fmt( [BUILD_EXPORT_SET ] + [INSTALL_EXPORT_SET ] + [ ...]) + +.. |PKG_NAME| replace:: fmt +.. include:: common_package_args.txt + +Result Targets +^^^^^^^^^^^^^^ + fmt::fmt, fmt::fmt-header-only targets will be created + +Result Variables +^^^^^^^^^^^^^^^^ + :cmake:variable:`fmt_SOURCE_DIR` is set to the path to the source directory of fmt. + :cmake:variable:`fmt_BINARY_DIR` is set to the path to the build directory of fmt. + :cmake:variable:`fmt_ADDED` is set to a true value if fmt has not been added before. + :cmake:variable:`fmt_VERSION` is set to the version of fmt specified by the versions.json. + +#]=======================================================================] +function(rapids_cpm_fmt) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.fmt") + + 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(fmt version repository tag shallow exclude) + + include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake") + rapids_cpm_generate_patch_command(fmt ${version} patch_command) + + include("${rapids-cmake-dir}/cpm/find.cmake") + rapids_cpm_find(fmt ${version} ${ARGN} + GLOBAL_TARGETS fmt::fmt fmt::fmt-header-only + CPM_ARGS + GIT_REPOSITORY ${repository} + GIT_TAG ${tag} + GIT_SHALLOW ${shallow} + PATCH_COMMAND ${patch_command} + EXCLUDE_FROM_ALL ${exclude} + OPTIONS "FMT_INSTALL ${to_install}") + + include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake") + rapids_cpm_display_patch_status(fmt) + + # Propagate up variables that CPMFindPackage provide + set(fmt_SOURCE_DIR "${fmt_SOURCE_DIR}" PARENT_SCOPE) + set(fmt_BINARY_DIR "${fmt_BINARY_DIR}" PARENT_SCOPE) + set(fmt_ADDED "${fmt_ADDED}" PARENT_SCOPE) + set(fmt_VERSION ${version} PARENT_SCOPE) + + # fmt creates the correct namespace aliases +endfunction() diff --git a/rapids-cmake/cpm/versions.json b/rapids-cmake/cpm/versions.json index 6f922af2..a3a87325 100644 --- a/rapids-cmake/cpm/versions.json +++ b/rapids-cmake/cpm/versions.json @@ -7,6 +7,11 @@ "git_url" : "https://github.com/NVIDIA/cuCollections.git", "git_tag" : "31e1d5df6869ef6cb60f36a614b30a244cf3bd78" }, + "fmt" : { + "version" : "9.1.0", + "git_url" : "https://github.com/fmtlib/fmt.git", + "git_tag" : "${version}" + }, "GBench" : { "version" : "1.5.3", "git_url" : "https://github.com/google/benchmark.git", diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 4a45d413..d93b5bd8 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -46,6 +46,9 @@ add_cmake_config_test( cpm_cuco-simple.cmake ) add_cmake_config_test( cpm_cuco-export.cmake ) add_cmake_config_test( cpm_cuco-libcudacxx-no-install-export.cmake ) +add_cmake_config_test( cpm_fmt-export.cmake ) +add_cmake_config_test( cpm_fmt-simple.cmake ) + add_cmake_config_test( cpm_gbench-export.cmake ) add_cmake_config_test( cpm_gbench-simple.cmake ) diff --git a/testing/cpm/cpm_fmt-export.cmake b/testing/cpm/cpm_fmt-export.cmake new file mode 100644 index 00000000..39601251 --- /dev/null +++ b/testing/cpm/cpm_fmt-export.cmake @@ -0,0 +1,37 @@ +#============================================================================= +# 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}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/fmt.cmake) + +rapids_cpm_init() + +rapids_cpm_fmt(BUILD_EXPORT_SET frank INSTALL_EXPORT_SET test) +rapids_cpm_fmt(INSTALL_EXPORT_SET test2) + +get_target_property(packages rapids_export_install_test PACKAGE_NAMES) +if(NOT fmt IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_fmt failed to record fmt needs to be exported") +endif() + +get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES) +if(NOT fmt IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_fmt failed to record fmt needs to be exported") +endif() + +get_target_property(packages rapids_export_build_frank PACKAGE_NAMES) +if(NOT fmt IN_LIST packages) + message(FATAL_ERROR "rapids_cpm_fmt failed to record fmt needs to be exported") +endif() diff --git a/testing/cpm/cpm_fmt-simple.cmake b/testing/cpm/cpm_fmt-simple.cmake new file mode 100644 index 00000000..221eb572 --- /dev/null +++ b/testing/cpm/cpm_fmt-simple.cmake @@ -0,0 +1,39 @@ +#============================================================================= +# 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}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/fmt.cmake) + +rapids_cpm_init() + +if(TARGET fmt::fmt-header-only) + message(FATAL_ERROR "Expected fmt::fmt-header-only expected to not exist") +endif() + +if(TARGET fmt::fmt) + message(FATAL_ERROR "Expected fmt::fmt expected to not exist") +endif() + +rapids_cpm_fmt() + +if(NOT TARGET fmt::fmt-header-only) + message(FATAL_ERROR "Expected fmt::fmt-header-only target to exist") +endif() + +if(NOT TARGET fmt::fmt) + message(FATAL_ERROR "Expected fmt::fmt target to exist") +endif() + +rapids_cpm_fmt() diff --git a/testing/utils/fill_cache/CMakeLists.txt b/testing/utils/fill_cache/CMakeLists.txt index ec84b524..80cb1131 100644 --- a/testing/utils/fill_cache/CMakeLists.txt +++ b/testing/utils/fill_cache/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-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. @@ -27,6 +27,7 @@ include(${rapids-cmake-dir}/cpm/nvbench.cmake) include(${rapids-cmake-dir}/cpm/nvcomp.cmake) include(${rapids-cmake-dir}/cpm/rmm.cmake) include(${rapids-cmake-dir}/cpm/spdlog.cmake) +include(${rapids-cmake-dir}/cpm/fmt.cmake) include(${rapids-cmake-dir}/cpm/thrust.cmake) rapids_cpm_init() @@ -42,6 +43,7 @@ rapids_cpm_libcudacxx(DOWNLOAD_ONLY ON) rapids_cpm_nvbench(DOWNLOAD_ONLY ON) rapids_cpm_rmm(DOWNLOAD_ONLY ON) rapids_cpm_spdlog(DOWNLOAD_ONLY ON) +rapids_cpm_fmt(DOWNLOAD_ONLY ON) rapids_cpm_thrust(temp DOWNLOAD_ONLY ON) rapids_cpm_find(skbuild 0.14.1 GIT_REPOSITORY https://github.com/scikit-build/scikit-build.git