forked from OSchip/llvm-project
[CMake] Properly detect whether we're building runtime for i386 or i686.
llvm-svn: 230569
This commit is contained in:
parent
dbdab4037e
commit
819045cdd6
|
@ -1,3 +1,4 @@
|
||||||
|
include(CMakePushCheckState)
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
include(CheckLibraryExists)
|
include(CheckLibraryExists)
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
|
@ -70,19 +71,39 @@ set(COMPILER_RT_SUPPORTED_ARCH)
|
||||||
set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
|
set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
|
||||||
file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
|
file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
|
||||||
|
|
||||||
# test_target_arch(<arch> <target flags...>)
|
function(check_compile_definition def argstring out_var)
|
||||||
# Sets the target flags for a given architecture and determines if this
|
if("${def}" STREQUAL "")
|
||||||
# architecture is supported by trying to build a simple file.
|
set(${out_var} TRUE PARENT_SCOPE)
|
||||||
macro(test_target_arch arch)
|
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(TARGET_${arch}_CFLAGS ${ARGN})
|
||||||
set(argstring "${CMAKE_EXE_LINKER_FLAGS}")
|
set(argstring "")
|
||||||
foreach(arg ${ARGN})
|
foreach(arg ${ARGN})
|
||||||
set(argstring "${argstring} ${arg}")
|
set(argstring "${argstring} ${arg}")
|
||||||
endforeach()
|
endforeach()
|
||||||
try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
|
check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
|
||||||
COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
|
if(NOT HAS_${arch}_DEF)
|
||||||
OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
|
set(CAN_TARGET_${arch} FALSE)
|
||||||
CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
|
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}})
|
if(${CAN_TARGET_${arch}})
|
||||||
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
|
||||||
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}")
|
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}")
|
||||||
|
@ -139,33 +160,34 @@ if(ANDROID)
|
||||||
else()
|
else()
|
||||||
if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
|
if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
test_target_arch(x86_64 "-m64")
|
test_target_arch(x86_64 "" "-m64")
|
||||||
test_target_arch(i386 "-m32")
|
test_target_arch(i386 __i386__ "-m32")
|
||||||
|
test_target_arch(i686 __i686__ "-m32")
|
||||||
else()
|
else()
|
||||||
test_target_arch(i386 "")
|
test_target_arch(i386 "" "")
|
||||||
endif()
|
endif()
|
||||||
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
|
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
|
||||||
TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
|
TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
|
||||||
if(HOST_IS_BIG_ENDIAN)
|
if(HOST_IS_BIG_ENDIAN)
|
||||||
test_target_arch(powerpc64 "-m64")
|
test_target_arch(powerpc64 "" "-m64")
|
||||||
else()
|
else()
|
||||||
test_target_arch(powerpc64le "-m64")
|
test_target_arch(powerpc64le "" "-m64")
|
||||||
endif()
|
endif()
|
||||||
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
|
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
|
||||||
if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "mipsel|mips64el")
|
if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "mipsel|mips64el")
|
||||||
# regex for mipsel, mips64el
|
# regex for mipsel, mips64el
|
||||||
test_target_arch(mipsel "-m32")
|
test_target_arch(mipsel "" "-m32")
|
||||||
test_target_arch(mips64el "-m64")
|
test_target_arch(mips64el "" "-m64")
|
||||||
else()
|
else()
|
||||||
test_target_arch(mips "-m32")
|
test_target_arch(mips "" "-m32")
|
||||||
test_target_arch(mips64 "-m64")
|
test_target_arch(mips64 "" "-m64")
|
||||||
endif()
|
endif()
|
||||||
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm")
|
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")
|
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")
|
elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch64")
|
||||||
test_target_arch(aarch64 "-march=armv8-a")
|
test_target_arch(aarch64 "" "-march=armv8-a")
|
||||||
endif()
|
endif()
|
||||||
set(COMPILER_RT_OS_SUFFIX "")
|
set(COMPILER_RT_OS_SUFFIX "")
|
||||||
endif()
|
endif()
|
||||||
|
|
Loading…
Reference in New Issue