File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,6 +136,8 @@ LEG_BUNDLED_LIB(FREETYPE Freetype2 "BUILD_CLIENT AND FEATURE_FREETYPE")
136136LEG_BUNDLED_LIB (SQLITE3 SQlite3 "BUILD_CLIENT OR BUILD_MOD" )
137137LEG_BUNDLED_LIB (CJSON cJSON "BUILD_ENGINE OR BUILD_MOD" )
138138
139+ option (ENABLE_LTO "Enable IPO/LTO for Release-style builds (toolchain must support it)" OFF )
140+
139141#-----------------------------------------------------------------
140142# Setup
141143#-----------------------------------------------------------------
@@ -174,6 +176,9 @@ include(cmake/ETLTargets.cmake)
174176# Platform specific compiler settings
175177include (cmake/ETLPlatform.cmake )
176178
179+ # Optional LTO (after compiler flags are established)
180+ include (cmake/ETLLTO.cmake )
181+
177182# Source globs
178183include (cmake/ETLSources.cmake )
179184
Original file line number Diff line number Diff line change @@ -151,6 +151,16 @@ make
151151sudo make install # optional; set install vars first
152152```
153153
154+ ** Release packaging — optional LTO**
155+
156+ For ** Release** / ** RelWithDebInfo** / ** MinSizeRel** , you can enable ** link-time optimization** if your toolchain supports it (CMake IPO):
157+
158+ ``` sh
159+ cmake -DENABLE_LTO=ON ..
160+ ```
161+
162+ Leave it ** off** for normal development (faster links). It cannot be combined with ** ` ENABLE_ASAN ` ** .
163+
154164** Notes**
155165
156166- 32-bit builds may need ** multilib / ` -devel ` ** packages.
Original file line number Diff line number Diff line change 1+ #-----------------------------------------------------------------
2+ # Optional link-time optimization (IPO / LTO)
3+ #-----------------------------------------------------------------
4+ #
5+ # Off by default: LTO increases link time and needs a capable toolchain.
6+ # When enabled, applies to Release-style configurations only.
7+
8+ if (NOT ENABLE_LTO)
9+ return ()
10+ endif ()
11+
12+ if (ENABLE_ASAN)
13+ message (FATAL_ERROR "ENABLE_LTO cannot be used together with ENABLE_ASAN." )
14+ endif ()
15+
16+ if (CMAKE_VERSION VERSION_LESS "3.9" )
17+ message (FATAL_ERROR "ENABLE_LTO requires CMake 3.9 or newer (CheckIPOSupported)." )
18+ endif ()
19+
20+ include (CheckIPOSupported )
21+ check_ipo_supported (RESULT _etl_ipo_supported OUTPUT _etl_ipo_error )
22+
23+ if (NOT _etl_ipo_supported)
24+ message (WARNING "ENABLE_LTO=ON but IPO is not supported by this toolchain: ${_etl_ipo_error} " )
25+ return ()
26+ endif ()
27+
28+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON )
29+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON )
30+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON )
31+
32+ message (STATUS "Link-time optimization (IPO/LTO) enabled for Release, RelWithDebInfo, MinSizeRel" )
You can’t perform that action at this time.
0 commit comments