From 945d3a1f93444f5b5594586aab886bb76a44aea9 Mon Sep 17 00:00:00 2001 From: Daniel Nachbaur Date: Thu, 19 Apr 2018 10:44:49 +0200 Subject: [PATCH] Visibility not needed for static build This also fixes CMake and gcc warnings when integrating async++ as a subproject. --- CMakeLists.txt | 8 ++++---- include/async++.h | 4 ++++ src/internal.h | 2 ++ src/scheduler.cpp | 2 ++ src/threadpool_scheduler.cpp | 2 ++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0cbe6a..6929b22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,13 +77,13 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(Async++ PUBLIC Threads::Threads) -# Minimize the set of symbols exported by libraries -set_target_properties(Async++ PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON) - # Set up preprocessor definitions target_include_directories(Async++ PRIVATE ${PROJECT_SOURCE_DIR}/include) set_target_properties(Async++ PROPERTIES DEFINE_SYMBOL LIBASYNC_BUILD) -if (NOT BUILD_SHARED_LIBS) +if (BUILD_SHARED_LIBS) + # Minimize the set of symbols exported by libraries + set_target_properties(Async++ PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON) +else() target_compile_definitions(Async++ PUBLIC LIBASYNC_STATIC) endif() diff --git a/include/async++.h b/include/async++.h index 111f144..36e1516 100644 --- a/include/async++.h +++ b/include/async++.h @@ -114,9 +114,11 @@ #endif // Force symbol visibility to hidden unless explicity exported +#ifndef LIBASYNC_STATIC #if defined(__GNUC__) && !defined(_WIN32) # pragma GCC visibility push(hidden) #endif +#endif // Some forward declarations namespace async { @@ -147,8 +149,10 @@ class event_task; #include "async++/parallel_for.h" #include "async++/parallel_reduce.h" +#ifndef LIBASYNC_STATIC #if defined(__GNUC__) && !defined(_WIN32) # pragma GCC visibility pop #endif +#endif #endif diff --git a/src/internal.h b/src/internal.h index dc260e2..4fa08c9 100644 --- a/src/internal.h +++ b/src/internal.h @@ -82,9 +82,11 @@ #endif // Force symbol visibility to hidden unless explicity exported +#ifndef LIBASYNC_STATIC #if defined(__GNUC__) && !defined(_WIN32) # pragma GCC visibility push(hidden) #endif +#endif // Include other internal headers #include "singleton.h" diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 0d5b653..5f36ca3 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -239,6 +239,8 @@ wait_handler set_thread_wait_handler(wait_handler handler) LIBASYNC_NOEXCEPT } // namespace async +#ifndef LIBASYNC_STATIC #if defined(__GNUC__) && !defined(_WIN32) # pragma GCC visibility pop #endif +#endif diff --git a/src/threadpool_scheduler.cpp b/src/threadpool_scheduler.cpp index b7a170d..c672f74 100644 --- a/src/threadpool_scheduler.cpp +++ b/src/threadpool_scheduler.cpp @@ -434,6 +434,8 @@ void threadpool_scheduler::schedule(task_run_handle t) } // namespace async +#ifndef LIBASYNC_STATIC #if defined(__GNUC__) && !defined(_WIN32) # pragma GCC visibility pop #endif +#endif