From f4683f27335b19f28ee9cc4a11a87c02559d07b7 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Fri, 1 Aug 2025 15:46:58 -0400 Subject: [PATCH] Add link-time optimization support #62 https://codeberg.org/srb2classic/srb2classic/pulls/62 --- CMakeLists.txt | 1 + src/CMakeLists.txt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e35cc685..567ab0ee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a1063e53..c67313b74 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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))