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) |
Jonathan Peyton | 69e596a | 2015-10-29 20:56:24 +0000 | [diff] [blame^] | 16 | include(CheckIncludeFiles) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 17 | include(LibompCheckLinkerFlag) |
| 18 | include(LibompCheckFortranFlag) |
| 19 | |
| 20 | # Check for versioned symbols |
| 21 | function(libomp_check_version_symbols retval) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 22 | set(source_code |
| 23 | "#include <stdio.h> |
| 24 | void func1() { printf(\"Hello\"); } |
| 25 | void func2() { printf(\"World\"); } |
| 26 | __asm__(\".symver func1, func@VER1\"); |
| 27 | __asm__(\".symver func2, func@VER2\"); |
| 28 | int main() { |
| 29 | func1(); |
| 30 | func2(); |
| 31 | return 0; |
| 32 | }") |
| 33 | set(version_script_source "VER1 { }; VER2 { } VER1;") |
| 34 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt "${version_script_source}") |
| 35 | set(CMAKE_REQUIRED_FLAGS -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt) |
| 36 | check_c_source_compiles("${source_code}" ${retval}) |
| 37 | set(${retval} ${${retval}} PARENT_SCOPE) |
| 38 | file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 39 | endfunction() |
| 40 | |
| 41 | # Includes the architecture flag in both compile and link phase |
| 42 | function(libomp_check_architecture_flag flag retval) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 43 | set(CMAKE_REQUIRED_FLAGS "${flag}") |
| 44 | check_c_compiler_flag("${flag}" ${retval}) |
| 45 | set(${retval} ${${retval}} PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 46 | endfunction() |
| 47 | |
| 48 | # Checking C, CXX, Linker Flags |
| 49 | check_cxx_compiler_flag(-std=c++11 LIBOMP_HAVE_STD_CPP11_FLAG) |
| 50 | check_cxx_compiler_flag(-fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG) |
| 51 | check_c_compiler_flag("-x c++" LIBOMP_HAVE_X_CPP_FLAG) |
Chandler Carruth | 5145156 | 2015-07-18 03:14:02 +0000 | [diff] [blame] | 52 | check_c_compiler_flag(-Werror LIBOMP_HAVE_WERROR_FLAG) |
| 53 | check_c_compiler_flag(-Wunused-function LIBOMP_HAVE_WNO_UNUSED_FUNCTION_FLAG) |
| 54 | check_c_compiler_flag(-Wunused-local-typedef LIBOMP_HAVE_WNO_UNUSED_LOCAL_TYPEDEF_FLAG) |
| 55 | check_c_compiler_flag(-Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG) |
| 56 | check_c_compiler_flag(-Wunused-variable LIBOMP_HAVE_WNO_UNUSED_VARIABLE_FLAG) |
| 57 | check_c_compiler_flag(-Wswitch LIBOMP_HAVE_WNO_SWITCH_FLAG) |
| 58 | check_c_compiler_flag(-Wcovered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG) |
| 59 | check_c_compiler_flag(-Wdeprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG) |
| 60 | check_c_compiler_flag(-Wsign-compare LIBOMP_HAVE_WNO_SIGN_COMPARE_FLAG) |
| 61 | check_c_compiler_flag(-Wgnu-anonymous-struct LIBOMP_HAVE_WNO_GNU_ANONYMOUS_STRUCT_FLAG) |
| 62 | check_c_compiler_flag(-Wunknown-pragmas LIBOMP_HAVE_WNO_UNKNOWN_PRAGMAS_FLAG) |
| 63 | check_c_compiler_flag(-Wmissing-field-initializers LIBOMP_HAVE_WNO_MISSING_FIELD_INITIALIZERS_FLAG) |
| 64 | check_c_compiler_flag(-Wmissing-braces LIBOMP_HAVE_WNO_MISSING_BRACES_FLAG) |
| 65 | check_c_compiler_flag(-Wcomment LIBOMP_HAVE_WNO_COMMENT_FLAG) |
| 66 | check_c_compiler_flag(-Wself-assign LIBOMP_HAVE_WNO_SELF_ASSIGN_FLAG) |
| 67 | check_c_compiler_flag(-Wvla-extension LIBOMP_HAVE_WNO_VLA_EXTENSION_FLAG) |
| 68 | check_c_compiler_flag(-Wformat-pedantic LIBOMP_HAVE_WNO_FORMAT_PEDANTIC_FLAG) |
| 69 | check_c_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG) |
| 70 | check_c_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 71 | libomp_check_architecture_flag(-mmic LIBOMP_HAVE_MMIC_FLAG) |
| 72 | libomp_check_architecture_flag(-m32 LIBOMP_HAVE_M32_FLAG) |
| 73 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 74 | # Check Windows MSVC style flags. |
| 75 | check_c_compiler_flag(/TP LIBOMP_HAVE_TP_FLAG) |
| 76 | check_cxx_compiler_flag(/EHsc LIBOMP_HAVE_EHSC_FLAG) |
| 77 | check_cxx_compiler_flag(/GS LIBOMP_HAVE_GS_FLAG) |
| 78 | check_cxx_compiler_flag(/Oy- LIBOMP_HAVE_Oy__FLAG) |
| 79 | check_cxx_compiler_flag(/arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG) |
| 80 | check_cxx_compiler_flag(/Qsafeseh LIBOMP_HAVE_QSAFESEH_FLAG) |
| 81 | # It is difficult to create a dummy masm assembly file |
| 82 | # and then check the MASM assembler to see if these flags exist and work, |
| 83 | # so we assume they do for Windows. |
| 84 | set(LIBOMP_HAVE_SAFESEH_MASM_FLAG TRUE) |
| 85 | set(LIBOMP_HAVE_COFF_MASM_FLAG TRUE) |
| 86 | # Change Windows flags /MDx to /MTx |
| 87 | foreach(libomp_lang IN ITEMS C CXX) |
| 88 | foreach(libomp_btype IN ITEMS DEBUG RELWITHDEBINFO RELEASE MINSIZEREL) |
| 89 | string(REPLACE "/MD" "/MT" |
| 90 | CMAKE_${libomp_lang}_FLAGS_${libomp_btype} |
| 91 | "${CMAKE_${libomp_lang}_FLAGS_${libomp_btype}}" |
| 92 | ) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 93 | endforeach() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 94 | endforeach() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 95 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 96 | # It is difficult to create a dummy assembly file that compiles into an |
| 97 | # exectuable for every architecture and then check the C compiler to |
| 98 | # see if -x assembler-with-cpp exists and works, so we assume it does for non-Windows. |
| 99 | set(LIBOMP_HAVE_X_ASSEMBLER_WITH_CPP_FLAG TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 100 | endif() |
| 101 | if(${LIBOMP_FORTRAN_MODULES}) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 102 | libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 103 | endif() |
| 104 | |
| 105 | # Check linker flags |
| 106 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 107 | libomp_check_linker_flag(/SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 108 | elseif(NOT APPLE) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 109 | libomp_check_linker_flag(-Wl,-x LIBOMP_HAVE_X_FLAG) |
| 110 | libomp_check_linker_flag(-Wl,--warn-shared-textrel LIBOMP_HAVE_WARN_SHARED_TEXTREL_FLAG) |
| 111 | libomp_check_linker_flag(-Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG) |
| 112 | libomp_check_linker_flag("-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG) |
| 113 | libomp_check_linker_flag(-static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG) |
| 114 | libomp_check_linker_flag(-Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG) |
| 115 | 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] | 116 | endif() |
| 117 | |
| 118 | # Check Intel(R) C Compiler specific flags |
| 119 | if(CMAKE_C_COMPILER_ID STREQUAL "Intel") |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 120 | check_cxx_compiler_flag(/Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG) |
| 121 | check_cxx_compiler_flag(/Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG) |
| 122 | check_cxx_compiler_flag(/Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG) |
| 123 | check_cxx_compiler_flag(-Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) |
| 124 | check_cxx_compiler_flag(-falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) |
| 125 | check_cxx_compiler_flag("-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG) |
| 126 | libomp_check_linker_flag(-static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) |
| 127 | libomp_check_linker_flag(-no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG) |
| 128 | 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] | 129 | endif() |
| 130 | |
| 131 | # Checking Threading requirements |
| 132 | find_package(Threads REQUIRED) |
| 133 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 134 | if(NOT CMAKE_USE_WIN32_THREADS_INIT) |
| 135 | libomp_error_say("Need Win32 thread interface on Windows.") |
| 136 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 137 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 138 | if(NOT CMAKE_USE_PTHREADS_INIT) |
| 139 | libomp_error_say("Need pthread interface on Unix-like systems.") |
| 140 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 141 | endif() |
| 142 | |
| 143 | # Find perl executable |
| 144 | # Perl is used to create omp.h (and other headers) along with kmp_i18n_id.inc and kmp_i18n_default.inc |
| 145 | find_package(Perl REQUIRED) |
| 146 | # The perl scripts take the --os= flag which expects a certain format for operating systems. Until the |
| 147 | # perl scripts are removed, the most portable way to handle this is to have all operating systems that |
| 148 | # are neither Windows nor Mac (Most Unix flavors) be considered lin to the perl scripts. This is rooted |
| 149 | # in that all the Perl scripts check the operating system and will fail if it isn't "valid". This |
| 150 | # temporary solution lets us avoid trying to enumerate all the possible OS values inside the Perl modules. |
| 151 | if(WIN32) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 152 | set(LIBOMP_PERL_SCRIPT_OS win) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 153 | elseif(APPLE) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 154 | set(LIBOMP_PERL_SCRIPT_OS mac) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 155 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 156 | set(LIBOMP_PERL_SCRIPT_OS lin) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 157 | endif() |
| 158 | |
| 159 | # Checking features |
| 160 | # Check if version symbol assembler directives are supported |
| 161 | libomp_check_version_symbols(LIBOMP_HAVE_VERSION_SYMBOLS) |
| 162 | |
| 163 | # Check if quad precision types are available |
| 164 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 165 | set(LIBOMP_HAVE_QUAD_PRECISION TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 166 | elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel") |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 167 | if(LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) |
| 168 | set(LIBOMP_HAVE_QUAD_PRECISION TRUE) |
| 169 | else() |
| 170 | set(LIBOMP_HAVE_QUAD_PRECISION TRUE) |
| 171 | endif() |
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_QUAD_PRECISION FALSE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 174 | endif() |
| 175 | |
| 176 | # Check if adaptive locks are available |
| 177 | if((${IA32} OR ${INTEL64}) AND NOT MSVC) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 178 | set(LIBOMP_HAVE_ADAPTIVE_LOCKS 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_ADAPTIVE_LOCKS FALSE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 181 | endif() |
| 182 | |
| 183 | # Check if stats-gathering is available |
| 184 | if(NOT (WIN32 OR APPLE) AND (${IA32} OR ${INTEL64} OR ${MIC})) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 185 | set(LIBOMP_HAVE_STATS TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 186 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 187 | set(LIBOMP_HAVE_STATS FALSE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 188 | endif() |
| 189 | |
| 190 | # Check if OMPT support is available |
Jonathan Peyton | 69e596a | 2015-10-29 20:56:24 +0000 | [diff] [blame^] | 191 | # Currently, __builtin_frame_address() is required for OMPT |
| 192 | # Weak attribute is required for Unices, LIBPSAPI is used for Windows |
| 193 | check_c_source_compiles("int main(int argc, char** argv) { |
| 194 | void* p = __builtin_frame_address(0); |
| 195 | return 0;}" LIBOMP_HAVE___BUILTIN_FRAME_ADDRESS) |
| 196 | check_c_source_compiles("__attribute__ ((weak)) int foo(int a) { return a*a; } |
| 197 | int main(int argc, char** argv) { |
| 198 | return foo(argc);}" LIBOMP_HAVE_WEAK_ATTRIBUTE) |
| 199 | check_include_files("windows.h;psapi.h" LIBOMP_HAVE_PSAPI_H) |
| 200 | check_library_exists(psapi EnumProcessModules "" LIBOMP_HAVE_LIBPSAPI) |
| 201 | if(LIBOMP_HAVE_PSAPI_H AND LIBOMP_HAVE_LIBPSAPI) |
| 202 | set(LIBOMP_HAVE_PSAPI TRUE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 203 | endif() |
Jonathan Peyton | 69e596a | 2015-10-29 20:56:24 +0000 | [diff] [blame^] | 204 | if(NOT LIBOMP_HAVE___BUILTIN_FRAME_ADDRESS) |
| 205 | set(LIBOMP_HAVE_OMPT_SUPPORT FALSE) |
| 206 | else() |
| 207 | if(LIBOMP_HAVE_WEAK_ATTRIBUTE OR LIBOMP_HAVE_PSAPI) |
| 208 | set(LIBOMP_HAVE_OMPT_SUPPORT TRUE) |
| 209 | else() |
| 210 | set(LIBOMP_HAVE_OMPT_SUPPORT FALSE) |
| 211 | endif() |
| 212 | endif() |
| 213 | |