From d028ac291c4f281ac6edc937bcbd0ad385ae031c Mon Sep 17 00:00:00 2001 From: Zephyron Date: Mon, 13 Jan 2025 18:26:44 +1000 Subject: [PATCH] CMake: Enforce x86-64-v2 ISA level across all dependencies Expand ISA level enforcement to ensure all components, including vcpkg dependencies, are built with x86-64-v2 instruction set. This addresses remaining compatibility issues where dependencies were potentially being built with higher ISA levels. Changes: - Add dedicated x86-64-v2 toolchain file for vcpkg - Set ISA flags for both main project and dependencies - Ensure proper quoting of compiler flags - Configure vcpkg to use consistent toolchain settings The fix requires cleaning both build and vcpkg directories before rebuilding: rm -rf build/ rm -rf vcpkg_installed/ Credits to Alex&Indie for the original ISA compatibility fix. Fixes remaining instances of Linux Compilation --- CMakeLists.txt | 20 ++++++++++++++------ cmake/x86-64-v2-toolchain.cmake | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 cmake/x86-64-v2-toolchain.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a6aac07d8..199232f84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -657,14 +657,22 @@ 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 quotes are preserved and flags are set for both main build and vcpkg + set(ISA_FLAGS "-march=x86-64-v2") + + # Set for main project + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ISA_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ISA_FLAGS}") + + # Set for vcpkg dependencies + set(VCPKG_CXX_FLAGS "${ISA_FLAGS}") + set(VCPKG_C_FLAGS "${ISA_FLAGS}") + + # Set toolchain options for vcpkg + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/x86-64-v2-toolchain.cmake") # Ensure we're not getting overridden by system defaults - add_compile_options(-march=x86-64-v2) + add_compile_options(${ISA_FLAGS}) # Force disable higher ISA levels add_compile_definitions( diff --git a/cmake/x86-64-v2-toolchain.cmake b/cmake/x86-64-v2-toolchain.cmake new file mode 100644 index 000000000..b29ba810c --- /dev/null +++ b/cmake/x86-64-v2-toolchain.cmake @@ -0,0 +1,2 @@ +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=x86-64-v2" CACHE STRING "C flags") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64-v2" CACHE STRING "C++ flags") \ No newline at end of file