Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fmt 9.1.0 #364

Merged
merged 8 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions rapids-cmake/cpm/fmt.cmake
Original file line number Diff line number Diff line change
@@ -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_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 <cpm_versions>` for consistency
across all RAPIDS projects.

.. code-block:: cmake

rapids_cpm_fmt( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
[<CPM_ARGS> ...])

.. |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}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to this option there's a FMT_SYSTEM_HEADERS option that treats them as system includes instead of user includes presumably to make things like clang-tidy happy. If we want that option I'm happy to add it here (as well as for spdlog which also has the option).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to say here. @vyasr @robertmaynard?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone know what the behavior of spdlog is when using an internal version of fmt? If it is marking the headers as system I don't mind re-producing that approach.

This will only effect when we are building fmt from source, since installed versions of fmt will always be treated as system due to how IMPORT targets in CMake behave.


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()
5 changes: 5 additions & 0 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"git_url" : "https://github.com/gabime/spdlog.git",
"git_tag" : "v${version}"
},
"fmt" : {
"version" : "9.1.0",
"git_url" : "https://github.com/fmtlib/fmt.git",
"git_tag" : "${version}"
},
"Thrust" : {
"version" : "1.17.2",
"git_url" : "https://github.com/NVIDIA/thrust.git",
Expand Down
37 changes: 37 additions & 0 deletions testing/cpm/cpm_fmt-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/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()
39 changes: 39 additions & 0 deletions testing/cpm/cpm_fmt-simple.cmake
Original file line number Diff line number Diff line change
@@ -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/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()