From 3f808d459656c849f93138ac90062e93cfa267f8 Mon Sep 17 00:00:00 2001 From: Robin van Emden Date: Mon, 6 Dec 2021 09:40:48 +0100 Subject: [PATCH] Fix -m32 unrecognized issue when compile 32-bit target on some 64-bit systems (#866) When compile 32-bit targets on some 64-bit systems, the "-m32" flag might be unrecognized by some gcc compilers, e.g. compiling arm32 in aarch64 system, compiling riscv32 in riscv64 system. Add check before adding "-m32" flag to gcc, and only add it if it is supported. --- build-scripts/config_common.cmake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 3d94acf5..c60725d4 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -61,9 +61,13 @@ if (CMAKE_SIZEOF_VOID_P EQUAL 8) set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC") endif () else () - add_definitions (-m32) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") - set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") + include(CheckCCompilerFlag) + Check_C_Compiler_Flag( -m32 M32_OK ) + if (M32_OK) + add_definitions (-m32) + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") + set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") + endif () endif () endif ()