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