Skip to content

Commit

Permalink
Support using an external version of libfmt instead of the bundled one.
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
odygrd committed Apr 12, 2020
1 parent 28a4575 commit b66fd65
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 34 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#-------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -126,4 +128,4 @@ if (QUILL_BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()

add_subdirectory(quill)
add_subdirectory(quill)
7 changes: 7 additions & 0 deletions quill/cmake/quill-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
64 changes: 42 additions & 22 deletions quill/quill/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 "")

Expand All @@ -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
Expand All @@ -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
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
Expand Down
25 changes: 25 additions & 0 deletions quill/quill/include/quill/Fmt.h
Original file line number Diff line number Diff line change
@@ -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 <fmt/chrono.h>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#endif
2 changes: 1 addition & 1 deletion quill/quill/include/quill/PatternFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions quill/quill/include/quill/TweakMe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fmt/format.h> 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
2 changes: 1 addition & 1 deletion quill/quill/include/quill/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 1 addition & 4 deletions quill/quill/include/quill/detail/LogMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion quill/quill/include/quill/detail/misc/Os.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion quill/quill/include/quill/detail/record/LogRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion quill/quill/include/quill/handlers/Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#pragma once

#include "quill/PatternFormatter.h"
#include "quill/bundled/fmt/format.h"
#include "quill/Fmt.h"

namespace quill
{
Expand Down
2 changes: 1 addition & 1 deletion quill/quill/src/detail/misc/FileUtilities.cpp
Original file line number Diff line number Diff line change
@@ -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 <system_error>
Expand Down

0 comments on commit b66fd65

Please sign in to comment.