Disable LTO by default. Add CMake option TD_ENABLE_LTO to enable it.

GitOrigin-RevId: 53fd2d4573946bfac27c10953874f96b2e8491d1
This commit is contained in:
levlam 2018-02-18 00:27:57 +03:00
parent 33225f66ae
commit a17c3c7ca9

View File

@ -16,14 +16,18 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
enable_testing() enable_testing()
if (POLICY CMP0069) if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW) option(TD_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.")
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED) if (TD_ENABLE_LTO)
if (IPO_SUPPORTED) cmake_policy(SET CMP0069 NEW)
#set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) do not work? include(CheckIPOSupported)
string(REPLACE ";" " " CXX_FLAGS_IPO "${CMAKE_CXX_COMPILE_OPTIONS_IPO}") check_ipo_supported(RESULT IPO_SUPPORTED)
message(STATUS "Use link time optimizations: ${CXX_FLAGS_IPO}") if (IPO_SUPPORTED)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_FLAGS_IPO}") #set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) do not work?
string(REPLACE ";" " " CXX_FLAGS_IPO "${CMAKE_CXX_COMPILE_OPTIONS_IPO}")
message(STATUS "Use link time optimizations: ${CXX_FLAGS_IPO}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_FLAGS_IPO}")
endif()
endif() endif()
endif() endif()