From cc897c3f0eac9fb77657a97abf7e9fec6c144b9f Mon Sep 17 00:00:00 2001 From: Zephyron Date: Mon, 13 Jan 2025 17:57:17 +1000 Subject: [PATCH] CMake: Force x86-64-v2 instruction set for better compatibility Enforce x86-64-v2 instruction set level to prevent compatibility issues on systems that default to higher ISA levels (v3/v4). This fixes crashes reported on certain Linux distributions like CachyOS that force higher instruction set levels by default. The fix: - Sets -march=x86-64-v2 for both C and CXX flags - Adds compile options to ensure system defaults don't override - Explicitly disables v3 and v4 instruction sets - Only applies to x86_64 architectures Credits to Alex&Indie for identifying the ISA level compatibility issue. Fixes: Linux Compilation. --- CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9c0e1a25..a6aac07d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -654,3 +654,21 @@ if(ENABLE_QT AND UNIX AND NOT APPLE) install(FILES "dist/org.citron_emu.citron.metainfo.xml" DESTINATION "share/metainfo") endif() + +# Set default x86-64-v2 instruction set for better compatibility +if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") + # Only set flags if not explicitly provided via command line + if (NOT CMAKE_C_FLAGS MATCHES "-march=" AND NOT CMAKE_CXX_FLAGS MATCHES "-march=") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64-v2") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=x86-64-v2") + endif() + + # Ensure we're not getting overridden by system defaults + add_compile_options(-march=x86-64-v2) + + # Force disable higher ISA levels + add_compile_definitions( + __x86_64_v3__=0 + __x86_64_v4__=0 + ) +endif()