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