From 0e49ce47a561e62ff80398f2b94d061e2271df6d Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 18 Jan 2025 13:04:10 +0200 Subject: [PATCH] Set CMAKE_CXX_VISIBILITY_PRESET and 3. VISIBILITY_INLINES_HIDDEN when build shared lib --- CMakeLists.txt | 4 ++++ include/spdlog/details/null_mutex.h | 6 +++--- src/sinks/ansicolor_sink.cpp | 2 ++ src/sinks/rotating_file_sink.cpp | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81df3bf8..b8517ea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,10 @@ if (BUILD_SHARED_LIBS) endif () add_library(spdlog SHARED ${VERSION_RC}) target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB) + set_target_properties(spdlog PROPERTIES + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON) + if (MSVC) # disable dlls related warnings on msvc target_compile_options(spdlog PUBLIC $<$,$>>:/wd4251 diff --git a/include/spdlog/details/null_mutex.h b/include/spdlog/details/null_mutex.h index 47b9845b..1dfff657 100644 --- a/include/spdlog/details/null_mutex.h +++ b/include/spdlog/details/null_mutex.h @@ -5,18 +5,18 @@ #include #include - +#include "../common.h" // null, no cost dummy "mutex" and dummy "atomic" log level namespace spdlog { namespace details { -struct null_mutex { +struct SPDLOG_API null_mutex { void lock() const {} void unlock() const {} }; template -struct null_atomic { +struct SPDLOG_API null_atomic { T value; null_atomic() = default; diff --git a/src/sinks/ansicolor_sink.cpp b/src/sinks/ansicolor_sink.cpp index 74593fac..b684ea0f 100644 --- a/src/sinks/ansicolor_sink.cpp +++ b/src/sinks/ansicolor_sink.cpp @@ -117,6 +117,8 @@ ansicolor_stderr_sink::ansicolor_stderr_sink(color_mode mode) // template instantiations #include "spdlog/details/null_mutex.h" +template class SPDLOG_API spdlog::sinks::ansicolor_sink; +template class SPDLOG_API spdlog::sinks::ansicolor_sink; template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink; template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink; template class SPDLOG_API spdlog::sinks::ansicolor_stderr_sink; diff --git a/src/sinks/rotating_file_sink.cpp b/src/sinks/rotating_file_sink.cpp index b58115bd..b43c4628 100644 --- a/src/sinks/rotating_file_sink.cpp +++ b/src/sinks/rotating_file_sink.cpp @@ -142,4 +142,4 @@ bool rotating_file_sink::rename_file_(const filename_t &src_filename, con // template instantiations #include "spdlog/details/null_mutex.h" template class SPDLOG_API spdlog::sinks::rotating_file_sink; -template class SPDLOG_API spdlog::sinks::rotating_file_sink; \ No newline at end of file +template class SPDLOG_API spdlog::sinks::rotating_file_sink;