Add link-time optimization support #62

https://codeberg.org/srb2classic/srb2classic/pulls/62
This commit is contained in:
NepDisk 2025-08-01 15:46:58 -04:00
parent 9b4c5a722c
commit f4683f2733
2 changed files with 5 additions and 0 deletions

View file

@ -85,6 +85,7 @@ option(SRB2_CONFIG_PROFILEMODE "Compile for profiling (GCC only)." OFF)
option(SRB2_CONFIG_TRACY "Compile with Tracy profiling enabled" OFF)
option(SRB2_CONFIG_ASAN "Compile with AddressSanitizer (libasan)." OFF)
set(SRB2_CONFIG_ASSET_DIRECTORY "" CACHE PATH "Path to directory that contains all asset files for the installer. If set, assets will be part of installation and cpack.")
option(SRB2_CONFIG_LTO "Enable link time optimizations, improves performance at the cost of longer link times." ON)
if(SRB2_CONFIG_ENABLE_TESTS)
# https://github.com/catchorg/Catch2

View file

@ -389,6 +389,10 @@ if(SRB2_CONFIG_PROFILEMODE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
target_link_options(SRB2SDL2 PRIVATE -pg)
endif()
if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE)
set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
# strip debug symbols into separate file when using gcc or clang.
# to be consistent with Makefile, don't generate for OS X.
if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin))