blob: bd798d6070b190f6c2d10c32d64a74cfbe2901b6 [file] [log] [blame]
Jonathan Peyton2e013352015-07-15 16:05:30 +00001#
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
12include(CheckCCompilerFlag)
13include(CheckCSourceCompiles)
14include(CheckCXXCompilerFlag)
15include(CheckLibraryExists)
16include(LibompCheckLinkerFlag)
17include(LibompCheckFortranFlag)
18
19# Check for versioned symbols
20function(libomp_check_version_symbols retval)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000021 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 Peyton2e013352015-07-15 16:05:30 +000038endfunction()
39
40# Includes the architecture flag in both compile and link phase
41function(libomp_check_architecture_flag flag retval)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000042 set(CMAKE_REQUIRED_FLAGS "${flag}")
43 check_c_compiler_flag("${flag}" ${retval})
44 set(${retval} ${${retval}} PARENT_SCOPE)
Jonathan Peyton2e013352015-07-15 16:05:30 +000045endfunction()
46
47# Checking C, CXX, Linker Flags
48check_cxx_compiler_flag(-std=c++11 LIBOMP_HAVE_STD_CPP11_FLAG)
49check_cxx_compiler_flag(-fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG)
50check_c_compiler_flag("-x c++" LIBOMP_HAVE_X_CPP_FLAG)
51check_cxx_compiler_flag(-Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG)
52check_cxx_compiler_flag(-Wswitch LIBOMP_HAVE_WNO_SWITCH_FLAG)
53check_cxx_compiler_flag(-Wdeprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG)
54check_cxx_compiler_flag(-Wsign-compare LIBOMP_HAVE_WSIGN_COMPARE_FLAG)
55check_cxx_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG)
56check_cxx_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
57libomp_check_architecture_flag(-mmic LIBOMP_HAVE_MMIC_FLAG)
58libomp_check_architecture_flag(-m32 LIBOMP_HAVE_M32_FLAG)
59if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000060 # 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 Peyton2e013352015-07-15 16:05:30 +000079 endforeach()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000080 endforeach()
Jonathan Peyton2e013352015-07-15 16:05:30 +000081else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000082 # 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 Peyton2e013352015-07-15 16:05:30 +000086endif()
87if(${LIBOMP_FORTRAN_MODULES})
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000088 libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
Jonathan Peyton2e013352015-07-15 16:05:30 +000089endif()
90
91# Check linker flags
92if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000093 libomp_check_linker_flag(/SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
Jonathan Peyton2e013352015-07-15 16:05:30 +000094elseif(NOT APPLE)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000095 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 Peyton2e013352015-07-15 16:05:30 +0000102endif()
103
104# Check Intel(R) C Compiler specific flags
105if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000106 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 Peyton2e013352015-07-15 16:05:30 +0000115endif()
116
117# Checking Threading requirements
118find_package(Threads REQUIRED)
119if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000120 if(NOT CMAKE_USE_WIN32_THREADS_INIT)
121 libomp_error_say("Need Win32 thread interface on Windows.")
122 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000123else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000124 if(NOT CMAKE_USE_PTHREADS_INIT)
125 libomp_error_say("Need pthread interface on Unix-like systems.")
126 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000127endif()
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
131find_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.
137if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000138 set(LIBOMP_PERL_SCRIPT_OS win)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000139elseif(APPLE)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000140 set(LIBOMP_PERL_SCRIPT_OS mac)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000141else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000142 set(LIBOMP_PERL_SCRIPT_OS lin)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000143endif()
144
145# Checking features
146# Check if version symbol assembler directives are supported
147libomp_check_version_symbols(LIBOMP_HAVE_VERSION_SYMBOLS)
148
149# Check if quad precision types are available
150if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000151 set(LIBOMP_HAVE_QUAD_PRECISION TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000152elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000153 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 Peyton2e013352015-07-15 16:05:30 +0000158else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000159 set(LIBOMP_HAVE_QUAD_PRECISION FALSE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000160endif()
161
162# Check if adaptive locks are available
163if((${IA32} OR ${INTEL64}) AND NOT MSVC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000164 set(LIBOMP_HAVE_ADAPTIVE_LOCKS TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000165else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000166 set(LIBOMP_HAVE_ADAPTIVE_LOCKS FALSE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000167endif()
168
169# Check if stats-gathering is available
170if(NOT (WIN32 OR APPLE) AND (${IA32} OR ${INTEL64} OR ${MIC}))
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000171 set(LIBOMP_HAVE_STATS TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000172else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000173 set(LIBOMP_HAVE_STATS FALSE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000174endif()
175
176# Check if OMPT support is available
177if(NOT WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000178 set(LIBOMP_HAVE_OMPT_SUPPORT TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000179else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000180 set(LIBOMP_HAVE_OMPT_SUPPORT FALSE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000181endif()