From 3467b98eb72f8971c83b25b920419b8d0d49016a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Thu, 22 Jul 2021 21:29:37 +0100 Subject: [PATCH] CMake: Make LTO default off, restrict to release build Link Time Optimizations increases build time a lot so restrict this optimization to release builds. Follow our build bots and make this option default off. Also LTO requires CMake >= 3.9 so make the LTO CMake option universally conditional on that requirement. --- CMakeLists.txt | 4 ++-- CMakeOptions.txt | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d6f2ac466..8ac3cf7e6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,8 +73,8 @@ if (ENABLE_LTO) include(CheckIPOSupported) check_ipo_supported(RESULT lto_supported OUTPUT lto_output) if(lto_supported) - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) - message(STATUS "LTO/IPO is enabled") + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) + message(STATUS "LTO/IPO is enabled for Release configuration") else() message(STATUS "LTO/IPO requested but it is not supported by the compiler: ${lto_output}") endif() diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 1beeb99f56..7296f16b01 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -63,10 +63,8 @@ else() option(ENABLE_COMPILER_COLOR_DIAGNOSTICS "Always enable the compiler's color diagnostic output" OFF) endif() -if(WIN32) - option(ENABLE_LTO "Improves performance using Link Time Optimization" ON) -elseif(CMAKE_VERSION VERSION_GREATER "3.8.99") - option(ENABLE_LTO "Improves performance using Link Time Optimization" OFF) +if(CMAKE_VERSION VERSION_GREATER "3.8.99") + option(ENABLE_LTO "Use Link Time Optimization (release configuration only)" OFF) endif() if(WIN32)