From 4caf0e4cb9153355239294ed96483bf49eb705a2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 25 Feb 2024 20:58:42 +0100 Subject: [PATCH] Update LTO exclusion list (#14407) --- CMakeLists.txt | 40 ++++++++++++++++++++++++++-------------- doc/compiling/README.md | 2 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47f1367a0..fefcef2c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,18 @@ set(DEFAULT_ENABLE_LTO TRUE) if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(DEFAULT_ENABLE_LTO FALSE) endif() +#### LTO testing list #### +# - Linux: seems to work always +# - win32/msvc: works +# - win32/gcc: fails to link +# - win32/clang: works +# - macOS on x86: seems to be fine +# - macOS on ARM: crashes, see +# Note: since CMake has no easy architecture detection disabling for Mac entirely +#### #### +if((WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR APPLE) + set(DEFAULT_ENABLE_LTO FALSE) +endif() set(ENABLE_LTO ${DEFAULT_ENABLE_LTO} CACHE BOOL "Use Link Time Optimization") set(DEFAULT_RUN_IN_PLACE FALSE) @@ -66,20 +78,6 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE) endif() -# FIXME: Windows build fails in multiple places to link, needs to be investigated. -if (ENABLE_LTO AND NOT WIN32) - 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") - else() - message(STATUS "LTO/IPO requested but it is not supported by the compiler: ${lto_output}") - endif() -else() - message(STATUS "LTO/IPO is not enabled") -endif() - set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL "Whether to enable update checks by default") @@ -163,6 +161,20 @@ elseif(BUILD_CLIENT AND TARGET IrrlichtMt::IrrlichtMt) endif() endif() +if (ENABLE_LTO OR CMAKE_INTERPROCEDURAL_OPTIMIZATION) + 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") + else() + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) + message(STATUS "LTO/IPO was requested but is not supported by the compiler: ${lto_output}") + endif() +else() + message(STATUS "LTO/IPO is not enabled") +endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GCC_MINIMUM_VERSION}") message(FATAL_ERROR "Insufficient gcc version, found ${CMAKE_CXX_COMPILER_VERSION}. " diff --git a/doc/compiling/README.md b/doc/compiling/README.md index 7ce06c2de..4ecaa88bb 100644 --- a/doc/compiling/README.md +++ b/doc/compiling/README.md @@ -28,7 +28,7 @@ General options and their default values: ENABLE_REDIS=ON - Build with libhiredis; Enables use of Redis map backend ENABLE_SPATIAL=ON - Build with LibSpatial; Speeds up AreaStores ENABLE_SOUND=ON - Build with OpenAL, libogg & libvorbis; in-game sounds - ENABLE_LTO=ON - Build with IPO/LTO optimizations (smaller and more efficient than regular build) + ENABLE_LTO= - Build with IPO/LTO optimizations (smaller and more efficient than regular build) ENABLE_LUAJIT=ON - Build with LuaJIT (much faster than non-JIT Lua) ENABLE_PROMETHEUS=OFF - Build with Prometheus metrics exporter (listens on tcp/30000 by default) ENABLE_SYSTEM_GMP=ON - Use GMP from system (much faster than bundled mini-gmp)