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

Support downloading spdlog when building rapids-logger #740

Draft
wants to merge 10 commits into
base: branch-25.02
Choose a base branch
from
Draft
52 changes: 49 additions & 3 deletions rapids-cmake/cpm/rapids_logger.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Unlike most `rapids_cpm` functions, this one does not support export sets becaus

.. code-block:: cmake

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

.. |PKG_NAME| replace:: logger
.. include:: common_package_args.txt
Expand All @@ -44,11 +46,55 @@ function(rapids_cpm_rapids_logger)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rapids_logger")

set(options)
set(one_value)
# Note: BUILD_EXPORT_SET and INSTALL_EXPORT_SET are not directly used for the logger but are
# instead forwarded to spdlog.
set(one_value FMT_OPTION BUILD_EXPORT_SET INSTALL_EXPORT_SET)
set(multi_value)
cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN})

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
# TODO: Need to also support this in exported config files so that header-only libraries like rmm
# can force their consumers to clone spdlog when a pre-built package is found.
include(${rapids-cmake-dir}/cpm/spdlog.cmake)
include(${rapids-cmake-dir}/cpm/detail/package_details.cmake)
if(RAPIDS_LOGGER_HIDE_ALL_SPDLOG_SYMBOLS)
get_property(_already_downloaded_spdlog GLOBAL PROPERTY RAPIDS_LOGGER_DOWNLOADED_SPDLOG)
if(NOT _already_downloaded_spdlog)
if(TARGET spdlog::spdlog OR TARGET spdlog::spdlog_header_only)
message(FATAL_ERROR "Expected spdlog::spdlog not to exist before the first call to rapids_cpm_rapids_logger when RAPIDS_LOGGER_HIDE_ALL_SPDLOG_SYMBOLS is ON"
)
endif()
set(CPM_DOWNLOAD_spdlog ON)
rapids_cpm_spdlog(FMT_OPTION "BUNDLED"
# TODO: I don't really expect this to work with the way that
# rapids_cpm_spdlog is set up right now, it's going to require
# some tweaking of argument forwarding I suspect.
CPM_ARGS EXCLUDE_FROM_ALL ON OPTIONS "BUILD_SHARED_LIBS OFF"
"SPDLOG_BUILD_SHARED OFF")
# TODO: Propagate the visibility settings to the export set as well.
set_target_properties(spdlog
PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON
POSITION_INDEPENDENT_CODE ON)

# Instead of passing build and install export sets to rapids_cpm_spdlog we call
# rapids_export_cpm directly for both the build and install export sets to support force
# downloading of spdlog in the generated config files.
rapids_cpm_package_details(spdlog version repository tag shallow exclude)
include(${rapids-cmake-dir}/export/cpm.cmake)
foreach(config BUILD INSTALL)
rapids_export_cpm("${config}" spdlog "${_RAPIDS_BUILD_EXPORT_SET}" DEFAULT_DOWNLOAD_OPTION
"RAPIDS_DOWNLOAD_SPDLOG"
CPM_ARGS NAME spdlog VERSION ${version} GIT_REPOSITORY ${repository}
GIT_TAG ${tag} GIT_SHALLOW ${shallow} EXCLUDE_FROM_ALL ON
OPTIONS "BUILD_SHARED_LIBS OFF" "SPDLOG_BUILD_SHARED OFF")
endforeach()
install(TARGETS spdlog EXPORT ${_RAPIDS_INSTALL_EXPORT_SET})
set_property(GLOBAL PROPERTY RAPIDS_LOGGER_DOWNLOADED_SPDLOG ON)
endif()
else()
rapids_cpm_spdlog(INSTALL_EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET}
BUILD_EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET})
endif()

rapids_cpm_package_details(rapids_logger version repository tag shallow exclude)

include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake")
Expand Down
4 changes: 2 additions & 2 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"version": "0.1.0",
"git_shallow": false,
"always_download": true,
"git_url": "https://github.com/rapidsai/rapids-logger.git",
"git_tag": "8968ab3337f31c845d4e3bf6c55ae89242ded22b"
"git_url": "https://github.com/vyasr/rapids-logger.git",
"git_tag": "feat/force_spdlog_clone"
},
"fmt": {
"version": "11.0.2",
Expand Down
13 changes: 12 additions & 1 deletion rapids-cmake/export/cpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ given export set
<ExportSet>
CPM_ARGS <standard cpm args>
[GLOBAL_TARGETS <targets...>]
[DEFAULT_DOWNLOAD_OPTION <option_name>]
)


Expand All @@ -46,6 +47,16 @@ generated information will include a :cmake:command:`CPMFindPackage` call for <P
``INSTALL``
Will record <PackageName> is part of the build directory export set

``CPM_ARGS``
Arguments to be passed to the generated CPM call.

``GLOBAL_TARGETS``
Which targets from this package should be made global. This information
will be propagated to any associated export set.

``DEFAULT_DOWNLOAD_OPTION``
If set, expose an option <option_name> in the config to use CPMAddPackage instead of CPMFindPackage. The option will default to true.

.. note::
It is an anti-pattern to use this command with `INSTALL` as most CMake
based projects should be installed, and :cmake:command:`rapids_export_package(INSTALL` used
Expand All @@ -60,7 +71,7 @@ function(rapids_export_cpm type name export_set)
string(TOLOWER ${type} type)

set(options "")
set(one_value EXPORT_SET)
set(one_value DEFAULT_DOWNLOAD_OPTION)
set(multi_value GLOBAL_TARGETS CPM_ARGS)
cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN})

Expand Down
19 changes: 16 additions & 3 deletions rapids-cmake/export/template/cpm.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@ if(possible_package_dir AND NOT DEFINED @name@_DIR)
set(@name@_DIR "${possible_package_dir}")
endif()

CPMFindPackage(
"@_RAPIDS_CPM_ARGS@"
)
if(NOT "@_RAPIDS_DEFAULT_DOWNLOAD_OPTION@" STREQUAL "")
option(@_RAPIDS_DEFAULT_DOWNLOAD_OPTION@ "Whether or not to download @name@" ON)
if(@_RAPIDS_DEFAULT_DOWNLOAD_OPTION@)
CPMAddPackage(
"@_RAPIDS_CPM_ARGS@"
)
else()
CPMFindPackage(
"@_RAPIDS_CPM_ARGS@"
)
endif()
else()
CPMFindPackage(
"@_RAPIDS_CPM_ARGS@"
)
endif()

if(possible_package_dir)
unset(possible_package_dir)
Expand Down
Loading