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

rapids_cpm_spdlog properly specify usage of external fmt library #375

Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 14 additions & 14 deletions rapids-cmake/cpm/spdlog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,27 @@ function(rapids_cpm_spdlog)

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")
elseif(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT")
set(spdlog_fmt_option "SPDLOG_FMT_EXTERNAL ON")
set(spdlog_fmt_target fmt::fmt)
elseif(_RAPIDS_FMT_OPTION STREQUAL "EXTERNAL_FMT_HO")
set(spdlog_fmt_option "SPDLOG_FMT_EXTERNAL_HO ON")
set(spdlog_fmt_target fmt::fmt-header-only)
elseif(_RAPIDS_FMT_OPTION STREQUAL "STD_FORMAT")
set(spdlog_fmt_option "SPDLOG_USE_STD_FORMAT 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()

if(_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")
vyasr marked this conversation as resolved.
Show resolved Hide resolved
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")
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ add_cmake_config_test( cpm_nvcomp-override-clears-proprietary_binary.cmake )
add_cmake_config_test( cpm_rmm-export.cmake )
add_cmake_config_test( cpm_rmm-simple.cmake )

add_cmake_build_test( cpm_spdlog-external-fmt.cmake )
add_cmake_config_test( cpm_spdlog-export.cmake )
add_cmake_config_test( cpm_spdlog-simple.cmake )

Expand Down
37 changes: 37 additions & 0 deletions testing/cpm/cpm_spdlog-external-fmt.cmake
Original file line number Diff line number Diff line change
@@ -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/spdlog.cmake)

enable_language(CXX)

rapids_cpm_init()
rapids_cpm_spdlog(FMT_OPTION "EXTERNAL_FMT_HO")


file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/use_external_fmt.cpp" [=[

#ifndef SPDLOG_FMT_EXTERNAL
#error "SPDLOG_FMT_EXTERNAL not defined"
#endif

]=])

add_library(spdlog_extern_fmt SHARED "${CMAKE_CURRENT_BINARY_DIR}/use_external_fmt.cpp")
target_link_libraries(spdlog_extern_fmt PRIVATE spdlog::spdlog)

add_library(spdlog-header-only_extern_fmt SHARED "${CMAKE_CURRENT_BINARY_DIR}/use_external_fmt.cpp")
target_link_libraries(spdlog-header-only_extern_fmt PRIVATE spdlog::spdlog_header_only)