feat: Add Profile-Guided Optimization (PGO) build support

Implements two-stage PGO build system with CMake integration and
automated build scripts for Windows, Linux, and macOS. Supports
MSVC, GCC, and Clang compilers.

PGO enables runtime profiling-based optimizations for improved
emulator performance. Includes helper scripts to streamline the
build workflow and resolve platform-specific issues.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-10-11 13:30:39 +10:00
parent 2a7e6c74bd
commit bdd2875642
6 changed files with 890 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modul
include(DownloadExternals)
include(CMakeDependentOption)
include(CTest)
include(PGO)
# Disable Warnings as Errors for MSVC
if (MSVC)
@@ -78,6 +79,10 @@ option(CITRON_CHECK_SUBMODULES "Check if submodules are present" ON)
option(CITRON_ENABLE_LTO "Enable link-time optimization" OFF)
option(CITRON_ENABLE_PGO_GENERATE "Build with PGO instrumentation to generate profile data (Stage 1)" OFF)
option(CITRON_ENABLE_PGO_USE "Build using PGO profile data for optimization (Stage 2)" OFF)
set(CITRON_PGO_PROFILE_DIR "${CMAKE_BINARY_DIR}/pgo-profiles" CACHE PATH "Directory to store PGO profile data")
option(CITRON_DOWNLOAD_TIME_ZONE_DATA "Always download time zone binaries" OFF)
option(CITRON_ENABLE_PORTABLE "Allow citron to enable portable mode if a user folder is found in the CWD" ON)
@@ -792,6 +797,22 @@ if(DEFINED HAS_BOOST_PROCESS_DEFINITION)
target_compile_definitions(core PRIVATE ${HAS_BOOST_PROCESS_DEFINITION})
endif()
# Apply PGO configuration to main targets
if(CITRON_ENABLE_PGO_GENERATE OR CITRON_ENABLE_PGO_USE)
if(TARGET citron)
citron_configure_pgo(citron)
endif()
if(TARGET citron-cmd)
citron_configure_pgo(citron-cmd)
endif()
if(TARGET citron-room)
citron_configure_pgo(citron-room)
endif()
# Print PGO instructions
citron_print_pgo_instructions()
endif()
# Set citron project or citron-cmd project as default StartUp Project in Visual Studio depending on whether QT is enabled or not
if(ENABLE_QT)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT citron)