Skip to content

Commit a21161d

Browse files
committed
fix(utils): clean CMake configuration and fix linking issues
- fix mixed signature usage in target_link_libraries - ensure consistent keyword-based linking - improve spdlog/fmt detection and fallback handling - stabilize build configuration for utils module result: clean CMake configuration with no warnings/errors
1 parent 01f7298 commit a21161d

File tree

1 file changed

+43
-49
lines changed

1 file changed

+43
-49
lines changed

CMakeLists.txt

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,10 @@ else()
9696
endif()
9797

9898
# -------------------------
99-
# Dependencies: spdlog (+ fmt when external)
99+
# Dependencies: spdlog + fmt (system)
100100
# -------------------------
101-
include(FetchContent)
102-
103-
find_package(spdlog CONFIG QUIET)
104-
find_package(fmt CONFIG QUIET)
105-
106-
# If spdlog is missing, fetch it (bundled fmt)
107-
if (NOT TARGET spdlog::spdlog AND NOT TARGET spdlog::spdlog_header_only)
108-
message(STATUS "[utils] spdlog not found -> fetching spdlog (bundled fmt)")
109-
110-
FetchContent_Declare(
111-
spdlog
112-
GIT_REPOSITORY https://github.com/gabime/spdlog.git
113-
GIT_TAG v1.14.1
114-
)
115-
116-
set(SPDLOG_BUILD_SHARED OFF CACHE BOOL "" FORCE)
117-
set(SPDLOG_BUILD_EXAMPLE OFF CACHE BOOL "" FORCE)
118-
set(SPDLOG_BUILD_TESTS OFF CACHE BOOL "" FORCE)
119-
set(SPDLOG_BUILD_BENCH OFF CACHE BOOL "" FORCE)
120-
set(SPDLOG_FMT_EXTERNAL OFF CACHE BOOL "" FORCE)
121-
122-
FetchContent_MakeAvailable(spdlog)
123-
endif()
124-
125-
set(_VIX_UTILS_SCOPE PUBLIC)
126-
if (VIX_HEADER_ONLY)
127-
set(_VIX_UTILS_SCOPE INTERFACE)
128-
endif()
101+
find_package(spdlog CONFIG REQUIRED)
102+
find_package(fmt CONFIG REQUIRED)
129103

130104
# Choose best spdlog target
131105
set(_VIX_SPDLOG_TARGET "")
@@ -134,10 +108,10 @@ if (TARGET spdlog::spdlog)
134108
elseif (TARGET spdlog::spdlog_header_only)
135109
set(_VIX_SPDLOG_TARGET spdlog::spdlog_header_only)
136110
else()
137-
message(FATAL_ERROR "[utils] spdlog target not found after fallback.")
111+
message(FATAL_ERROR "[utils] spdlog target not found.")
138112
endif()
139113

140-
target_link_libraries(vix_utils ${_VIX_UTILS_SCOPE} ${_VIX_SPDLOG_TARGET})
114+
target_link_libraries(vix_utils PRIVATE ${_VIX_SPDLOG_TARGET})
141115

142116
# Detect if spdlog requires external fmt (SPDLOG_FMT_EXTERNAL)
143117
set(_VIX_SPDLOG_NEEDS_FMT OFF)
@@ -162,45 +136,65 @@ endif()
162136

163137
if (_VIX_SPDLOG_NEEDS_FMT)
164138
if (TARGET fmt::fmt)
165-
target_link_libraries(vix_utils ${_VIX_UTILS_SCOPE} fmt::fmt)
139+
target_link_libraries(vix_utils PRIVATE fmt::fmt)
166140
elseif (TARGET fmt::fmt-header-only)
167-
target_link_libraries(vix_utils ${_VIX_UTILS_SCOPE} fmt::fmt-header-only)
141+
target_link_libraries(vix_utils PRIVATE fmt::fmt-header-only)
168142
else()
169143
message(FATAL_ERROR "[utils] spdlog requires external fmt (SPDLOG_FMT_EXTERNAL) but fmt package was not found.")
170144
endif()
171145
endif()
172-
173146
# -------------------------
174147
# Windows: prevent Win32 API usage by spdlog
175148
# -------------------------
176149
if (WIN32)
177-
target_compile_definitions(vix_utils ${_VIX_UTILS_SCOPE} SPDLOG_NO_WIN32_API=1)
150+
if (VIX_HEADER_ONLY)
151+
target_compile_definitions(vix_utils INTERFACE SPDLOG_NO_WIN32_API=1)
152+
else()
153+
target_compile_definitions(vix_utils PRIVATE SPDLOG_NO_WIN32_API=1)
154+
endif()
178155
endif()
179156

180157
# Compiler warnings
181158
if (TARGET vix_warnings)
182-
target_link_libraries(vix_utils ${_VIX_UTILS_SCOPE} vix_warnings)
183-
else()
184-
set(_VIX_UTILS_WARN_SCOPE PRIVATE)
185159
if (VIX_HEADER_ONLY)
186-
set(_VIX_UTILS_WARN_SCOPE INTERFACE)
160+
target_link_libraries(vix_utils INTERFACE vix_warnings)
161+
else()
162+
target_link_libraries(vix_utils PRIVATE vix_warnings)
187163
endif()
164+
else()
165+
if (VIX_HEADER_ONLY)
166+
if (NOT MSVC)
167+
target_compile_options(vix_utils INTERFACE
168+
-Wall -Wextra -Wpedantic
169+
-Wno-array-bounds
170+
-Wno-stringop-overflow
171+
)
172+
endif()
188173

189-
if (NOT MSVC)
190-
target_compile_options(vix_utils ${_VIX_UTILS_WARN_SCOPE}
191-
-Wall -Wextra -Wpedantic
192-
-Wno-array-bounds
193-
-Wno-stringop-overflow
194-
)
195-
endif()
174+
if (VIX_STRICT AND NOT MSVC)
175+
target_compile_options(vix_utils INTERFACE -Werror)
176+
endif()
177+
else()
178+
if (NOT MSVC)
179+
target_compile_options(vix_utils PRIVATE
180+
-Wall -Wextra -Wpedantic
181+
-Wno-array-bounds
182+
-Wno-stringop-overflow
183+
)
184+
endif()
196185

197-
if (VIX_STRICT AND NOT MSVC)
198-
target_compile_options(vix_utils ${_VIX_UTILS_WARN_SCOPE} -Werror)
186+
if (VIX_STRICT AND NOT MSVC)
187+
target_compile_options(vix_utils PRIVATE -Werror)
188+
endif()
199189
endif()
200190
endif()
201191

202192
if (VIX_ENABLE_SANITIZERS AND TARGET vix_sanitizers)
203-
target_link_libraries(vix_utils ${_VIX_UTILS_SCOPE} vix_sanitizers)
193+
if (VIX_HEADER_ONLY)
194+
target_link_libraries(vix_utils INTERFACE vix_sanitizers)
195+
else()
196+
target_link_libraries(vix_utils PRIVATE vix_sanitizers)
197+
endif()
204198
endif()
205199

206200
# LTO (Release)

0 commit comments

Comments
 (0)