From 83df555406eb1dbe5e653816bbff9fd098596876 Mon Sep 17 00:00:00 2001 From: Wen Yang Date: Thu, 18 Dec 2025 17:59:38 +0800 Subject: [PATCH] fix: Correctly handle ARM64 cross-compilation The previous CMake script unconditionally added `-m64` or `-m32` flags for GCC builds based on the `BUILD64` variable. This caused build failures when cross-compiling for ARM64, as the ARM toolchain does not recognize the `-m64` flag. This patch introduces a check for the target architecture. The `-m64` and `-m32` flags are now only applied for non-ARM architectures, resolving the cross-compilation issue. --- src/CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0a7b26b..a90ec6b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -214,12 +214,15 @@ elseif( CMAKE_COMPILER_IS_GNUCXX ) add_definitions( "/D_DEBUG" ) endif( ) - if( BUILD64 ) - set( CMAKE_CXX_FLAGS "-m64 ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-m64 ${CMAKE_C_FLAGS}" ) - else( ) - set( CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}" ) + # For x86/amd64 architectures, set 32/64 bit flags + if( CMAKE_SYSTEM_PROCESSOR MATCHES "x86|i.86|AMD64" ) + if( BUILD64 ) + set( CMAKE_CXX_FLAGS "-m64 ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "-m64 ${CMAKE_C_FLAGS}" ) + else( ) + set( CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}" ) + endif( ) endif( ) if( CODE_COVERAGE )