Commit d09bab9b authored by Michael R. Crusoe's avatar Michael R. Crusoe 🏳️‍🌈
Browse files

New upstream version 1.4.1

parent f61795eb
Loading
Loading
Loading
Loading

.gitattributes

0 → 100644
+1 −0
Original line number Diff line number Diff line
* text=false
+17 −2
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@ build/*
# Codelite
.codelite

# KDevelop
*.kdev4

# .orig files
*.orig

@@ -46,6 +49,7 @@ example/*
!example/example.sln
!example/example.vcxproj
!example/CMakeLists.txt
!example/meson.build
!example/multisink.cpp
!example/jni

@@ -66,3 +70,14 @@ install_manifest.txt

# idea
.idea/
cmake-build-*/
*.db
*.ipch
*.filters
*.db-wal
*.opendb
*.db-shm
*.vcxproj
*.tcl
*.user
*.sln
+21 −26
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
sudo: required
language: cpp

# gcc 4.8
addons: &gcc48
  apt:
    packages:
@@ -12,6 +13,7 @@ addons: &gcc48
    sources:
      - ubuntu-toolchain-r-test

# gcc 7.0
addons: &gcc7
  apt:
    packages:
@@ -19,6 +21,7 @@ addons: &gcc7
    sources:
      - ubuntu-toolchain-r-test

# Clang 3.5
addons: &clang35
  apt:
    packages:
@@ -27,13 +30,15 @@ addons: &clang35
      - ubuntu-toolchain-r-test
      - llvm-toolchain-precise-3.5
      
addons: &clang6
# Clang 7.0
addons: &clang70
  apt:
    packages:
      - clang-6.0
      - clang-7      
    sources:
      - ubuntu-toolchain-r-test
      - llvm-toolchain-trusty-6.0
      - llvm-toolchain-trusty-7



matrix:
@@ -60,23 +65,12 @@ matrix:
      os: linux
      addons: *clang35

      # Test clang-6.0: C++11, Build=Debug, ASAN=On
    - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On TSAN=Off
      os: linux
      addons: *clang6
      # Test clang-7.0: C++11, Build=Debug, ASAN=On
    - env: CLANG_VERSION=7 BUILD_TYPE=Debug CPP=11 ASAN=On TSAN=Off
      dist: bionic      

    - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=On TSAN=Off
      os: linux
      addons: *clang6
      
      # Test clang-6.0: C++11, Build=Debug, TSAN=On
    - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=Off TSAN=On
      os: linux
      addons: *clang6
      
    - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=On
      os: linux
      addons: *clang6
    - env: CLANG_VERSION=7 BUILD_TYPE=Release CPP=11 ASAN=On TSAN=Off
      dist: bionic
      
      # osx
    - env: BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off
@@ -84,7 +78,6 @@ matrix:




before_script:
  - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
  - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi
@@ -102,11 +95,13 @@ script:
      --warn-uninitialized \
      -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
      -DCMAKE_CXX_STANDARD=$CPP \
      -DSPDLOG_BUILD_EXAMPLES=ON \
      -DSPDLOG_BUILD_EXAMPLE=ON \
      -DSPDLOG_BUILD_EXAMPLE_HO=ON \
      -DSPDLOG_BUILD_BENCH=OFF \
      -DSPDLOG_BUILD_TESTS=ON \
      -DSPDLOG_SANITIZE_ADDRESS=$ASAN \
      -DSPDLOG_SANITIZE_THREAD=$TSAN
      -DSPDLOG_BUILD_TESTS_HO=OFf \
      -DSPDLOG_SANITIZE_ADDRESS=$ASAN 
      
  - make VERBOSE=1 -j2
  - ctest -j2 --output-on-failure

+178 −112
Original line number Diff line number Diff line
#
# Copyright(c) 2015 Ruslan Baratov.
# Copyright(c) 2019 spdlog authors
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
#

cmake_minimum_required(VERSION 3.1)
project(spdlog VERSION 1.3.1 LANGUAGES CXX)
include(CMakeDependentOption)
cmake_minimum_required(VERSION 3.2)

#---------------------------------------------------------------------------------------
# Start spdlog project
#---------------------------------------------------------------------------------------
include(GNUInstallDirs)
include(cmake/utils.cmake)
include(cmake/ide.cmake)

spdlog_extract_version()

#---------------------------------------------------------------------------------------
# set default build to release
# Set default build to release
#---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()

message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
project(spdlog VERSION ${SPDLOG_VERSION} LANGUAGES CXX)
message(STATUS "Build spdlog: ${SPDLOG_VERSION}")

#---------------------------------------------------------------------------------------
# compiler config
# Compiler config
#---------------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    add_compile_options("-Wall")
    add_compile_options("-Wextra")
    add_compile_options("-Wconversion")
    add_compile_options("-pedantic")
    add_compile_options("-Wfatal-errors")
#---------------------------------------------------------------------------------------
# Set SPDLOG_MASTER_PROJECT to ON if we are building spdlog
#---------------------------------------------------------------------------------------
# Check if spdlog is being used directly or via add_subdirectory, but allow overriding
if (NOT DEFINED SPDLOG_MASTER_PROJECT)
    if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
        set(SPDLOG_MASTER_PROJECT ON)
    else()
        set(SPDLOG_MASTER_PROJECT OFF)
    endif()
endif ()

# build shared option
if(NOT WIN32)
    option(SPDLOG_BUILD_SHARED "Build shared library" OFF)
endif()

# example options
option(SPDLOG_BUILD_EXAMPLE "Build example" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_BUILD_EXAMPLE_HO "Build header only example" OFF)

# testing options
option(SPDLOG_BUILD_TESTS "Build tests" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_BUILD_TESTS_HO "Build tests using the header only version" OFF)

# bench options
option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)

# sanitizer options
option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)

# install options
option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)

if(WIN32)
	option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
endif()

option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)


find_package(Threads REQUIRED)

message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})

#---------------------------------------------------------------------------------------
# address sanitizers check
# Static/Shared library (shared not supported in windows yet)
#---------------------------------------------------------------------------------------
include(cmake/sanitizers.cmake)
set(SPDLOG_SRCS
        src/spdlog.cpp
        src/stdout_sinks.cpp
        src/fmt.cpp
        src/color_sinks.cpp
        src/file_sinks.cpp
        src/async.cpp)

set(SPDLOG_CFLAGS "${PROJECT_NAME}")

if (SPDLOG_BUILD_SHARED)
    if(WIN32)
        message(FATAL_ERROR "spdlog shared lib is not yet supported under windows")
    endif()
    add_library(spdlog SHARED ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
else()
    add_library(spdlog STATIC ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
endif()

add_library(spdlog::spdlog ALIAS spdlog)

target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB)
target_include_directories(spdlog PUBLIC
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
        "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(spdlog PUBLIC Threads::Threads)
spdlog_enable_warnings(spdlog)

set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION ${SPDLOG_VERSION_MAJOR})
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d)

#---------------------------------------------------------------------------------------
# spdlog target
# Header only version
#---------------------------------------------------------------------------------------
add_library(spdlog INTERFACE)
add_library(spdlog::spdlog ALIAS spdlog)
add_library(spdlog_header_only INTERFACE)
add_library(spdlog::spdlog_header_only ALIAS spdlog_header_only)

# Check if spdlog is being used directly or via add_subdirectory
set(SPDLOG_MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  set(SPDLOG_MASTER_PROJECT ON)
endif()
target_include_directories(spdlog_header_only INTERFACE
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
        "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(spdlog_header_only INTERFACE Threads::Threads)

option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_BUILD_BENCH "Build benchmarks" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_BUILD_TESTS "Build tests" ${SPDLOG_MASTER_PROJECT})
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)

#---------------------------------------------------------------------------------------
# Use fmt package if using exertnal fmt
#---------------------------------------------------------------------------------------
if(SPDLOG_FMT_EXTERNAL)
    find_package(fmt REQUIRED CONFIG)
    if (NOT TARGET fmt::fmt)
        find_package(fmt REQUIRED)
    endif ()

target_include_directories(
    spdlog
    INTERFACE
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
    set(SPDLOG_CFLAGS "${SPDLOG_CFLAGS} -DSPDLOG_FMT_EXTERNAL")

if(SPDLOG_FMT_EXTERNAL)
    target_compile_definitions(spdlog INTERFACE SPDLOG_FMT_EXTERNAL)
    target_link_libraries(spdlog INTERFACE fmt::fmt)
    target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
    target_link_libraries(spdlog PUBLIC fmt::fmt)

    target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
    target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
endif()

if(SPDLOG_WCHAR_SUPPORT)
	target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_TO_UTF8_SUPPORT)
	target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
 endif()

 if(SPDLOG_NO_EXCEPTIONS)
	target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)	

	target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_EXCEPTIONS)

    if(NOT MSVC)
        target_compile_options(spdlog PRIVATE -fno-exceptions)
    endif()
endif()

set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include")

if(SPDLOG_BUILD_EXAMPLES)
#---------------------------------------------------------------------------------------
# Build binaries
#---------------------------------------------------------------------------------------
if(SPDLOG_BUILD_EXAMPLE OR SPDLOG_BUILD_EXAMPLE_HO)
    message(STATUS "Generating examples")
    add_subdirectory(example)
endif()

if(SPDLOG_BUILD_TESTS)
    include(CTest)
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_TESTS_HO)
    message(STATUS "Generating tests")
    enable_testing()
    add_subdirectory(tests)
endif()

if(SPDLOG_BUILD_BENCH)
    message(STATUS "Generating benchmarks")
    add_subdirectory(bench)
endif()

#---------------------------------------------------------------------------------------
# Install/export targets and files
# Install
#---------------------------------------------------------------------------------------
# set files and directories
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(include_install_dir "${CMAKE_INSTALL_INCLUDEDIR}")
if (SPDLOG_INSTALL)
    message(STATUS "Generating install")
    set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/spdlogConfig.cmake.in")
    set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
    set(config_targets_file "spdlogConfigTargets.cmake")
    set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
    set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/spdlog/cmake")
    set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(version_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
set(targets_config "${PROJECT_NAME}Targets.cmake")
    set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")

# generate package version file
    #---------------------------------------------------------------------------------------
    # Include files
    #---------------------------------------------------------------------------------------
    install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" PATTERN "fmt/bundled" EXCLUDE)
    install(TARGETS spdlog spdlog_header_only EXPORT spdlog DESTINATION "${CMAKE_INSTALL_LIBDIR}/spdlog")

    if(NOT SPDLOG_FMT_EXTERNAL)
        install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
                DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")
    endif()

    #---------------------------------------------------------------------------------------
    # Package and version files
    #---------------------------------------------------------------------------------------
    configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
    install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")

    install(EXPORT spdlog
            DESTINATION ${export_dest_dir}
            NAMESPACE spdlog::
            FILE ${config_targets_file})

    include(CMakePackageConfigHelpers)
write_basic_package_version_file(
    "${version_config}" COMPATIBILITY SameMajorVersion
)

# configure pkg config file
configure_file("cmake/spdlog.pc.in" "${pkg_config}" @ONLY)
# configure spdlogConfig.cmake file
configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY)

# install targets
install(
    TARGETS spdlog
    EXPORT "${targets_export_name}"
)

# install headers
install(
    DIRECTORY "${HEADER_BASE}/${PROJECT_NAME}"
    DESTINATION "${include_install_dir}"
)

# install project config and version file
install(
    FILES "${project_config}" "${version_config}"
    DESTINATION "${config_install_dir}"
)

# install pkg config file
install(
    FILES "${pkg_config}"
    DESTINATION "${pkgconfig_install_dir}"
)

# install targets config file
install(
    EXPORT "${targets_export_name}"
    NAMESPACE "${namespace}"
    DESTINATION "${config_install_dir}"
    FILE ${targets_config}
)

# export build directory targets file
export(
    EXPORT ${targets_export_name}
    NAMESPACE "${namespace}"
    FILE ${targets_config}
)

# register project in CMake user registry
export(PACKAGE ${PROJECT_NAME})

file(GLOB_RECURSE spdlog_include_SRCS "${HEADER_BASE}/*.h")
add_custom_target(spdlog_headers_for_ide SOURCES ${spdlog_include_SRCS})
    configure_file("${project_config_in}" "${project_config_out}" @ONLY)
    write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
    install(FILES
            "${project_config_out}"
            "${version_config_file}" DESTINATION "${export_dest_dir}")

    #---------------------------------------------------------------------------------------
    # Support creation of installable packages
    #---------------------------------------------------------------------------------------
    include(cmake/spdlogCPack.cmake)

endif ()
+16 −5
Original line number Diff line number Diff line
spdlog is header only library.
Just copy the files to your build tree and use a C++11 compiler
Header only version:
==================================================================
Just copy the files to your build tree and use a C++11 compiler.
Or use CMake:
  add_executable(example_header_only example.cpp)
  target_link_libraries(example_header_only spdlog::spdlog_header_only)


Compiled library version:
==================================================================
CMake:
  add_executable(example example.cpp)
  target_link_libraries(example spdlog::spdlog)

Or copy src/spdlog.cpp to your build tree and pass the -DSPDLOG_COMPILED_LIB to the compiler.

Tested on:
gcc 4.8.1 and above
clang 3.5
Visual Studio 2013

gcc 4.8 flags: --std==c++11 -pthread -O3 -flto -Wl,--no-as-needed
gcc 4.9 flags: --std=c++11 -pthread -O3 -flto


see the makefile in the example folder
Loading