From baa0f56eb8e973daee33dd07a93b59d04af62b04 Mon Sep 17 00:00:00 2001 From: GTTeancum Date: Fri, 4 Sep 2026 22:24:24 -0400 Subject: [PATCH] Allow disabling IPO for large generated game targets --- ps2xRuntime/CMakeLists.txt | 8 +++++++- ps2xRuntime/cmake/ReleaseMode.cmake | 26 +++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ps2xRuntime/CMakeLists.txt b/ps2xRuntime/CMakeLists.txt index e4dc1956d..18d6b1fcf 100644 --- a/ps2xRuntime/CMakeLists.txt +++ b/ps2xRuntime/CMakeLists.txt @@ -8,6 +8,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) option(PS2X_ENABLE_RUNNER_UNITY_BUILD "Build ps2EntryRunner with CMake unity build" ON) set(PS2X_RUNNER_UNITY_BUILD_BATCH_SIZE 32 CACHE STRING "Unity build batch size for ps2EntryRunner") option(PS2X_ENABLE_RUNNER_PCH "Precompile the heavy runtime headers for ps2EntryRunner" ON) +option(PS2X_ENABLE_RUNNER_IPO "Allow link-time optimization of the generated game target when IPO is enabled" ON) option(PS2X_ENABLE_SCCACHE "Use sccache as compiler launcher when available" ON) option(PS2X_ENABLE_RUNTIME_LOGS "Enable PS2 runtime logs" OFF) @@ -554,7 +555,12 @@ endif() if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") EnableFastReleaseMode(ps2_runtime) - EnableFastReleaseMode(ps2EntryRunner) + if(PS2X_ENABLE_RUNNER_IPO) + EnableFastReleaseMode(ps2EntryRunner) + else() + # Large generated games can exceed linker memory limits even with one worker. + EnableFastReleaseMode(ps2EntryRunner NO_IPO) + endif() if(WIN32 AND NOT PS2X_SHOW_WINDOWS_CONSOLE) if(MSVC) diff --git a/ps2xRuntime/cmake/ReleaseMode.cmake b/ps2xRuntime/cmake/ReleaseMode.cmake index 92ef0d54d..81a77c9a3 100644 --- a/ps2xRuntime/cmake/ReleaseMode.cmake +++ b/ps2xRuntime/cmake/ReleaseMode.cmake @@ -3,6 +3,7 @@ include(CheckIPOSupported) check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_ERROR) function(EnableFastReleaseMode TargetName) + cmake_parse_arguments(RELEASE_MODE "NO_IPO" "" "" ${ARGN}) message("> Enabling optimization for: ${TargetName}") if(MSVC) target_compile_options(${TargetName} PRIVATE @@ -10,7 +11,6 @@ function(EnableFastReleaseMode TargetName) /O2 # speed /Ob2 # inline aggressively /Oi # intrinsics - /GL # whole program opt /Gy # function-level linking /Gw # global data in COMDAT /GF # string pooling @@ -23,20 +23,32 @@ function(EnableFastReleaseMode TargetName) > ) + if(NOT RELEASE_MODE_NO_IPO) + target_compile_options(${TargetName} PRIVATE + $<$:/GL> + ) + endif() + if(TARGET ${TargetName}) target_link_options(${TargetName} PRIVATE $<$: - /LTCG # link-time code generation /OPT:REF # remove unreferenced /OPT:ICF # fold identical COMDATs > ) + if(NOT RELEASE_MODE_NO_IPO) + target_link_options(${TargetName} PRIVATE + $<$:/LTCG> + ) + endif() endif() endif() - if(IPO_SUPPORTED) - set_property(TARGET ${TargetName} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) - else() - message(WARNING "Interprocedural optimization not supported: ${ipo_error}") + if(NOT RELEASE_MODE_NO_IPO) + if(IPO_SUPPORTED) + set_property(TARGET ${TargetName} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) + else() + message(WARNING "Interprocedural optimization not supported: ${ipo_error}") + endif() endif() -endfunction() \ No newline at end of file +endfunction()