Skip to content

Commit

Permalink
CMake: add lto options
Browse files Browse the repository at this point in the history
  • Loading branch information
enetheru committed Jan 14, 2025
1 parent befe3ee commit 06216a4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ function( common_compiler_flags )
$<${IS_GNU}:-fno-gnu-unique>
>

$<${IS_LTO}:
$<${IS_MSVC}: /GL >
$<${IS_CLANG}: -flto=${LTO_TYPE} >
$<${IS_APPLECLANG}: -flto=${LTO_TYPE} >
$<${IS_GNU}: -flto >
>

# MSVC only
$<${IS_MSVC}:
# /MP isn't valid for clang-cl with msvc frontend
Expand Down Expand Up @@ -170,6 +177,13 @@ function( common_compiler_flags )
$<${IS_CLANG}:-s>
$<${IS_APPLECLANG}:-Wl,-S -Wl,-x -Wl,-dead_strip>
>

$<${IS_LTO}:
$<${IS_MSVC}: /LTCG:INCREMENTAL >
$<${IS_CLANG}: -flto=${LTO_TYPE} >
$<${IS_APPLECLANG}: -flto=${LTO_TYPE} >
$<${IS_GNU}: -flto >
>
)

endfunction()
28 changes: 28 additions & 0 deletions cmake/godotcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web.cmake)
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows.cmake)
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/python_callouts.cmake)

# IPO Check for when GODOT_LTO is set to fail more gracefully.
include(CheckIPOSupported)

# Detect number of processors
include(ProcessorCount)
ProcessorCount(PROC_MAX)
Expand Down Expand Up @@ -127,6 +130,9 @@ function( godotcpp_options )

#TODO optimize

set( GODOT_LTO "none" CACHE STRING "Link-time optimization" )
set_property( CACHE GODOT_LTO PROPERTY STRINGS "none;auto;thin;full" )

option( GODOT_DEV_BUILD "Developer build with dev-only debugging code (DEV_ENABLED)" OFF )

#[[ debug_symbols
Expand Down Expand Up @@ -159,6 +165,28 @@ endfunction()

# Function to configure and generate the targets
function( godotcpp_generate )
#[[ Link-Time Optimization ]]
if( GODOT_LTO STREQUAL "none") # Default Value
set( IS_LTO 0 )
elseif( GODOT_LTO STREQUAL "thin" )
set( IS_LTO 1 )
set( LTO_TYPE "thin" )
else() # auto or full
set( IS_LTO 1 )
set( LTO_TYPE "full" )
endif()
if( IS_LTO )
check_ipo_supported(RESULT result OUTPUT output LANGUAGES CXX )
if( NOT result)
message( FATAL_ERROR "GODOT_LTO=${GODOT_LTO}, but IPO/LTO is not supported by the current compiler")
endif()
if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
message( STATUS "Using LTO: ${LTO_TYPE}" )
else( )
message( STATUS "Using LTO" )
endif( )
endif()

#[[ Multi-Threaded MSVC Compilation
When using the MSVC compiler the build command -j <n> only specifies
parallel jobs or targets, and not multi-threaded compilation To speed up
Expand Down

0 comments on commit 06216a4

Please sign in to comment.