Check for support before adding bigtoc linker flag

Fixes: #20076
This commit is contained in:
Alexander Grund 2019-12-09 09:42:40 +01:00 committed by Brad King
parent 8c7b7df788
commit 958f858ad8
2 changed files with 39 additions and 2 deletions

View File

@ -54,12 +54,20 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc")
endif()
# Workaround for TOC Overflow on ppc64
set(bigTocFlag "")
if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND
CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-bbigtoc")
set(bigTocFlag "-Wl,-bbigtoc")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-multi-toc")
set(bigTocFlag "-Wl,--no-multi-toc")
endif()
if(bigTocFlag)
include(CheckCXXLinkerFlag)
check_cxx_linker_flag(${bigTocFlag} BIG_TOC_FLAG_SUPPORTED)
if(BIG_TOC_FLAG_SUPPORTED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${bigTocFlag}")
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND

View File

@ -0,0 +1,29 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
include_guard(GLOBAL)
include(CheckCXXSourceCompiles)
include(CMakeCheckCompilerFlagCommonPatterns)
function(check_cxx_linker_flag _flag _var)
if(CMAKE_VERSION VERSION_LESS "3.14")
set(CMAKE_REQUIRED_LIBRARIES "${_flag}")
else()
set(CMAKE_REQUIRED_LINK_OPTIONS "${_flag}")
endif()
# Normalize locale during test compilation.
set(_locale_vars LC_ALL LC_MESSAGES LANG)
foreach(v IN LISTS _locale_vars)
set(_locale_vars_saved_${v} "$ENV{${v}}")
set(ENV{${v}} C)
endforeach()
check_compiler_flag_common_patterns(_common_patterns)
check_cxx_source_compiles("int main() { return 0; }" ${_var}
${_common_patterns}
)
foreach(v IN LISTS _locale_vars)
set(ENV{${v}} ${_locale_vars_saved_${v}})
endforeach()
set(${_var} "${${_var}}" PARENT_SCOPE)
endfunction()