@@ -63,31 +63,43 @@ option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
63
63
# install options
64
64
option (SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT} )
65
65
option (SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF )
66
+ option (SPDLOG_FMT_EXTERNAL_HO "Use external fmt header-only library instead of bundled" OFF )
67
+ option (SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF )
66
68
67
- if (WIN32 )
68
- option (SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF )
69
- option (SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF )
69
+ if (SPDLOG_FMT_EXTERNAL AND SPDLOG_FMT_EXTERNAL_HO)
70
+ message (FATAL_ERROR "SPDLOG_FMT_EXTERNAL and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive" )
70
71
endif ()
71
72
72
- option (SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF )
73
+ # misc tweakme options
74
+ if (WIN32 )
75
+ option (SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF )
76
+ option (SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF )
77
+ endif ()
78
+ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
79
+ option (SPDLOG_CLOCK_COARSE "Use the much faster (but much less accurate) CLOCK_REALTIME_COARSE instead of the regular clock," OFF )
80
+ endif ()
73
81
82
+ option (SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF )
83
+ option (SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" OFF )
84
+ option (SPDLOG_NO_TLS "prevent spdlog from using thread local storage" OFF )
85
+ option (SPDLOG_NO_ATOMIC_LEVELS "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently" OFF )
74
86
75
87
find_package (Threads REQUIRED)
76
-
77
88
message (STATUS "Build type: " ${CMAKE_BUILD_TYPE} )
78
-
79
89
#---------------------------------------------------------------------------------------
80
90
# Static/Shared library (shared not supported in windows yet)
81
91
#---------------------------------------------------------------------------------------
82
92
set (SPDLOG_SRCS
83
93
src/spdlog.cpp
84
94
src/stdout_sinks.cpp
85
- src/fmt.cpp
86
95
src/color_sinks.cpp
87
96
src/file_sinks.cpp
88
97
src/async.cpp)
89
98
90
- set (SPDLOG_CFLAGS "${PROJECT_NAME} " )
99
+
100
+ if (NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
101
+ list (APPEND SPDLOG_SRCS src/fmt.cpp)
102
+ endif ()
91
103
92
104
if (SPDLOG_BUILD_SHARED)
93
105
if (WIN32 )
@@ -123,22 +135,30 @@ target_link_libraries(spdlog_header_only INTERFACE Threads::Threads)
123
135
124
136
125
137
#---------------------------------------------------------------------------------------
126
- # Use fmt package if using exertnal fmt
138
+ # Use fmt package if using external fmt
127
139
#---------------------------------------------------------------------------------------
128
- if (SPDLOG_FMT_EXTERNAL)
140
+ if (SPDLOG_FMT_EXTERNAL OR SPDLOG_FMT_EXTERNAL_HO )
129
141
if (NOT TARGET fmt::fmt)
130
142
find_package (fmt REQUIRED)
131
143
endif ()
132
-
133
- set (SPDLOG_CFLAGS "${SPDLOG_CFLAGS} -DSPDLOG_FMT_EXTERNAL" )
134
-
135
144
target_compile_definitions (spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
136
- target_link_libraries (spdlog PUBLIC fmt::fmt)
137
-
138
145
target_compile_definitions (spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
139
- target_link_libraries (spdlog_header_only INTERFACE fmt::fmt)
146
+
147
+ # use external fmt-header-nly
148
+ if (SPDLOG_FMT_EXTERNAL_HO)
149
+ target_link_libraries (spdlog PUBLIC fmt::fmt-header-only)
150
+ target_link_libraries (spdlog_header_only INTERFACE fmt::fmt-header-only)
151
+ else () # use external compile fmt
152
+ target_link_libraries (spdlog PUBLIC fmt::fmt)
153
+ target_link_libraries (spdlog_header_only INTERFACE fmt::fmt)
154
+ endif ()
155
+
156
+ set (PKG_CONFIG_REQUIRES fmt) # add dependency to pkg-config
140
157
endif ()
141
158
159
+ #---------------------------------------------------------------------------------------
160
+ # Misc definitions according to tweak options
161
+ #---------------------------------------------------------------------------------------
142
162
if (SPDLOG_WCHAR_SUPPORT)
143
163
target_compile_definitions (spdlog PUBLIC SPDLOG_WCHAR_TO_UTF8_SUPPORT)
144
164
target_compile_definitions (spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
@@ -159,6 +179,31 @@ if(SPDLOG_WCHAR_SUPPORT)
159
179
endif ()
160
180
endif ()
161
181
182
+ if (SPDLOG_CLOCK_COARSE)
183
+ target_compile_definitions (spdlog PRIVATE SPDLOG_CLOCK_COARSE)
184
+ target_compile_definitions (spdlog_header_only INTERFACE SPDLOG_CLOCK_COARSE)
185
+ endif ()
186
+
187
+ if (SPDLOG_PREVENT_CHILD_FD)
188
+ target_compile_definitions (spdlog PRIVATE SPDLOG_PREVENT_CHILD_FD)
189
+ target_compile_definitions (spdlog_header_only INTERFACE SPDLOG_PREVENT_CHILD_FD)
190
+ endif ()
191
+
192
+ if (SPDLOG_NO_THREAD_ID)
193
+ target_compile_definitions (spdlog PRIVATE SPDLOG_NO_THREAD_ID)
194
+ target_compile_definitions (spdlog_header_only INTERFACE SPDLOG_NO_THREAD_ID)
195
+ endif ()
196
+
197
+ if (SPDLOG_NO_TLS)
198
+ target_compile_definitions (spdlog PRIVATE SPDLOG_NO_TLS)
199
+ target_compile_definitions (spdlog_header_only INTERFACE SPDLOG_NO_TLS)
200
+ endif ()
201
+
202
+ if (SPDLOG_NO_ATOMIC_LEVELS)
203
+ target_compile_definitions (spdlog PUBLIC SPDLOG_NO_ATOMIC_LEVELS)
204
+ target_compile_definitions (spdlog_header_only INTERFACE SPDLOG_NO_ATOMIC_LEVELS)
205
+ endif ()
206
+
162
207
163
208
#---------------------------------------------------------------------------------------
164
209
# Build binaries
@@ -188,34 +233,41 @@ if (SPDLOG_INSTALL)
188
233
set (project_config_out "${CMAKE_CURRENT_BINARY_DIR} /spdlogConfig.cmake" )
189
234
set (config_targets_file "spdlogConfigTargets.cmake" )
190
235
set (version_config_file "${CMAKE_CURRENT_BINARY_DIR} /spdlogConfigVersion.cmake" )
191
- set (export_dest_dir "${CMAKE_INSTALL_LIBDIR} /spdlog/ cmake" )
236
+ set (export_dest_dir "${CMAKE_INSTALL_LIBDIR} /cmake/spdlog " )
192
237
set (pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR} /pkgconfig" )
193
238
set (pkg_config "${CMAKE_BINARY_DIR} /${PROJECT_NAME} .pc" )
194
239
195
240
#---------------------------------------------------------------------------------------
196
241
# Include files
197
242
#---------------------------------------------------------------------------------------
198
243
install (DIRECTORY include / DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} " PATTERN "fmt/bundled" EXCLUDE )
199
- install (TARGETS spdlog spdlog_header_only EXPORT spdlog DESTINATION "${CMAKE_INSTALL_LIBDIR} /spdlog " )
244
+ install (TARGETS spdlog spdlog_header_only EXPORT spdlog DESTINATION "${CMAKE_INSTALL_LIBDIR} " )
200
245
201
- if (NOT SPDLOG_FMT_EXTERNAL)
246
+ if (NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO )
202
247
install (DIRECTORY include /${PROJECT_NAME} /fmt/bundled/
203
248
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} /${PROJECT_NAME} /fmt/bundled/" )
204
249
endif ()
205
250
206
251
#---------------------------------------------------------------------------------------
207
- # Package and version files
252
+ # Install pkg-config file
208
253
#---------------------------------------------------------------------------------------
254
+ get_target_property (PKG_CONFIG_DEFINES spdlog INTERFACE_COMPILE_DEFINITIONS )
255
+ string (REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES} " )
256
+ string (CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES} " )
209
257
configure_file ("cmake/${PROJECT_NAME} .pc.in" "${pkg_config} " @ONLY)
210
258
install (FILES "${pkg_config} " DESTINATION "${pkgconfig_install_dir} " )
211
259
260
+ #---------------------------------------------------------------------------------------
261
+ # Install CMake config files
262
+ #---------------------------------------------------------------------------------------
212
263
install (EXPORT spdlog
213
264
DESTINATION ${export_dest_dir}
214
265
NAMESPACE spdlog::
215
266
FILE ${config_targets_file} )
216
267
217
268
include (CMakePackageConfigHelpers)
218
269
configure_file ("${project_config_in} " "${project_config_out} " @ONLY)
270
+
219
271
write_basic_package_version_file("${version_config_file} " COMPATIBILITY SameMajorVersion)
220
272
install (FILES
221
273
"${project_config_out} "
@@ -227,3 +279,4 @@ if (SPDLOG_INSTALL)
227
279
include (cmake/spdlogCPack.cmake)
228
280
229
281
endif ()
282
+
0 commit comments