@@ -32,6 +32,9 @@ include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web.cmake)
3232include ( ${CMAKE_CURRENT_SOURCE_DIR} /cmake/windows.cmake )
3333include ( ${CMAKE_CURRENT_SOURCE_DIR} /cmake/python_callouts.cmake )
3434
35+ # IPO Check for when GODOT_LTO is set to fail more gracefully.
36+ include (CheckIPOSupported )
37+
3538# Detect number of processors
3639include (ProcessorCount )
3740ProcessorCount (PROC_MAX )
@@ -127,6 +130,9 @@ function( godotcpp_options )
127130
128131 #TODO optimize
129132
133+ set ( GODOT_LTO "none" CACHE STRING "Link-time optimization" )
134+ set_property ( CACHE GODOT_LTO PROPERTY STRINGS "none;auto;thin;full" )
135+
130136 option ( GODOT_DEV_BUILD "Developer build with dev-only debugging code (DEV_ENABLED)" OFF )
131137
132138 #[[ debug_symbols
@@ -159,6 +165,28 @@ endfunction()
159165
160166# Function to configure and generate the targets
161167function ( godotcpp_generate )
168+ #[[ Link-Time Optimization ]]
169+ if ( GODOT_LTO STREQUAL "none" ) # Default Value
170+ set ( IS_LTO 0 )
171+ elseif ( GODOT_LTO STREQUAL "thin" )
172+ set ( IS_LTO 1 )
173+ set ( LTO_TYPE "thin" )
174+ else () # auto or full
175+ set ( IS_LTO 1 )
176+ set ( LTO_TYPE "full" )
177+ endif ()
178+ if ( IS_LTO )
179+ check_ipo_supported (RESULT result OUTPUT output LANGUAGES CXX )
180+ if ( NOT result)
181+ message ( FATAL_ERROR "GODOT_LTO=${GODOT_LTO} , but IPO/LTO is not supported by the current compiler" )
182+ endif ()
183+ if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
184+ message ( STATUS "Using LTO: ${LTO_TYPE} " )
185+ else ( )
186+ message ( STATUS "Using LTO" )
187+ endif ( )
188+ endif ()
189+
162190 #[[ Multi-Threaded MSVC Compilation
163191 When using the MSVC compiler the build command -j <n> only specifies
164192 parallel jobs or targets, and not multi-threaded compilation To speed up
0 commit comments