Skip to content

Commit cefc858

Browse files
committed
fix(utils): prefer header-only fmt and spdlog targets
2 parents 1caaaac + 9ea64be commit cefc858

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

CMakeLists.txt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,30 @@ else()
9696
endif()
9797

9898
# -------------------------
99-
# Dependencies: spdlog + fmt (system)
99+
# Dependencies: spdlog + fmt
100+
# Prefer header-only targets to avoid runtime shared-library ABI issues
101+
# in released Linux binaries.
100102
# -------------------------
101103
find_package(spdlog CONFIG REQUIRED)
102104
find_package(fmt CONFIG REQUIRED)
103105

104-
# Choose best spdlog target
105106
set(_VIX_SPDLOG_TARGET "")
106-
if (TARGET spdlog::spdlog)
107-
set(_VIX_SPDLOG_TARGET spdlog::spdlog)
108-
elseif (TARGET spdlog::spdlog_header_only)
107+
set(_VIX_FMT_TARGET "")
108+
109+
# Prefer header-only spdlog to avoid libspdlog.so runtime dependency
110+
if (TARGET spdlog::spdlog_header_only)
109111
set(_VIX_SPDLOG_TARGET spdlog::spdlog_header_only)
112+
elseif (TARGET spdlog::spdlog)
113+
set(_VIX_SPDLOG_TARGET spdlog::spdlog)
110114
else()
111115
message(FATAL_ERROR "[utils] spdlog target not found.")
112116
endif()
113117

114-
# fmt is a direct dependency because Logger.hpp includes <fmt/ostream.h>
115-
if (TARGET fmt::fmt)
116-
set(_VIX_FMT_TARGET fmt::fmt)
117-
elseif (TARGET fmt::fmt-header-only)
118+
# Prefer header-only fmt to avoid libfmt.so runtime dependency
119+
if (TARGET fmt::fmt-header-only)
118120
set(_VIX_FMT_TARGET fmt::fmt-header-only)
121+
elseif (TARGET fmt::fmt)
122+
set(_VIX_FMT_TARGET fmt::fmt)
119123
else()
120124
message(FATAL_ERROR "[utils] fmt target not found.")
121125
endif()
@@ -126,6 +130,11 @@ target_link_libraries(vix_utils
126130
${_VIX_FMT_TARGET}
127131
)
128132

133+
if (VIX_HEADER_ONLY)
134+
target_compile_definitions(vix_utils INTERFACE SPDLOG_FMT_EXTERNAL=1)
135+
else()
136+
target_compile_definitions(vix_utils PUBLIC SPDLOG_FMT_EXTERNAL=1)
137+
endif()
129138
# -------------------------
130139
# Windows: prevent Win32 API usage by spdlog
131140
# -------------------------

0 commit comments

Comments
 (0)