CMake options for LTO, fixes #4430
Using LTO with older versions of binutils requires setting extra flags.
This commit is contained in:
@@ -334,6 +334,16 @@ if(WITH_MYFILE_MMAP)
|
||||
endif()
|
||||
|
||||
if(WITH_LTO)
|
||||
# Using LTO with older versions of binutils requires setting extra flags
|
||||
SET(BINUTILS_VERSION_MININUM "2.29")
|
||||
execute_process(COMMAND ar --version OUTPUT_VARIABLE BINUTILS_VERSION_DETECTED)
|
||||
string(REGEX REPLACE ".* ([0-9.]+)\n.*" "\\1" BINUTILS_VERSION_DETECTED "${BINUTILS_VERSION_DETECTED}")
|
||||
if("${BINUTILS_VERSION_DETECTED}" VERSION_LESS "${BINUTILS_VERSION_MININUM}")
|
||||
SET(CMAKE_AR "/usr/bin/gcc-ar")
|
||||
SET(CMAKE_RANLIB "/usr/bin/gcc-ranlib")
|
||||
message(STATUS "Binutils version detected as less than " ${BINUTILS_VERSION_MININUM} " - setting CMake parameters to enable LTO linking:\n CMAKE_AR=\"" ${CMAKE_AR} "\"\n CMAKE_RANLIB=\"" ${CMAKE_RANLIB} "\"")
|
||||
endif()
|
||||
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
|
||||
|
Reference in New Issue
Block a user