Рефакторинг

This commit is contained in:
Andrei Astafev 2020-06-25 11:30:48 +03:00
parent a8e546734a
commit 954b27fa27
2 changed files with 31 additions and 21 deletions

View File

@ -57,28 +57,13 @@ function(common_target_properties target)
if(target_type STREQUAL "EXECUTABLE" AND CMAKE_BUILD_TYPE STREQUAL "Release") if(target_type STREQUAL "EXECUTABLE" AND CMAKE_BUILD_TYPE STREQUAL "Release")
check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG) check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG)
check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_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) if(CXX_HAS_LTO_FLAG)
find_program(CMAKE_GCC_AR NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX}" target_compile_options(${target} PUBLIC "-flto")
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar" HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) set_target_properties(${target} PROPERTIES LINK_FLAGS_RELEASE "-flto")
find_program(CMAKE_GCC_NM NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm${_CMAKE_TOOLCHAIN_SUFFIX}" if(CXX_HAS_NO_FAT_LTO_FLAG)
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm" HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) target_compile_options(${target} PUBLIC "-fno-fat-lto-objects")
find_program( set_target_properties(${target} PROPERTIES LINK_FLAGS_RELEASE "-fno-fat-lto-objects")
CMAKE_GCC_RANLIB NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_TOOLCHAIN_SUFFIX}"
"${_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() endif()
else()
check_enable_compiler_flag(-flto)
check_enable_compiler_flag(-fno-fat-lto-objects)
endif() endif()
endif() endif()

View File

@ -19,3 +19,28 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_COMPILER_IS_MSVC ON) set(CMAKE_CXX_COMPILER_IS_MSVC ON)
endif() endif()
# Предпочтительные пути к утилитам для компоновки
if(CMAKE_CXX_COMPILER_IS_GCC)
find_program(
CMAKE_GCC_AR NAMES "/usr/e2k-linux/bin/ar" "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX}"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar" "ar" HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(CMAKE_GCC_AR)
set(CMAKE_AR ${CMAKE_GCC_AR} CACHE STRING "" FORCE)
endif()
find_program(
CMAKE_GCC_NM NAMES "/usr/e2k-linux/bin/nm" "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm${_CMAKE_TOOLCHAIN_SUFFIX}"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm" "nm" HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(CMAKE_GCC_NM)
set(CMAKE_NM ${CMAKE_GCC_NM} CACHE STRING "" FORCE)
endif()
find_program(
CMAKE_GCC_RANLIB
NAMES "/usr/e2k-linux/bin/ranlib" "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_TOOLCHAIN_SUFFIX}"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib" "ranlib" HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(CMAKE_GCC_RANLIB)
set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE STRING "" FORCE)
endif()
endif()