Skip to content

Commit af30f4c

Browse files
author
Kent Knox
committed
Merge pull request #222 from dividiti/arm-support
Only use the "-m32" or "-m64" compiler flags on x86.
2 parents e3c306a + c716d40 commit af30f4c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,17 @@ if(CMAKE_COMPILER_IS_GNUCXX)
296296
# Don't use -rpath.
297297
set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
298298

299-
set(CMAKE_C_FLAGS "-m${TARGET_PLATFORM} ${CMAKE_C_FLAGS}")
300-
set(CMAKE_CXX_FLAGS "-m${TARGET_PLATFORM} ${CMAKE_CXX_FLAGS}")
301-
set(CMAKE_Fortran_FLAGS "-m${TARGET_PLATFORM} ${CMAKE_Fortran_FLAGS}")
299+
# Need to determine the target machine of the C compiler, because
300+
# the '-m32' and '-m64' flags are supported on x86 but not on e.g. ARM.
301+
exec_program( "${CMAKE_C_COMPILER} -dumpmachine"
302+
OUTPUT_VARIABLE CMAKE_C_COMPILER_MACHINE )
303+
message( STATUS "CMAKE_C_COMPILER_MACHINE: ${CMAKE_C_COMPILER_MACHINE}" )
304+
# The "86" regular expression matches x86, x86_64, i686, etc.
305+
if(${CMAKE_C_COMPILER_MACHINE} MATCHES "86")
306+
set(CMAKE_C_FLAGS "-m${TARGET_PLATFORM} ${CMAKE_C_FLAGS}")
307+
set(CMAKE_CXX_FLAGS "-m${TARGET_PLATFORM} ${CMAKE_CXX_FLAGS}")
308+
set(CMAKE_Fortran_FLAGS "-m${TARGET_PLATFORM} ${CMAKE_Fortran_FLAGS}")
309+
endif()
302310

303311
if(TARGET_PLATFORM EQUAL 32)
304312
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin")

0 commit comments

Comments
 (0)