Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ LEG_BUNDLED_LIB(FREETYPE Freetype2 "BUILD_CLIENT AND FEATURE_FREETYPE")
LEG_BUNDLED_LIB(SQLITE3 SQlite3 "BUILD_CLIENT OR BUILD_MOD")
LEG_BUNDLED_LIB(CJSON cJSON "BUILD_ENGINE OR BUILD_MOD")

option(ENABLE_LTO "Enable IPO/LTO for Release-style builds (toolchain must support it)" OFF)

#-----------------------------------------------------------------
# Setup
#-----------------------------------------------------------------
Expand Down Expand Up @@ -174,6 +176,9 @@ include(cmake/ETLTargets.cmake)
# Platform specific compiler settings
include(cmake/ETLPlatform.cmake)

# Optional LTO (after compiler flags are established)
include(cmake/ETLLTO.cmake)

# Source globs
include(cmake/ETLSources.cmake)

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ make
sudo make install # optional; set install vars first
```

**Release packaging — optional LTO**

For **Release** / **RelWithDebInfo** / **MinSizeRel**, you can enable **link-time optimization** if your toolchain supports it (CMake IPO):

```sh
cmake -DENABLE_LTO=ON ..
```

Leave it **off** for normal development (faster links). It cannot be combined with **`ENABLE_ASAN`**.

**Notes**

- 32-bit builds may need **multilib / `-devel`** packages.
Expand Down
32 changes: 32 additions & 0 deletions cmake/ETLLTO.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#-----------------------------------------------------------------
# Optional link-time optimization (IPO / LTO)
#-----------------------------------------------------------------
#
# Off by default: LTO increases link time and needs a capable toolchain.
# When enabled, applies to Release-style configurations only.

if(NOT ENABLE_LTO)
return()
endif()

if(ENABLE_ASAN)
message(FATAL_ERROR "ENABLE_LTO cannot be used together with ENABLE_ASAN.")
endif()

if(CMAKE_VERSION VERSION_LESS "3.9")
message(FATAL_ERROR "ENABLE_LTO requires CMake 3.9 or newer (CheckIPOSupported).")
endif()

include(CheckIPOSupported)
check_ipo_supported(RESULT _etl_ipo_supported OUTPUT _etl_ipo_error)

if(NOT _etl_ipo_supported)
message(WARNING "ENABLE_LTO=ON but IPO is not supported by this toolchain: ${_etl_ipo_error}")
return()
endif()

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON)

message(STATUS "Link-time optimization (IPO/LTO) enabled for Release, RelWithDebInfo, MinSizeRel")
Loading