blob: bc4604ffda96856635645ec72e8c24b5058c342b [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)
21 set(source_code
22"#include <stdio.h>
23void func1() { printf(\"Hello\"); }
24void func2() { printf(\"World\"); }
25__asm__(\".symver func1, func@VER1\");
26__asm__(\".symver func2, func@VER2\");
27int 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)
38endfunction()
39
40# Includes the architecture flag in both compile and link phase
41function(libomp_check_architecture_flag flag retval)
42 set(CMAKE_REQUIRED_FLAGS "${flag}")
43 check_c_compiler_flag("${flag}" ${retval})
44 set(${retval} ${${retval}} PARENT_SCOPE)
45endfunction()
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)
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 )
79 endforeach()
80 endforeach()
81else()
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)
86endif()
87if(${LIBOMP_FORTRAN_MODULES})
88 libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
89endif()
90
91# Check linker flags
92if(WIN32)
93 libomp_check_linker_flag(/SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
94elseif(NOT APPLE)
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)
102endif()
103
104# Check Intel(R) C Compiler specific flags
105if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
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)
115endif()
116
117# Checking Threading requirements
118find_package(Threads REQUIRED)
119if(WIN32)
120 if(NOT CMAKE_USE_WIN32_THREADS_INIT)
121 libomp_error_say("Need Win32 thread interface on Windows.")
122 endif()
123else()
124 if(NOT CMAKE_USE_PTHREADS_INIT)
125 libomp_error_say("Need pthread interface on Unix-like systems.")
126 endif()
127endif()
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)
138 set(LIBOMP_PERL_SCRIPT_OS win)
139elseif(APPLE)
140 set(LIBOMP_PERL_SCRIPT_OS mac)
141else()
142 set(LIBOMP_PERL_SCRIPT_OS lin)
143endif()
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")
151 set(LIBOMP_HAVE_QUAD_PRECISION TRUE)
152elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
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()
158else()
159 set(LIBOMP_HAVE_QUAD_PRECISION FALSE)
160endif()
161
162# Check if adaptive locks are available
163if((${IA32} OR ${INTEL64}) AND NOT MSVC)
164 set(LIBOMP_HAVE_ADAPTIVE_LOCKS TRUE)
165else()
166 set(LIBOMP_HAVE_ADAPTIVE_LOCKS FALSE)
167endif()
168
169# Check if stats-gathering is available
170if(NOT (WIN32 OR APPLE) AND (${IA32} OR ${INTEL64} OR ${MIC}))
171 set(LIBOMP_HAVE_STATS TRUE)
172else()
173 set(LIBOMP_HAVE_STATS FALSE)
174endif()
175
176# Check if OMPT support is available
177if(NOT WIN32)
178 set(LIBOMP_HAVE_OMPT_SUPPORT TRUE)
179else()
180 set(LIBOMP_HAVE_OMPT_SUPPORT FALSE)
181endif()