2015-01-13 22:35:23 +08:00
|
|
|
#
|
|
|
|
#//===----------------------------------------------------------------------===//
|
|
|
|
#//
|
|
|
|
#// The LLVM Compiler Infrastructure
|
|
|
|
#//
|
|
|
|
#// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
#// Source Licenses. See LICENSE.txt for details.
|
|
|
|
#//
|
|
|
|
#//===----------------------------------------------------------------------===//
|
|
|
|
#
|
|
|
|
|
|
|
|
# Determine the architecture from predefined compiler macros
|
|
|
|
# The architecture name can only contain alphanumeric characters and underscores (i.e., C identifier)
|
|
|
|
|
|
|
|
# void get_architecture(string* return_arch)
|
|
|
|
# - Returns the architecture in return_arch
|
2015-07-16 00:05:30 +08:00
|
|
|
function(libomp_get_architecture return_arch)
|
2015-07-16 00:57:19 +08:00
|
|
|
set(detect_arch_src_txt "
|
2015-01-13 22:35:23 +08:00
|
|
|
#if defined(__KNC__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=mic
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=x86_64
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__i386) || defined(__i386__) || defined(__IA32__) || defined(_M_I86) || defined(_M_IX86) || defined(__X86__) || defined(_X86_)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=i386
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=arm
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6ZK__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=arm
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=arm
|
2015-07-16 00:05:30 +08:00
|
|
|
#elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=arm
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=arm
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__ARM_ARCH_2__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=arm
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__arm__) || defined(_M_ARM) || defined(_ARM)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=arm
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__aarch64__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=aarch64
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=ppc64le
|
2015-01-13 22:35:23 +08:00
|
|
|
#elif defined(__powerpc64__)
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=ppc64
|
2016-12-08 17:22:24 +08:00
|
|
|
#elif defined(__mips__) && defined(__mips64)
|
|
|
|
#error ARCHITECTURE=mips64
|
|
|
|
#elif defined(__mips__) && !defined(__mips64)
|
|
|
|
#error ARCHITECTURE=mips
|
2015-01-13 22:35:23 +08:00
|
|
|
#else
|
2015-07-16 00:57:19 +08:00
|
|
|
#error ARCHITECTURE=UnknownArchitecture
|
2015-01-13 22:35:23 +08:00
|
|
|
#endif
|
2015-07-16 00:57:19 +08:00
|
|
|
")
|
|
|
|
# Write out ${detect_arch_src_txt} to a file within the cmake/ subdirectory
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" ${detect_arch_src_txt})
|
2015-01-13 22:35:23 +08:00
|
|
|
|
2015-07-16 00:57:19 +08:00
|
|
|
# Try to compile using the C Compiler. It will always error out with an #error directive, so store error output to ${local_architecture}
|
|
|
|
try_run(run_dummy compile_dummy "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c" COMPILE_OUTPUT_VARIABLE local_architecture)
|
2015-01-13 22:35:23 +08:00
|
|
|
|
2015-07-16 00:57:19 +08:00
|
|
|
# Match the important architecture line and store only that matching string in ${local_architecture}
|
|
|
|
string(REGEX MATCH "ARCHITECTURE=([a-zA-Z0-9_]+)" local_architecture "${local_architecture}")
|
2015-01-13 22:35:23 +08:00
|
|
|
|
2015-07-16 00:57:19 +08:00
|
|
|
# Get rid of the ARCHITECTURE= part of the string
|
|
|
|
string(REPLACE "ARCHITECTURE=" "" local_architecture "${local_architecture}")
|
2015-01-13 22:35:23 +08:00
|
|
|
|
2015-07-16 00:57:19 +08:00
|
|
|
# set the return value to the architecture detected (e.g., 32e, 32, arm, ppc64, etc.)
|
|
|
|
set(${return_arch} "${local_architecture}" PARENT_SCOPE)
|
2015-01-13 22:35:23 +08:00
|
|
|
|
2015-07-16 00:57:19 +08:00
|
|
|
# Remove ${detect_arch_src_txt} from cmake/ subdirectory
|
|
|
|
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c")
|
2015-01-13 22:35:23 +08:00
|
|
|
endfunction()
|