[CMake] Add -stdlib=libc++ to host Clang build flags before performing any header...
[oota-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(CheckCXXSourceCompiles)
12 include(TestBigEndian)
13
14 if( UNIX AND NOT BEOS )
15   # Used by check_symbol_exists:
16   set(CMAKE_REQUIRED_LIBRARIES m)
17 endif()
18
19 # Helper macros and functions
20 macro(add_cxx_include result files)
21   set(${result} "")
22   foreach (file_name ${files})
23      set(${result} "${${result}}#include<${file_name}>\n")
24   endforeach()
25 endmacro(add_cxx_include files result)
26
27 function(check_type_exists type files variable)
28   add_cxx_include(includes "${files}")
29   CHECK_CXX_SOURCE_COMPILES("
30     ${includes} ${type} typeVar;
31     int main() {
32         return 0;
33     }
34     " ${variable})
35 endfunction()
36
37 function(append_if condition value)
38   if (${condition})
39     foreach(variable ${ARGN})
40       set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
41     endforeach(variable)
42   endif()
43 endfunction()
44
45 include(CheckCXXCompilerFlag)
46 if( LLVM_COMPILER_IS_GCC_COMPATIBLE )
47   if( LLVM_ENABLE_LIBCXX )
48     check_cxx_compiler_flag("-stdlib=libc++" CXX_SUPPORTS_STDLIB)
49     append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_CXX_FLAGS)
50     append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_EXE_LINKER_FLAGS)
51     append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_SHARED_LINKER_FLAGS)
52     append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_MODULE_LINKER_FLAGS)
53   endif()
54 endif()
55
56 # include checks
57 check_include_file_cxx(cxxabi.h HAVE_CXXABI_H)
58 check_include_file(dirent.h HAVE_DIRENT_H)
59 check_include_file(dlfcn.h HAVE_DLFCN_H)
60 check_include_file(errno.h HAVE_ERRNO_H)
61 check_include_file(execinfo.h HAVE_EXECINFO_H)
62 check_include_file(fcntl.h HAVE_FCNTL_H)
63 check_include_file(inttypes.h HAVE_INTTYPES_H)
64 check_include_file(limits.h HAVE_LIMITS_H)
65 check_include_file(malloc.h HAVE_MALLOC_H)
66 check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
67 check_include_file(ndir.h HAVE_NDIR_H)
68 if( NOT PURE_WINDOWS )
69   check_include_file(pthread.h HAVE_PTHREAD_H)
70 endif()
71 check_include_file(sanitizer/msan_interface.h HAVE_SANITIZER_MSAN_INTERFACE_H)
72 check_include_file(signal.h HAVE_SIGNAL_H)
73 check_include_file(stdint.h HAVE_STDINT_H)
74 check_include_file(sys/dir.h HAVE_SYS_DIR_H)
75 check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
76 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
77 check_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
78 check_include_file(sys/param.h HAVE_SYS_PARAM_H)
79 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
80 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
81 check_include_file(sys/time.h HAVE_SYS_TIME_H)
82 check_include_file(sys/uio.h HAVE_SYS_UIO_H)
83 check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
84 check_include_file(termios.h HAVE_TERMIOS_H)
85 check_include_file(unistd.h HAVE_UNISTD_H)
86 check_include_file(utime.h HAVE_UTIME_H)
87 check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
88 check_include_file(zlib.h HAVE_ZLIB_H)
89 check_include_file(fenv.h HAVE_FENV_H)
90 check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
91 check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
92
93 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
94 check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
95
96 # library checks
97 if( NOT PURE_WINDOWS )
98   check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
99   if (HAVE_LIBPTHREAD)
100     check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
101     check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
102     check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
103   else()
104     # this could be Android
105     check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)
106     if (PTHREAD_IN_LIBC)
107       check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
108       check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
109       check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
110     endif()
111   endif()
112   check_library_exists(dl dlopen "" HAVE_LIBDL)
113   check_library_exists(rt clock_gettime "" HAVE_LIBRT)
114   if (LLVM_ENABLE_ZLIB)
115     check_library_exists(z compress2 "" HAVE_LIBZ)
116   else()
117     set(HAVE_LIBZ 0)
118   endif()
119   check_library_exists(edit el_init "" HAVE_LIBEDIT)
120   if(LLVM_ENABLE_TERMINFO)
121     set(HAVE_TERMINFO 0)
122     foreach(library tinfo terminfo curses ncurses ncursesw)
123       string(TOUPPER ${library} library_suffix)
124       check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
125       if(HAVE_TERMINFO_${library_suffix})
126         set(HAVE_TERMINFO 1)
127         set(TERMINFO_LIBS "${library}")
128         break()
129       endif()
130     endforeach()
131   else()
132     set(HAVE_TERMINFO 0)
133   endif()
134 endif()
135
136 # function checks
137 check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM)
138 check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
139 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
140 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
141 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
142 check_symbol_exists(isatty unistd.h HAVE_ISATTY)
143 check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
144 check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
145 check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H)
146 check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
147 check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
148 check_symbol_exists(ceilf math.h HAVE_CEILF)
149 check_symbol_exists(floorf math.h HAVE_FLOORF)
150 check_symbol_exists(fmodf math.h HAVE_FMODF)
151 check_symbol_exists(log math.h HAVE_LOG)
152 check_symbol_exists(log2 math.h HAVE_LOG2)
153 check_symbol_exists(log10 math.h HAVE_LOG10)
154 check_symbol_exists(exp math.h HAVE_EXP)
155 check_symbol_exists(exp2 math.h HAVE_EXP2)
156 check_symbol_exists(exp10 math.h HAVE_EXP10)
157 check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
158 check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
159 if( HAVE_SETJMP_H )
160   check_symbol_exists(longjmp setjmp.h HAVE_LONGJMP)
161   check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
162   check_symbol_exists(siglongjmp setjmp.h HAVE_SIGLONGJMP)
163   check_symbol_exists(sigsetjmp setjmp.h HAVE_SIGSETJMP)
164 endif()
165 if( HAVE_SYS_UIO_H )
166   check_symbol_exists(writev sys/uio.h HAVE_WRITEV)
167 endif()
168 check_symbol_exists(nearbyintf math.h HAVE_NEARBYINTF)
169 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
170 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
171                     HAVE_MALLOC_ZONE_STATISTICS)
172 check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
173 check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
174 check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
175 check_symbol_exists(closedir "sys/types.h;dirent.h" HAVE_CLOSEDIR)
176 check_symbol_exists(opendir "sys/types.h;dirent.h" HAVE_OPENDIR)
177 check_symbol_exists(readdir "sys/types.h;dirent.h" HAVE_READDIR)
178 check_symbol_exists(getcwd unistd.h HAVE_GETCWD)
179 check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
180 check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
181 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
182 check_symbol_exists(pread unistd.h HAVE_PREAD)
183 check_symbol_exists(realpath stdlib.h HAVE_REALPATH)
184 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
185 check_symbol_exists(srand48 stdlib.h HAVE_RAND48_SRAND48)
186 if( HAVE_RAND48_SRAND48 )
187   check_symbol_exists(lrand48 stdlib.h HAVE_RAND48_LRAND48)
188   if( HAVE_RAND48_LRAND48 )
189     check_symbol_exists(drand48 stdlib.h HAVE_RAND48_DRAND48)
190     if( HAVE_RAND48_DRAND48 )
191       set(HAVE_RAND48 1 CACHE INTERNAL "are srand48/lrand48/drand48 available?")
192     endif()
193   endif()
194 endif()
195 check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
196 check_symbol_exists(strtoq stdlib.h HAVE_STRTOQ)
197 check_symbol_exists(strerror string.h HAVE_STRERROR)
198 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
199 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
200 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
201 if( PURE_WINDOWS )
202   check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
203
204   check_function_exists(_alloca HAVE__ALLOCA)
205   check_function_exists(__alloca HAVE___ALLOCA)
206   check_function_exists(__chkstk HAVE___CHKSTK)
207   check_function_exists(___chkstk HAVE____CHKSTK)
208
209   check_function_exists(__ashldi3 HAVE___ASHLDI3)
210   check_function_exists(__ashrdi3 HAVE___ASHRDI3)
211   check_function_exists(__divdi3 HAVE___DIVDI3)
212   check_function_exists(__fixdfdi HAVE___FIXDFDI)
213   check_function_exists(__fixsfdi HAVE___FIXSFDI)
214   check_function_exists(__floatdidf HAVE___FLOATDIDF)
215   check_function_exists(__lshrdi3 HAVE___LSHRDI3)
216   check_function_exists(__moddi3 HAVE___MODDI3)
217   check_function_exists(__udivdi3 HAVE___UDIVDI3)
218   check_function_exists(__umoddi3 HAVE___UMODDI3)
219
220   check_function_exists(__main HAVE___MAIN)
221   check_function_exists(__cmpdi2 HAVE___CMPDI2)
222 endif()
223 if( HAVE_DLFCN_H )
224   if( HAVE_LIBDL )
225     list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
226   endif()
227   check_symbol_exists(dlerror dlfcn.h HAVE_DLERROR)
228   check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
229   if( HAVE_LIBDL )
230     list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
231   endif()
232 endif()
233
234 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
235 if( LLVM_USING_GLIBC )
236   add_llvm_definitions( -D_GNU_SOURCE )
237 endif()
238
239 set(headers "sys/types.h")
240
241 if (HAVE_INTTYPES_H)
242   set(headers ${headers} "inttypes.h")
243 endif()
244
245 if (HAVE_STDINT_H)
246   set(headers ${headers} "stdint.h")
247 endif()
248
249 check_type_exists(int64_t "${headers}" HAVE_INT64_T)
250 check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
251 check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
252
253 # available programs checks
254 function(llvm_find_program name)
255   string(TOUPPER ${name} NAME)
256   string(REGEX REPLACE "\\." "_" NAME ${NAME})
257
258   find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
259   mark_as_advanced(LLVM_PATH_${NAME})
260   if(LLVM_PATH_${NAME})
261     set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
262     mark_as_advanced(HAVE_${NAME})
263   else(LLVM_PATH_${NAME})
264     set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
265   endif(LLVM_PATH_${NAME})
266 endfunction()
267
268 llvm_find_program(gv)
269 llvm_find_program(circo)
270 llvm_find_program(twopi)
271 llvm_find_program(neato)
272 llvm_find_program(fdp)
273 llvm_find_program(dot)
274 llvm_find_program(dotty)
275 llvm_find_program(xdot xdot.py)
276 llvm_find_program(Graphviz)
277
278 if( LLVM_ENABLE_FFI )
279   find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
280   if( FFI_INCLUDE_PATH )
281     set(FFI_HEADER ffi.h CACHE INTERNAL "")
282     set(HAVE_FFI_H 1 CACHE INTERNAL "")
283   else()
284     find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
285     if( FFI_INCLUDE_PATH )
286       set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
287       set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
288     endif()
289   endif()
290
291   if( NOT FFI_HEADER )
292     message(FATAL_ERROR "libffi includes are not found.")
293   endif()
294
295   find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
296   if( NOT FFI_LIBRARY_PATH )
297     message(FATAL_ERROR "libffi is not found.")
298   endif()
299
300   list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
301   list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
302   check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
303   list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
304   list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
305 else()
306   unset(HAVE_FFI_FFI_H CACHE)
307   unset(HAVE_FFI_H CACHE)
308   unset(HAVE_FFI_CALL CACHE)
309 endif( LLVM_ENABLE_FFI )
310
311 # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
312 include(CheckAtomic)
313
314 if( LLVM_ENABLE_PIC )
315   set(ENABLE_PIC 1)
316 else()
317   set(ENABLE_PIC 0)
318 endif()
319
320 find_package(LibXml2)
321 if (LIBXML2_FOUND)
322   set(CLANG_HAVE_LIBXML 1)
323   # When cross-compiling, liblzma is not detected as a dependency for libxml2,
324   # which makes linking c-index-test fail. But for native builds, all libraries
325   # are installed and checked by CMake before Makefiles are generated and everything
326   # works according to the plan. However, if a -llzma is added to native builds,
327   # an additional requirement on the static liblzma.a is required, but will not
328   # be checked by CMake, breaking native compilation.
329   # Since this is only pertinent to cross-compilations, and there's no way CMake
330   # can check for every foreign library on every OS, we add the dep and warn the dev.
331   if ( CMAKE_CROSSCOMPILING )
332     if (NOT PC_LIBXML_VERSION VERSION_LESS "2.8.0")
333       message(STATUS "Adding LZMA as a dep to XML2 for cross-compilation, make sure liblzma.a is available.")
334       set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} "-llzma")
335     endif ()
336   endif ()
337 endif ()
338
339 check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
340
341 set(USE_NO_MAYBE_UNINITIALIZED 0)
342 set(USE_NO_UNINITIALIZED 0)
343
344 # Disable gcc's potentially uninitialized use analysis as it presents lots of
345 # false positives.
346 if (CMAKE_COMPILER_IS_GNUCXX)
347   check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
348   if (HAS_MAYBE_UNINITIALIZED)
349     set(USE_NO_MAYBE_UNINITIALIZED 1)
350   else()
351     # Only recent versions of gcc make the distinction between -Wuninitialized
352     # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
353     # turn off all uninitialized use warnings.
354     check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
355     set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
356   endif()
357 endif()
358
359 # By default, we target the host, but this can be overridden at CMake
360 # invocation time.
361 include(GetHostTriple)
362 get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
363
364 set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
365     "Host on which LLVM binaries will run")
366
367 # Determine the native architecture.
368 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
369 if( LLVM_NATIVE_ARCH STREQUAL "host" )
370   string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
371 endif ()
372
373 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
374   set(LLVM_NATIVE_ARCH X86)
375 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
376   set(LLVM_NATIVE_ARCH X86)
377 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
378   set(LLVM_NATIVE_ARCH X86)
379 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
380   set(LLVM_NATIVE_ARCH X86)
381 elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
382   set(LLVM_NATIVE_ARCH Sparc)
383 elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
384   set(LLVM_NATIVE_ARCH PowerPC)
385 elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
386   set(LLVM_NATIVE_ARCH AArch64)
387 elseif (LLVM_NATIVE_ARCH MATCHES "arm")
388   set(LLVM_NATIVE_ARCH ARM)
389 elseif (LLVM_NATIVE_ARCH MATCHES "mips")
390   set(LLVM_NATIVE_ARCH Mips)
391 elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
392   set(LLVM_NATIVE_ARCH XCore)
393 elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
394   set(LLVM_NATIVE_ARCH MSP430)
395 elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
396   set(LLVM_NATIVE_ARCH Hexagon)
397 elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
398   set(LLVM_NATIVE_ARCH SystemZ)
399 else ()
400   message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
401 endif ()
402
403 # If build targets includes "host", then replace with native architecture.
404 list(FIND LLVM_TARGETS_TO_BUILD "host" idx)
405 if( NOT idx LESS 0 )
406   list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
407   list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
408   list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
409 endif()
410
411 list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
412 if (NATIVE_ARCH_IDX EQUAL -1)
413   message(STATUS
414     "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
415 else ()
416   message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
417   set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
418   set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
419   set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
420   set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
421
422   # We don't have an ASM parser for all architectures yet.
423   if (EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
424     set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
425   endif ()
426
427   # We don't have an disassembler for all architectures yet.
428   if (EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
429     set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
430   endif ()
431 endif ()
432
433 if( MINGW )
434   set(HAVE_LIBIMAGEHLP 1)
435   set(HAVE_LIBPSAPI 1)
436   set(HAVE_LIBSHELL32 1)
437   # TODO: Check existence of libraries.
438   #   include(CheckLibraryExists)
439   #   CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
440 endif( MINGW )
441
442 if (NOT HAVE_STRTOLL)
443   # Use _strtoi64 if strtoll is not available.
444   check_symbol_exists(_strtoi64 stdlib.h have_strtoi64)
445   if (have_strtoi64)
446     set(HAVE_STRTOLL 1)
447     set(strtoll "_strtoi64")
448     set(strtoull "_strtoui64")
449   endif ()
450 endif ()
451
452 if( MSVC )
453   set(SHLIBEXT ".lib")
454   set(stricmp "_stricmp")
455   set(strdup "_strdup")
456 endif( MSVC )
457
458 if( PURE_WINDOWS )
459   CHECK_CXX_SOURCE_COMPILES("
460     #include <windows.h>
461     #include <imagehlp.h>
462     extern \"C\" void foo(PENUMLOADED_MODULES_CALLBACK);
463     extern \"C\" void foo(BOOL(CALLBACK*)(PCSTR,ULONG_PTR,ULONG,PVOID));
464     int main(){return 0;}"
465     HAVE_ELMCB_PCSTR)
466   if( HAVE_ELMCB_PCSTR )
467     set(WIN32_ELMCB_PCSTR "PCSTR")
468   else()
469     set(WIN32_ELMCB_PCSTR "PSTR")
470   endif()
471 endif( PURE_WINDOWS )
472
473 # FIXME: Signal handler return type, currently hardcoded to 'void'
474 set(RETSIGTYPE void)
475
476 if( LLVM_ENABLE_THREADS )
477   # Check if threading primitives aren't supported on this platform
478   if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
479     set(LLVM_ENABLE_THREADS 0)
480   endif()
481 endif()
482
483 if( LLVM_ENABLE_THREADS )
484   message(STATUS "Threads enabled.")
485 else( LLVM_ENABLE_THREADS )
486   message(STATUS "Threads disabled.")
487 endif()
488
489 if (LLVM_ENABLE_ZLIB )
490   # Check if zlib is available in the system.
491   if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
492     set(LLVM_ENABLE_ZLIB 0)
493   endif()
494 endif()
495
496 set(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
497
498 if (LLVM_ENABLE_DOXYGEN)
499   message(STATUS "Doxygen enabled.")
500   find_package(Doxygen)
501
502   if (DOXYGEN_FOUND)
503     # If we find doxygen and we want to enable doxygen by default create a
504     # global aggregate doxygen target for generating llvm and any/all
505     # subprojects doxygen documentation.
506     if (LLVM_BUILD_DOCS)
507       add_custom_target(doxygen ALL)
508     endif()
509
510     option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
511     if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
512       set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external searhc.")
513       set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
514     endif()
515   endif()
516 else()
517   message(STATUS "Doxygen disabled.")
518 endif()