Skip to content

Commit

Permalink
Use CMake-standard LTO option and deprecate ENABLE_LTO
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Simmons <[email protected]>
  • Loading branch information
linuxrocks123 committed Nov 6, 2024
1 parent 1610386 commit febf96b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit febf96b

Please sign in to comment.