Only set the COMPILER_HAS_HIDDEN_VISIBILITY if GCC >= 4.2

Hearsay has it that before that version it didn't work properly.

Hopefully this will fix more dashboard builds.
This commit is contained in:
Stephen Kelly 2011-08-10 21:13:33 +02:00
parent af443b830b
commit cff9493598
2 changed files with 23 additions and 35 deletions

View File

@ -116,10 +116,28 @@ include(CMakeParseArguments)
include(CheckCXXCompilerFlag)
macro(_test_compiler_hidden_visibility)
check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
check_cxx_compiler_flag(-fvisibility-inlines-hidden COMPILER_HAS_HIDDEN_INLINE_VISIBILITY)
option(USE_COMPILER_HIDDEN_VISIBILITY "Use HIDDEN visibility support if available." ON)
mark_as_advanced(USE_COMPILER_HIDDEN_VISIBILITY)
if (CMAKE_COMPILER_IS_GNUCXX)
exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
string (REGEX MATCH "[345]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}")
# gcc on mac just reports: "gcc (GCC) 3.3 20030304 ..." without the
# patch level, handle this here:
if(NOT _gcc_version)
string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" _gcc_version "${_gcc_version_info}")
endif()
if(${_gcc_version} VERSION_LESS "4.2")
set(GCC_TOO_OLD TRUE)
message(WARNING "GCC version older than 4.2")
endif()
endif()
if (NOT GCC_TOO_OLD)
check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
check_cxx_compiler_flag(-fvisibility-inlines-hidden COMPILER_HAS_HIDDEN_INLINE_VISIBILITY)
option(USE_COMPILER_HIDDEN_VISIBILITY "Use HIDDEN visibility support if available." ON)
mark_as_advanced(USE_COMPILER_HIDDEN_VISIBILITY)
endif()
endmacro()
set(myDir ${CMAKE_CURRENT_LIST_DIR})
@ -233,21 +251,6 @@ function(add_compiler_export_flags)
return()
endif()
if (CMAKE_COMPILER_IS_GNUCXX)
exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
string (REGEX MATCH "[345]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}")
# gcc on mac just reports: "gcc (GCC) 3.3 20030304 ..." without the
# patch level, handle this here:
if(NOT _gcc_version)
string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" _gcc_version "${_gcc_version_info}")
endif()
if(${_gcc_version} VERSION_LESS "4.2")
message(WARNING "GCC version older than 4.2")
return()
endif()
endif()
set (EXTRA_FLAGS "-fvisibility=hidden")
if(COMPILER_HAS_HIDDEN_INLINE_VISIBILITY)

View File

@ -76,24 +76,9 @@ macro(_do_build Include Library LibrarySource Source)
)
endmacro()
if (CMAKE_COMPILER_IS_GNUCXX)
exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
string (REGEX MATCH "[345]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}")
# gcc on mac just reports: "gcc (GCC) 3.3 20030304 ..." without the
# patch level, handle this here:
if(NOT _gcc_version)
string (REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" _gcc_version "${_gcc_version_info}")
endif()
if(${_gcc_version} VERSION_LESS "4.2")
set(GCC_IS_LESS_THAN_4_2 TRUE)
message(WARNING "GCC version older than 4.2. Actual version: ${_gcc_version}")
endif()
endif()
macro(build_fail Include Library LibrarySource Source Message)
_do_build(${Include} ${Library} ${LibrarySource} "${Source}")
if(NOT GCC_IS_LESS_THAN_4_2 AND (USE_COMPILER_HIDDEN_VISIBILITY AND COMPILER_HAS_HIDDEN_VISIBILITY) OR WIN32 OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang))
if(COMPILER_HAS_HIDDEN_VISIBILITY OR WIN32 OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang))
test_fail(Result ${Message})
else()
test_pass(Result ${Message})