cmake: Make symbols hidden by default on GCC/Clang
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 2 Sep 2018 21:26:24 +0000 (23:26 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
With symbols now being explicitly marked as exported where needed,
there is no need to globally export all symbols anymore.
Tell CMake to set the appropriate compiler flags
(i.e. -fvisibility=hidden) for GCC and Clang so, they only export
requested symbols.

cmake/QuasselCompileSettings.cmake

index ec3e17a..4c4c8b4 100644 (file)
@@ -21,6 +21,9 @@ endfunction()
 set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_STANDARD_REQUIRED OFF)    # Rely on compile features if standard is not supported
 set(CMAKE_CXX_EXTENSIONS OFF)           # We like to be standard conform
+
+set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 
 # For GCC and Clang, enable a whole bunch of warnings
@@ -36,8 +39,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
         -Wundef
         -fno-common
         -fstack-protector-strong
-        -fvisibility=default
-        -fvisibility-inlines-hidden
         "$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>"
     )