summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorZephyron <zephyron@citron-emu.org>2025-01-13 17:57:17 +1000
committerZephyron <zephyron@citron-emu.org>2025-01-13 17:57:17 +1000
commitcc897c3f0eac9fb77657a97abf7e9fec6c144b9f (patch)
tree72ba885b025ade62d95877e4eaf6314c108ef85a /CMakeLists.txt
parentcce4abbb0b0c5902939a05d79016b2de672b9457 (diff)
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.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt18
1 files changed, 18 insertions, 0 deletions
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()