From 539f11fb4e906bc7b93140397705f0a486aebf49 Mon Sep 17 00:00:00 2001 From: Patrick Simmons Date: Wed, 6 Nov 2024 14:43:24 -0500 Subject: [PATCH] Use CMake-standard LTO option and deprecate ENABLE_LTO Signed-off-by: Patrick Simmons --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6711866e2c..42d5d364ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,13 +58,14 @@ STATIC_BUILD_WITH_DYNAMIC_STDLIB." OFF) OPTION (STATIC_BUILD_WITH_DYNAMIC_STDLIB "Build a (mostly) statically linked release binary. \ Glibc and C++ standard library is linked dynamically." OFF) -if (STATIC_BUILD_WITH_DYNAMIC_GLIBC OR STATIC_BUILD_WITH_DYNAMIC_STDLIB OR CMAKE_INTERPROCEDURAL_OPTIMIZATION) +OPTION (ENABLE_LTO "Build with LTO (deprecated: use CMAKE_INTERPROCEDURAL_OPTIMIZATION)" OFF) + +if (STATIC_BUILD_WITH_DYNAMIC_GLIBC OR STATIC_BUILD_WITH_DYNAMIC_STDLIB OR ENABLE_LTO) # We want to optimize the binary size for a static release binary by default. - set (_ENABLE_LTO_DEFAULT ON) + set (CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) else() - set (_ENABLE_LTO_DEFAULT OFF) + set (CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF) endif() -OPTION (ENABLE_LTO "Enable Link Time Optimization (LTO)" ${_ENABLE_LTO_DEFAULT}) OPTION (BUILD_AUTO_VAR_INIT_PATTERN "Initialize variables with pattern during build" OFF) OPTION (ENABLE_IWYU "Enable checking includes with IWYU" OFF) @@ -324,12 +325,11 @@ set(BUILD_LINK_WITH_GOLD ON CACHE BOOL "Use Gold linker for build if available") set(BUILD_LINK_WITH_LLD ON CACHE BOOL "Use LLD linker for build if available (overrides BUILD_LINK_WITH_GOLD)") # Build with LTO -if (ENABLE_LTO AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +if (CMAKE_INTERPROCEDURAL_OPTIMIZATION AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (BUILD_LINK_WITH_LLD) message(WARNING "LLD does not work with GCC's LTO object format, switching to Gold.") set(BUILD_LINK_WITH_LLD OFF) endif () - add_cxx_compiler_option("-flto") endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")