summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2015-02-25 23:07:32 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2015-02-25 23:07:32 +0000
commit84c0804900ddc9da76e08a24c95d34b1dd81f92a (patch)
tree007e0c8dd5bfaf3851276203cc33977dd86dbb5f /cmake
parent46ee47654c1bed3080be442d953c46f874f1f408 (diff)
[CMake] Properly detect whether we're building runtime for i386 or i686.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230569 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/config-ix.cmake64
1 files changed, 43 insertions, 21 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 97a22cbdc..48f9117e4 100644
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -1,3 +1,4 @@
+include(CMakePushCheckState)
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
include(CheckSymbolExists)
@@ -70,19 +71,39 @@ set(COMPILER_RT_SUPPORTED_ARCH)
set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
-# test_target_arch(<arch> <target flags...>)
-# Sets the target flags for a given architecture and determines if this
-# architecture is supported by trying to build a simple file.
-macro(test_target_arch arch)
+function(check_compile_definition def argstring out_var)
+ if("${def}" STREQUAL "")
+ set(${out_var} TRUE PARENT_SCOPE)
+ return()
+ endif()
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
+ check_symbol_exists(${def} "" ${out_var})
+ cmake_pop_check_state()
+endfunction()
+
+# test_target_arch(<arch> <def> <target flags...>)
+# Checks if architecture is supported: runs host compiler with provided
+# flags to verify that:
+# 1) <def> is defined (if non-empty)
+# 2) simple file can be successfully built.
+# If successful, saves target flags for this architecture.
+macro(test_target_arch arch def)
set(TARGET_${arch}_CFLAGS ${ARGN})
- set(argstring "${CMAKE_EXE_LINKER_FLAGS}")
+ set(argstring "")
foreach(arg ${ARGN})
set(argstring "${argstring} ${arg}")
endforeach()
- try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
- COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
- OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
- CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
+ check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
+ if(NOT HAS_${arch}_DEF)
+ set(CAN_TARGET_${arch} FALSE)
+ else()
+ set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
+ try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
+ COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
+ OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
+ CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
+ endif()
if(${CAN_TARGET_${arch}})
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}")
@@ -139,33 +160,34 @@ if(ANDROID)
else()
if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
if(NOT MSVC)
- test_target_arch(x86_64 "-m64")
- test_target_arch(i386 "-m32")
+ test_target_arch(x86_64 "" "-m64")
+ test_target_arch(i386 __i386__ "-m32")
+ test_target_arch(i686 __i686__ "-m32")
else()
- test_target_arch(i386 "")
+ test_target_arch(i386 "" "")
endif()
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
if(HOST_IS_BIG_ENDIAN)
- test_target_arch(powerpc64 "-m64")
+ test_target_arch(powerpc64 "" "-m64")
else()
- test_target_arch(powerpc64le "-m64")
+ test_target_arch(powerpc64le "" "-m64")
endif()
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "mipsel|mips64el")
# regex for mipsel, mips64el
- test_target_arch(mipsel "-m32")
- test_target_arch(mips64el "-m64")
+ test_target_arch(mipsel "" "-m32")
+ test_target_arch(mips64el "" "-m64")
else()
- test_target_arch(mips "-m32")
- test_target_arch(mips64 "-m64")
+ test_target_arch(mips "" "-m32")
+ test_target_arch(mips64 "" "-m64")
endif()
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm")
- test_target_arch(arm "-march=armv7-a")
+ test_target_arch(arm "" "-march=armv7-a")
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch32")
- test_target_arch(aarch32 "-march=armv8-a")
+ test_target_arch(aarch32 "" "-march=armv8-a")
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch64")
- test_target_arch(aarch64 "-march=armv8-a")
+ test_target_arch(aarch64 "" "-march=armv8-a")
endif()
set(COMPILER_RT_OS_SUFFIX "")
endif()