Skip to content

Commit 9f27732

Browse files
authored
Bump spdlog to 1.11, add fmt as dependency for spdlog (#368)
Bumps spdlog to 1.11.0 and adds `fmt` as a dependency of spdlog and sets the `SPDLOG_FMT_EXTERNAL_HO` cmake option for spdlog. Happy to change that to be controlled by an argument to the `rapids_cpm_spdlog` function if desired. I believe the existing testing should cover the changes made here as the `spdlog` and `rmm` related tests were failing until adding `fmt` to the `spdlog` `BUILD_EXPORT_SET` and `INSTALL_EXPORT_SET`. Authors: - Keith Kraus (https://github.com/kkraus14) - Bradley Dice (https://github.com/bdice) Approvers: - Robert Maynard (https://github.com/robertmaynard) URL: #368
1 parent c988569 commit 9f27732

3 files changed

Lines changed: 69 additions & 6 deletions

File tree

cmake-format-rapids-cmake.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
},
167167
"kwargs": {
168168
"BUILD_EXPORT_SET": 1,
169+
"FMT_OPTION": 1,
169170
"INSTALL_EXPORT_SET": 1
170171
}
171172
},

rapids-cmake/cpm/spdlog.cmake

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#=============================================================================
2-
# Copyright (c) 2021, NVIDIA CORPORATION.
2+
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -29,10 +29,26 @@ across all RAPIDS projects.
2929
3030
.. code-block:: cmake
3131
32-
rapids_cpm_spdlog( [BUILD_EXPORT_SET <export-name>]
32+
rapids_cpm_spdlog( [FMT_OPTION <fmt-option-name>]
33+
[BUILD_EXPORT_SET <export-name>]
3334
[INSTALL_EXPORT_SET <export-name>]
3435
[<CPM_ARGS> ...])
3536
37+
``FMT_OPTION``
38+
.. versionadded:: v23.04.00
39+
40+
Spdlog depends on the fmt library and offers multiple ways of handling this dependency when spdlog is built. This
41+
option only controls the behavior when spdlog is fetched and built, NOT when an installed spdlog is found on the
42+
system.
43+
44+
This option can be set to: `BUNDLED`, `EXTERNAL_FMT`, `EXTERNAL_FMT_HO`, or `STD_FORMAT`. If set to
45+
`BUNDLED`, then spdlog will use its own bundled version of fmt. If set to `EXTERNAL_FMT` then spdlog will use the
46+
`fmt::fmt` target and be linked with the fmt library. If set to `EXTERNAL_FMT_HO` then spdlog will use the
47+
`fmt::fmt-header-only` target and be linked with a header only fmt library. If set to `STD_FORMAT` then spdlog
48+
will use `std::format` instead of the fmt library.
49+
50+
Defaults to `EXTERNAL_FMT_HO`.
51+
3652
.. |PKG_NAME| replace:: spdlog
3753
.. include:: common_package_args.txt
3854
@@ -46,13 +62,28 @@ Result Variables
4662
:cmake:variable:`spdlog_BINARY_DIR` is set to the path to the build directory of spdlog.
4763
:cmake:variable:`spdlog_ADDED` is set to a true value if spdlog has not been added before.
4864
:cmake:variable:`spdlog_VERSION` is set to the version of spdlog specified by the versions.json.
65+
:cmake:variable:`spdlog_fmt_target` is set to the fmt target used, if used
4966
5067
#]=======================================================================]
5168
function(rapids_cpm_spdlog)
5269
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.spdlog")
5370

71+
set(options)
72+
set(one_value FMT_OPTION BUILD_EXPORT_SET INSTALL_EXPORT_SET)
73+
set(multi_value)
74+
cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN})
75+
76+
# Fix up _RAPIDS_UNPARSED_ARGUMENTS to have EXPORT_SETS as this is need for rapids_cpm_find. Also
77+
# propagate the user provided build and install export sets.
78+
if(_RAPIDS_INSTALL_EXPORT_SET)
79+
list(APPEND _RAPIDS_UNPARSED_ARGUMENTS INSTALL_EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET})
80+
endif()
81+
if(_RAPIDS_BUILD_EXPORT_SET)
82+
list(APPEND _RAPIDS_UNPARSED_ARGUMENTS BUILD_EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET})
83+
endif()
84+
5485
set(to_install OFF)
55-
if(INSTALL_EXPORT_SET IN_LIST ARGN)
86+
if(_RAPIDS_INSTALL_EXPORT_SET)
5687
set(to_install ON)
5788
endif()
5889

@@ -62,16 +93,46 @@ function(rapids_cpm_spdlog)
6293
include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake")
6394
rapids_cpm_generate_patch_command(spdlog ${version} patch_command)
6495

96+
# If the option wasn't passed to the command, default to header only fmt
97+
if(NOT _RAPIDS_FMT_OPTION)
98+
set(_RAPIDS_FMT_OPTION "EXTERNAL_FMT_HO")
99+
endif()
100+
101+
if(_RAPIDS_FMT_OPTION STREQUAL "BUNDLED")
102+
set(spdlog_fmt_option "")
103+
elseif(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT" OR _RAPIDS_FMT_OPTION STREQUAL
104+
"EXTERNAL_FMT_HO")
105+
include("${rapids-cmake-dir}/cpm/fmt.cmake")
106+
107+
# Using `spdlog_ROOT` needs to cause any internal find calls in `spdlog-config.cmake` to first
108+
# search beside it before looking globally.
109+
list(APPEND fmt_ROOT ${spdlog_ROOT})
110+
111+
rapids_cpm_fmt(${_RAPIDS_UNPARSED_ARGUMENTS})
112+
113+
set(spdlog_fmt_option "SPDLOG_${_RAPIDS_FMT_OPTION} ON")
114+
if(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT")
115+
set(spdlog_fmt_target fmt::fmt)
116+
elseif(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT_HO")
117+
set(spdlog_fmt_target fmt::fmt-header-only)
118+
endif()
119+
elseif(_RAPIDS_FMT_OPTION STREQUAL "STD_FORMAT")
120+
set(spdlog_fmt_option "SPDLOG_USE_${_RAPIDS_FMT_OPTION} ON")
121+
else()
122+
message(FATAL_ERROR "Invalid option used for FMT_OPTION, got: ${_RAPIDS_FMT_OPTION}, expected one of: 'BUNDLED', 'EXTERNAL_FMT', 'EXTERNAL_FMT_HO', 'STD_FORMAT'"
123+
)
124+
endif()
125+
65126
include("${rapids-cmake-dir}/cpm/find.cmake")
66-
rapids_cpm_find(spdlog ${version} ${ARGN}
127+
rapids_cpm_find(spdlog ${version} ${_RAPIDS_UNPARSED_ARGUMENTS}
67128
GLOBAL_TARGETS spdlog::spdlog spdlog::spdlog_header_only
68129
CPM_ARGS
69130
GIT_REPOSITORY ${repository}
70131
GIT_TAG ${tag}
71132
GIT_SHALLOW ${shallow}
72133
PATCH_COMMAND ${patch_command}
73134
EXCLUDE_FROM_ALL ${exclude}
74-
OPTIONS "SPDLOG_INSTALL ${to_install}")
135+
OPTIONS "SPDLOG_INSTALL ${to_install}" "${spdlog_fmt_option}")
75136

76137
include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
77138
rapids_cpm_display_patch_status(spdlog)
@@ -81,6 +142,7 @@ function(rapids_cpm_spdlog)
81142
set(spdlog_BINARY_DIR "${spdlog_BINARY_DIR}" PARENT_SCOPE)
82143
set(spdlog_ADDED "${spdlog_ADDED}" PARENT_SCOPE)
83144
set(spdlog_VERSION ${version} PARENT_SCOPE)
145+
set(spdlog_fmt_target ${spdlog_fmt_target} PARENT_SCOPE)
84146

85147
# spdlog creates the correct namespace aliases
86148
endfunction()

rapids-cmake/cpm/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"git_tag" : "branch-${version}"
4949
},
5050
"spdlog" : {
51-
"version" : "1.8.5",
51+
"version" : "1.11.0",
5252
"git_url" : "https://github.com/gabime/spdlog.git",
5353
"git_tag" : "v${version}"
5454
},

0 commit comments

Comments
 (0)