Просмотр исходного кода

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.
Robin van Emden 4 лет назад
Родитель
Сommit
3f808d4596
1 измененных файлов с 7 добавлено и 3 удалено
  1. 7 3
      build-scripts/config_common.cmake

+ 7 - 3
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 ()