Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ps2xRuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 19 additions & 7 deletions ps2xRuntime/cmake/ReleaseMode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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
$<$<CONFIG:Release>:
/O2 # speed
/Ob2 # inline aggressively
/Oi # intrinsics
/GL # whole program opt
/Gy # function-level linking
/Gw # global data in COMDAT
/GF # string pooling
Expand All @@ -23,20 +23,32 @@ function(EnableFastReleaseMode TargetName)
>
)

if(NOT RELEASE_MODE_NO_IPO)
target_compile_options(${TargetName} PRIVATE
$<$<CONFIG:Release>:/GL>
)
endif()

if(TARGET ${TargetName})
target_link_options(${TargetName} PRIVATE
$<$<CONFIG:Release>:
/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
$<$<CONFIG:Release>:/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()
endfunction()