From b0e836b00039d886ca0369862a877847722589a8 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 29 Nov 2024 15:02:13 +0200 Subject: [PATCH] clang-format --- CMakeLists.txt | 61 ++++++++++++----------------- bench/CMakeLists.txt | 2 +- bench/bench.cpp | 12 +++--- cmake/fmtlib.cmake | 10 ++--- example/CMakeLists.txt | 2 +- example/example.cpp | 2 - include/spdlog/common.h | 9 ++--- include/spdlog/details/fmt_helper.h | 10 ++--- include/spdlog/fmt/bin_to_hex.h | 2 +- include/spdlog/stopwatch.h | 5 +-- tests/CMakeLists.txt | 12 +++--- tests/test_create_dir.cpp | 3 +- tests/test_errors.cpp | 1 - 13 files changed, 57 insertions(+), 74 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53ac7436..20f6a7df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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}) @@ -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) @@ -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/$) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) - set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + # place dlls and libs and executables in the same directory + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) - # make sure __cplusplus is defined - add_compile_options(/Zc:__cplusplus) - # enable parallel build for the solution - add_compile_options(/MP) + # 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}) @@ -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() @@ -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" @@ -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 @@ -275,14 +268,14 @@ endif() set_target_properties(spdlog PROPERTIES PUBLIC_HEADER "${SPDLOG_HEADERS}") -target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC - "$" - "$") +target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$" + "$") 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 @@ -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 # --------------------------------------------------------------------------------------- @@ -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() diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 4fbce553..a20acda3 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -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) diff --git a/bench/bench.cpp b/bench/bench.cpp index c21a1158..66d1621d 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -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 + #include #include // EXIT_FAILURE #include #include #include +#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 log); diff --git a/cmake/fmtlib.cmake b/cmake/fmtlib.cmake index a8443f0f..4c6833a2 100644 --- a/cmake/fmtlib.cmake +++ b/cmake/fmtlib.cmake @@ -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() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index b197afe1..90211423 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -9,4 +9,4 @@ if(NOT TARGET spdlog) endif() add_executable(example example.cpp) -target_link_libraries(example PRIVATE spdlog::spdlog $<$:ws2_32>) \ No newline at end of file +target_link_libraries(example PRIVATE spdlog::spdlog $<$:ws2_32>) diff --git a/example/example.cpp b/example/example.cpp index 9a3361f1..31f4258b 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -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 buf; @@ -238,7 +237,6 @@ struct my_type { : i(i) {} }; - template <> struct fmt::formatter : fmt::formatter { auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) { diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 495c4e9a..d076d455 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -21,7 +21,6 @@ #include #endif - #if defined(SPDLOG_SHARED_LIB) #if defined(_WIN32) #ifdef spdlog_EXPORTS @@ -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(__FUNCTION__) diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index 751bd696..ff10dcc3 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -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(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(n))); } diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 4dc6f337..ae3c1588 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -203,4 +203,4 @@ struct formatter, char> { } } }; -} // namespace std +} // namespace fmt diff --git a/include/spdlog/stopwatch.h b/include/spdlog/stopwatch.h index 61f168bc..f101749e 100644 --- a/include/spdlog/stopwatch.h +++ b/include/spdlog/stopwatch.h @@ -51,8 +51,7 @@ public: } // namespace spdlog // Support for fmt formatting (e.g. "{:012.9}" or just "{}") -namespace fmt -{ +namespace fmt { template <> struct formatter : formatter { @@ -61,4 +60,4 @@ struct formatter : formatter { return formatter::format(sw.elapsed().count(), ctx); } }; -} // namespace std +} // namespace fmt diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fa245b97..a963fc72 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 @@ -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() diff --git a/tests/test_create_dir.cpp b/tests/test_create_dir.cpp index 6f38006c..7d46dfc0 100644 --- a/tests/test_create_dir.cpp +++ b/tests/test_create_dir.cpp @@ -81,8 +81,7 @@ TEST_CASE("dir_name", "[create_dir]") { // clang-format off #include #include - // clang-format on - +// clang-format on std::string get_full_path(const std::string &relative_folder_path) { char full_path[MAX_PATH]; diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index 0f164b0a..25d0f335 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -18,7 +18,6 @@ protected: }; struct custom_ex {}; - TEST_CASE("default_error_handler", "[errors]") { prepare_logdir(); spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);