Browse Source

Do not use hidden visibility for gcc < 4.5.

With gcc < 4.5, RTTI symbols from classes declared in third-party
libraries which are not "gcc visibility aware" are marked with
hidden visibility in DSOs which include the class declaration and
which are compiled with hidden visibility. This leads to
dynamic_cast and exception handling problems. While this problem
could be worked around by sandwiching the include directives for
the third-party headers between "#pragma visibility push/pop"
statements, it is generally safer to just use default visibility
with gcc < 4.5.
Sascha Zelzer 13 years ago
parent
commit
e1a1434551
4 changed files with 31 additions and 5 deletions
  1. 12 2
      CMake/ctkMacroBuildPlugin.cmake
  2. 4 0
      CMake/ctkMacroSetupExternalPlugins.cmake
  3. 14 3
      CMakeLists.txt
  4. 1 0
      CTKConfig.cmake.in

+ 12 - 2
CMake/ctkMacroBuildPlugin.cmake

@@ -277,8 +277,18 @@ MACRO(ctkMacroBuildPlugin)
   ENDIF()
   ENDIF()
 
 
   SET(plugin_compile_flags "-DQT_PLUGIN")
   SET(plugin_compile_flags "-DQT_PLUGIN")
-  # MinGW does not export all symbols automatically, so no need to set flags
-  IF(CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
+
+  # MinGW does not export all symbols automatically, so no need to set flags.
+  #
+  # With gcc < 4.5, RTTI symbols from classes declared in third-party libraries
+  # which are not "gcc visibility aware" are marked with hidden visibility in
+  # DSOs which include the class declaration and which are compiled with
+  # hidden visibility. This leads to dynamic_cast and exception handling problems.
+  # While this problem could be worked around by sandwiching the include
+  # directives for the third-party headers between "#pragma visibility push/pop"
+  # statements, it is generally safer to just use default visibility with
+  # gcc < 4.5.
+  IF(CMAKE_COMPILER_IS_GNUCXX AND ${GCC_VERSION} VERSION_GREATER "4.4.0" AND NOT MINGW)
     SET(plugin_compile_flags "${plugin_compile_flags} -fvisibility=hidden -fvisibility-inlines-hidden")
     SET(plugin_compile_flags "${plugin_compile_flags} -fvisibility=hidden -fvisibility-inlines-hidden")
   ENDIF()
   ENDIF()
 
 

+ 4 - 0
CMake/ctkMacroSetupExternalPlugins.cmake

@@ -80,6 +80,10 @@ MACRO(ctkMacroSetupExternalPlugins )
   ctkFunctionGenerateDGraphInput(${CMAKE_CURRENT_BINARY_DIR} "${plugin_dirswithoption}" WITH_EXTERNALS)
   ctkFunctionGenerateDGraphInput(${CMAKE_CURRENT_BINARY_DIR} "${plugin_dirswithoption}" WITH_EXTERNALS)
   ctkMacroValidateBuildOptions("${CMAKE_CURRENT_BINARY_DIR}" "${CTK_DGRAPH_EXECUTABLE}" "${plugin_dirswithoption}")
   ctkMacroValidateBuildOptions("${CMAKE_CURRENT_BINARY_DIR}" "${CTK_DGRAPH_EXECUTABLE}" "${plugin_dirswithoption}")
 
 
+  # Get the gcc version (GCC_VERSION will be empty if the compiler is not gcc).
+  # This will be used in the ctkMacroBuildPlugin macro to conditionally set compiler flags.
+  ctkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
+
   FOREACH(plugin ${plugin_subdirs})
   FOREACH(plugin ${plugin_subdirs})
     IF(${${plugin}_option_name})
     IF(${${plugin}_option_name})
       ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/${plugin})
       ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/${plugin})

+ 14 - 3
CMakeLists.txt

@@ -265,8 +265,20 @@ MARK_AS_ADVANCED(ADDITIONAL_CXX_FLAGS)
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
 # Set symbol visibility Flags
 # Set symbol visibility Flags
 #
 #
-# MinGW does not export all symbols automatically, so no need to set flags
-IF(CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
+
+ctkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
+
+# MinGW does not export all symbols automatically, so no need to set flags.
+#
+# With gcc < 4.5, RTTI symbols from classes declared in third-party libraries
+# which are not "gcc visibility aware" are marked with hidden visibility in
+# DSOs which include the class declaration and which are compiled with
+# hidden visibility. This leads to dynamic_cast and exception handling problems.
+# While this problem could be worked around by sandwiching the include
+# directives for the third-party headers between "#pragma visibility push/pop"
+# statements, it is generally safer to just use default visibility with
+# gcc < 4.5.
+IF(CMAKE_COMPILER_IS_GNUCXX AND ${GCC_VERSION} VERSION_GREATER "4.4.0" AND NOT MINGW)
   SET(VISIBILITY_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
   SET(VISIBILITY_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
 ENDIF()
 ENDIF()
 
 
@@ -293,7 +305,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
   ctkFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
   ctkFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
   ctkFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
   ctkFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
 
 
-  ctkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
   # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
   # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
   # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
   # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
   # Doing so should allow to build package made for distribution using older linux distro.
   # Doing so should allow to build package made for distribution using older linux distro.

+ 1 - 0
CTKConfig.cmake.in

@@ -47,6 +47,7 @@ IF(NOT CTK_EXPORTS_INCLUDED)
 ENDIF()
 ENDIF()
 
 
 # Include CTK macros
 # Include CTK macros
+INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetGccVersion.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroParseArguments.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroParseArguments.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroSetPaths.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroSetPaths.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroListFilter.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroListFilter.cmake")