Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 1 | # |
| 2 | #//===----------------------------------------------------------------------===// |
| 3 | #// |
| 4 | #// The LLVM Compiler Infrastructure |
| 5 | #// |
| 6 | #// This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | #// Source Licenses. See LICENSE.txt for details. |
| 8 | #// |
| 9 | #//===----------------------------------------------------------------------===// |
| 10 | # |
| 11 | |
| 12 | include(CheckCCompilerFlag) |
| 13 | include(CheckCSourceCompiles) |
| 14 | include(CheckCXXCompilerFlag) |
| 15 | include(CheckLibraryExists) |
| 16 | include(LibompCheckLinkerFlag) |
| 17 | include(LibompCheckFortranFlag) |
| 18 | |
| 19 | # Check for versioned symbols |
| 20 | function(libomp_check_version_symbols retval) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 21 | set(source_code |
| 22 | "#include <stdio.h> |
| 23 | void func1() { printf(\"Hello\"); } |
| 24 | void func2() { printf(\"World\"); } |
| 25 | __asm__(\".symver func1, func@VER1\"); |
| 26 | __asm__(\".symver func2, func@VER2\"); |
| 27 | int main() { |
| 28 | func1(); |
| 29 | func2(); |
| 30 | return 0; |
| 31 | }") |
| 32 | set(version_script_source "VER1 { }; VER2 { } VER1;") |
| 33 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt "${version_script_source}") |
| 34 | set(CMAKE_REQUIRED_FLAGS -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt) |
| 35 | check_c_source_compiles("${source_code}" ${retval}) |
| 36 | set(${retval} ${${retval}} PARENT_SCOPE) |
| 37 | file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 38 | endfunction() |
| 39 | |
| 40 | # Includes the architecture flag in both compile and link phase |
| 41 | function(libomp_check_architecture_flag flag retval) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 42 | set(CMAKE_REQUIRED_FLAGS "${flag}") |
| 43 | check_c_compiler_flag("${flag}" ${retval}) |
| 44 | set(${retval} ${${retval}} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 45 | endfunction() |
| 46 | |
| 47 | # Checking C, CXX, Linker Flags |
| 48 | check_cxx_compiler_flag(-std=c++11 LIBOMP_HAVE_STD_CPP11_FLAG) |
| 49 | check_cxx_compiler_flag(-fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG) |
| 50 | check_c_compiler_flag("-x c++" LIBOMP_HAVE_X_CPP_FLAG) |
| 51 | check_cxx_compiler_flag(-Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG) |
| 52 | check_cxx_compiler_flag(-Wswitch LIBOMP_HAVE_WNO_SWITCH_FLAG) |
| 53 | check_cxx_compiler_flag(-Wdeprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG) |
| 54 | check_cxx_compiler_flag(-Wsign-compare LIBOMP_HAVE_WSIGN_COMPARE_FLAG) |
| 55 | check_cxx_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG) |
| 56 | check_cxx_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG) |
| 57 | libomp_check_architecture_flag(-mmic LIBOMP_HAVE_MMIC_FLAG) |
| 58 | libomp_check_architecture_flag(-m32 LIBOMP_HAVE_M32_FLAG) |
| 59 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 60 | # Check Windows MSVC style flags. |
| 61 | check_c_compiler_flag(/TP LIBOMP_HAVE_TP_FLAG) |
| 62 | check_cxx_compiler_flag(/EHsc LIBOMP_HAVE_EHSC_FLAG) |
| 63 | check_cxx_compiler_flag(/GS LIBOMP_HAVE_GS_FLAG) |
| 64 | check_cxx_compiler_flag(/Oy- LIBOMP_HAVE_Oy__FLAG) |
| 65 | check_cxx_compiler_flag(/arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG) |
| 66 | check_cxx_compiler_flag(/Qsafeseh LIBOMP_HAVE_QSAFESEH_FLAG) |
| 67 | # It is difficult to create a dummy masm assembly file |
| 68 | # and then check the MASM assembler to see if these flags exist and work, |
| 69 | # so we assume they do for Windows. |
| 70 | set(LIBOMP_HAVE_SAFESEH_MASM_FLAG TRUE) |
| 71 | set(LIBOMP_HAVE_COFF_MASM_FLAG TRUE) |
| 72 | # Change Windows flags /MDx to /MTx |
| 73 | foreach(libomp_lang IN ITEMS C CXX) |
| 74 | foreach(libomp_btype IN ITEMS DEBUG RELWITHDEBINFO RELEASE MINSIZEREL) |
| 75 | string(REPLACE "/MD" "/MT" |
| 76 | CMAKE_${libomp_lang}_FLAGS_${libomp_btype} |
| 77 | "${CMAKE_${libomp_lang}_FLAGS_${libomp_btype}}" |
| 78 | ) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 79 | endforeach() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 80 | endforeach() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 81 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 82 | # It is difficult to create a dummy assembly file that compiles into an |
| 83 | # exectuable for every architecture and then check the C compiler to |
| 84 | # see if -x assembler-with-cpp exists and works, so we assume it does for non-Windows. |
| 85 | set(LIBOMP_HAVE_X_ASSEMBLER_WITH_CPP_FLAG TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 86 | endif() |
| 87 | if(${LIBOMP_FORTRAN_MODULES}) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 88 | libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 89 | endif() |
| 90 | |
| 91 | # Check linker flags |
| 92 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 93 | libomp_check_linker_flag(/SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 94 | elseif(NOT APPLE) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 95 | libomp_check_linker_flag(-Wl,-x LIBOMP_HAVE_X_FLAG) |
| 96 | libomp_check_linker_flag(-Wl,--warn-shared-textrel LIBOMP_HAVE_WARN_SHARED_TEXTREL_FLAG) |
| 97 | libomp_check_linker_flag(-Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG) |
| 98 | libomp_check_linker_flag("-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) |
| 99 | libomp_check_linker_flag(-static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG) |
| 100 | libomp_check_linker_flag(-Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG) |
| 101 | libomp_check_linker_flag(-Wl,-fini=__kmp_internal_end_fini LIBOMP_HAVE_FINI_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 102 | endif() |
| 103 | |
| 104 | # Check Intel(R) C Compiler specific flags |
| 105 | if(CMAKE_C_COMPILER_ID STREQUAL "Intel") |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 106 | check_cxx_compiler_flag(/Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG) |
| 107 | check_cxx_compiler_flag(/Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG) |
| 108 | check_cxx_compiler_flag(/Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG) |
| 109 | check_cxx_compiler_flag(-Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) |
| 110 | check_cxx_compiler_flag(-falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) |
| 111 | check_cxx_compiler_flag("-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG) |
| 112 | libomp_check_linker_flag(-static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) |
| 113 | libomp_check_linker_flag(-no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG) |
| 114 | check_library_exists(irc_pic _intel_fast_memcpy "" LIBOMP_HAVE_IRC_PIC_LIBRARY) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 115 | endif() |
| 116 | |
| 117 | # Checking Threading requirements |
| 118 | find_package(Threads REQUIRED) |
| 119 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 120 | if(NOT CMAKE_USE_WIN32_THREADS_INIT) |
| 121 | libomp_error_say("Need Win32 thread interface on Windows.") |
| 122 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 123 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 124 | if(NOT CMAKE_USE_PTHREADS_INIT) |
| 125 | libomp_error_say("Need pthread interface on Unix-like systems.") |
| 126 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 127 | endif() |
| 128 | |
| 129 | # Find perl executable |
| 130 | # Perl is used to create omp.h (and other headers) along with kmp_i18n_id.inc and kmp_i18n_default.inc |
| 131 | find_package(Perl REQUIRED) |
| 132 | # The perl scripts take the --os= flag which expects a certain format for operating systems. Until the |
| 133 | # perl scripts are removed, the most portable way to handle this is to have all operating systems that |
| 134 | # are neither Windows nor Mac (Most Unix flavors) be considered lin to the perl scripts. This is rooted |
| 135 | # in that all the Perl scripts check the operating system and will fail if it isn't "valid". This |
| 136 | # temporary solution lets us avoid trying to enumerate all the possible OS values inside the Perl modules. |
| 137 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 138 | set(LIBOMP_PERL_SCRIPT_OS win) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 139 | elseif(APPLE) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 140 | set(LIBOMP_PERL_SCRIPT_OS mac) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 141 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 142 | set(LIBOMP_PERL_SCRIPT_OS lin) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 143 | endif() |
| 144 | |
| 145 | # Checking features |
| 146 | # Check if version symbol assembler directives are supported |
| 147 | libomp_check_version_symbols(LIBOMP_HAVE_VERSION_SYMBOLS) |
| 148 | |
| 149 | # Check if quad precision types are available |
| 150 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 151 | set(LIBOMP_HAVE_QUAD_PRECISION TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 152 | elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel") |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 153 | if(LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) |
| 154 | set(LIBOMP_HAVE_QUAD_PRECISION TRUE) |
| 155 | else() |
| 156 | set(LIBOMP_HAVE_QUAD_PRECISION TRUE) |
| 157 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 158 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 159 | set(LIBOMP_HAVE_QUAD_PRECISION FALSE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 160 | endif() |
| 161 | |
| 162 | # Check if adaptive locks are available |
| 163 | if((${IA32} OR ${INTEL64}) AND NOT MSVC) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 164 | set(LIBOMP_HAVE_ADAPTIVE_LOCKS TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 165 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 166 | set(LIBOMP_HAVE_ADAPTIVE_LOCKS FALSE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 167 | endif() |
| 168 | |
| 169 | # Check if stats-gathering is available |
| 170 | if(NOT (WIN32 OR APPLE) AND (${IA32} OR ${INTEL64} OR ${MIC})) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 171 | set(LIBOMP_HAVE_STATS TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 172 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 173 | set(LIBOMP_HAVE_STATS FALSE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 174 | endif() |
| 175 | |
| 176 | # Check if OMPT support is available |
| 177 | if(NOT WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 178 | set(LIBOMP_HAVE_OMPT_SUPPORT TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 179 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame^] | 180 | set(LIBOMP_HAVE_OMPT_SUPPORT FALSE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 181 | endif() |