mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-19 02:33:32 +00:00
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:
@@ -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
|
||||
|
||||
@@ -232,6 +232,8 @@ if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
|
||||
target_link_libraries(audio_core PRIVATE dynarmic::dynarmic)
|
||||
endif()
|
||||
|
||||
citron_configure_lto(audio_core)
|
||||
|
||||
if (ENABLE_CUBEB)
|
||||
target_sources(audio_core PRIVATE
|
||||
sink/cubeb_sink.cpp
|
||||
|
||||
@@ -266,4 +266,6 @@ if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(common PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
citron_configure_lto(common)
|
||||
|
||||
create_target_directory_groups(common)
|
||||
|
||||
@@ -1294,8 +1294,6 @@ if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(core PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
if (CITRON_ENABLE_LTO)
|
||||
set_property(TARGET core PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
endif()
|
||||
citron_configure_lto(core)
|
||||
|
||||
create_target_directory_groups(core)
|
||||
|
||||
@@ -9,3 +9,5 @@ add_library(frontend_common STATIC
|
||||
|
||||
create_target_directory_groups(frontend_common)
|
||||
target_link_libraries(frontend_common PUBLIC core SimpleIni::SimpleIni PRIVATE common Boost::headers)
|
||||
|
||||
citron_configure_lto(frontend_common)
|
||||
|
||||
@@ -164,3 +164,5 @@ target_link_libraries(hid_core PUBLIC core)
|
||||
if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(hid_core PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
citron_configure_lto(hid_core)
|
||||
|
||||
@@ -93,6 +93,8 @@ if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(input_common PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
citron_configure_lto(input_common)
|
||||
|
||||
if (ANDROID)
|
||||
target_sources(input_common PRIVATE
|
||||
drivers/android.cpp
|
||||
|
||||
@@ -28,3 +28,5 @@ endif()
|
||||
if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(network PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
citron_configure_lto(network)
|
||||
|
||||
@@ -266,3 +266,5 @@ create_target_directory_groups(shader_recompiler)
|
||||
if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(shader_recompiler PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
citron_configure_lto(shader_recompiler)
|
||||
|
||||
@@ -388,9 +388,7 @@ if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(video_core PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
if (CITRON_ENABLE_LTO)
|
||||
set_property(TARGET video_core PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
endif()
|
||||
citron_configure_lto(video_core)
|
||||
|
||||
if (ANDROID AND ARCHITECTURE_arm64)
|
||||
target_link_libraries(video_core PRIVATE adrenotools)
|
||||
|
||||
@@ -22,3 +22,5 @@ target_link_libraries(web_service PRIVATE common network nlohmann_json::nlohmann
|
||||
if (CITRON_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(web_service PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
citron_configure_lto(web_service)
|
||||
|
||||
Reference in New Issue
Block a user