Skip to content

Commit

Permalink
Bump spdlog to 1.11, add fmt as dependency for spdlog (#368)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kkraus14 authored Feb 13, 2023
1 parent c988569 commit 9f27732
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"FMT_OPTION": 1,
"INSTALL_EXPORT_SET": 1
}
},
Expand Down
72 changes: 67 additions & 5 deletions rapids-cmake/cpm/spdlog.cmake
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,10 +29,26 @@ across all RAPIDS projects.

.. code-block:: cmake

rapids_cpm_spdlog( [BUILD_EXPORT_SET <export-name>]
rapids_cpm_spdlog( [FMT_OPTION <fmt-option-name>]
[BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
[<CPM_ARGS> ...])

``FMT_OPTION``
.. versionadded:: v23.04.00

Spdlog depends on the fmt library and offers multiple ways of handling this dependency when spdlog is built. This
option only controls the behavior when spdlog is fetched and built, NOT when an installed spdlog is found on the
system.

This option can be set to: `BUNDLED`, `EXTERNAL_FMT`, `EXTERNAL_FMT_HO`, or `STD_FORMAT`. If set to
`BUNDLED`, then spdlog will use its own bundled version of fmt. If set to `EXTERNAL_FMT` then spdlog will use the
`fmt::fmt` target and be linked with the fmt library. If set to `EXTERNAL_FMT_HO` then spdlog will use the
`fmt::fmt-header-only` target and be linked with a header only fmt library. If set to `STD_FORMAT` then spdlog
will use `std::format` instead of the fmt library.

Defaults to `EXTERNAL_FMT_HO`.

.. |PKG_NAME| replace:: spdlog
.. include:: common_package_args.txt

Expand All @@ -46,13 +62,28 @@ Result Variables
:cmake:variable:`spdlog_BINARY_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.
:cmake:variable:`spdlog_fmt_target` is set to the fmt target used, if used

#]=======================================================================]
function(rapids_cpm_spdlog)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.spdlog")

set(options)
set(one_value FMT_OPTION BUILD_EXPORT_SET INSTALL_EXPORT_SET)
set(multi_value)
cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN})

# Fix up _RAPIDS_UNPARSED_ARGUMENTS to have EXPORT_SETS as this is need for rapids_cpm_find. Also
# propagate the user provided build and install export sets.
if(_RAPIDS_INSTALL_EXPORT_SET)
list(APPEND _RAPIDS_UNPARSED_ARGUMENTS INSTALL_EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET})
endif()
if(_RAPIDS_BUILD_EXPORT_SET)
list(APPEND _RAPIDS_UNPARSED_ARGUMENTS BUILD_EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET})
endif()

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

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

# If the option wasn't passed to the command, default to header only fmt
if(NOT _RAPIDS_FMT_OPTION)
set(_RAPIDS_FMT_OPTION "EXTERNAL_FMT_HO")
endif()

if(_RAPIDS_FMT_OPTION STREQUAL "BUNDLED")
set(spdlog_fmt_option "")
elseif(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT" OR _RAPIDS_FMT_OPTION STREQUAL
"EXTERNAL_FMT_HO")
include("${rapids-cmake-dir}/cpm/fmt.cmake")

# Using `spdlog_ROOT` needs to cause any internal find calls in `spdlog-config.cmake` to first
# search beside it before looking globally.
list(APPEND fmt_ROOT ${spdlog_ROOT})

rapids_cpm_fmt(${_RAPIDS_UNPARSED_ARGUMENTS})

set(spdlog_fmt_option "SPDLOG_${_RAPIDS_FMT_OPTION} ON")
if(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT")
set(spdlog_fmt_target fmt::fmt)
elseif(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT_HO")
set(spdlog_fmt_target fmt::fmt-header-only)
endif()
elseif(_RAPIDS_FMT_OPTION STREQUAL "STD_FORMAT")
set(spdlog_fmt_option "SPDLOG_USE_${_RAPIDS_FMT_OPTION} ON")
else()
message(FATAL_ERROR "Invalid option used for FMT_OPTION, got: ${_RAPIDS_FMT_OPTION}, expected one of: 'BUNDLED', 'EXTERNAL_FMT', 'EXTERNAL_FMT_HO', 'STD_FORMAT'"
)
endif()

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(spdlog ${version} ${ARGN}
rapids_cpm_find(spdlog ${version} ${_RAPIDS_UNPARSED_ARGUMENTS}
GLOBAL_TARGETS spdlog::spdlog spdlog::spdlog_header_only
CPM_ARGS
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow}
PATCH_COMMAND ${patch_command}
EXCLUDE_FROM_ALL ${exclude}
OPTIONS "SPDLOG_INSTALL ${to_install}")
OPTIONS "SPDLOG_INSTALL ${to_install}" "${spdlog_fmt_option}")

include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
rapids_cpm_display_patch_status(spdlog)
Expand All @@ -81,6 +142,7 @@ function(rapids_cpm_spdlog)
set(spdlog_BINARY_DIR "${spdlog_BINARY_DIR}" PARENT_SCOPE)
set(spdlog_ADDED "${spdlog_ADDED}" PARENT_SCOPE)
set(spdlog_VERSION ${version} PARENT_SCOPE)
set(spdlog_fmt_target ${spdlog_fmt_target} PARENT_SCOPE)

# spdlog creates the correct namespace aliases
endfunction()
2 changes: 1 addition & 1 deletion rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"git_tag" : "branch-${version}"
},
"spdlog" : {
"version" : "1.8.5",
"version" : "1.11.0",
"git_url" : "https://github.com/gabime/spdlog.git",
"git_tag" : "v${version}"
},
Expand Down

0 comments on commit 9f27732

Please sign in to comment.