summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH-Plus-Time <hydrogenplustime@gmail.com>2017-04-25 04:52:09 +1000
committerAlon Zakai <alonzakai@gmail.com>2017-04-24 11:52:09 -0700
commita0b162d13c7e8d5df1f1b6e33efd4d9e3f699aa9 (patch)
treea883e6026b02da601972eeb50652fe7bbb18b7a3
parentb16768ec9b72d075ae2e36cc85aa216fdf4fd354 (diff)
downloadbinaryen-a0b162d13c7e8d5df1f1b6e33efd4d9e3f699aa9.tar.gz
binaryen-a0b162d13c7e8d5df1f1b6e33efd4d9e3f699aa9.tar.bz2
binaryen-a0b162d13c7e8d5df1f1b6e33efd4d9e3f699aa9.zip
Fixed issue 965 as per @binji's wabt fix (#978)
* Fixed issue 965 as per @binji's wabt fix, add platform-specific build options, which fixes building on ARM. * Added logging for platform-specific flags
-rw-r--r--CMakeLists.txt49
1 files changed, 47 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6c75b5688..46e22b7e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -95,8 +95,53 @@ ELSE()
SET(CMAKE_THREAD_PREFER_PTHREAD ON)
FIND_PACKAGE(Threads REQUIRED)
ADD_COMPILE_FLAG("-std=c++11")
- ADD_COMPILE_FLAG("-msse2")
- ADD_COMPILE_FLAG("-mfpmath=sse")
+ if (NOT EMSCRIPTEN)
+ # try to get the target architecture by compiling a dummy.c file and
+ # checking the architecture using the file command.
+ file(WRITE ${PROJECT_BINARY_DIR}/dummy.c "main(){}")
+ try_compile(
+ COMPILE_OK
+ ${PROJECT_BINARY_DIR}
+ ${PROJECT_BINARY_DIR}/dummy.c
+ COPY_FILE ${PROJECT_BINARY_DIR}/dummy
+ )
+ if (COMPILE_OK)
+ execute_process(
+ COMMAND file ${PROJECT_BINARY_DIR}/dummy
+ RESULT_VARIABLE FILE_RESULT
+ OUTPUT_VARIABLE FILE_OUTPUT
+ ERROR_QUIET
+ )
+
+ if (FILE_RESULT EQUAL 0)
+ if (${FILE_OUTPUT} MATCHES "x86[-_]64")
+ set(TARGET_ARCH "x86-64")
+ elseif (${FILE_OUTPUT} MATCHES "Intel 80386")
+ set(TARGET_ARCH "i386")
+ elseif (${FILE_OUTPUT} MATCHES "ARM")
+ set(TARGET_ARCH "ARM")
+ else ()
+ message(WARNING "Unknown target architecture!")
+ endif ()
+ if(TARGET_ARCH)
+ MESSAGE(STATUS "Building for platform ${TARGET_ARCH}")
+ endif ()
+ else ()
+ message(WARNING "Error running file on dummy executable")
+ endif ()
+ else ()
+ message(WARNING "Error compiling dummy.c file")
+ endif ()
+
+ if (TARGET_ARCH STREQUAL "i386")
+ # wasm doesn't allow for x87 floating point math
+ ADD_COMPILE_FLAG("-msse2")
+ ADD_COMPILE_FLAG("-mfpmath=sse")
+ elseif(TARGET_ARCH STREQUAL "ARM")
+ # stub for ARM-specific instructions. GCC6 adds NEON with the below flags
+ ADD_COMPILE_FLAG("-march=native")
+ endif ()
+ endif ()
ADD_COMPILE_FLAG("-Wall")
ADD_COMPILE_FLAG("-Werror")
ADD_COMPILE_FLAG("-Wextra")