fix: CachyOS LTO Compilation

Fix LTO linking issues on CachyOS with GCC 15.x

- Add LTO support to all core library targets (input_common, frontend_common,
  network, shader_recompiler, web_service) that were missing LTO configuration
- Create citron_configure_lto() helper function for consistent LTO handling
- Implement CachyOS-specific detection via /etc/os-release and kernel version
- Apply conservative LTO flags (-flto=auto -ffat-lto-objects) only for
  CachyOS + GCC 15+ to resolve linking errors with newer toolchains
- Other distributions continue using aggressive LTO settings for maximum performance
- Disable LTO on executable targets to prevent main function optimization issues

This resolves "undefined symbol" errors when building with -DCITRON_ENABLE_LTO=ON
on CachyOS while maintaining optimal LTO performance on other distributions.

Fixes linking errors including:
- Core::Frontend::EmuWindow symbols
- Core::System methods
- Settings::values
- Common logging functions

Tested on CachyOS with GCC 15.1.1 + LLD 20.1.8

Signed-off-by: Boss.sfc <boss.sfc@citron-emu.org>
This commit is contained in:
Boss.sfc
2025-07-22 21:37:37 +07:00
parent d0ae8f1582
commit fc480dcb69
11 changed files with 49 additions and 6 deletions

View File

@@ -686,6 +686,37 @@ function(create_target_directory_groups target_name)
endforeach()
endfunction()
# Helper function to configure LTO for a target with CachyOS-specific compatibility
function(citron_configure_lto target_name)
if (CITRON_ENABLE_LTO)
set_property(TARGET ${target_name} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
# Detect CachyOS and apply conservative LTO settings only for CachyOS
set(IS_CACHYOS FALSE)
if (EXISTS "/etc/os-release")
file(READ "/etc/os-release" OS_RELEASE_CONTENT)
if (OS_RELEASE_CONTENT MATCHES "ID=cachyos")
set(IS_CACHYOS TRUE)
endif()
endif()
# Alternative detection via kernel name
if (NOT IS_CACHYOS)
execute_process(COMMAND uname -r OUTPUT_VARIABLE KERNEL_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
if (KERNEL_VERSION MATCHES "cachyos")
set(IS_CACHYOS TRUE)
endif()
endif()
# Apply conservative LTO settings only for CachyOS with GCC 15+
if (IS_CACHYOS AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "15.0")
message(STATUS "Detected CachyOS with GCC ${CMAKE_CXX_COMPILER_VERSION} - using conservative LTO settings for ${target_name}")
target_compile_options(${target_name} PRIVATE "-flto=auto" "-ffat-lto-objects")
target_link_options(${target_name} PRIVATE "-flto=auto" "-ffat-lto-objects")
endif()
endif()
endfunction()
# Prevent boost from linking against libs when building
target_link_libraries(Boost::headers INTERFACE Boost::disable_autolinking)
# Adjustments for MSVC + Ninja