Skip to content

Commit

Permalink
Use separate fmt dependency
Browse files Browse the repository at this point in the history
Instead of the library that may be bundled with spdlog, because spdlog may be distributed without a bundled fmt (e.g. in Arch Linux's repositories).

This also changes both fmt and spdlog to be built as static libraries instead of used as header-only libraries, as that's the recommended approach.
  • Loading branch information
Ortham committed Sep 15, 2024
1 parent cfa2835 commit 1832552
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
19 changes: 17 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ else()
set(LCI_LIBRARIES ${LCI_LIBRARIES} dl)
endif()

FetchContent_Declare(
fmt
URL "https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz"
FIND_PACKAGE_ARGS)

set(SPDLOG_FMT_EXTERNAL ON)
FetchContent_Declare(
spdlog
URL "https://github.com/gabime/spdlog/archive/v1.14.1.tar.gz"
Expand All @@ -173,7 +179,15 @@ FetchContent_Declare(
URL_HASH "SHA256=e91779044cd4025ec10ed31986031031ef22ebce90a64cc8f85e7c7e95a1abc6"
FIND_PACKAGE_ARGS)

FetchContent_MakeAvailable(spdlog yaml-cpp)
# Set BUILD_SHARED_LIBS=OFF to prevent fmt and spdlog from being built as shared
# libraries.
set(LIBLOOT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)

FetchContent_MakeAvailable(fmt spdlog yaml-cpp)

# Restore the original value of BUILD_SHARED_LIBS.
set(BUILD_SHARED_LIBS ${LIBLOOT_BUILD_SHARED_LIBS})

##############################
# General Settings
Expand Down Expand Up @@ -301,7 +315,8 @@ target_link_libraries(loot PRIVATE
${ESPLUGIN_LIBRARIES}
${LIBLOADORDER_LIBRARIES}
${LCI_LIBRARIES}
spdlog::spdlog_header_only
fmt::fmt
spdlog::spdlog
yaml-cpp::yaml-cpp)

##############################
Expand Down
3 changes: 2 additions & 1 deletion cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ target_link_libraries(libloot_internals_tests PRIVATE
${ESPLUGIN_LIBRARIES}
${LIBLOADORDER_LIBRARIES}
${LCI_LIBRARIES}
spdlog::spdlog_header_only
fmt::fmt
spdlog::spdlog
yaml-cpp::yaml-cpp
GTest::gtest_main)

Expand Down
1 change: 1 addition & 0 deletions src/api/bsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "api/bsa.h"

#include <array>
#include <boost/algorithm/string.hpp>
#include <fstream>

Expand Down
3 changes: 2 additions & 1 deletion src/api/helpers/crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

#include "api/helpers/crc.h"

#include <spdlog/fmt/fmt.h>
#include <fmt/base.h>

#include <array>
#include <boost/crc.hpp>
#include <fstream>

Expand Down
2 changes: 0 additions & 2 deletions src/api/helpers/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include "api/helpers/logging.h"

#define FMT_USE_STD_STRING_VIEW

#include <spdlog/sinks/base_sink.h>

namespace {
Expand Down
3 changes: 1 addition & 2 deletions src/api/metadata/yaml/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

#define YAML_CPP_SUPPORT_MERGE_KEYS

#include <spdlog/fmt/bundled/args.h>
#include <spdlog/fmt/fmt.h>
#include <fmt/args.h>
#include <yaml-cpp/yaml.h>

#include <string>
Expand Down
4 changes: 0 additions & 4 deletions src/api/sorting/plugin_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
#ifndef LOOT_API_SORTING_PLUGIN_SORTER
#define LOOT_API_SORTING_PLUGIN_SORTER

#define FMT_NO_FMT_STRING_ALIAS

#include <spdlog/spdlog.h>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
#include <map>
Expand Down

0 comments on commit 1832552

Please sign in to comment.