diff options
author | Andrey Churbanov <Andrey.Churbanov@intel.com> | 2015-01-13 14:35:23 +0000 |
---|---|---|
committer | Andrey Churbanov <Andrey.Churbanov@intel.com> | 2015-01-13 14:35:23 +0000 |
commit | 17cce42f4b25ec55a86cd55cb4e7b141a891c0f0 (patch) | |
tree | 305e299fd8a581e5ff25199b2fd8a7d8318b45c9 | |
parent | 8bd9897730f5f2c238876ac407054c346dd46a21 (diff) | |
download | bcm5719-llvm-17cce42f4b25ec55a86cd55cb4e7b141a891c0f0.tar.gz bcm5719-llvm-17cce42f4b25ec55a86cd55cb4e7b141a891c0f0.zip |
Return the architecture by probing predefined compiler macros
llvm-svn: 225789
-rw-r--r-- | openmp/runtime/CMakeLists.txt | 23 | ||||
-rw-r--r-- | openmp/runtime/cmake/GetArchitecture.cmake | 67 |
2 files changed, 77 insertions, 13 deletions
diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt index b620f5af1c9..c8effe02f02 100644 --- a/openmp/runtime/CMakeLists.txt +++ b/openmp/runtime/CMakeLists.txt @@ -32,6 +32,7 @@ include(CommonFlags) # compiler, assembler, fortran, linker flags common for all include(SourceFiles) # source files to compile include(PerlFlags) # Perl flags for generate-def.pl and expand-vars.pl include(FindPerl) # Standard cmake module to check for Perl +include(GetArchitecture) # get_architecture() #################################################################### # CONFIGURATION @@ -56,30 +57,26 @@ set(lib_type_possible_values normal profile stubs) set(mic_arch_possible_values knf knc) set(mic_os_possible_values bsd lin) -# Below, cmake will try and determine the operating system and architecture for you (it assumes Intel architecture) +# Below, cmake will try and determine the operating system and architecture for you. # These values are set in CMakeCache.txt when cmake is first run (-Dvar_name=... will take precedence) # parameter | default value # ---------------------------- # Right now, this build system considers os=lin to mean "Unix-like that is not MAC" if(${APPLE}) # Apple goes first because CMake considers Mac to be a Unix based operating system, while libiomp5 considers it a special case - set(os mac CACHE STRING "The operating system to build for (lin/mac/win/mic)") + set(temp_os mac) elseif(${UNIX}) - set(os lin CACHE STRING "The operating system to build for (lin/mac/win/mic)") + set(temp_os lin) elseif(${WIN32}) - set(os win CACHE STRING "The operating system to build for (lin/mac/win/mic)") + set(temp_os win) else() - set(os lin CACHE STRING "The operating system to build for (lin/mac/win/mic)") + set(temp_os lin) endif() -# set to default architecture if the user did not specify an architecture explicitly -if(NOT arch) - if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") - set(arch 32 CACHE STRING "The architecture to build for (32e/32/arm/ppc64). 32e is Intel(R) 64 architecture, 32 is IA-32 architecture") - else() - set(arch 32e CACHE STRING "The architecture to build for (32e/32/arm/ppc64). 32e is Intel(R) 64 architecture, 32 is IA-32 architecture") - endif() -endif() +# If adding a new architecture, take a look at cmake/GetArchitecture.cmake +get_architecture(detected_arch) +set(os ${temp_os} CACHE STRING "The operating system to build for (lin/mac/win/mic)") +set(arch ${detected_arch} CACHE STRING "The architecture to build for (32e/32/arm/ppc64). 32e is Intel(R) 64 architecture, 32 is IA-32 architecture") set(lib_type normal CACHE STRING "Performance,Profiling,Stubs library (normal/profile/stubs)") set(version 5 CACHE STRING "Produce libguide (version 4) or libiomp5 (version 5)") set(omp_version 40 CACHE STRING "The OpenMP version (40/30)") diff --git a/openmp/runtime/cmake/GetArchitecture.cmake b/openmp/runtime/cmake/GetArchitecture.cmake new file mode 100644 index 00000000000..3b74bc0f80f --- /dev/null +++ b/openmp/runtime/cmake/GetArchitecture.cmake @@ -0,0 +1,67 @@ +# +#//===----------------------------------------------------------------------===// +#// +#// 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 +function(get_architecture return_arch) + set(detect_arch_src_txt " + #if defined(__KNC__) + #error ARCHITECTURE=mic + #elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) + #error ARCHITECTURE=32e + #elif defined(__i386) || defined(__i386__) || defined(__IA32__) || defined(_M_I86) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) + #error ARCHITECTURE=32 + #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) + #error ARCHITECTURE=arm + #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__) + #error ARCHITECTURE=arm + #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__) + #error ARCHITECTURE=arm + #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) + #error ARCHITECTURE=arm + #elif defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) + #error ARCHITECTURE=arm + #elif defined(__ARM_ARCH_2__) + #error ARCHITECTURE=arm + #elif defined(__arm__) || defined(_M_ARM) || defined(_ARM) + #error ARCHITECTURE=arm + #elif defined(__aarch64__) + #error ARCHITECTURE=aarch64 + #elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) + #error ARCHITECTURE=ppc64le + #elif defined(__powerpc64__) + #error ARCHITECTURE=ppc64 + #else + #error ARCHITECTURE=UnknownArchitecture + #endif + " + ) + # Write out ${detect_arch_src_txt} to a file within the cmake/ subdirectory + file(WRITE "${LIBOMP_WORK}/cmake/detect_arch.c" ${detect_arch_src_txt}) + + # 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}" "${LIBOMP_WORK}/cmake/detect_arch.c" COMPILE_OUTPUT_VARIABLE local_architecture) + + # 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}") + + # Get rid of the ARCHITECTURE= part of the string + string(REPLACE "ARCHITECTURE=" "" local_architecture "${local_architecture}") + + # set the return value to the architecture detected (e.g., 32e, 32, arm, ppc64, etc.) + set(${return_arch} "${local_architecture}" PARENT_SCOPE) + + # Remove ${detect_arch_src_txt} from cmake/ subdirectory + file(REMOVE "${LIBOMP_WORK}/cmake/detect_arch.c") +endfunction() |