Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Nov 29, 2024
1 parent ea89688 commit b0e836b
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 75 deletions.
63 changes: 27 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ elseif(CMAKE_CXX_STANDARD LESS 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)


set(CMAKE_CXX_EXTENSIONS OFF)

if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW")
Expand All @@ -58,7 +57,6 @@ option(SPDLOG_BUILD_ALL "Build all artifacts" OFF)
# build shared option
option(SPDLOG_BUILD_SHARED "Build shared library" OFF)


# example options
option(SPDLOG_BUILD_EXAMPLE "Build example" ${SPDLOG_MASTER_PROJECT})

Expand All @@ -80,7 +78,6 @@ option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of of fetching from gitub." OFF)
option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)


# misc tweakme options
if(WIN32)
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
Expand Down Expand Up @@ -117,19 +114,18 @@ if(SPDLOG_BUILD_SHARED)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# place dlls and libs and executables in the same directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)

# make sure __cplusplus is defined
add_compile_options(/Zc:__cplusplus)
# enable parallel build for the solution
add_compile_options(/MP)
# place dlls and libs and executables in the same directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)

# make sure __cplusplus is defined
add_compile_options(/Zc:__cplusplus)
# enable parallel build for the solution
add_compile_options(/MP)
endif()


message(STATUS "spdlog version: ${SPDLOG_VERSION}")
message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE})
message(STATUS "spdlog build shared: " ${BUILD_SHARED_LIBS})
Expand All @@ -138,7 +134,7 @@ message(STATUS "spdlog fmt external: " ${SPDLOG_FMT_EXTERNAL})
# ---------------------------------------------------------------------------------------
# Find {fmt} library
# ---------------------------------------------------------------------------------------
if (SPDLOG_FMT_EXTERNAL)
if(SPDLOG_FMT_EXTERNAL)
find_package(fmt REQUIRED)
message(STATUS "Using external fmt lib version: ${fmt_VERSION}")
else()
Expand Down Expand Up @@ -205,8 +201,7 @@ set(SPDLOG_HEADERS
"include/spdlog/sinks/syslog_sink.h"
"include/spdlog/sinks/systemd_sink.h"
"include/spdlog/sinks/tcp_sink.h"
"include/spdlog/sinks/udp_sink.h"
)
"include/spdlog/sinks/udp_sink.h")

set(SPDLOG_SRCS
"src/async_logger.cpp"
Expand All @@ -230,20 +225,18 @@ set(SPDLOG_SRCS
"src/sinks/stdout_sinks.cpp")

if(WIN32)
list(APPEND SPDLOG_SRCS
"src/details/os_windows.cpp"
"src/sinks/wincolor_sink.cpp")
list(APPEND SPDLOG_HEADERS
"include/spdlog/details/tcp_client_windows.h"
"include/spdlog/details/udp_client_windows.h"
"include/spdlog/details/windows_include.h"
"include/spdlog/sinks/win_eventlog_sink.h"
"include/spdlog/sinks/wincolor_sink.h")
list(APPEND SPDLOG_SRCS "src/details/os_windows.cpp" "src/sinks/wincolor_sink.cpp")
list(
APPEND
SPDLOG_HEADERS
"include/spdlog/details/tcp_client_windows.h"
"include/spdlog/details/udp_client_windows.h"
"include/spdlog/details/windows_include.h"
"include/spdlog/sinks/win_eventlog_sink.h"
"include/spdlog/sinks/wincolor_sink.h")
else()
list(APPEND SPDLOG_SRCS "src/details/os_unix.cpp")
list(APPEND SPDLOG_HEADERS
"include/spdlog/details/tcp_client_unix.h"
"include/spdlog/details/udp_client_unix.h")
list(APPEND SPDLOG_HEADERS "include/spdlog/details/tcp_client_unix.h" "include/spdlog/details/udp_client_unix.h")
endif()

# Generate spdlog_config.h based on the current configuration
Expand Down Expand Up @@ -275,14 +268,14 @@ endif()

set_target_properties(spdlog PROPERTIES PUBLIC_HEADER "${SPDLOG_HEADERS}")

target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

target_link_libraries(spdlog PUBLIC Threads::Threads)
target_link_libraries(spdlog PUBLIC fmt::fmt)
spdlog_enable_warnings(spdlog)
set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION ${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION
${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d)

# set source groups for visual studio
Expand All @@ -299,7 +292,6 @@ if(ANDROID)
target_link_libraries(spdlog PUBLIC log)
endif()


# ---------------------------------------------------------------------------------------
# If exceptions are disabled, disable them in the bundled fmt as well
# ---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -389,8 +381,7 @@ if(SPDLOG_INSTALL)
# ---------------------------------------------------------------------------------------
include(cmake/spdlogCPack.cmake)

# Install spdlog_config.h file
# Assume your tweakme.h.in is located in the same directory as CMakeLists.txt
# Install spdlog_config.h file Assume your tweakme.h.in is located in the same directory as CMakeLists.txt
set(TWEAKME_IN "${CMAKE_CURRENT_SOURCE_DIR}/tweakme.h.in")
set(TWEAKME_OUT "${CMAKE_CURRENT_BINARY_DIR}/include/spdlog/tweakme.h")
endif()
2 changes: 1 addition & 1 deletion bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(NOT benchmark_FOUND)
# Do not build and run googlebenchmark tests
FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.6.0)
FetchContent_MakeAvailable(googlebenchmark)
set_target_properties(benchmark PROPERTIES FOLDER "third-party")
set_target_properties(benchmark PROPERTIES FOLDER "third-party")
endif()

add_executable(bench bench.cpp)
Expand Down
12 changes: 6 additions & 6 deletions bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
//
// bench.cpp : spdlog benchmarks
//
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/null_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/spdlog.h"

#include <fmt/format.h>

#include <atomic>
#include <cstdlib> // EXIT_FAILURE
#include <memory>
#include <string>
#include <thread>

#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/null_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/spdlog.h"
#include "utils.h"

void bench(int howmany, std::shared_ptr<spdlog::logger> log);
Expand Down
10 changes: 4 additions & 6 deletions cmake/fmtlib.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
include(FetchContent)

FetchContent_Declare(
fmt
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz
URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f)
fmt DOWNLOAD_EXTRACT_TIMESTAMP FALSE URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz
URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f)
FetchContent_GetProperties(fmt)
if(NOT fmt_POPULATED)
FetchContent_Populate(fmt)
# We do not require os features of fmt
set(FMT_OS OFF CACHE BOOL "Disable FMT_OS" FORCE)
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR})
set_target_properties(fmt PROPERTIES FOLDER "third-party")
endif ()
set_target_properties(fmt PROPERTIES FOLDER "third-party")
endif()
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ if(NOT TARGET spdlog)
endif()

add_executable(example example.cpp)
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
2 changes: 0 additions & 2 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ void async_example() {
// {:p} - don't print the position on each line start.
// {:n} - don't split the output to lines.


#include "spdlog/fmt/bin_to_hex.h"
void binary_example() {
std::vector<char> buf;
Expand Down Expand Up @@ -238,7 +237,6 @@ struct my_type {
: i(i) {}
};


template <>
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
Expand Down
9 changes: 4 additions & 5 deletions include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <version>
#endif


#if defined(SPDLOG_SHARED_LIB)
#if defined(_WIN32)
#ifdef spdlog_EXPORTS
Expand All @@ -39,10 +38,10 @@
#include "fmt/fmt.h"

#define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string)
#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string)
#if defined(SPDLOG_WCHAR_FILENAMES)
#include "fmt/xchar.h"
#endif
#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string)
#if defined(SPDLOG_WCHAR_FILENAMES)
#include "fmt/xchar.h"
#endif

#ifndef SPDLOG_FUNCTION
#define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__)
Expand Down
10 changes: 5 additions & 5 deletions include/spdlog/details/fmt_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ inline unsigned int count_digits(T n) {
using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;

return static_cast<unsigned int>(fmt::
// fmt 7.0.0 renamed the internal namespace to detail.
// See: https://github.com/fmtlib/fmt/issues/1538
#if FMT_VERSION < 70000
// fmt 7.0.0 renamed the internal namespace to detail.
// See: https://github.com/fmtlib/fmt/issues/1538
#if FMT_VERSION < 70000
internal
#else
#else
detail
#endif
#endif
::count_digits(static_cast<count_type>(n)));
}

Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/fmt/bin_to_hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ struct formatter<spdlog::details::dump_info<T>, char> {
}
}
};
} // namespace std
} // namespace fmt
5 changes: 2 additions & 3 deletions include/spdlog/stopwatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class stopwatch {
} // namespace spdlog

// Support for fmt formatting (e.g. "{:012.9}" or just "{}")
namespace fmt
{
namespace fmt {

template <>
struct formatter<spdlog::stopwatch> : formatter<double> {
Expand All @@ -61,4 +60,4 @@ struct formatter<spdlog::stopwatch> : formatter<double> {
return formatter<double>::format(sw.elapsed().count(), ctx);
}
};
} // namespace std
} // namespace fmt
12 changes: 6 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ if(Catch2_FOUND)
else()
message(STATUS "Bundled version of Catch will be downloaded and used.")
include(FetchContent)
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 53d0d913a422d356b23dd927547febdf69ee9081 # v3.5.0
FetchContent_Declare(
Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 53d0d913a422d356b23dd927547febdf69ee9081 # v3.5.0
)
FetchContent_MakeAvailable(Catch2)
set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "third-party")
set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "third-party")
endif()

set(SPDLOG_UTESTS_SOURCES
Expand Down Expand Up @@ -79,9 +79,9 @@ function(spdlog_prepare_test test_target spdlog_lib)
target_link_libraries(${test_target} PRIVATE Catch2::Catch2WithMain)
if(SPDLOG_SANITIZE_ADDRESS)
spdlog_enable_addr_sanitizer(${test_target})
elseif (SPDLOG_SANITIZE_THREAD)
elseif(SPDLOG_SANITIZE_THREAD)
spdlog_enable_thread_sanitizer(${test_target})
endif ()
endif()
add_test(NAME ${test_target} COMMAND ${test_target})
set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON)
endfunction()
Expand Down
3 changes: 1 addition & 2 deletions tests/test_create_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ TEST_CASE("dir_name", "[create_dir]") {
// clang-format off
#include <windows.h>
#include <fileapi.h>
// clang-format on

// clang-format on

std::string get_full_path(const std::string &relative_folder_path) {
char full_path[MAX_PATH];
Expand Down
1 change: 0 additions & 1 deletion tests/test_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class failing_sink : public spdlog::sinks::base_sink<std::mutex> {
};
struct custom_ex {};


TEST_CASE("default_error_handler", "[errors]") {
prepare_logdir();
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
Expand Down

0 comments on commit b0e836b

Please sign in to comment.