diff --git a/CMakeLists.txt b/CMakeLists.txt index 17d992d4..001cd102 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ endif () # build shared option if(NOT WIN32) option(SPDLOG_BUILD_SHARED "Build shared library" OFF) + option(SPDLOG_DLL_LOCAL_REGISTRY "If enabled, the logger registry will not be shared between shared objects" OFF) endif() # example options @@ -122,6 +123,10 @@ else() add_library(spdlog STATIC ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS}) endif() +if (SPDLOG_DLL_LOCAL_REGISTRY) + target_compile_definitions(spdlog PUBLIC SPDLOG_DLL_LOCAL_REGISTRY) +endif() + add_library(spdlog::spdlog ALIAS spdlog) target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index e1108a0a..7a26178e 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -54,6 +54,12 @@ #define SPDLOG_DEPRECATED #endif +#if defined(SPDLOG_DLL_LOCAL_REGISTRY) && (defined(__GNUC__) || defined(__clang__)) +#define SPDLOG_REGISTRY_ATTRIBUTES __attribute__((visibility("hidden"))) +#else +#define SPDLOG_REGISTRY_ATTRIBUTES +#endif + // disable thread local on msvc 2013 #ifndef SPDLOG_NO_TLS #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 6ac571dc..d73c6e79 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -24,7 +24,7 @@ namespace details { class thread_pool; class periodic_worker; -class registry +class SPDLOG_REGISTRY_ATTRIBUTES registry { public: registry(const registry &) = delete;