Новый вариант обработки флага -flto

This commit is contained in:
Andrei Astafev 2019-08-22 07:30:50 +03:00
parent 9c371dc1a2
commit 5ca58eda09

View File

@ -88,11 +88,26 @@ if(CMAKE_CXX_COMPILER_IS_CLANG
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
check_enable_cxx_flag(-flto)
if(CMAKE_CXX_COMPILER_IS_GCC
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8")
# Doesn't work with GCC 4.7.2 in Astra Linux 1.5
check_enable_cxx_flag(-fno-fat-lto-objects)
check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG)
check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_LTO_FLAG)
if(CMAKE_CXX_COMPILER_IS_GCC AND CXX_HAS_LTO_FLAG)
find_program(CMAKE_GCC_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_GCC_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_GCC_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(CMAKE_GCC_AR AND CMAKE_GCC_NM AND CMAKE_GCC_RANLIB)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
if(CXX_HAS_NO_FAT_LTO_FLAG)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-fat-lto-objects")
endif()
set(CMAKE_AR "${CMAKE_GCC_AR}")
set(CMAKE_NM "${CMAKE_GCC_NM}")
set(CMAKE_RANLIB "${CMAKE_GCC_RANLIB}")
else()
message(WARNING "GCC indicates LTO support, but binutils wrappers could not be found. Disabling LTO.")
endif()
else()
check_enable_compiler_flag(-flto)
check_enable_compiler_flag(-fno-fat-lto-objects)
endif()
endif()
endif()