blob: b1f8b6711c032d0407d0a9e5dc3edb4174a4934c [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)
Jonathan Peyton01dcf362015-11-30 20:02:59 +000015include(CheckIncludeFile)
Jonathan Peyton2e013352015-07-15 16:05:30 +000016include(CheckLibraryExists)
Jonathan Peyton69e596a2015-10-29 20:56:24 +000017include(CheckIncludeFiles)
Jonathan Peyton2e013352015-07-15 16:05:30 +000018include(LibompCheckLinkerFlag)
19include(LibompCheckFortranFlag)
20
21# Check for versioned symbols
22function(libomp_check_version_symbols retval)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000023 set(source_code
24 "#include <stdio.h>
25 void func1() { printf(\"Hello\"); }
26 void func2() { printf(\"World\"); }
27 __asm__(\".symver func1, func@VER1\");
28 __asm__(\".symver func2, func@VER2\");
29 int main() {
30 func1();
31 func2();
32 return 0;
33 }")
34 set(version_script_source "VER1 { }; VER2 { } VER1;")
35 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt "${version_script_source}")
36 set(CMAKE_REQUIRED_FLAGS -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt)
37 check_c_source_compiles("${source_code}" ${retval})
38 set(${retval} ${${retval}} PARENT_SCOPE)
39 file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/__version_script.txt)
Jonathan Peyton2e013352015-07-15 16:05:30 +000040endfunction()
41
42# Includes the architecture flag in both compile and link phase
43function(libomp_check_architecture_flag flag retval)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000044 set(CMAKE_REQUIRED_FLAGS "${flag}")
45 check_c_compiler_flag("${flag}" ${retval})
46 set(${retval} ${${retval}} PARENT_SCOPE)
Jonathan Peyton2e013352015-07-15 16:05:30 +000047endfunction()
48
49# Checking C, CXX, Linker Flags
50check_cxx_compiler_flag(-std=c++11 LIBOMP_HAVE_STD_CPP11_FLAG)
51check_cxx_compiler_flag(-fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG)
52check_c_compiler_flag("-x c++" LIBOMP_HAVE_X_CPP_FLAG)
Chandler Carruth51451562015-07-18 03:14:02 +000053check_c_compiler_flag(-Werror LIBOMP_HAVE_WERROR_FLAG)
54check_c_compiler_flag(-Wunused-function LIBOMP_HAVE_WNO_UNUSED_FUNCTION_FLAG)
55check_c_compiler_flag(-Wunused-local-typedef LIBOMP_HAVE_WNO_UNUSED_LOCAL_TYPEDEF_FLAG)
56check_c_compiler_flag(-Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG)
57check_c_compiler_flag(-Wunused-variable LIBOMP_HAVE_WNO_UNUSED_VARIABLE_FLAG)
58check_c_compiler_flag(-Wswitch LIBOMP_HAVE_WNO_SWITCH_FLAG)
59check_c_compiler_flag(-Wcovered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG)
60check_c_compiler_flag(-Wdeprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG)
61check_c_compiler_flag(-Wsign-compare LIBOMP_HAVE_WNO_SIGN_COMPARE_FLAG)
62check_c_compiler_flag(-Wgnu-anonymous-struct LIBOMP_HAVE_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
63check_c_compiler_flag(-Wunknown-pragmas LIBOMP_HAVE_WNO_UNKNOWN_PRAGMAS_FLAG)
64check_c_compiler_flag(-Wmissing-field-initializers LIBOMP_HAVE_WNO_MISSING_FIELD_INITIALIZERS_FLAG)
65check_c_compiler_flag(-Wmissing-braces LIBOMP_HAVE_WNO_MISSING_BRACES_FLAG)
66check_c_compiler_flag(-Wcomment LIBOMP_HAVE_WNO_COMMENT_FLAG)
67check_c_compiler_flag(-Wself-assign LIBOMP_HAVE_WNO_SELF_ASSIGN_FLAG)
68check_c_compiler_flag(-Wvla-extension LIBOMP_HAVE_WNO_VLA_EXTENSION_FLAG)
69check_c_compiler_flag(-Wformat-pedantic LIBOMP_HAVE_WNO_FORMAT_PEDANTIC_FLAG)
70check_c_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG)
71check_c_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
Jonathan Peyton2e013352015-07-15 16:05:30 +000072libomp_check_architecture_flag(-mmic LIBOMP_HAVE_MMIC_FLAG)
73libomp_check_architecture_flag(-m32 LIBOMP_HAVE_M32_FLAG)
74if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000075 # Check Windows MSVC style flags.
76 check_c_compiler_flag(/TP LIBOMP_HAVE_TP_FLAG)
77 check_cxx_compiler_flag(/EHsc LIBOMP_HAVE_EHSC_FLAG)
78 check_cxx_compiler_flag(/GS LIBOMP_HAVE_GS_FLAG)
79 check_cxx_compiler_flag(/Oy- LIBOMP_HAVE_Oy__FLAG)
80 check_cxx_compiler_flag(/arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG)
81 check_cxx_compiler_flag(/Qsafeseh LIBOMP_HAVE_QSAFESEH_FLAG)
82 # It is difficult to create a dummy masm assembly file
83 # and then check the MASM assembler to see if these flags exist and work,
84 # so we assume they do for Windows.
85 set(LIBOMP_HAVE_SAFESEH_MASM_FLAG TRUE)
86 set(LIBOMP_HAVE_COFF_MASM_FLAG TRUE)
87 # Change Windows flags /MDx to /MTx
88 foreach(libomp_lang IN ITEMS C CXX)
89 foreach(libomp_btype IN ITEMS DEBUG RELWITHDEBINFO RELEASE MINSIZEREL)
90 string(REPLACE "/MD" "/MT"
91 CMAKE_${libomp_lang}_FLAGS_${libomp_btype}
92 "${CMAKE_${libomp_lang}_FLAGS_${libomp_btype}}"
93 )
Jonathan Peyton2e013352015-07-15 16:05:30 +000094 endforeach()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000095 endforeach()
Jonathan Peyton2e013352015-07-15 16:05:30 +000096else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000097 # It is difficult to create a dummy assembly file that compiles into an
98 # exectuable for every architecture and then check the C compiler to
99 # see if -x assembler-with-cpp exists and works, so we assume it does for non-Windows.
100 set(LIBOMP_HAVE_X_ASSEMBLER_WITH_CPP_FLAG TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000101endif()
102if(${LIBOMP_FORTRAN_MODULES})
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000103 libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000104endif()
105
106# Check linker flags
107if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000108 libomp_check_linker_flag(/SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000109elseif(NOT APPLE)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000110 libomp_check_linker_flag(-Wl,-x LIBOMP_HAVE_X_FLAG)
111 libomp_check_linker_flag(-Wl,--warn-shared-textrel LIBOMP_HAVE_WARN_SHARED_TEXTREL_FLAG)
112 libomp_check_linker_flag(-Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG)
113 libomp_check_linker_flag("-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
114 libomp_check_linker_flag(-static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG)
115 libomp_check_linker_flag(-Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG)
116 libomp_check_linker_flag(-Wl,-fini=__kmp_internal_end_fini LIBOMP_HAVE_FINI_FLAG)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000117endif()
118
119# Check Intel(R) C Compiler specific flags
120if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000121 check_cxx_compiler_flag(/Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG)
122 check_cxx_compiler_flag(/Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG)
123 check_cxx_compiler_flag(/Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG)
124 check_cxx_compiler_flag(-Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG)
125 check_cxx_compiler_flag(-falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG)
126 check_cxx_compiler_flag("-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG)
127 libomp_check_linker_flag(-static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG)
128 libomp_check_linker_flag(-no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG)
129 check_library_exists(irc_pic _intel_fast_memcpy "" LIBOMP_HAVE_IRC_PIC_LIBRARY)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000130endif()
131
132# Checking Threading requirements
133find_package(Threads REQUIRED)
134if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000135 if(NOT CMAKE_USE_WIN32_THREADS_INIT)
136 libomp_error_say("Need Win32 thread interface on Windows.")
137 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000138else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000139 if(NOT CMAKE_USE_PTHREADS_INIT)
140 libomp_error_say("Need pthread interface on Unix-like systems.")
141 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000142endif()
143
144# Find perl executable
145# Perl is used to create omp.h (and other headers) along with kmp_i18n_id.inc and kmp_i18n_default.inc
146find_package(Perl REQUIRED)
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000147# The perl scripts take the --os=/--arch= flags which expect a certain format for operating systems and arch's.
148# Until the perl scripts are removed, the most portable way to handle this is to have all operating systems that
Jonathan Peyton2e013352015-07-15 16:05:30 +0000149# are neither Windows nor Mac (Most Unix flavors) be considered lin to the perl scripts. This is rooted
150# in that all the Perl scripts check the operating system and will fail if it isn't "valid". This
151# temporary solution lets us avoid trying to enumerate all the possible OS values inside the Perl modules.
152if(WIN32)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000153 set(LIBOMP_PERL_SCRIPT_OS win)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000154elseif(APPLE)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000155 set(LIBOMP_PERL_SCRIPT_OS mac)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000156else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000157 set(LIBOMP_PERL_SCRIPT_OS lin)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000158endif()
Jonathan Peyton4c91ad12016-01-26 19:44:31 +0000159if(IA32)
160 set(LIBOMP_PERL_SCRIPT_ARCH 32)
161elseif(MIC)
162 set(LIBOMP_PERL_SCRIPT_ARCH mic)
163elseif(INTEL64)
164 set(LIBOMP_PERL_SCRIPT_ARCH 32e)
165else()
166 set(LIBOMP_PERL_SCRIPT_ARCH ${LIBOMP_ARCH})
167endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000168
169# Checking features
170# Check if version symbol assembler directives are supported
171libomp_check_version_symbols(LIBOMP_HAVE_VERSION_SYMBOLS)
172
173# Check if quad precision types are available
174if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000175 set(LIBOMP_HAVE_QUAD_PRECISION TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000176elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000177 if(LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG)
178 set(LIBOMP_HAVE_QUAD_PRECISION TRUE)
179 else()
180 set(LIBOMP_HAVE_QUAD_PRECISION TRUE)
181 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000182else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000183 set(LIBOMP_HAVE_QUAD_PRECISION FALSE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000184endif()
185
186# Check if adaptive locks are available
187if((${IA32} OR ${INTEL64}) AND NOT MSVC)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000188 set(LIBOMP_HAVE_ADAPTIVE_LOCKS TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000189else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000190 set(LIBOMP_HAVE_ADAPTIVE_LOCKS FALSE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000191endif()
192
193# Check if stats-gathering is available
Jonathan Peytonb9e83262015-12-18 16:19:35 +0000194if(${LIBOMP_STATS})
195 check_c_source_compiles(
196 "__thread int x;
Jonathan Peyton975dabc2016-05-17 20:51:24 +0000197 int main(int argc, char** argv)
Jonathan Peytonb9e83262015-12-18 16:19:35 +0000198 { x = argc; return x; }"
199 LIBOMP_HAVE___THREAD)
200 check_c_source_compiles(
Jonathan Peyton975dabc2016-05-17 20:51:24 +0000201 "int main(int argc, char** argv)
Jonathan Peytonb9e83262015-12-18 16:19:35 +0000202 { unsigned long long t = __builtin_readcyclecounter(); return 0; }"
203 LIBOMP_HAVE___BUILTIN_READCYCLECOUNTER)
204 if(NOT LIBOMP_HAVE___BUILTIN_READCYCLECOUNTER)
Jonathan Peyton316af8d2016-03-28 18:53:10 +0000205 if(${IA32} OR ${INTEL64} OR ${MIC})
Jonathan Peytonb9e83262015-12-18 16:19:35 +0000206 check_include_file(x86intrin.h LIBOMP_HAVE_X86INTRIN_H)
207 libomp_append(CMAKE_REQUIRED_DEFINITIONS -DLIBOMP_HAVE_X86INTRIN_H LIBOMP_HAVE_X86INTRIN_H)
208 check_c_source_compiles(
209 "#ifdef LIBOMP_HAVE_X86INTRIN_H
210 # include <x86intrin.h>
211 #endif
212 int main(int argc, char** argv) { unsigned long long t = __rdtsc(); return 0; }" LIBOMP_HAVE___RDTSC)
213 set(CMAKE_REQUIRED_DEFINITIONS)
214 endif()
215 endif()
216 if(LIBOMP_HAVE___THREAD AND (LIBOMP_HAVE___RDTSC OR LIBOMP_HAVE___BUILTIN_READCYCLECOUNTER))
217 set(LIBOMP_HAVE_STATS TRUE)
218 else()
219 set(LIBOMP_HAVE_STATS FALSE)
220 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000221endif()
222
223# Check if OMPT support is available
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000224# Currently, __builtin_frame_address() is required for OMPT
225# Weak attribute is required for Unices, LIBPSAPI is used for Windows
226check_c_source_compiles("int main(int argc, char** argv) {
227 void* p = __builtin_frame_address(0);
228 return 0;}" LIBOMP_HAVE___BUILTIN_FRAME_ADDRESS)
229check_c_source_compiles("__attribute__ ((weak)) int foo(int a) { return a*a; }
230 int main(int argc, char** argv) {
231 return foo(argc);}" LIBOMP_HAVE_WEAK_ATTRIBUTE)
232check_include_files("windows.h;psapi.h" LIBOMP_HAVE_PSAPI_H)
233check_library_exists(psapi EnumProcessModules "" LIBOMP_HAVE_LIBPSAPI)
234if(LIBOMP_HAVE_PSAPI_H AND LIBOMP_HAVE_LIBPSAPI)
235 set(LIBOMP_HAVE_PSAPI TRUE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000236endif()
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000237if(NOT LIBOMP_HAVE___BUILTIN_FRAME_ADDRESS)
238 set(LIBOMP_HAVE_OMPT_SUPPORT FALSE)
239else()
240 if(LIBOMP_HAVE_WEAK_ATTRIBUTE OR LIBOMP_HAVE_PSAPI)
241 set(LIBOMP_HAVE_OMPT_SUPPORT TRUE)
242 else()
243 set(LIBOMP_HAVE_OMPT_SUPPORT FALSE)
244 endif()
245endif()
246
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000247# Check if HWLOC support is available
248if(${LIBOMP_USE_HWLOC})
249 if(WIN32)
250 set(LIBOMP_HAVE_HWLOC FALSE)
251 libomp_say("Using hwloc not supported on Windows yet")
252 else()
253 set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INSTALL_DIR}/include)
254 check_include_file(hwloc.h LIBOMP_HAVE_HWLOC_H)
255 set(CMAKE_REQUIRED_INCLUDES)
Jonathan Peyton975dabc2016-05-17 20:51:24 +0000256 check_library_exists(hwloc hwloc_topology_init
Jonathan Peyton01dcf362015-11-30 20:02:59 +0000257 ${LIBOMP_HWLOC_INSTALL_DIR}/lib LIBOMP_HAVE_LIBHWLOC)
258 find_library(LIBOMP_HWLOC_LIBRARY hwloc ${LIBOMP_HWLOC_INSTALL_DIR}/lib)
259 get_filename_component(LIBOMP_HWLOC_LIBRARY_DIR ${LIBOMP_HWLOC_LIBRARY} PATH)
260 if(LIBOMP_HAVE_HWLOC_H AND LIBOMP_HAVE_LIBHWLOC AND LIBOMP_HWLOC_LIBRARY)
261 set(LIBOMP_HAVE_HWLOC TRUE)
262 else()
263 set(LIBOMP_HAVE_HWLOC FALSE)
264 libomp_say("Could not find hwloc")
265 endif()
266 endif()
267endif()
268