From b66fd65a4757556b5623ba3b5c6b327e605b7f4e Mon Sep 17 00:00:00 2001 From: odygrd Date: Sun, 12 Apr 2020 16:16:42 +0100 Subject: [PATCH] Support using an external version of libfmt instead of the bundled one. Fixes #11 --- CHANGELOG.md | 5 +- CMakeLists.txt | 4 +- quill/cmake/quill-config.cmake.in | 7 ++ quill/quill/CMakeLists.txt | 64 ++++++++++++------- quill/quill/include/quill/Fmt.h | 25 ++++++++ quill/quill/include/quill/PatternFormatter.h | 2 +- quill/quill/include/quill/TweakMe.h | 13 ++++ quill/quill/include/quill/Version.h | 2 +- quill/quill/include/quill/detail/LogMacros.h | 5 +- quill/quill/include/quill/detail/misc/Os.h | 2 +- .../include/quill/detail/record/LogRecord.h | 2 +- quill/quill/include/quill/handlers/Handler.h | 2 +- quill/quill/src/detail/misc/FileUtilities.cpp | 2 +- 13 files changed, 101 insertions(+), 34 deletions(-) create mode 100644 quill/quill/include/quill/Fmt.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 254160b8..057f032a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +- [v1.2.0](#v1.2.0) - [v1.1.0](#v1.1.0) - [v1.0.0](#v1.0.0) +## v1.2.0 +* Linking and including an external version of `fmt` is now supported. See TweakMe.h + ## v1.1.0 * Daily file handler. The file handler rollover every 24 hours * Rotating file handler. The file handler will rollover based on the size of the file @@ -13,7 +17,6 @@ * Rename `emit` as it can confict with Qt macros. Fixes [#4](https://github.com/odygrd/quill/issues/4). * Upgraded `libfmt` to `6.2.0`. - ## v1.0.0 * Initial release. * Using `libfmt` to `6.1.2`. diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d6cb96f..7e044c7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ option(QUILL_CODE_COVERAGE "Enable code coverage" OFF) option(QUILL_USE_VALGRIND "Use valgrind as the default memcheck tool in CTest (Requires Valgrind)" OFF) +option(QUILL_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF) + #------------------------------------------------------------------------------------------------------- # Use newer policies if possible, up to most recent tested version of CMake. #------------------------------------------------------------------------------------------------------- @@ -126,4 +128,4 @@ if (QUILL_BUILD_EXAMPLES) add_subdirectory(examples) endif () -add_subdirectory(quill) \ No newline at end of file +add_subdirectory(quill) diff --git a/quill/cmake/quill-config.cmake.in b/quill/cmake/quill-config.cmake.in index 25f8ee5c..b35d1199 100644 --- a/quill/cmake/quill-config.cmake.in +++ b/quill/cmake/quill-config.cmake.in @@ -2,5 +2,12 @@ find_package(Threads REQUIRED) +set(QUILL_FMT_EXTERNAL @QUILL_FMT_EXTERNAL@) + +if(QUILL_FMT_EXTERNAL) + include(CMakeFindDependencyMacro) + find_dependency(fmt CONFIG) +endif() + include(${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake) check_required_components(quill) \ No newline at end of file diff --git a/quill/quill/CMakeLists.txt b/quill/quill/CMakeLists.txt index 0dbe01f4..481590b3 100644 --- a/quill/quill/CMakeLists.txt +++ b/quill/quill/CMakeLists.txt @@ -7,20 +7,6 @@ set(TARGET_NAME quill) # header files set(HEADER_FILES - # Bundled fmt - include/quill/bundled/fmt/chrono.h - include/quill/bundled/fmt/color.h - include/quill/bundled/fmt/compile.h - include/quill/bundled/fmt/core.h - include/quill/bundled/fmt/format.h - include/quill/bundled/fmt/format-inl.h - include/quill/bundled/fmt/locale.h - include/quill/bundled/fmt/os.h - include/quill/bundled/fmt/ostream.h - include/quill/bundled/fmt/posix.h - include/quill/bundled/fmt/printf.h - include/quill/bundled/fmt/ranges.h - # Bundled invoke include/quill/bundled/invoke/invoke.h @@ -57,6 +43,7 @@ set(HEADER_FILES include/quill/handlers/Handler.h include/quill/handlers/RotatingFileHandler.h include/quill/handlers/StreamHandler.h + include/quill/Fmt.h include/quill/Logger.h include/quill/LogLevel.h include/quill/PatternFormatter.h @@ -68,11 +55,6 @@ set(HEADER_FILES # source files set(SOURCE_FILES - # Bundled fmt - src/bundled/fmt/format.cc - src/bundled/fmt/os.cc - - # quill src/detail/misc/Utilities.cpp src/detail/misc/Os.cpp src/detail/misc/RdtscClock.cpp @@ -96,6 +78,27 @@ set(SOURCE_FILES src/Utility.cpp ) +if(NOT QUILL_FMT_EXTERNAL) + # if not using external fmt, include the bundled version of libfmt + list(APPEND HEADER_FILES + include/quill/bundled/fmt/chrono.h + include/quill/bundled/fmt/color.h + include/quill/bundled/fmt/compile.h + include/quill/bundled/fmt/core.h + include/quill/bundled/fmt/format.h + include/quill/bundled/fmt/format-inl.h + include/quill/bundled/fmt/locale.h + include/quill/bundled/fmt/os.h + include/quill/bundled/fmt/ostream.h + include/quill/bundled/fmt/posix.h + include/quill/bundled/fmt/printf.h + include/quill/bundled/fmt/ranges.h) + + list(APPEND SOURCE_FILES + src/bundled/fmt/format.cc + src/bundled/fmt/os.cc) +endif() + # Add as a library add_library(${TARGET_NAME} STATIC "") @@ -104,6 +107,26 @@ add_library(${TARGET_NAME}::${TARGET_NAME} ALIAS ${TARGET_NAME}) # Add target sources target_sources(${TARGET_NAME} PRIVATE ${SOURCE_FILES} ${HEADER_FILES}) +# Check if using external fmt +if(NOT QUILL_FMT_EXTERNAL) + # Link dependencies + target_link_libraries(${TARGET_NAME} PUBLIC Threads::Threads) +else() + # if fmt is not a target in the project trying to find it system wise + if (NOT TARGET fmt::fmt AND NOT TARGET fmt) + find_package(fmt REQUIRED) + endif() + + # define QUILL_FMT_EXTERNAL + target_compile_definitions(${TARGET_NAME} PUBLIC QUILL_FMT_EXTERNAL) + + # Link dependencies + target_link_libraries(${TARGET_NAME} PUBLIC Threads::Threads fmt::fmt) + + # Add dependency to pkg-config + set(PKG_CONFIG_REQUIRES fmt) +endif() + # Add include directories for this library target_include_directories(${TARGET_NAME} PUBLIC @@ -112,9 +135,6 @@ target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -# Link dependencies -target_link_libraries(${TARGET_NAME} PUBLIC Threads::Threads) - # Compiler options target_compile_options(${TARGET_NAME} PRIVATE $<$,$,$>: diff --git a/quill/quill/include/quill/Fmt.h b/quill/quill/include/quill/Fmt.h new file mode 100644 index 00000000..77e7dabb --- /dev/null +++ b/quill/quill/include/quill/Fmt.h @@ -0,0 +1,25 @@ +/** + * Copyright(c) 2020-present, Odysseas Georgoudis & quill contributors. + * Distributed under the MIT License (http://opensource.org/licenses/MIT) + */ + +#pragma once + +#include "TweakMe.h" + +/** + * Include a bundled header-only copy of lib fmt or an external one. + * By default Quill includes it's bundled copy. + */ +#if !defined(QUILL_FMT_EXTERNAL) + #include "quill/bundled/fmt/chrono.h" + #include "quill/bundled/fmt/format.h" + #include "quill/bundled/fmt/ostream.h" + #include "quill/bundled/fmt/ranges.h" +#else + // use external fmtlib + #include + #include + #include + #include +#endif \ No newline at end of file diff --git a/quill/quill/include/quill/PatternFormatter.h b/quill/quill/include/quill/PatternFormatter.h index 8846fcac..015813bb 100644 --- a/quill/quill/include/quill/PatternFormatter.h +++ b/quill/quill/include/quill/PatternFormatter.h @@ -5,7 +5,7 @@ #pragma once -#include "quill/bundled/fmt/format.h" +#include "quill/Fmt.h" #include "quill/bundled/invoke/invoke.h" #include "quill/detail/misc/Attributes.h" #include "quill/detail/misc/Common.h" diff --git a/quill/quill/include/quill/TweakMe.h b/quill/quill/include/quill/TweakMe.h index a44edd01..cc697e10 100644 --- a/quill/quill/include/quill/TweakMe.h +++ b/quill/quill/include/quill/TweakMe.h @@ -71,3 +71,16 @@ * QUILL_LOG_LEVEL_CRITICAL */ // #define QUILL_ACTIVE_LOG_LEVEL QUILL_LOG_LEVEL_TRACE_L3 + +/** + * Uses a custom copy of the fmt library instead of quill's bundled copy. + * In this case quill will try to include so make sure to set -I directories + * accordingly if not using CMake. + * + * This is also available as CMake option -DQUILL_FMT_EXTERNAL=ON. + * When -DQUILL_FMT_EXTERNAL=ON is used the below line does not need to be uncommented as CMake will + * define it automatically. + * Quill will look for a CMake Target with name `fmt`. If the target is not found it will + * use find_package(fmt REQUIRED) so make sure that fmt library is installed in your system + */ +// #define QUILL_FMT_EXTERNAL \ No newline at end of file diff --git a/quill/quill/include/quill/Version.h b/quill/quill/include/quill/Version.h index 53fd3ec6..f6ad1c86 100644 --- a/quill/quill/include/quill/Version.h +++ b/quill/quill/include/quill/Version.h @@ -6,7 +6,7 @@ #pragma once #define QUILL_VERSION_MAJOR 1 -#define QUILL_VERSION_MINOR 1 +#define QUILL_VERSION_MINOR 2 #define QUILL_VERSION_PATCH 0 #define QUILL_VERSION \ diff --git a/quill/quill/include/quill/detail/LogMacros.h b/quill/quill/include/quill/detail/LogMacros.h index 62c7d3bf..69d249f5 100644 --- a/quill/quill/include/quill/detail/LogMacros.h +++ b/quill/quill/include/quill/detail/LogMacros.h @@ -8,10 +8,7 @@ #include "quill/detail/misc/Common.h" #include "quill/Logger.h" -#include "quill/bundled/fmt/chrono.h" -#include "quill/bundled/fmt/format.h" -#include "quill/bundled/fmt/ostream.h" -#include "quill/bundled/fmt/ranges.h" +#include "quill/Fmt.h" #include "quill/detail/misc/Macros.h" // Config Options diff --git a/quill/quill/include/quill/detail/misc/Os.h b/quill/quill/include/quill/detail/misc/Os.h index eca4b127..609f42dd 100644 --- a/quill/quill/include/quill/detail/misc/Os.h +++ b/quill/quill/include/quill/detail/misc/Os.h @@ -5,7 +5,7 @@ #pragma once -#include "quill/bundled/fmt/format.h" +#include "quill/Fmt.h" #include "quill/detail/misc/Attributes.h" #include "quill/detail/misc/Common.h" #include diff --git a/quill/quill/include/quill/detail/record/LogRecord.h b/quill/quill/include/quill/detail/record/LogRecord.h index cbfffa47..ae4f1874 100644 --- a/quill/quill/include/quill/detail/record/LogRecord.h +++ b/quill/quill/include/quill/detail/record/LogRecord.h @@ -5,7 +5,7 @@ #pragma once -#include "quill/bundled/fmt/format.h" +#include "quill/Fmt.h" #include "quill/bundled/invoke/invoke.h" #include "quill/detail/misc/TypeTraits.h" #include "quill/detail/record/RecordBase.h" diff --git a/quill/quill/include/quill/handlers/Handler.h b/quill/quill/include/quill/handlers/Handler.h index 59f3d55d..9d9085d6 100644 --- a/quill/quill/include/quill/handlers/Handler.h +++ b/quill/quill/include/quill/handlers/Handler.h @@ -6,7 +6,7 @@ #pragma once #include "quill/PatternFormatter.h" -#include "quill/bundled/fmt/format.h" +#include "quill/Fmt.h" namespace quill { diff --git a/quill/quill/src/detail/misc/FileUtilities.cpp b/quill/quill/src/detail/misc/FileUtilities.cpp index adc7e3be..36bf0e28 100644 --- a/quill/quill/src/detail/misc/FileUtilities.cpp +++ b/quill/quill/src/detail/misc/FileUtilities.cpp @@ -1,5 +1,5 @@ #include "quill/detail/misc/FileUtilities.h" -#include "quill/bundled/fmt/format.h" +#include "quill/Fmt.h" #include "quill/detail/misc/Macros.h" #include "quill/detail/misc/Os.h" #include