OSDN Git Service

Remove stro(u?)ll() config checks. Those were needed pre-MSVC2013, but we require...
[android-x86/external-llvm.git] / cmake / config-ix.cmake
1 if( WIN32 AND NOT CYGWIN )
2   # We consider Cygwin as another Unix
3   set(PURE_WINDOWS 1)
4 endif()
5
6 include(CheckIncludeFile)
7 include(CheckIncludeFileCXX)
8 include(CheckLibraryExists)
9 include(CheckSymbolExists)
10 include(CheckFunctionExists)
11 include(CheckCCompilerFlag)
12 include(CheckCXXSourceCompiles)
13 include(TestBigEndian)
14
15 include(CheckCompilerVersion)
16 include(HandleLLVMStdlib)
17
18 if( UNIX AND NOT (BEOS OR HAIKU) )
19   # Used by check_symbol_exists:
20   list(APPEND CMAKE_REQUIRED_LIBRARIES "m")
21 endif()
22 # x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.
23 if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND
24     CMAKE_SIZEOF_VOID_P EQUAL 8 )
25   list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt")
26 endif()
27
28 # include checks
29 check_include_file(dirent.h HAVE_DIRENT_H)
30 check_include_file(dlfcn.h HAVE_DLFCN_H)
31 check_include_file(errno.h HAVE_ERRNO_H)
32 check_include_file(fcntl.h HAVE_FCNTL_H)
33 check_include_file(link.h HAVE_LINK_H)
34 check_include_file(malloc.h HAVE_MALLOC_H)
35 check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
36 check_include_file(ndir.h HAVE_NDIR_H)
37 if( NOT PURE_WINDOWS )
38   check_include_file(pthread.h HAVE_PTHREAD_H)
39 endif()
40 check_include_file(signal.h HAVE_SIGNAL_H)
41 check_include_file(sys/dir.h HAVE_SYS_DIR_H)
42 check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
43 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
44 check_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
45 check_include_file(sys/param.h HAVE_SYS_PARAM_H)
46 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
47 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
48 check_include_file(sys/time.h HAVE_SYS_TIME_H)
49 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
50 check_include_file(termios.h HAVE_TERMIOS_H)
51 check_include_file(unistd.h HAVE_UNISTD_H)
52 check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
53 check_include_file(zlib.h HAVE_ZLIB_H)
54 check_include_file(fenv.h HAVE_FENV_H)
55 check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
56 check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
57
58 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
59 check_include_file(histedit.h HAVE_HISTEDIT_H)
60 check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
61 if(APPLE)
62   include(CheckCSourceCompiles)
63   CHECK_C_SOURCE_COMPILES("
64      static const char *__crashreporter_info__ = 0;
65      asm(\".desc ___crashreporter_info__, 0x10\");
66      int main() { return 0; }"
67     HAVE_CRASHREPORTER_INFO)
68 endif()
69
70 if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
71   check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H)
72   if(NOT HAVE_LINUX_MAGIC_H)
73     # older kernels use split files
74     check_include_file(linux/nfs_fs.h HAVE_LINUX_NFS_FS_H)
75     check_include_file(linux/smb.h HAVE_LINUX_SMB_H)
76   endif()
77 endif()
78
79 # library checks
80 if( NOT PURE_WINDOWS )
81   check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
82   if (HAVE_LIBPTHREAD)
83     check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
84     check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
85     check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
86   else()
87     # this could be Android
88     check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)
89     if (PTHREAD_IN_LIBC)
90       check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
91       check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
92       check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
93     endif()
94   endif()
95   check_library_exists(dl dlopen "" HAVE_LIBDL)
96   check_library_exists(rt clock_gettime "" HAVE_LIBRT)
97 endif()
98
99 if(HAVE_LIBPTHREAD)
100   # We want to find pthreads library and at the moment we do want to
101   # have it reported as '-l<lib>' instead of '-pthread'.
102   # TODO: switch to -pthread once the rest of the build system can deal with it.
103   set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
104   set(THREADS_HAVE_PTHREAD_ARG Off)
105   find_package(Threads REQUIRED)
106   set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
107 endif()
108
109 # Don't look for these libraries if we're using MSan, since uninstrumented third
110 # party code may call MSan interceptors like strlen, leading to false positives.
111 if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
112   set(HAVE_LIBZ 0)
113   if(LLVM_ENABLE_ZLIB)
114     foreach(library z zlib_static zlib)
115       string(TOUPPER ${library} library_suffix)
116       check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix})
117       if(HAVE_LIBZ_${library_suffix})
118         set(HAVE_LIBZ 1)
119         set(ZLIB_LIBRARIES "${library}")
120         break()
121       endif()
122     endforeach()
123   endif()
124
125   # Don't look for these libraries on Windows.
126   if (NOT PURE_WINDOWS)
127     # Skip libedit if using ASan as it contains memory leaks.
128     if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")
129       check_library_exists(edit el_init "" HAVE_LIBEDIT)
130     else()
131       set(HAVE_LIBEDIT 0)
132     endif()
133     if(LLVM_ENABLE_TERMINFO)
134       set(HAVE_TERMINFO 0)
135       foreach(library tinfo terminfo curses ncurses ncursesw)
136         string(TOUPPER ${library} library_suffix)
137         check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
138         if(HAVE_TERMINFO_${library_suffix})
139           set(HAVE_TERMINFO 1)
140           set(TERMINFO_LIBS "${library}")
141           break()
142         endif()
143       endforeach()
144     else()
145       set(HAVE_TERMINFO 0)
146     endif()
147
148     find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c)
149     set(LLVM_LIBXML2_ENABLED 0)
150     set(LIBXML2_FOUND 0)
151     if((LLVM_ENABLE_LIBXML2) AND ((CMAKE_SYSTEM_NAME MATCHES "Linux") AND (ICONV_LIBRARY_PATH) OR APPLE))
152       find_package(LibXml2)
153       if (LIBXML2_FOUND)
154         set(LLVM_LIBXML2_ENABLED 1)
155         include_directories(${LIBXML2_INCLUDE_DIR})
156         set(LIBXML2_LIBS "xml2")
157       endif()
158     endif()
159   endif()
160 endif()
161
162 if (LLVM_ENABLE_LIBXML2 STREQUAL "FORCE_ON" AND NOT LLVM_LIBXML2_ENABLED)
163   message(FATAL_ERROR "Failed to congifure libxml2")
164 endif()
165
166 check_library_exists(xar xar_open "" HAVE_LIBXAR)
167 if(HAVE_LIBXAR)
168   set(XAR_LIB xar)
169 endif()
170
171 # function checks
172 check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
173 find_package(Backtrace)
174 set(HAVE_BACKTRACE ${Backtrace_FOUND})
175 set(BACKTRACE_HEADER ${Backtrace_HEADER})
176
177 # Prevent check_symbol_exists from using API that is not supported for a given
178 # deployment target.
179 check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW")
180 if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW)
181   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new")
182 endif()
183
184 check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE)
185 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
186 check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
187 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
188 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
189 check_symbol_exists(isatty unistd.h HAVE_ISATTY)
190 check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
191 check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
192 check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE)
193 # AddressSanitizer conflicts with lib/Support/Unix/Signals.inc
194 # Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it
195 # (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind
196 # past the signal handler after an assertion failure (rdar://29866587).
197 if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )
198   check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
199 endif()
200 set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE")
201 check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)
202 set(CMAKE_REQUIRED_DEFINITIONS "")
203 check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
204 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
205 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
206                     HAVE_MALLOC_ZONE_STATISTICS)
207 check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
208 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
209 check_symbol_exists(pread unistd.h HAVE_PREAD)
210 check_symbol_exists(realpath stdlib.h HAVE_REALPATH)
211 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
212 check_symbol_exists(strerror string.h HAVE_STRERROR)
213 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
214 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
215 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
216 if( PURE_WINDOWS )
217   check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
218
219   check_function_exists(_alloca HAVE__ALLOCA)
220   check_function_exists(__alloca HAVE___ALLOCA)
221   check_function_exists(__chkstk HAVE___CHKSTK)
222   check_function_exists(__chkstk_ms HAVE___CHKSTK_MS)
223   check_function_exists(___chkstk HAVE____CHKSTK)
224   check_function_exists(___chkstk_ms HAVE____CHKSTK_MS)
225
226   check_function_exists(__ashldi3 HAVE___ASHLDI3)
227   check_function_exists(__ashrdi3 HAVE___ASHRDI3)
228   check_function_exists(__divdi3 HAVE___DIVDI3)
229   check_function_exists(__fixdfdi HAVE___FIXDFDI)
230   check_function_exists(__fixsfdi HAVE___FIXSFDI)
231   check_function_exists(__floatdidf HAVE___FLOATDIDF)
232   check_function_exists(__lshrdi3 HAVE___LSHRDI3)
233   check_function_exists(__moddi3 HAVE___MODDI3)
234   check_function_exists(__udivdi3 HAVE___UDIVDI3)
235   check_function_exists(__umoddi3 HAVE___UMODDI3)
236
237   check_function_exists(__main HAVE___MAIN)
238   check_function_exists(__cmpdi2 HAVE___CMPDI2)
239 endif()
240 if( HAVE_DLFCN_H )
241   if( HAVE_LIBDL )
242     list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
243   endif()
244   check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
245   check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR)
246   if( HAVE_LIBDL )
247     list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
248   endif()
249 endif()
250
251 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
252 if( LLVM_USING_GLIBC )
253   add_definitions( -D_GNU_SOURCE )
254   list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
255 endif()
256 # This check requires _GNU_SOURCE
257 check_symbol_exists(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY)
258 check_symbol_exists(CPU_COUNT sched.h HAVE_CPU_COUNT)
259 if(HAVE_LIBPTHREAD)
260   check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
261   check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
262 elseif(PTHREAD_IN_LIBC)
263   check_library_exists(c pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP)
264   check_library_exists(c pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP)
265 endif()
266
267 # available programs checks
268 function(llvm_find_program name)
269   string(TOUPPER ${name} NAME)
270   string(REGEX REPLACE "\\." "_" NAME ${NAME})
271
272   find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
273   mark_as_advanced(LLVM_PATH_${NAME})
274   if(LLVM_PATH_${NAME})
275     set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
276     mark_as_advanced(HAVE_${NAME})
277   else(LLVM_PATH_${NAME})
278     set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
279   endif(LLVM_PATH_${NAME})
280 endfunction()
281
282 if (LLVM_ENABLE_DOXYGEN)
283   llvm_find_program(dot)
284 endif ()
285
286 if( LLVM_ENABLE_FFI )
287   find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
288   if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" )
289     set(FFI_HEADER ffi.h CACHE INTERNAL "")
290     set(HAVE_FFI_H 1 CACHE INTERNAL "")
291   else()
292     find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
293     if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" )
294       set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
295       set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
296     endif()
297   endif()
298
299   if( NOT FFI_HEADER )
300     message(FATAL_ERROR "libffi includes are not found.")
301   endif()
302
303   find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
304   if( NOT FFI_LIBRARY_PATH )
305     message(FATAL_ERROR "libffi is not found.")
306   endif()
307
308   list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
309   list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
310   check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
311   list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
312   list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
313 else()
314   unset(HAVE_FFI_FFI_H CACHE)
315   unset(HAVE_FFI_H CACHE)
316   unset(HAVE_FFI_CALL CACHE)
317 endif( LLVM_ENABLE_FFI )
318
319 # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
320 include(CheckAtomic)
321
322 if( LLVM_ENABLE_PIC )
323   set(ENABLE_PIC 1)
324 else()
325   set(ENABLE_PIC 0)
326   check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG)
327   if(SUPPORTS_NO_PIE_FLAG)
328     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
329   endif()
330 endif()
331
332 check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG)
333 check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments"
334                         SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
335
336 set(USE_NO_MAYBE_UNINITIALIZED 0)
337 set(USE_NO_UNINITIALIZED 0)
338
339 # Disable gcc's potentially uninitialized use analysis as it presents lots of
340 # false positives.
341 if (CMAKE_COMPILER_IS_GNUCXX)
342   check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
343   if (HAS_MAYBE_UNINITIALIZED)
344     set(USE_NO_MAYBE_UNINITIALIZED 1)
345   else()
346     # Only recent versions of gcc make the distinction between -Wuninitialized
347     # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
348     # turn off all uninitialized use warnings.
349     check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
350     set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
351   endif()
352 endif()
353
354 # By default, we target the host, but this can be overridden at CMake
355 # invocation time.
356 include(GetHostTriple)
357 get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
358
359 set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
360     "Host on which LLVM binaries will run")
361
362 # Determine the native architecture.
363 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
364 if( LLVM_NATIVE_ARCH STREQUAL "host" )
365   string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
366 endif ()
367
368 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
369   set(LLVM_NATIVE_ARCH X86)
370 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
371   set(LLVM_NATIVE_ARCH X86)
372 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
373   set(LLVM_NATIVE_ARCH X86)
374 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
375   set(LLVM_NATIVE_ARCH X86)
376 elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
377   set(LLVM_NATIVE_ARCH Sparc)
378 elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
379   set(LLVM_NATIVE_ARCH PowerPC)
380 elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
381   set(LLVM_NATIVE_ARCH AArch64)
382 elseif (LLVM_NATIVE_ARCH MATCHES "arm64")
383   set(LLVM_NATIVE_ARCH AArch64)
384 elseif (LLVM_NATIVE_ARCH MATCHES "arm")
385   set(LLVM_NATIVE_ARCH ARM)
386 elseif (LLVM_NATIVE_ARCH MATCHES "mips")
387   set(LLVM_NATIVE_ARCH Mips)
388 elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
389   set(LLVM_NATIVE_ARCH XCore)
390 elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
391   set(LLVM_NATIVE_ARCH MSP430)
392 elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
393   set(LLVM_NATIVE_ARCH Hexagon)
394 elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
395   set(LLVM_NATIVE_ARCH SystemZ)
396 elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
397   set(LLVM_NATIVE_ARCH WebAssembly)
398 elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
399   set(LLVM_NATIVE_ARCH WebAssembly)
400 elseif (LLVM_NATIVE_ARCH MATCHES "riscv32")
401   set(LLVM_NATIVE_ARCH RISCV)
402 elseif (LLVM_NATIVE_ARCH MATCHES "riscv64")
403   set(LLVM_NATIVE_ARCH RISCV)
404 else ()
405   message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
406 endif ()
407
408 # If build targets includes "host", then replace with native architecture.
409 list(FIND LLVM_TARGETS_TO_BUILD "host" idx)
410 if( NOT idx LESS 0 )
411   list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
412   list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
413   list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
414 endif()
415
416 list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
417 if (NATIVE_ARCH_IDX EQUAL -1)
418   message(STATUS
419     "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
420 else ()
421   message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
422   set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
423   set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
424   set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
425   set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
426
427   # We don't have an ASM parser for all architectures yet.
428   if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
429     set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
430   endif ()
431
432   # We don't have an disassembler for all architectures yet.
433   if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
434     set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
435   endif ()
436 endif ()
437
438 if( MINGW )
439   set(HAVE_LIBPSAPI 1)
440   set(HAVE_LIBSHELL32 1)
441   # TODO: Check existence of libraries.
442   #   include(CheckLibraryExists)
443 endif( MINGW )
444
445 if( MSVC )
446   set(SHLIBEXT ".lib")
447   set(stricmp "_stricmp")
448   set(strdup "_strdup")
449
450   # See if the DIA SDK is available and usable.
451   set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
452
453   # Due to a bug in MSVC 2013's installation software, it is possible
454   # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
455   # install directory.  If this happens, the installation is corrupt
456   # and there's nothing we can do.  It happens with enough frequency
457   # though that we should handle it.  We do so by simply checking that
458   # the DIA SDK folder exists.  Should this happen you will need to
459   # uninstall VS 2012 and then re-install VS 2013.
460   if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
461     set(HAVE_DIA_SDK 1)
462   else()
463     set(HAVE_DIA_SDK 0)
464   endif()
465
466   option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available."
467                              ${HAVE_DIA_SDK})
468
469   if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK)
470     message(FATAL_ERROR "DIA SDK not found. If you have both VS 2012 and 2013 installed, you may need to uninstall the former and re-install the latter afterwards.")
471   endif()
472 else()
473   set(LLVM_ENABLE_DIA_SDK 0)
474 endif( MSVC )
475
476 # FIXME: Signal handler return type, currently hardcoded to 'void'
477 set(RETSIGTYPE void)
478
479 if( LLVM_ENABLE_THREADS )
480   # Check if threading primitives aren't supported on this platform
481   if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
482     set(LLVM_ENABLE_THREADS 0)
483   endif()
484 endif()
485
486 if( LLVM_ENABLE_THREADS )
487   message(STATUS "Threads enabled.")
488 else( LLVM_ENABLE_THREADS )
489   message(STATUS "Threads disabled.")
490 endif()
491
492 if (LLVM_ENABLE_ZLIB )
493   # Check if zlib is available in the system.
494   if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
495     set(LLVM_ENABLE_ZLIB 0)
496   endif()
497 endif()
498
499 if (LLVM_ENABLE_DOXYGEN)
500   message(STATUS "Doxygen enabled.")
501   find_package(Doxygen REQUIRED)
502
503   if (DOXYGEN_FOUND)
504     # If we find doxygen and we want to enable doxygen by default create a
505     # global aggregate doxygen target for generating llvm and any/all
506     # subprojects doxygen documentation.
507     if (LLVM_BUILD_DOCS)
508       add_custom_target(doxygen ALL)
509     endif()
510
511     option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
512     if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
513       set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.")
514       set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
515     endif()
516   endif()
517 else()
518   message(STATUS "Doxygen disabled.")
519 endif()
520
521 set(LLVM_BINDINGS "")
522 if(WIN32)
523   message(STATUS "Go bindings disabled.")
524 else()
525   find_program(GO_EXECUTABLE NAMES go DOC "go executable")
526   if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND")
527     message(STATUS "Go bindings disabled.")
528   else()
529     execute_process(COMMAND ${GO_EXECUTABLE} run ${PROJECT_SOURCE_DIR}/bindings/go/conftest.go
530                     RESULT_VARIABLE GO_CONFTEST)
531     if(GO_CONFTEST STREQUAL "0")
532       set(LLVM_BINDINGS "${LLVM_BINDINGS} go")
533       message(STATUS "Go bindings enabled.")
534     else()
535       message(STATUS "Go bindings disabled, need at least Go 1.2.")
536     endif()
537   endif()
538 endif()
539
540 find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker")
541 set(LLVM_BINUTILS_INCDIR "" CACHE PATH
542         "PATH to binutils/include containing plugin-api.h for gold plugin.")
543
544 if(CMAKE_HOST_APPLE AND APPLE)
545   if(NOT CMAKE_XCRUN)
546     find_program(CMAKE_XCRUN NAMES xcrun)
547   endif()
548   if(CMAKE_XCRUN)
549     execute_process(COMMAND ${CMAKE_XCRUN} -find ld
550       OUTPUT_VARIABLE LD64_EXECUTABLE
551       OUTPUT_STRIP_TRAILING_WHITESPACE)
552   else()
553     find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker")
554   endif()
555
556   if(LD64_EXECUTABLE)
557     set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable")
558     message(STATUS "Found ld64 - ${LD64_EXECUTABLE}")
559   endif()
560 endif()
561
562 # Keep the version requirements in sync with bindings/ocaml/README.txt.
563 include(FindOCaml)
564 include(AddOCaml)
565 if(WIN32)
566   message(STATUS "OCaml bindings disabled.")
567 else()
568   find_package(OCaml)
569   if( NOT OCAML_FOUND )
570     message(STATUS "OCaml bindings disabled.")
571   else()
572     if( OCAML_VERSION VERSION_LESS "4.00.0" )
573       message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.")
574     else()
575       find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL)
576       if( HAVE_OCAML_CTYPES )
577         message(STATUS "OCaml bindings enabled.")
578         find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
579         set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
580
581         set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING
582             "Install directory for LLVM OCaml packages")
583       else()
584         message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
585       endif()
586     endif()
587   endif()
588 endif()
589
590 string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")
591
592 function(find_python_module module)
593   string(REPLACE "." "_" module_name ${module})
594   string(TOUPPER ${module_name} module_upper)
595   set(FOUND_VAR PY_${module_upper}_FOUND)
596
597   execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}"
598     RESULT_VARIABLE status
599     ERROR_QUIET)
600
601   if(status)
602     set(${FOUND_VAR} 0 PARENT_SCOPE)
603     message(STATUS "Could NOT find Python module ${module}")
604   else()
605     set(${FOUND_VAR} 1 PARENT_SCOPE)
606     message(STATUS "Found Python module ${module}")
607   endif()
608 endfunction()
609
610 set (PYTHON_MODULES
611   pygments
612   # Some systems still don't have pygments.lexers.c_cpp which was introduced in
613   # version 2.0 in 2014...
614   pygments.lexers.c_cpp
615   yaml
616   )
617 foreach(module ${PYTHON_MODULES})
618   find_python_module(${module})
619 endforeach()
620
621 if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND)
622   set (LLVM_HAVE_OPT_VIEWER_MODULES 1)
623 else()
624   set (LLVM_HAVE_OPT_VIEWER_MODULES 0)
625 endif()