Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gabime/spdlog.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zemon <david@zemon.name>2019-05-18 07:09:22 +0300
committerDavid Zemon <david@zemon.name>2019-05-18 07:26:06 +0300
commit8dd85285e7a87a1a7347f3d6b4d409e4eed44eb6 (patch)
tree77ad41060a02c72a4fda53a32aecc906cfdac82e
parentdbcbeb7a571e50446e7eef5b36e47911b229ac9f (diff)
Allow user to choose between static or shared library
-rw-r--r--CMakeLists.txt23
-rw-r--r--bench/CMakeLists.txt8
-rw-r--r--example/CMakeLists.txt8
-rw-r--r--include/spdlog/common.h4
-rw-r--r--include/spdlog/sinks/base_sink.h4
-rw-r--r--src/spdlog.cpp6
-rw-r--r--tests/CMakeLists.txt2
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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>")
-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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>")
+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 <locale>
#endif
-#ifdef SPDLOG_STATIC_LIB
+#ifdef SPDLOG_COMPILED_LIB
#undef SPDLOG_HEADER_ONLY
#define SPDLOG_INLINE
#else
@@ -216,4 +216,4 @@ std::unique_ptr<T> 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 <mutex>
@@ -100,4 +100,4 @@ template FMT_API int internal::char_traits<wchar_t>::format_float(wchar_t *, std
template FMT_API std::wstring internal::vformat<wchar_t>(wstring_view, basic_format_args<wformat_context>);
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")