From a9aee1c5b384e5a3e2a9efbd3b8cec8afbd7bc6f Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:02:39 -0500 Subject: [PATCH 01/21] Disable automatic handling of line endings --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..fe505b27 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=false From dbcbeb7a571e50446e7eef5b36e47911b229ac9f Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:05:48 -0500 Subject: [PATCH 02/21] Ignore CLion's default build directories --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b1a41919..fafa874a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Auto generated files -build/* +build/* *.slo *.lo *.o @@ -65,4 +65,5 @@ install_manifest.txt /tests/logs/* # idea -.idea/ \ No newline at end of file +.idea/ +cmake-build-*/ From 8dd85285e7a87a1a7347f3d6b4d409e4eed44eb6 Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:09:22 -0500 Subject: [PATCH 03/21] Allow user to choose between static or shared library --- CMakeLists.txt | 23 +++++++++++------------ bench/CMakeLists.txt | 8 ++++---- example/CMakeLists.txt | 8 ++++---- include/spdlog/common.h | 4 ++-- include/spdlog/sinks/base_sink.h | 4 ++-- src/spdlog.cpp | 6 +++--- tests/CMakeLists.txt | 2 +- 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed6a21b..042ac7a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ else() set(SPDLOG_MASTER_PROJECT OFF) endif() +option(BUILD_SHARED_LIBS "Global flag to cause add_library to create shared libraries if on." ON) option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF) option(SPDLOG_BUILD_TESTS "Build tests" ON) @@ -55,15 +56,13 @@ set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include/spdlog") message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) -# Build static lib -set(SRC_BASE "${CMAKE_CURRENT_SOURCE_DIR}/src") -set(STATIC_SRC_FILES "${SRC_BASE}/spdlog.cpp") -add_library(spdlog_static STATIC ${STATIC_SRC_FILES}) -add_library(spdlog::static ALIAS spdlog_static) -target_compile_definitions(spdlog_static PUBLIC SPDLOG_STATIC_LIB ) -target_include_directories(spdlog_static PUBLIC "$") -set_target_properties(spdlog_static PROPERTIES OUTPUT_NAME "spdlog") -set_target_properties(spdlog_static PROPERTIES DEBUG_POSTFIX "-debug") +# Build library +add_library(spdlog src/spdlog.cpp) +add_library(spdlog::spdlog ALIAS spdlog) +target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB ) +target_include_directories(spdlog PUBLIC "$") +set_target_properties(spdlog PROPERTIES OUTPUT_NAME "spdlog") +set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "-debug") # Headr only add_library(spdlog_header_only INTERFACE) @@ -75,8 +74,8 @@ if(SPDLOG_FMT_EXTERNAL AND NOT TARGET fmt::fmt) endif() if(SPDLOG_FMT_EXTERNAL) - target_compile_definitions(spdlog_static INTERFACE SPDLOG_FMT_EXTERNAL) - target_link_libraries(spdlog_static INTERFACE fmt::fmt) + target_compile_definitions(spdlog INTERFACE SPDLOG_FMT_EXTERNAL) + target_link_libraries(spdlog INTERFACE fmt::fmt) target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL) target_link_libraries(spdlog_header_only INTERFACE fmt::fmt) endif() @@ -98,7 +97,7 @@ endif() # install #--------------------------------------------------------------------------------------- install(DIRECTORY ${HEADER_BASE} DESTINATION include) -install(TARGETS spdlog_static ARCHIVE DESTINATION lib) +install(TARGETS spdlog DESTINATION lib) #--------------------------------------------------------------------------------------- # register project in CMake user registry diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 9280ebad..3c4a3f9d 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -33,16 +33,16 @@ find_package(Threads REQUIRED) find_package(benchmark CONFIG REQUIRED) add_executable(bench bench.cpp) -target_link_libraries(bench PRIVATE spdlog::static Threads::Threads) +target_link_libraries(bench PRIVATE spdlog::spdlog Threads::Threads) add_executable(async_bench async_bench.cpp) -target_link_libraries(async_bench PRIVATE spdlog::static Threads::Threads) +target_link_libraries(async_bench PRIVATE spdlog::spdlog Threads::Threads) add_executable(latency latency.cpp) -target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::static Threads::Threads) +target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog Threads::Threads) add_executable(formatter-bench formatter-bench.cpp) -target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::static Threads::Threads) +target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog Threads::Threads) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f0a917f2..98bdca6e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 3.1) project(SpdlogExamples CXX) -if(NOT TARGET spdlog) +if(NOT TARGET spdlog::spdlog) # Stand-alone build find_package(spdlog CONFIG REQUIRED) endif() @@ -34,14 +34,14 @@ find_package(Threads REQUIRED) add_executable(example example.cpp) if(CMAKE_SYSTEM_NAME STREQUAL "Android") find_library(log-lib log) - target_link_libraries(example spdlog::static Threads::Threads log) + target_link_libraries(example spdlog::spdlog Threads::Threads log) else() - target_link_libraries(example spdlog::static Threads::Threads) + target_link_libraries(example spdlog::spdlog Threads::Threads) endif() add_executable(multisink multisink.cpp) -target_link_libraries(multisink spdlog::static Threads::Threads) +target_link_libraries(multisink spdlog::spdlog Threads::Threads) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 819f3abb..ccc1d990 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -19,7 +19,7 @@ #include #endif -#ifdef SPDLOG_STATIC_LIB +#ifdef SPDLOG_COMPILED_LIB #undef SPDLOG_HEADER_ONLY #define SPDLOG_INLINE #else @@ -216,4 +216,4 @@ std::unique_ptr make_unique(Args &&... args) #ifdef SPDLOG_HEADER_ONLY #include "common-inl.h" -#endif \ No newline at end of file +#endif diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index 2ecf11b1..c9f5670e 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -37,6 +37,6 @@ protected: } // namespace sinks } // namespace spdlog -#ifndef SPDLOG_STATIC_LIB +#ifndef SPDLOG_COMPILED_LIB #include "base_sink-inl.h" -#endif \ No newline at end of file +#endif diff --git a/src/spdlog.cpp b/src/spdlog.cpp index d98458ca..d51c6186 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -1,8 +1,8 @@ // Copyright(c) 2015-present Gabi Melman & spdlog contributors. // Distributed under the MIT License (http://opensource.org/licenses/MIT) -#ifndef SPDLOG_STATIC_LIB -#error Please define SPDLOG_STATIC_LIB to compile this file. +#ifndef SPDLOG_COMPILED_LIB +#error Please define SPDLOG_COMPILED_LIB to compile this file. #endif #include @@ -100,4 +100,4 @@ template FMT_API int internal::char_traits::format_float(wchar_t *, std template FMT_API std::wstring internal::vformat(wstring_view, basic_format_args); FMT_END_NAMESPACE -#endif \ No newline at end of file +#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2950f99e..48f80e0e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,7 +21,7 @@ set(SPDLOG_UTESTS_SOURCES add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) -target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::static) +target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") From 55e7844ca079c31d798aeb77339df404fcc1626a Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:15:08 -0500 Subject: [PATCH 04/21] Remove the namespaced Namespaces are good for avoiding collisions, but since the non-namespaced targets still exist, it does no good to add the namespaced targets on top. --- CMakeLists.txt | 2 -- example/CMakeLists.txt | 11 ++++++++--- tests/CMakeLists.txt | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 042ac7a7..c939248b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,6 @@ message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) # Build library add_library(spdlog src/spdlog.cpp) -add_library(spdlog::spdlog ALIAS spdlog) target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB ) target_include_directories(spdlog PUBLIC "$") set_target_properties(spdlog PROPERTIES OUTPUT_NAME "spdlog") @@ -67,7 +66,6 @@ set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "-debug") # Headr only add_library(spdlog_header_only INTERFACE) target_include_directories(spdlog_header_only INTERFACE "$") -add_library(spdlog::header_only ALIAS spdlog_header_only) if(SPDLOG_FMT_EXTERNAL AND NOT TARGET fmt::fmt) find_package(fmt REQUIRED CONFIG) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 98bdca6e..9dc977e7 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -24,9 +24,14 @@ cmake_minimum_required(VERSION 3.1) project(SpdlogExamples CXX) -if(NOT TARGET spdlog::spdlog) - # Stand-alone build - find_package(spdlog CONFIG REQUIRED) +if(TARGET spdlog) + # If we're running this example as part of the primary spdlog applciation + # then add an alias. This allows us to use the same "spdlog::spdlog" + # below that a user would use (with the namespace) + add_library(spdlog::spdlog ALIAS spdlog) +else() + # Stand-alone build + find_package(spdlog REQUIRED) endif() find_package(Threads REQUIRED) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 48f80e0e..8679174d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,7 +21,7 @@ set(SPDLOG_UTESTS_SOURCES add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) -target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog) +target_link_libraries(${PROJECT_NAME} PRIVATE spdlog) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") From b021be29e56a6b539c067a247904d54d051ca492 Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:17:46 -0500 Subject: [PATCH 05/21] Add support for .tar.gz and .zip packages via CPack --- CMakeLists.txt | 26 ++++++++++++++++++++------ SpdlogCPack.cmake | 26 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 SpdlogCPack.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c939248b..b1971b26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,13 +91,27 @@ if(SPDLOG_BUILD_BENCH) add_subdirectory(bench) endif() -#--------------------------------------------------------------------------------------- -# install -#--------------------------------------------------------------------------------------- -install(DIRECTORY ${HEADER_BASE} DESTINATION include) -install(TARGETS spdlog DESTINATION lib) +if (SPDLOG_INSTALL) + #--------------------------------------------------------------------------------------- + # install + #--------------------------------------------------------------------------------------- + install(DIRECTORY include/ DESTINATION include) + install(TARGETS spdlog EXPORT ${PROJECT_NAME} DESTINATION lib) + install(EXPORT ${PROJECT_NAME} + DESTINATION lib/${PROJECT_NAME}/cmake + NAMESPACE ${PROJECT_NAME}:: + FILE ${PROJECT_NAME}Config.cmake + ) + + #--------------------------------------------------------------------------------------- + # Support creation of installable packages + #--------------------------------------------------------------------------------------- + include(SpdlogCPack.cmake) +endif () #--------------------------------------------------------------------------------------- -# register project in CMake user registry +# register project in CMake user registry - disabled by default since the +# installed/packaged version of the project is preferred. #--------------------------------------------------------------------------------------- +option(CMAKE_EXPORT_NO_PACKAGE_REGISTRY "Disable registration of CMake's build directory." ON) export(PACKAGE ${PROJECT_NAME}) diff --git a/SpdlogCPack.cmake b/SpdlogCPack.cmake new file mode 100644 index 00000000..432503cb --- /dev/null +++ b/SpdlogCPack.cmake @@ -0,0 +1,26 @@ +set(CPACK_GENERATOR + TGZ + ZIP + ) + +set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) +set(CPACK_INSTALL_CMAKE_PROJECTS + "${CMAKE_BINARY_DIR}" + "${PROJECT_NAME}" + ALL + . + ) + +set(CPACK_PROJECT_URL "https://github.com/gabime/spdlog") +set(CPACK_PACKAGE_VENDOR "Gabi Melman") +set(CPACK_PACKAGE_CONTACT "Gabi Melman ") +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) +if (PROJECT_VERSION_TWEAK) + set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}.${PROJECT_VERSION_TWEAK}) +endif () +set(CPACK_PACKAGE_RELOCATABLE ON) + +include(CPack) From 107fe0a14231587a03921a22300fb988e0a9ebe0 Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:20:30 -0500 Subject: [PATCH 06/21] Ensure header_only library works by adding another example exe --- example/CMakeLists.txt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 9dc977e7..b25ca252 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -36,14 +36,22 @@ endif() find_package(Threads REQUIRED) +# Example of using pre-compiled library add_executable(example example.cpp) +target_link_libraries(example spdlog::spdlog Threads::Threads) if(CMAKE_SYSTEM_NAME STREQUAL "Android") find_library(log-lib log) - target_link_libraries(example spdlog::spdlog Threads::Threads log) -else() - target_link_libraries(example spdlog::spdlog Threads::Threads) + target_link_libraries(example log) endif() +# Example of using header-only library +add_executable(example_header_only example.cpp) +get_target_property(SPDLOG_INCLUDE_DIRS spdlog::spdlog INTERFACE_INCLUDE_DIRECTORIES) +target_include_directories(example_header_only PRIVATE ${SPDLOG_INCLUDE_DIRS}) +target_link_libraries(example_header_only Threads::Threads) +if(CMAKE_SYSTEM_NAME STREQUAL "Android") + target_link_libraries(example_header_only log) +endif () add_executable(multisink multisink.cpp) target_link_libraries(multisink spdlog::spdlog Threads::Threads) @@ -52,3 +60,4 @@ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") enable_testing() add_test(NAME example COMMAND example) +add_test(NAME example_header_only COMMAND example) From 6fe899af104930c381b8bb0498e93b7a09418241 Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:23:51 -0500 Subject: [PATCH 07/21] Set Threads::Threads dependency on spdlog libs - don't make user do it --- CMakeLists.txt | 20 +++++++++++++------- bench/CMakeLists.txt | 8 ++++---- example/CMakeLists.txt | 4 ++-- tests/CMakeLists.txt | 1 - 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1971b26..2ef3b16f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,24 +56,30 @@ set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include/spdlog") message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) +find_package(Threads REQUIRED) + # Build library add_library(spdlog src/spdlog.cpp) target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB ) target_include_directories(spdlog PUBLIC "$") set_target_properties(spdlog PROPERTIES OUTPUT_NAME "spdlog") set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "-debug") +target_link_libraries(spdlog PUBLIC Threads::Threads) -# Headr only +# Header only add_library(spdlog_header_only INTERFACE) -target_include_directories(spdlog_header_only INTERFACE "$") +target_include_directories(spdlog_header_only INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include") +target_link_libraries(spdlog_header_only INTERFACE Threads::Threads) -if(SPDLOG_FMT_EXTERNAL AND NOT TARGET fmt::fmt) - find_package(fmt REQUIRED CONFIG) -endif() if(SPDLOG_FMT_EXTERNAL) - target_compile_definitions(spdlog INTERFACE SPDLOG_FMT_EXTERNAL) - target_link_libraries(spdlog INTERFACE fmt::fmt) + if (NOT TARGET fmt::fmt) + find_package(fmt REQUIRED) + endif () + + 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() diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 3c4a3f9d..dcb03a9e 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -33,16 +33,16 @@ find_package(Threads REQUIRED) find_package(benchmark CONFIG REQUIRED) add_executable(bench bench.cpp) -target_link_libraries(bench PRIVATE spdlog::spdlog Threads::Threads) +target_link_libraries(bench PRIVATE spdlog::spdlog) add_executable(async_bench async_bench.cpp) -target_link_libraries(async_bench PRIVATE spdlog::spdlog Threads::Threads) +target_link_libraries(async_bench PRIVATE spdlog::spdlog) add_executable(latency latency.cpp) -target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog Threads::Threads) +target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog) add_executable(formatter-bench formatter-bench.cpp) -target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog Threads::Threads) +target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index b25ca252..033e7af6 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -38,7 +38,7 @@ find_package(Threads REQUIRED) # Example of using pre-compiled library add_executable(example example.cpp) -target_link_libraries(example spdlog::spdlog Threads::Threads) +target_link_libraries(example spdlog::spdlog) if(CMAKE_SYSTEM_NAME STREQUAL "Android") find_library(log-lib log) target_link_libraries(example log) @@ -54,7 +54,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Android") endif () add_executable(multisink multisink.cpp) -target_link_libraries(multisink spdlog::spdlog Threads::Threads) +target_link_libraries(multisink spdlog::spdlog) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8679174d..f02dea91 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,7 +20,6 @@ set(SPDLOG_UTESTS_SOURCES test_fmt_helper.cpp) add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) -target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) target_link_libraries(${PROJECT_NAME} PRIVATE spdlog) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") From 24e4f0aa872d1fb600520fcf9f57bb9a9cfcfbb7 Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:31:30 -0500 Subject: [PATCH 08/21] Allowed overriding of `SPDLOG_MASTER_PROJECT` to better support Conan --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ef3b16f..ba146ca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,12 +38,14 @@ include(cmake/sanitizers.cmake) # spdlog target #--------------------------------------------------------------------------------------- -# Check if spdlog is being used directly or via add_subdirectory +# 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 () option(BUILD_SHARED_LIBS "Global flag to cause add_library to create shared libraries if on." ON) option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) From dd2f293f339afa0a5a3637c7c4c890b43a76e12b Mon Sep 17 00:00:00 2001 From: David Zemon Date: Fri, 17 May 2019 23:33:44 -0500 Subject: [PATCH 09/21] Clean up CMake a bit more --- CMakeLists.txt | 9 ++++----- tests/CMakeLists.txt | 10 +++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba146ca1..a8e2f2ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,8 +54,6 @@ option(SPDLOG_BUILD_TESTS "Build tests" ON) option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF) option(SPDLOG_INSTALL "Generate the install target." ${SPDLOG_MASTER_PROJECT}) -set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include/spdlog") - message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) find_package(Threads REQUIRED) @@ -63,9 +61,10 @@ find_package(Threads REQUIRED) # Build library add_library(spdlog src/spdlog.cpp) target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB ) -target_include_directories(spdlog PUBLIC "$") -set_target_properties(spdlog PROPERTIES OUTPUT_NAME "spdlog") -set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "-debug") +target_include_directories(spdlog PUBLIC + "$" + "$" +) target_link_libraries(spdlog PUBLIC Threads::Threads) # Header only diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f02dea91..3275694a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,3 @@ -project(spdlog-utests CXX) - -find_package(Threads REQUIRED) - set(SPDLOG_UTESTS_SOURCES test_errors.cpp test_file_helper.cpp @@ -19,10 +15,10 @@ set(SPDLOG_UTESTS_SOURCES test_sink.h test_fmt_helper.cpp) -add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) -target_link_libraries(${PROJECT_NAME} PRIVATE spdlog) +add_executable(spdlog-utests ${SPDLOG_UTESTS_SOURCES}) +target_link_libraries(spdlog-utests spdlog) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") enable_testing() -add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) +add_test(NAME spdlog-utests COMMAND spdlog-utests) From 87eb569929c2502a7706478b5c7ae642757080b5 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 19 May 2019 15:47:49 +0300 Subject: [PATCH 10/21] More updates to CMake (version support , cmake.in) --- CMakeLists.txt | 71 ++++++++++++++------ cmake/Config.cmake.in | 31 --------- SpdlogCPack.cmake => cmake/SpdlogCPack.cmake | 0 cmake/spdlog.pc.in | 6 -- cmake/spdlogConfig.cmake.in | 15 +++++ example/CMakeLists.txt | 4 +- example/logs/.gitignore | 1 - 7 files changed, 69 insertions(+), 59 deletions(-) delete mode 100644 cmake/Config.cmake.in rename SpdlogCPack.cmake => cmake/SpdlogCPack.cmake (100%) delete mode 100644 cmake/spdlog.pc.in create mode 100644 cmake/spdlogConfig.cmake.in delete mode 100644 example/logs/.gitignore diff --git a/CMakeLists.txt b/CMakeLists.txt index a8e2f2ea..57307b15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,15 +29,13 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCH add_compile_options("-Wfatal-errors") endif() -#--------------------------------------------------------------------------------------- -# address sanitizers check -#--------------------------------------------------------------------------------------- -include(cmake/sanitizers.cmake) + #--------------------------------------------------------------------------------------- # spdlog target #--------------------------------------------------------------------------------------- + # 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) @@ -47,10 +45,9 @@ else() endif() endif () -option(BUILD_SHARED_LIBS "Global flag to cause add_library to create shared libraries if on." ON) option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF) -option(SPDLOG_BUILD_TESTS "Build tests" ON) +option(SPDLOG_BUILD_TESTS "Build tests" OFF) option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF) option(SPDLOG_INSTALL "Generate the install target." ${SPDLOG_MASTER_PROJECT}) @@ -60,11 +57,12 @@ find_package(Threads REQUIRED) # Build library add_library(spdlog src/spdlog.cpp) -target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB ) +target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB) target_include_directories(spdlog PUBLIC "$" "$" ) + target_link_libraries(spdlog PUBLIC Threads::Threads) # Header only @@ -73,6 +71,16 @@ target_include_directories(spdlog_header_only INTERFACE "${CMAKE_CURRENT_LIST_DI target_link_libraries(spdlog_header_only INTERFACE Threads::Threads) +#--------------------------------------------------------------------------------------- +# address sanitizers check +#--------------------------------------------------------------------------------------- +if(SPDLOG_MASTER_PROJECT) + include(cmake/sanitizers.cmake) +endif() + +#--------------------------------------------------------------------------------------- +# use fmt package if using exertnal fmt +#--------------------------------------------------------------------------------------- if(SPDLOG_FMT_EXTERNAL) if (NOT TARGET fmt::fmt) find_package(fmt REQUIRED) @@ -85,6 +93,9 @@ if(SPDLOG_FMT_EXTERNAL) target_link_libraries(spdlog_header_only INTERFACE fmt::fmt) endif() +#--------------------------------------------------------------------------------------- +# build binries +#--------------------------------------------------------------------------------------- if(SPDLOG_BUILD_EXAMPLES) add_subdirectory(example) endif() @@ -98,27 +109,49 @@ if(SPDLOG_BUILD_BENCH) add_subdirectory(bench) endif() +#--------------------------------------------------------------------------------------- +# install +#--------------------------------------------------------------------------------------- if (SPDLOG_INSTALL) + set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in") + set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake") + set(config_targets_file "${PROJECT_NAME}ConfigTargets.cmake") + set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") + set(dest_dir lib/${PROJECT_NAME}/cmake) + #--------------------------------------------------------------------------------------- - # install + # lib in include files #--------------------------------------------------------------------------------------- install(DIRECTORY include/ DESTINATION include) install(TARGETS spdlog EXPORT ${PROJECT_NAME} DESTINATION lib) + + #--------------------------------------------------------------------------------------- + # package and version files + #--------------------------------------------------------------------------------------- install(EXPORT ${PROJECT_NAME} - DESTINATION lib/${PROJECT_NAME}/cmake - NAMESPACE ${PROJECT_NAME}:: - FILE ${PROJECT_NAME}Config.cmake - ) + DESTINATION ${dest_dir} + NAMESPACE ${PROJECT_NAME}:: + FILE ${config_targets_file}) + + include(CMakePackageConfigHelpers) + 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 "${dest_dir}") #--------------------------------------------------------------------------------------- # Support creation of installable packages #--------------------------------------------------------------------------------------- - include(SpdlogCPack.cmake) + include(cmake/SpdlogCPack.cmake) + + #--------------------------------------------------------------------------------------- + # register project in CMake user registry - disabled by default since the + # installed/packaged version of the project is preferred. + #--------------------------------------------------------------------------------------- + option(CMAKE_EXPORT_NO_PACKAGE_REGISTRY "Disable registration of CMake's build directory." ON) + export(PACKAGE ${PROJECT_NAME}) + endif () -#--------------------------------------------------------------------------------------- -# register project in CMake user registry - disabled by default since the -# installed/packaged version of the project is preferred. -#--------------------------------------------------------------------------------------- -option(CMAKE_EXPORT_NO_PACKAGE_REGISTRY "Disable registration of CMake's build directory." ON) -export(PACKAGE ${PROJECT_NAME}) + diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in deleted file mode 100644 index 0b0fd119..00000000 --- a/cmake/Config.cmake.in +++ /dev/null @@ -1,31 +0,0 @@ -# *************************************************************************/ -# * Copyright (c) 2015 Ruslan Baratov. */ -# * */ -# * Permission is hereby granted, free of charge, to any person obtaining */ -# * a copy of this software and associated documentation files (the */ -# * "Software"), to deal in the Software without restriction, including */ -# * without limitation the rights to use, copy, modify, merge, publish, */ -# * distribute, sublicense, and/or sell copies of the Software, and to */ -# * permit persons to whom the Software is furnished to do so, subject to */ -# * the following conditions: */ -# * */ -# * The above copyright notice and this permission notice shall be */ -# * included in all copies or substantial portions of the Software. */ -# * */ -# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -# *************************************************************************/ - -set(SPDLOG_FMT_EXTERNAL @SPDLOG_FMT_EXTERNAL@) - -include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") - -if(SPDLOG_FMT_EXTERNAL) - include(CMakeFindDependencyMacro) - find_dependency(fmt CONFIG) -endif() diff --git a/SpdlogCPack.cmake b/cmake/SpdlogCPack.cmake similarity index 100% rename from SpdlogCPack.cmake rename to cmake/SpdlogCPack.cmake diff --git a/cmake/spdlog.pc.in b/cmake/spdlog.pc.in deleted file mode 100644 index 262248a7..00000000 --- a/cmake/spdlog.pc.in +++ /dev/null @@ -1,6 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -includedir=${prefix}/include - -Name: @PROJECT_NAME@ -Description: Super fast C++ logging library. -Version: @PROJECT_VERSION@ diff --git a/cmake/spdlogConfig.cmake.in b/cmake/spdlogConfig.cmake.in new file mode 100644 index 00000000..43ffcf7e --- /dev/null +++ b/cmake/spdlogConfig.cmake.in @@ -0,0 +1,15 @@ +# Copyright(c) 2019 spdlog authors +# Distributed under the MIT License (http://opensource.org/licenses/MIT) + +find_package(Threads REQUIRED) + +set(SPDLOG_FMT_EXTERNAL @SPDLOG_FMT_EXTERNAL@) +set(config_targets_file @config_targets_file@) + +if(SPDLOG_FMT_EXTERNAL) + include(CMakeFindDependencyMacro) + find_dependency(fmt CONFIG) +endif() + + +include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 033e7af6..6907b7ae 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -29,12 +29,12 @@ if(TARGET spdlog) # then add an alias. This allows us to use the same "spdlog::spdlog" # below that a user would use (with the namespace) add_library(spdlog::spdlog ALIAS spdlog) + find_package(Threads REQUIRED) else() # Stand-alone build find_package(spdlog REQUIRED) endif() -find_package(Threads REQUIRED) # Example of using pre-compiled library add_executable(example example.cpp) @@ -50,7 +50,7 @@ get_target_property(SPDLOG_INCLUDE_DIRS spdlog::spdlog INTERFACE_INCLUDE_DIRECTO target_include_directories(example_header_only PRIVATE ${SPDLOG_INCLUDE_DIRS}) target_link_libraries(example_header_only Threads::Threads) if(CMAKE_SYSTEM_NAME STREQUAL "Android") - target_link_libraries(example_header_only log) + target_link_libraries(example_header_only log Threads::Threads) endif () add_executable(multisink multisink.cpp) diff --git a/example/logs/.gitignore b/example/logs/.gitignore deleted file mode 100644 index 20325135..00000000 --- a/example/logs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.txt From 18ccd55725b1bc27aaee90db9d442eb614f8a4e3 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 19 May 2019 15:57:22 +0300 Subject: [PATCH 11/21] Removed multisink and test in example --- example/CMakeLists.txt | 7 ------- example/multisink.cpp | 47 ------------------------------------------ 2 files changed, 54 deletions(-) delete mode 100644 example/multisink.cpp diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 6907b7ae..bd722d45 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -53,11 +53,4 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Android") target_link_libraries(example_header_only log Threads::Threads) endif () -add_executable(multisink multisink.cpp) -target_link_libraries(multisink spdlog::spdlog) - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") - -enable_testing() -add_test(NAME example COMMAND example) -add_test(NAME example_header_only COMMAND example) diff --git a/example/multisink.cpp b/example/multisink.cpp deleted file mode 100644 index fd79231c..00000000 --- a/example/multisink.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "spdlog/spdlog.h" -#include "spdlog/sinks/basic_file_sink.h" -#include "spdlog/sinks/stdout_sinks.h" - -#include -#include - -int main(int, char *[]) -{ - bool enable_debug = true; - try - { - // This other example use a single logger with multiple sinks. - // This means that the same log_msg is forwarded to multiple sinks; - // Each sink can have it's own log level and a message will be logged. - std::vector sinks; - sinks.push_back(std::make_shared()); - sinks.push_back(std::make_shared("./log_regular_file.txt")); - sinks.push_back(std::make_shared("./log_debug_file.txt")); - - spdlog::logger console_multisink("multisink", sinks.begin(), sinks.end()); - console_multisink.set_level(spdlog::level::warn); - - sinks[0]->set_level(spdlog::level::trace); // console. Allow everything. Default value - sinks[1]->set_level(spdlog::level::trace); // regular file. Allow everything. Default value - sinks[2]->set_level(spdlog::level::off); // regular file. Ignore everything. - - console_multisink.warn("warn: will print only on console and regular file"); - - if (enable_debug) - { - console_multisink.set_level(spdlog::level::debug); // level of the logger - sinks[1]->set_level(spdlog::level::debug); // regular file - sinks[2]->set_level(spdlog::level::debug); // debug file - } - console_multisink.debug("Debug: you should see this on console and both files"); - - // Release and close all loggers - spdlog::drop_all(); - } - // Exceptions will only be thrown upon failed logger or sink construction (not during logging) - catch (const spdlog::spdlog_ex &ex) - { - std::cout << "Log init failed: " << ex.what() << std::endl; - return 1; - } -} From 2cd53c6ff1e057349e8a2c6db2f05ab27f767fdd Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 19 May 2019 16:34:38 +0300 Subject: [PATCH 12/21] Updated cmake example --- example/CMakeLists.txt | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index bd722d45..8efc1eb1 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -29,28 +29,23 @@ if(TARGET spdlog) # then add an alias. This allows us to use the same "spdlog::spdlog" # below that a user would use (with the namespace) add_library(spdlog::spdlog ALIAS spdlog) - find_package(Threads REQUIRED) + add_library(spdlog::spdlog_header_only ALIAS spdlog_header_only) else() # Stand-alone build find_package(spdlog REQUIRED) endif() - +#--------------------------------------------------------------------------------------- # Example of using pre-compiled library +#--------------------------------------------------------------------------------------- add_executable(example example.cpp) target_link_libraries(example spdlog::spdlog) -if(CMAKE_SYSTEM_NAME STREQUAL "Android") - find_library(log-lib log) - target_link_libraries(example log) -endif() +#--------------------------------------------------------------------------------------- # Example of using header-only library +#--------------------------------------------------------------------------------------- add_executable(example_header_only example.cpp) -get_target_property(SPDLOG_INCLUDE_DIRS spdlog::spdlog INTERFACE_INCLUDE_DIRECTORIES) -target_include_directories(example_header_only PRIVATE ${SPDLOG_INCLUDE_DIRS}) -target_link_libraries(example_header_only Threads::Threads) -if(CMAKE_SYSTEM_NAME STREQUAL "Android") - target_link_libraries(example_header_only log Threads::Threads) -endif () +target_link_libraries(example_header_only spdlog::spdlog_header_only) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") From a532a072cee5841b8fb8bd766c491ae24fa48d13 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:06:22 +0300 Subject: [PATCH 13/21] Update CMakeLists.txt --- CMakeLists.txt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57307b15..c55fa191 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,6 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE) endif() - - #--------------------------------------------------------------------------------------- # compiler config #--------------------------------------------------------------------------------------- @@ -29,13 +27,10 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCH add_compile_options("-Wfatal-errors") endif() - - #--------------------------------------------------------------------------------------- # spdlog target #--------------------------------------------------------------------------------------- - # 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) @@ -55,7 +50,7 @@ message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) find_package(Threads REQUIRED) -# Build library +# Static library version add_library(spdlog src/spdlog.cpp) target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB) target_include_directories(spdlog PUBLIC @@ -65,12 +60,11 @@ target_include_directories(spdlog PUBLIC target_link_libraries(spdlog PUBLIC Threads::Threads) -# Header only +# Header only version add_library(spdlog_header_only INTERFACE) target_include_directories(spdlog_header_only INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include") target_link_libraries(spdlog_header_only INTERFACE Threads::Threads) - #--------------------------------------------------------------------------------------- # address sanitizers check #--------------------------------------------------------------------------------------- @@ -151,7 +145,5 @@ if (SPDLOG_INSTALL) #--------------------------------------------------------------------------------------- option(CMAKE_EXPORT_NO_PACKAGE_REGISTRY "Disable registration of CMake's build directory." ON) export(PACKAGE ${PROJECT_NAME}) - endif () - From 48acafd10da684133a029fb0565ea47afc0caaef Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:16:22 +0300 Subject: [PATCH 14/21] Update CMakeLists.txt --- example/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8efc1eb1..9f69ccc8 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -47,5 +47,5 @@ target_link_libraries(example spdlog::spdlog) add_executable(example_header_only example.cpp) target_link_libraries(example_header_only spdlog::spdlog_header_only) - +# Create logs directory file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") From 576fec4c3604e5fe68cdc6fb2a23e58f00dc9144 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:17:58 +0300 Subject: [PATCH 15/21] Update CMakeLists.txt --- example/CMakeLists.txt | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 9f69ccc8..2fbbf1d2 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,25 +1,5 @@ -# *************************************************************************/ -# * Copyright (c) 2015 Ruslan Baratov. */ -# * */ -# * Permission is hereby granted, free of charge, to any person obtaining */ -# * a copy of this software and associated documentation files (the */ -# * "Software"), to deal in the Software without restriction, including */ -# * without limitation the rights to use, copy, modify, merge, publish, */ -# * distribute, sublicense, and/or sell copies of the Software, and to */ -# * permit persons to whom the Software is furnished to do so, subject to */ -# * the following conditions: */ -# * */ -# * The above copyright notice and this permission notice shall be */ -# * included in all copies or substantial portions of the Software. */ -# * */ -# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -# *************************************************************************/ +# Copyright(c) 2019 spdlog authors +# Distributed under the MIT License (http://opensource.org/licenses/MIT) cmake_minimum_required(VERSION 3.1) project(SpdlogExamples CXX) From 84f25b9f18a00641e013753325e81e145ae1a964 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:19:35 +0300 Subject: [PATCH 16/21] Update CMakeLists.txt --- bench/CMakeLists.txt | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index dcb03a9e..5b88d41a 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -1,25 +1,5 @@ -# *************************************************************************/ -# * Copyright (c) 2015 Ruslan Baratov. */ -# * */ -# * Permission is hereby granted, free of charge, to any person obtaining */ -# * a copy of this software and associated documentation files (the */ -# * "Software"), to deal in the Software without restriction, including */ -# * without limitation the rights to use, copy, modify, merge, publish, */ -# * distribute, sublicense, and/or sell copies of the Software, and to */ -# * permit persons to whom the Software is furnished to do so, subject to */ -# * the following conditions: */ -# * */ -# * The above copyright notice and this permission notice shall be */ -# * included in all copies or substantial portions of the Software. */ -# * */ -# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -# *************************************************************************/ +# Copyright(c) 2019 spdlog authors +# Distributed under the MIT License (http://opensource.org/licenses/MIT) cmake_minimum_required(VERSION 3.1) project(SpdlogBench CXX) From d21bcd2f876a0e310889e37551130c2b07a687fc Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:57:18 +0300 Subject: [PATCH 17/21] Delete utils.h --- example/utils.h | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 example/utils.h diff --git a/example/utils.h b/example/utils.h deleted file mode 100644 index 91610128..00000000 --- a/example/utils.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright(c) 2015 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once - -#include -#include -#include - -namespace utils { - -template -inline std::string format(const T &value) -{ - static std::locale loc(""); - std::stringstream ss; - ss.imbue(loc); - ss << value; - return ss.str(); -} - -template<> -inline std::string format(const double &value) -{ - static std::locale loc(""); - std::stringstream ss; - ss.imbue(loc); - ss << std::fixed << std::setprecision(1) << value; - return ss.str(); -} - -} // namespace utils From c264c3e2dddf7c98885094001cde80b9e3588292 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:58:44 +0300 Subject: [PATCH 18/21] Delete Android.mk --- example/jni/Android.mk | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 example/jni/Android.mk diff --git a/example/jni/Android.mk b/example/jni/Android.mk deleted file mode 100644 index 7accbad3..00000000 --- a/example/jni/Android.mk +++ /dev/null @@ -1,15 +0,0 @@ -# Setup a project -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := example -LOCAL_SRC_FILES := example.cpp -LOCAL_CPPFLAGS += -Wall -Wshadow -Wextra -pedantic -std=c++11 -fPIE -pie -LOCAL_LDFLAGS += -fPIE -pie - -# Add exception support and set path for spdlog's headers -LOCAL_CPPFLAGS += -fexceptions -I../include -# Use android's log library -LOCAL_LDFLAGS += -llog - -include $(BUILD_EXECUTABLE) From cfa6d12691c10c0df2c74f1c15bba5731a7ff5ee Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:58:52 +0300 Subject: [PATCH 19/21] Delete Application.mk --- example/jni/Application.mk | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 example/jni/Application.mk diff --git a/example/jni/Application.mk b/example/jni/Application.mk deleted file mode 100644 index dccd2a5a..00000000 --- a/example/jni/Application.mk +++ /dev/null @@ -1,2 +0,0 @@ -# Exceptions are used in spdlog. Link to an exception-ready C++ runtime. -APP_STL = gnustl_static From 322665a22f8b60a1d5497ec57879bfcbe9593b06 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sun, 19 May 2019 17:59:00 +0300 Subject: [PATCH 20/21] Delete example.cpp --- example/jni/example.cpp | 157 ---------------------------------------- 1 file changed, 157 deletions(-) delete mode 100644 example/jni/example.cpp diff --git a/example/jni/example.cpp b/example/jni/example.cpp deleted file mode 100644 index 48c4b19e..00000000 --- a/example/jni/example.cpp +++ /dev/null @@ -1,157 +0,0 @@ -// -// Copyright(c) 2015 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// -// -// spdlog usage example -// -// - -#define SPDLOG_TRACE_ON -#define SPDLOG_DEBUG_ON - -#include "spdlog/spdlog.h" - -#include -#include - -void async_example(); -void syslog_example(); -void android_example(); -void user_defined_example(); -void err_handler_example(); - -namespace spd = spdlog; -int main(int, char *[]) -{ - try - { - // Console logger with color - auto console = spd::stdout_color_mt("console"); - console->info("Welcome to spdlog!"); - console->error("Some error message with arg{}..", 1); - - // Formatting examples - console->warn("Easy padding in numbers like {:08d}", 12); - console->critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); - console->info("Support for floats {:03.2f}", 1.23456); - console->info("Positional args are {1} {0}..", "too", "supported"); - console->info("{:<30}", "left aligned"); - - spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function"); - - // Create basic file logger (not rotated) - auto my_logger = spd::basic_logger_mt("basic_logger", "logs/basic-log.txt"); - my_logger->info("Some log message"); - - // Create a file rotating logger with 5mb size max and 3 rotated files - auto rotating_logger = spd::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3); - for (int i = 0; i < 10; ++i) - rotating_logger->info("{} * {} equals {:>10}", i, i, i * i); - - // Create a daily logger - a new file is created every day on 2:30am - auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30); - // trigger flush if the log severity is error or higher - daily_logger->flush_on(spd::level::err); - daily_logger->info(123.44); - - // Customize msg format for all messages - spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***"); - rotating_logger->info("This is another message with custom format"); - - // Runtime log levels - spd::set_level(spd::level::info); // Set global log level to info - console->debug("This message should not be displayed!"); - console->set_level(spd::level::debug); // Set specific logger's log level - console->debug("This message should be displayed.."); - - // Compile time log levels - // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON - SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23); - SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23); - - // Asynchronous logging is very fast.. - // Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous.. - async_example(); - - // syslog example. linux/osx only - syslog_example(); - - // android example. compile with NDK - android_example(); - - // Log user-defined types example - user_defined_example(); - - // Change default log error handler - err_handler_example(); - - // Apply a function on all registered loggers - spd::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); - - // Release and close all loggers - spdlog::drop_all(); - } - // Exceptions will only be thrown upon failed logger or sink construction (not during logging) - catch (const spd::spdlog_ex &ex) - { - std::cout << "Log init failed: " << ex.what() << std::endl; - return 1; - } -} - -void async_example() -{ - size_t q_size = 4096; // queue size must be power of 2 - spdlog::set_async_mode(q_size); - auto async_file = spd::daily_logger_st("async_file_logger", "logs/async_log.txt"); - for (int i = 0; i < 100; ++i) - async_file->info("Async message #{}", i); -} - -// syslog example (linux/osx/freebsd) -void syslog_example() -{ -#ifdef SPDLOG_ENABLE_SYSLOG - std::string ident = "spdlog-example"; - auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID); - syslog_logger->warn("This is warning that will end up in syslog."); -#endif -} - -// Android example -void android_example() -{ -#if defined(__ANDROID__) - std::string tag = "spdlog-android"; - auto android_logger = spd::android_logger("android", tag); - android_logger->critical("Use \"adb shell logcat\" to view this message."); -#endif -} - -// user defined types logging by implementing operator<< -struct my_type -{ - int i; - template - friend OStream &operator<<(OStream &os, const my_type &c) - { - return os << "[my_type i=" << c.i << "]"; - } -}; - -#include "spdlog/fmt/ostr.h" // must be included -void user_defined_example() -{ - spd::get("console")->info("user defined type: {}", my_type{14}); -} - -// -// custom error handler -// -void err_handler_example() -{ - // can be set globaly or per logger(logger->set_error_handler(..)) - spdlog::set_error_handler([](const std::string &msg) { std::cerr << "my err handler: " << msg << std::endl; }); - spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3); -} From 1ef80d63304c19015164c1e7fafd99385eac4deb Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 19 May 2019 19:39:38 +0300 Subject: [PATCH 21/21] Updated CMakeLists.txt --- CMakeLists.txt | 65 ++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c55fa191..169b229a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,18 +19,9 @@ 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") -endif() - #--------------------------------------------------------------------------------------- -# spdlog target +# 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) @@ -40,29 +31,46 @@ else() endif() endif () -option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) -option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF) -option(SPDLOG_BUILD_TESTS "Build tests" OFF) +option(BUILD_SHARED_LIBS "Build as shared library" OFF) option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF) +option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) +option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" ${SPDLOG_MASTER_PROJECT}) +option(SPDLOG_BUILD_TESTS "Build tests" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_INSTALL "Generate the install target." ${SPDLOG_MASTER_PROJECT}) +option(CMAKE_EXPORT_NO_PACKAGE_REGISTRY "Disable registration of CMake's build directory." ON) + message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) find_package(Threads REQUIRED) +if(SPDLOG_MASTER_PROJECT AND ("${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") +endif() + + +#--------------------------------------------------------------------------------------- # Static library version +#--------------------------------------------------------------------------------------- add_library(spdlog src/spdlog.cpp) target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB) target_include_directories(spdlog PUBLIC "$" - "$" -) - + "$") target_link_libraries(spdlog PUBLIC Threads::Threads) +#--------------------------------------------------------------------------------------- # Header only version +#--------------------------------------------------------------------------------------- add_library(spdlog_header_only INTERFACE) -target_include_directories(spdlog_header_only INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include") + +target_include_directories(spdlog_header_only INTERFACE + "$" + "$") target_link_libraries(spdlog_header_only INTERFACE Threads::Threads) #--------------------------------------------------------------------------------------- @@ -107,24 +115,24 @@ endif() # install #--------------------------------------------------------------------------------------- if (SPDLOG_INSTALL) - set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in") - set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake") - set(config_targets_file "${PROJECT_NAME}ConfigTargets.cmake") - set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") - set(dest_dir lib/${PROJECT_NAME}/cmake) + 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 lib/spdlog/cmake) #--------------------------------------------------------------------------------------- # lib in include files #--------------------------------------------------------------------------------------- install(DIRECTORY include/ DESTINATION include) - install(TARGETS spdlog EXPORT ${PROJECT_NAME} DESTINATION lib) + install(TARGETS spdlog spdlog_header_only EXPORT spdlog DESTINATION lib) #--------------------------------------------------------------------------------------- # package and version files #--------------------------------------------------------------------------------------- - install(EXPORT ${PROJECT_NAME} - DESTINATION ${dest_dir} - NAMESPACE ${PROJECT_NAME}:: + install(EXPORT spdlog + DESTINATION ${export_dest_dir} + NAMESPACE spdlog:: FILE ${config_targets_file}) include(CMakePackageConfigHelpers) @@ -132,7 +140,7 @@ if (SPDLOG_INSTALL) write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion) install(FILES "${project_config_out}" - "${version_config_file}" DESTINATION "${dest_dir}") + "${version_config_file}" DESTINATION "${export_dest_dir}") #--------------------------------------------------------------------------------------- # Support creation of installable packages @@ -143,7 +151,6 @@ if (SPDLOG_INSTALL) # register project in CMake user registry - disabled by default since the # installed/packaged version of the project is preferred. #--------------------------------------------------------------------------------------- - option(CMAKE_EXPORT_NO_PACKAGE_REGISTRY "Disable registration of CMake's build directory." ON) - export(PACKAGE ${PROJECT_NAME}) + export(PACKAGE spdlog) endif ()