Skip to content

Commit 432624d

Browse files
committed
update spdlog
1 parent 9c047fa commit 432624d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3319
-2211
lines changed

third_party/spdlog/CMakeLists.txt

+73-20
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,43 @@ option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
6363
# install options
6464
option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})
6565
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)
6668

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")
7071
endif()
7172

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()
7381

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)
7486

7587
find_package(Threads REQUIRED)
76-
7788
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
78-
7989
#---------------------------------------------------------------------------------------
8090
# Static/Shared library (shared not supported in windows yet)
8191
#---------------------------------------------------------------------------------------
8292
set(SPDLOG_SRCS
8393
src/spdlog.cpp
8494
src/stdout_sinks.cpp
85-
src/fmt.cpp
8695
src/color_sinks.cpp
8796
src/file_sinks.cpp
8897
src/async.cpp)
8998

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()
91103

92104
if (SPDLOG_BUILD_SHARED)
93105
if(WIN32)
@@ -123,22 +135,30 @@ target_link_libraries(spdlog_header_only INTERFACE Threads::Threads)
123135

124136

125137
#---------------------------------------------------------------------------------------
126-
# Use fmt package if using exertnal fmt
138+
# Use fmt package if using external fmt
127139
#---------------------------------------------------------------------------------------
128-
if(SPDLOG_FMT_EXTERNAL)
140+
if(SPDLOG_FMT_EXTERNAL OR SPDLOG_FMT_EXTERNAL_HO)
129141
if (NOT TARGET fmt::fmt)
130142
find_package(fmt REQUIRED)
131143
endif ()
132-
133-
set(SPDLOG_CFLAGS "${SPDLOG_CFLAGS} -DSPDLOG_FMT_EXTERNAL")
134-
135144
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
136-
target_link_libraries(spdlog PUBLIC fmt::fmt)
137-
138145
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
140157
endif()
141158

159+
#---------------------------------------------------------------------------------------
160+
# Misc definitions according to tweak options
161+
#---------------------------------------------------------------------------------------
142162
if(SPDLOG_WCHAR_SUPPORT)
143163
target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_TO_UTF8_SUPPORT)
144164
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
@@ -159,6 +179,31 @@ if(SPDLOG_WCHAR_SUPPORT)
159179
endif()
160180
endif()
161181

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+
162207

163208
#---------------------------------------------------------------------------------------
164209
# Build binaries
@@ -188,34 +233,41 @@ if (SPDLOG_INSTALL)
188233
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
189234
set(config_targets_file "spdlogConfigTargets.cmake")
190235
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")
192237
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
193238
set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
194239

195240
#---------------------------------------------------------------------------------------
196241
# Include files
197242
#---------------------------------------------------------------------------------------
198243
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}")
200245

201-
if(NOT SPDLOG_FMT_EXTERNAL)
246+
if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
202247
install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
203248
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")
204249
endif()
205250

206251
#---------------------------------------------------------------------------------------
207-
# Package and version files
252+
# Install pkg-config file
208253
#---------------------------------------------------------------------------------------
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}")
209257
configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
210258
install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")
211259

260+
#---------------------------------------------------------------------------------------
261+
# Install CMake config files
262+
#---------------------------------------------------------------------------------------
212263
install(EXPORT spdlog
213264
DESTINATION ${export_dest_dir}
214265
NAMESPACE spdlog::
215266
FILE ${config_targets_file})
216267

217268
include(CMakePackageConfigHelpers)
218269
configure_file("${project_config_in}" "${project_config_out}" @ONLY)
270+
219271
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
220272
install(FILES
221273
"${project_config_out}"
@@ -227,3 +279,4 @@ if (SPDLOG_INSTALL)
227279
include(cmake/spdlogCPack.cmake)
228280

229281
endif ()
282+

third_party/spdlog/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ $ cmake .. && make -j
3030
* Gentoo: `emerge dev-libs/spdlog`
3131
* Arch Linux: `yaourt -S spdlog-git`
3232
* vcpkg: `vcpkg install spdlog`
33+
* conan: `spdlog/[>=1.4.1]@bincrafters/stable`
34+
3335

3436
## Features
3537
* Very fast (see [benchmarks](#benchmarks) below).

third_party/spdlog/appveyor.yml

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
version: 1.0.{build}
2-
image: Visual Studio 2015
2+
image: Visual Studio 2017
33
environment:
44
matrix:
5-
- GENERATOR: '"MinGW Makefiles"'
6-
BUILD_TYPE: Debug
7-
- GENERATOR: '"MinGW Makefiles"'
8-
BUILD_TYPE: Release
95
- GENERATOR: '"Visual Studio 14 2015"'
106
BUILD_TYPE: Debug
7+
WCHAR: 'OFF'
118
- GENERATOR: '"Visual Studio 14 2015"'
129
BUILD_TYPE: Release
10+
WCHAR: 'ON'
1311
- GENERATOR: '"Visual Studio 14 2015 Win64"'
1412
BUILD_TYPE: Debug
13+
WCHAR: 'ON'
1514
- GENERATOR: '"Visual Studio 14 2015 Win64"'
1615
BUILD_TYPE: Release
16+
WCHAR: 'ON'
17+
- GENERATOR: '"Visual Studio 15 2017 Win64"'
18+
BUILD_TYPE: Debug
19+
WCHAR: 'ON'
20+
- GENERATOR: '"Visual Studio 15 2017 Win64"'
21+
BUILD_TYPE: Release
22+
WCHAR: 'OFf'
1723
build_script:
1824
- cmd: >-
1925
set
20-
26+
2127
mkdir build
28+
29+
cd build
2230
23-
cd build
24-
25-
set PATH=%PATH:C:\Program Files\Git\usr\bin;=%
26-
27-
set PATH=C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH%
28-
29-
cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_WCHAR_SUPPORT=ON -DSPDLOG_BUILD_EXAMPLE=ON -DSPDLOG_BUILD_EXAMPLE_HO=ON -DSPDLOG_BUILD_TESTS=ON -DSPDLOG_BUILD_TESTS_HO=OFF
31+
set PATH=%PATH%:C:\Program Files\Git\usr\bin
32+
33+
cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_WCHAR_SUPPORT=%WCHAR% -DSPDLOG_BUILD_EXAMPLE=ON -DSPDLOG_BUILD_EXAMPLE_HO=ON -DSPDLOG_BUILD_TESTS=ON -DSPDLOG_BUILD_TESTS_HO=OFF
3034
3135
cmake --build . --config %BUILD_TYPE%
3236

third_party/spdlog/bench/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog)
2424

2525
add_executable(formatter-bench formatter-bench.cpp)
2626
target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog)
27-
28-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")

third_party/spdlog/bench/latency.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@
1616
#include "spdlog/sinks/null_sink.h"
1717
#include "spdlog/sinks/rotating_file_sink.h"
1818

19-
void prepare_logdir()
20-
{
21-
spdlog::info("Preparing latency_logs directory..");
22-
#ifdef _WIN32
23-
system("if not exist logs mkdir latency_logs");
24-
system("del /F /Q logs\\*");
25-
#else
26-
auto rv = system("mkdir -p latency_logs");
27-
if (rv != 0)
28-
{
29-
throw std::runtime_error("Failed to mkdir -p latency_logs");
30-
}
31-
rv = system("rm -f latency_logs/*");
32-
if (rv != 0)
33-
{
34-
throw std::runtime_error("Failed to rm -f latency_logs/*");
35-
}
36-
#endif
37-
}
38-
3919
void bench_c_string(benchmark::State &state, std::shared_ptr<spdlog::logger> logger)
4020
{
4121
const char *msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra metus cursus "
@@ -83,8 +63,6 @@ int main(int argc, char *argv[])
8363
size_t rotating_files = 5;
8464
int n_threads = benchmark::CPUInfo::Get().num_cpus;
8565

86-
prepare_logdir();
87-
8866
// disabled loggers
8967
auto disabled_logger = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
9068
disabled_logger->set_level(spdlog::level::off);

third_party/spdlog/bench/meson.build

-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ foreach i : bench_matrix
1212
benchmark('bench_' + i[0], bench_exe, args: i[2])
1313
endforeach
1414

15-
run_command(find_program('mkdir'), meson.current_build_dir() + '/logs')

third_party/spdlog/cmake/spdlog.pc.in

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ Name: lib@PROJECT_NAME@
77
Description: Fast C++ logging library.
88
URL: https://github.com/gabime/@PROJECT_NAME@
99
Version: @SPDLOG_VERSION@
10-
CFlags: -I${includedir}/@SPDLOG_CFLAGS@
11-
Libs: -L${libdir}/@PROJECT_NAME@ -l@PROJECT_NAME@
10+
CFlags: -I${includedir} @PKG_CONFIG_DEFINES@
11+
Libs: -L${libdir} -lspdlog -pthread
12+
Requires: @PKG_CONFIG_REQUIRES@
13+

third_party/spdlog/cmake/utils.cmake

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ function(spdlog_enable_warnings target_name)
2929
target_compile_options(${target_name} PRIVATE
3030
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
3131
-Wall -Wextra -Wconversion -pedantic -Wfatal-errors>
32-
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>)
32+
$<$<CXX_COMPILER_ID:MSVC>:/W4>)
33+
if(MSVC_VERSION GREATER_EQUAL 1910) #Allow non fatal security wanrnings for msvc 2015
34+
target_compile_options(${target_name} PRIVATE /WX)
35+
endif()
3336
endfunction()
3437

3538

third_party/spdlog/example/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ if(SPDLOG_BUILD_EXAMPLE_HO)
2525
target_link_libraries(example_header_only PRIVATE spdlog::spdlog_header_only)
2626
endif()
2727

28-
# Create logs directory
29-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")

third_party/spdlog/example/example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void async_example()
143143
#include "spdlog/fmt/bin_to_hex.h"
144144
void binary_example()
145145
{
146-
std::vector<char> buf;
146+
std::vector<char> buf(80);
147147
for (int i = 0; i < 80; i++)
148148
{
149149
buf.push_back(static_cast<char>(i & 0xff));
-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
executable('example', 'example.cpp', dependencies: spdlog_dep)
22
executable('example_header_only', 'example.cpp', dependencies: spdlog_headeronly_dep)
3-
run_command(find_program('mkdir'), meson.current_build_dir() + '/logs')
43

54

third_party/spdlog/include/spdlog/async.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
//
77
// Async logging using global thread pool
88
// All loggers created here share same global thread pool.
9-
// Each log message is pushed to a queue along withe a shared pointer to the
9+
// Each log message is pushed to a queue along with a shared pointer to the
1010
// logger.
1111
// If a logger deleted while having pending messages in the queue, it's actual
1212
// destruction will defer
1313
// until all its messages are processed by the thread pool.
1414
// This is because each message in the queue holds a shared_ptr to the
1515
// originating logger.
1616

17-
#include "spdlog/async_logger.h"
18-
#include "spdlog/details/registry.h"
19-
#include "spdlog/details/thread_pool.h"
17+
#include <spdlog/async_logger.h>
18+
#include <spdlog/details/registry.h>
19+
#include <spdlog/details/thread_pool.h>
2020

2121
#include <memory>
2222
#include <mutex>

third_party/spdlog/include/spdlog/async_logger-inl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#pragma once
55

66
#ifndef SPDLOG_HEADER_ONLY
7-
#include "spdlog/async_logger.h"
7+
#include <spdlog/async_logger.h>
88
#endif
99

10-
#include "spdlog/sinks/sink.h"
11-
#include "spdlog/details/thread_pool.h"
10+
#include <spdlog/sinks/sink.h>
11+
#include <spdlog/details/thread_pool.h>
1212

1313
#include <memory>
1414
#include <string>

third_party/spdlog/include/spdlog/async_logger.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Upon destruction, logs all remaining messages in the queue before
1515
// destructing..
1616

17-
#include "spdlog/logger.h"
17+
#include <spdlog/logger.h>
1818

1919
namespace spdlog {
2020

third_party/spdlog/include/spdlog/common-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#pragma once
55

66
#ifndef SPDLOG_HEADER_ONLY
7-
#include "spdlog/common.h"
7+
#include <spdlog/common.h>
88
#endif
99

1010
namespace spdlog {

0 commit comments

Comments
 (0)