xref: /aosp_15_r20/external/llvm/cmake/config-ix.cmake (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Workerif( WIN32 AND NOT CYGWIN )
2*9880d681SAndroid Build Coastguard Worker  # We consider Cygwin as another Unix
3*9880d681SAndroid Build Coastguard Worker  set(PURE_WINDOWS 1)
4*9880d681SAndroid Build Coastguard Workerendif()
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerinclude(CheckIncludeFile)
7*9880d681SAndroid Build Coastguard Workerinclude(CheckIncludeFileCXX)
8*9880d681SAndroid Build Coastguard Workerinclude(CheckLibraryExists)
9*9880d681SAndroid Build Coastguard Workerinclude(CheckSymbolExists)
10*9880d681SAndroid Build Coastguard Workerinclude(CheckFunctionExists)
11*9880d681SAndroid Build Coastguard Workerinclude(CheckCXXSourceCompiles)
12*9880d681SAndroid Build Coastguard Workerinclude(TestBigEndian)
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerinclude(CheckCompilerVersion)
15*9880d681SAndroid Build Coastguard Workerinclude(HandleLLVMStdlib)
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Workerif( UNIX AND NOT (BEOS OR HAIKU) )
18*9880d681SAndroid Build Coastguard Worker  # Used by check_symbol_exists:
19*9880d681SAndroid Build Coastguard Worker  set(CMAKE_REQUIRED_LIBRARIES m)
20*9880d681SAndroid Build Coastguard Workerendif()
21*9880d681SAndroid Build Coastguard Worker# x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.
22*9880d681SAndroid Build Coastguard Workerif( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND
23*9880d681SAndroid Build Coastguard Worker    CMAKE_SIZEOF_VOID_P EQUAL 8 )
24*9880d681SAndroid Build Coastguard Worker  list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt")
25*9880d681SAndroid Build Coastguard Workerendif()
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker# Helper macros and functions
28*9880d681SAndroid Build Coastguard Workermacro(add_cxx_include result files)
29*9880d681SAndroid Build Coastguard Worker  set(${result} "")
30*9880d681SAndroid Build Coastguard Worker  foreach (file_name ${files})
31*9880d681SAndroid Build Coastguard Worker     set(${result} "${${result}}#include<${file_name}>\n")
32*9880d681SAndroid Build Coastguard Worker  endforeach()
33*9880d681SAndroid Build Coastguard Workerendmacro(add_cxx_include files result)
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Workerfunction(check_type_exists type files variable)
36*9880d681SAndroid Build Coastguard Worker  add_cxx_include(includes "${files}")
37*9880d681SAndroid Build Coastguard Worker  CHECK_CXX_SOURCE_COMPILES("
38*9880d681SAndroid Build Coastguard Worker    ${includes} ${type} typeVar;
39*9880d681SAndroid Build Coastguard Worker    int main() {
40*9880d681SAndroid Build Coastguard Worker        return 0;
41*9880d681SAndroid Build Coastguard Worker    }
42*9880d681SAndroid Build Coastguard Worker    " ${variable})
43*9880d681SAndroid Build Coastguard Workerendfunction()
44*9880d681SAndroid Build Coastguard Worker
45*9880d681SAndroid Build Coastguard Worker# include checks
46*9880d681SAndroid Build Coastguard Workercheck_include_file(dirent.h HAVE_DIRENT_H)
47*9880d681SAndroid Build Coastguard Workercheck_include_file(dlfcn.h HAVE_DLFCN_H)
48*9880d681SAndroid Build Coastguard Workercheck_include_file(errno.h HAVE_ERRNO_H)
49*9880d681SAndroid Build Coastguard Workercheck_include_file(execinfo.h HAVE_EXECINFO_H)
50*9880d681SAndroid Build Coastguard Workercheck_include_file(fcntl.h HAVE_FCNTL_H)
51*9880d681SAndroid Build Coastguard Workercheck_include_file(inttypes.h HAVE_INTTYPES_H)
52*9880d681SAndroid Build Coastguard Workercheck_include_file(limits.h HAVE_LIMITS_H)
53*9880d681SAndroid Build Coastguard Workercheck_include_file(link.h HAVE_LINK_H)
54*9880d681SAndroid Build Coastguard Workercheck_include_file(malloc.h HAVE_MALLOC_H)
55*9880d681SAndroid Build Coastguard Workercheck_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
56*9880d681SAndroid Build Coastguard Workercheck_include_file(ndir.h HAVE_NDIR_H)
57*9880d681SAndroid Build Coastguard Workerif( NOT PURE_WINDOWS )
58*9880d681SAndroid Build Coastguard Worker  check_include_file(pthread.h HAVE_PTHREAD_H)
59*9880d681SAndroid Build Coastguard Workerendif()
60*9880d681SAndroid Build Coastguard Workercheck_include_file(signal.h HAVE_SIGNAL_H)
61*9880d681SAndroid Build Coastguard Workercheck_include_file(stdint.h HAVE_STDINT_H)
62*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/dir.h HAVE_SYS_DIR_H)
63*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
64*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/mman.h HAVE_SYS_MMAN_H)
65*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
66*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/param.h HAVE_SYS_PARAM_H)
67*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
68*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/stat.h HAVE_SYS_STAT_H)
69*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/time.h HAVE_SYS_TIME_H)
70*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/types.h HAVE_SYS_TYPES_H)
71*9880d681SAndroid Build Coastguard Workercheck_include_file(sys/uio.h HAVE_SYS_UIO_H)
72*9880d681SAndroid Build Coastguard Workercheck_include_file(termios.h HAVE_TERMIOS_H)
73*9880d681SAndroid Build Coastguard Workercheck_include_file(unistd.h HAVE_UNISTD_H)
74*9880d681SAndroid Build Coastguard Workercheck_include_file(utime.h HAVE_UTIME_H)
75*9880d681SAndroid Build Coastguard Workercheck_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
76*9880d681SAndroid Build Coastguard Workercheck_include_file(zlib.h HAVE_ZLIB_H)
77*9880d681SAndroid Build Coastguard Workercheck_include_file(fenv.h HAVE_FENV_H)
78*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
79*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
80*9880d681SAndroid Build Coastguard Worker
81*9880d681SAndroid Build Coastguard Workercheck_include_file(mach/mach.h HAVE_MACH_MACH_H)
82*9880d681SAndroid Build Coastguard Workercheck_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
83*9880d681SAndroid Build Coastguard Workercheck_include_file(histedit.h HAVE_HISTEDIT_H)
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Worker# size_t must be defined before including cxxabi.h on FreeBSD 10.0.
86*9880d681SAndroid Build Coastguard Workercheck_cxx_source_compiles("
87*9880d681SAndroid Build Coastguard Worker#include <stddef.h>
88*9880d681SAndroid Build Coastguard Worker#include <cxxabi.h>
89*9880d681SAndroid Build Coastguard Workerint main() { return 0; }
90*9880d681SAndroid Build Coastguard Worker" HAVE_CXXABI_H)
91*9880d681SAndroid Build Coastguard Worker
92*9880d681SAndroid Build Coastguard Worker# library checks
93*9880d681SAndroid Build Coastguard Workerif( NOT PURE_WINDOWS )
94*9880d681SAndroid Build Coastguard Worker  check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
95*9880d681SAndroid Build Coastguard Worker  if (HAVE_LIBPTHREAD)
96*9880d681SAndroid Build Coastguard Worker    check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
97*9880d681SAndroid Build Coastguard Worker    check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
98*9880d681SAndroid Build Coastguard Worker    check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
99*9880d681SAndroid Build Coastguard Worker  else()
100*9880d681SAndroid Build Coastguard Worker    # this could be Android
101*9880d681SAndroid Build Coastguard Worker    check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)
102*9880d681SAndroid Build Coastguard Worker    if (PTHREAD_IN_LIBC)
103*9880d681SAndroid Build Coastguard Worker      check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
104*9880d681SAndroid Build Coastguard Worker      check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
105*9880d681SAndroid Build Coastguard Worker      check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
106*9880d681SAndroid Build Coastguard Worker    endif()
107*9880d681SAndroid Build Coastguard Worker  endif()
108*9880d681SAndroid Build Coastguard Worker  check_library_exists(dl dlopen "" HAVE_LIBDL)
109*9880d681SAndroid Build Coastguard Worker  check_library_exists(rt clock_gettime "" HAVE_LIBRT)
110*9880d681SAndroid Build Coastguard Workerendif()
111*9880d681SAndroid Build Coastguard Worker
112*9880d681SAndroid Build Coastguard Workerif(HAVE_LIBPTHREAD)
113*9880d681SAndroid Build Coastguard Worker  # We want to find pthreads library and at the moment we do want to
114*9880d681SAndroid Build Coastguard Worker  # have it reported as '-l<lib>' instead of '-pthread'.
115*9880d681SAndroid Build Coastguard Worker  # TODO: switch to -pthread once the rest of the build system can deal with it.
116*9880d681SAndroid Build Coastguard Worker  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
117*9880d681SAndroid Build Coastguard Worker  set(THREADS_HAVE_PTHREAD_ARG Off)
118*9880d681SAndroid Build Coastguard Worker  find_package(Threads REQUIRED)
119*9880d681SAndroid Build Coastguard Worker  set(PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
120*9880d681SAndroid Build Coastguard Workerendif()
121*9880d681SAndroid Build Coastguard Worker
122*9880d681SAndroid Build Coastguard Worker# Don't look for these libraries on Windows. Also don't look for them if we're
123*9880d681SAndroid Build Coastguard Worker# using MSan, since uninstrmented third party code may call MSan interceptors
124*9880d681SAndroid Build Coastguard Worker# like strlen, leading to false positives.
125*9880d681SAndroid Build Coastguard Workerif( NOT PURE_WINDOWS AND NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
126*9880d681SAndroid Build Coastguard Worker  if (LLVM_ENABLE_ZLIB)
127*9880d681SAndroid Build Coastguard Worker    check_library_exists(z compress2 "" HAVE_LIBZ)
128*9880d681SAndroid Build Coastguard Worker  else()
129*9880d681SAndroid Build Coastguard Worker    set(HAVE_LIBZ 0)
130*9880d681SAndroid Build Coastguard Worker  endif()
131*9880d681SAndroid Build Coastguard Worker  if (HAVE_HISTEDIT_H)
132*9880d681SAndroid Build Coastguard Worker    check_library_exists(edit el_init "" HAVE_LIBEDIT)
133*9880d681SAndroid Build Coastguard Worker  endif()
134*9880d681SAndroid Build Coastguard Worker  if(LLVM_ENABLE_TERMINFO)
135*9880d681SAndroid Build Coastguard Worker    set(HAVE_TERMINFO 0)
136*9880d681SAndroid Build Coastguard Worker    foreach(library tinfo terminfo curses ncurses ncursesw)
137*9880d681SAndroid Build Coastguard Worker      string(TOUPPER ${library} library_suffix)
138*9880d681SAndroid Build Coastguard Worker      check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
139*9880d681SAndroid Build Coastguard Worker      if(HAVE_TERMINFO_${library_suffix})
140*9880d681SAndroid Build Coastguard Worker        set(HAVE_TERMINFO 1)
141*9880d681SAndroid Build Coastguard Worker        set(TERMINFO_LIBS "${library}")
142*9880d681SAndroid Build Coastguard Worker        break()
143*9880d681SAndroid Build Coastguard Worker      endif()
144*9880d681SAndroid Build Coastguard Worker    endforeach()
145*9880d681SAndroid Build Coastguard Worker  else()
146*9880d681SAndroid Build Coastguard Worker    set(HAVE_TERMINFO 0)
147*9880d681SAndroid Build Coastguard Worker  endif()
148*9880d681SAndroid Build Coastguard Workerendif()
149*9880d681SAndroid Build Coastguard Worker
150*9880d681SAndroid Build Coastguard Workercheck_library_exists(xar xar_open "" HAVE_LIBXAR)
151*9880d681SAndroid Build Coastguard Workerif(HAVE_LIBXAR)
152*9880d681SAndroid Build Coastguard Worker  set(XAR_LIB xar)
153*9880d681SAndroid Build Coastguard Workerendif()
154*9880d681SAndroid Build Coastguard Worker
155*9880d681SAndroid Build Coastguard Worker# function checks
156*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
157*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
158*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE_UNWIND_BACKTRACE)
159*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
160*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
161*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
162*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(isatty unistd.h HAVE_ISATTY)
163*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
164*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
165*9880d681SAndroid Build Coastguard Workerif( HAVE_SETJMP_H )
166*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(longjmp setjmp.h HAVE_LONGJMP)
167*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
168*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(siglongjmp setjmp.h HAVE_SIGLONGJMP)
169*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(sigsetjmp setjmp.h HAVE_SIGSETJMP)
170*9880d681SAndroid Build Coastguard Workerendif()
171*9880d681SAndroid Build Coastguard Workerif( HAVE_SIGNAL_H )
172*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
173*9880d681SAndroid Build Coastguard Workerendif()
174*9880d681SAndroid Build Coastguard Workerif( HAVE_SYS_UIO_H )
175*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(writev sys/uio.h HAVE_WRITEV)
176*9880d681SAndroid Build Coastguard Workerendif()
177*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
178*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
179*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(malloc_zone_statistics malloc/malloc.h
180*9880d681SAndroid Build Coastguard Worker                    HAVE_MALLOC_ZONE_STATISTICS)
181*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
182*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
183*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
184*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(closedir "sys/types.h;dirent.h" HAVE_CLOSEDIR)
185*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(opendir "sys/types.h;dirent.h" HAVE_OPENDIR)
186*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(readdir "sys/types.h;dirent.h" HAVE_READDIR)
187*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(getcwd unistd.h HAVE_GETCWD)
188*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
189*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
190*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
191*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(pread unistd.h HAVE_PREAD)
192*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(realpath stdlib.h HAVE_REALPATH)
193*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(sbrk unistd.h HAVE_SBRK)
194*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(srand48 stdlib.h HAVE_RAND48_SRAND48)
195*9880d681SAndroid Build Coastguard Workerif( HAVE_RAND48_SRAND48 )
196*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(lrand48 stdlib.h HAVE_RAND48_LRAND48)
197*9880d681SAndroid Build Coastguard Worker  if( HAVE_RAND48_LRAND48 )
198*9880d681SAndroid Build Coastguard Worker    check_symbol_exists(drand48 stdlib.h HAVE_RAND48_DRAND48)
199*9880d681SAndroid Build Coastguard Worker    if( HAVE_RAND48_DRAND48 )
200*9880d681SAndroid Build Coastguard Worker      set(HAVE_RAND48 1 CACHE INTERNAL "are srand48/lrand48/drand48 available?")
201*9880d681SAndroid Build Coastguard Worker    endif()
202*9880d681SAndroid Build Coastguard Worker  endif()
203*9880d681SAndroid Build Coastguard Workerendif()
204*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
205*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(strtoq stdlib.h HAVE_STRTOQ)
206*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(strerror string.h HAVE_STRERROR)
207*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
208*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
209*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(setenv stdlib.h HAVE_SETENV)
210*9880d681SAndroid Build Coastguard Workerif( PURE_WINDOWS )
211*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
212*9880d681SAndroid Build Coastguard Worker
213*9880d681SAndroid Build Coastguard Worker  check_function_exists(_alloca HAVE__ALLOCA)
214*9880d681SAndroid Build Coastguard Worker  check_function_exists(__alloca HAVE___ALLOCA)
215*9880d681SAndroid Build Coastguard Worker  check_function_exists(__chkstk HAVE___CHKSTK)
216*9880d681SAndroid Build Coastguard Worker  check_function_exists(__chkstk_ms HAVE___CHKSTK_MS)
217*9880d681SAndroid Build Coastguard Worker  check_function_exists(___chkstk HAVE____CHKSTK)
218*9880d681SAndroid Build Coastguard Worker  check_function_exists(___chkstk_ms HAVE____CHKSTK_MS)
219*9880d681SAndroid Build Coastguard Worker
220*9880d681SAndroid Build Coastguard Worker  check_function_exists(__ashldi3 HAVE___ASHLDI3)
221*9880d681SAndroid Build Coastguard Worker  check_function_exists(__ashrdi3 HAVE___ASHRDI3)
222*9880d681SAndroid Build Coastguard Worker  check_function_exists(__divdi3 HAVE___DIVDI3)
223*9880d681SAndroid Build Coastguard Worker  check_function_exists(__fixdfdi HAVE___FIXDFDI)
224*9880d681SAndroid Build Coastguard Worker  check_function_exists(__fixsfdi HAVE___FIXSFDI)
225*9880d681SAndroid Build Coastguard Worker  check_function_exists(__floatdidf HAVE___FLOATDIDF)
226*9880d681SAndroid Build Coastguard Worker  check_function_exists(__lshrdi3 HAVE___LSHRDI3)
227*9880d681SAndroid Build Coastguard Worker  check_function_exists(__moddi3 HAVE___MODDI3)
228*9880d681SAndroid Build Coastguard Worker  check_function_exists(__udivdi3 HAVE___UDIVDI3)
229*9880d681SAndroid Build Coastguard Worker  check_function_exists(__umoddi3 HAVE___UMODDI3)
230*9880d681SAndroid Build Coastguard Worker
231*9880d681SAndroid Build Coastguard Worker  check_function_exists(__main HAVE___MAIN)
232*9880d681SAndroid Build Coastguard Worker  check_function_exists(__cmpdi2 HAVE___CMPDI2)
233*9880d681SAndroid Build Coastguard Workerendif()
234*9880d681SAndroid Build Coastguard Workerif( HAVE_DLFCN_H )
235*9880d681SAndroid Build Coastguard Worker  if( HAVE_LIBDL )
236*9880d681SAndroid Build Coastguard Worker    list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
237*9880d681SAndroid Build Coastguard Worker  endif()
238*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(dlerror dlfcn.h HAVE_DLERROR)
239*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
240*9880d681SAndroid Build Coastguard Worker  if( HAVE_LIBDL )
241*9880d681SAndroid Build Coastguard Worker    list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
242*9880d681SAndroid Build Coastguard Worker  endif()
243*9880d681SAndroid Build Coastguard Workerendif()
244*9880d681SAndroid Build Coastguard Worker
245*9880d681SAndroid Build Coastguard Workercheck_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
246*9880d681SAndroid Build Coastguard Workerif( LLVM_USING_GLIBC )
247*9880d681SAndroid Build Coastguard Worker  add_llvm_definitions( -D_GNU_SOURCE )
248*9880d681SAndroid Build Coastguard Workerendif()
249*9880d681SAndroid Build Coastguard Worker
250*9880d681SAndroid Build Coastguard Workerset(headers "sys/types.h")
251*9880d681SAndroid Build Coastguard Worker
252*9880d681SAndroid Build Coastguard Workerif (HAVE_INTTYPES_H)
253*9880d681SAndroid Build Coastguard Worker  set(headers ${headers} "inttypes.h")
254*9880d681SAndroid Build Coastguard Workerendif()
255*9880d681SAndroid Build Coastguard Worker
256*9880d681SAndroid Build Coastguard Workerif (HAVE_STDINT_H)
257*9880d681SAndroid Build Coastguard Worker  set(headers ${headers} "stdint.h")
258*9880d681SAndroid Build Coastguard Workerendif()
259*9880d681SAndroid Build Coastguard Worker
260*9880d681SAndroid Build Coastguard Workercheck_type_exists(int64_t "${headers}" HAVE_INT64_T)
261*9880d681SAndroid Build Coastguard Workercheck_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
262*9880d681SAndroid Build Coastguard Workercheck_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
263*9880d681SAndroid Build Coastguard Worker
264*9880d681SAndroid Build Coastguard Worker# available programs checks
265*9880d681SAndroid Build Coastguard Workerfunction(llvm_find_program name)
266*9880d681SAndroid Build Coastguard Worker  string(TOUPPER ${name} NAME)
267*9880d681SAndroid Build Coastguard Worker  string(REGEX REPLACE "\\." "_" NAME ${NAME})
268*9880d681SAndroid Build Coastguard Worker
269*9880d681SAndroid Build Coastguard Worker  find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
270*9880d681SAndroid Build Coastguard Worker  mark_as_advanced(LLVM_PATH_${NAME})
271*9880d681SAndroid Build Coastguard Worker  if(LLVM_PATH_${NAME})
272*9880d681SAndroid Build Coastguard Worker    set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
273*9880d681SAndroid Build Coastguard Worker    mark_as_advanced(HAVE_${NAME})
274*9880d681SAndroid Build Coastguard Worker  else(LLVM_PATH_${NAME})
275*9880d681SAndroid Build Coastguard Worker    set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
276*9880d681SAndroid Build Coastguard Worker  endif(LLVM_PATH_${NAME})
277*9880d681SAndroid Build Coastguard Workerendfunction()
278*9880d681SAndroid Build Coastguard Worker
279*9880d681SAndroid Build Coastguard Workerif (LLVM_ENABLE_DOXYGEN)
280*9880d681SAndroid Build Coastguard Worker  llvm_find_program(dot)
281*9880d681SAndroid Build Coastguard Workerendif ()
282*9880d681SAndroid Build Coastguard Worker
283*9880d681SAndroid Build Coastguard Workerif( LLVM_ENABLE_FFI )
284*9880d681SAndroid Build Coastguard Worker  find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
285*9880d681SAndroid Build Coastguard Worker  if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" )
286*9880d681SAndroid Build Coastguard Worker    set(FFI_HEADER ffi.h CACHE INTERNAL "")
287*9880d681SAndroid Build Coastguard Worker    set(HAVE_FFI_H 1 CACHE INTERNAL "")
288*9880d681SAndroid Build Coastguard Worker  else()
289*9880d681SAndroid Build Coastguard Worker    find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
290*9880d681SAndroid Build Coastguard Worker    if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" )
291*9880d681SAndroid Build Coastguard Worker      set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
292*9880d681SAndroid Build Coastguard Worker      set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
293*9880d681SAndroid Build Coastguard Worker    endif()
294*9880d681SAndroid Build Coastguard Worker  endif()
295*9880d681SAndroid Build Coastguard Worker
296*9880d681SAndroid Build Coastguard Worker  if( NOT FFI_HEADER )
297*9880d681SAndroid Build Coastguard Worker    message(FATAL_ERROR "libffi includes are not found.")
298*9880d681SAndroid Build Coastguard Worker  endif()
299*9880d681SAndroid Build Coastguard Worker
300*9880d681SAndroid Build Coastguard Worker  find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
301*9880d681SAndroid Build Coastguard Worker  if( NOT FFI_LIBRARY_PATH )
302*9880d681SAndroid Build Coastguard Worker    message(FATAL_ERROR "libffi is not found.")
303*9880d681SAndroid Build Coastguard Worker  endif()
304*9880d681SAndroid Build Coastguard Worker
305*9880d681SAndroid Build Coastguard Worker  list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
306*9880d681SAndroid Build Coastguard Worker  list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
307*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
308*9880d681SAndroid Build Coastguard Worker  list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
309*9880d681SAndroid Build Coastguard Worker  list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
310*9880d681SAndroid Build Coastguard Workerelse()
311*9880d681SAndroid Build Coastguard Worker  unset(HAVE_FFI_FFI_H CACHE)
312*9880d681SAndroid Build Coastguard Worker  unset(HAVE_FFI_H CACHE)
313*9880d681SAndroid Build Coastguard Worker  unset(HAVE_FFI_CALL CACHE)
314*9880d681SAndroid Build Coastguard Workerendif( LLVM_ENABLE_FFI )
315*9880d681SAndroid Build Coastguard Worker
316*9880d681SAndroid Build Coastguard Worker# Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
317*9880d681SAndroid Build Coastguard Workerinclude(CheckAtomic)
318*9880d681SAndroid Build Coastguard Worker
319*9880d681SAndroid Build Coastguard Workerif( LLVM_ENABLE_PIC )
320*9880d681SAndroid Build Coastguard Worker  set(ENABLE_PIC 1)
321*9880d681SAndroid Build Coastguard Workerelse()
322*9880d681SAndroid Build Coastguard Worker  set(ENABLE_PIC 0)
323*9880d681SAndroid Build Coastguard Worker  check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG)
324*9880d681SAndroid Build Coastguard Worker  if(SUPPORTS_NO_PIE_FLAG)
325*9880d681SAndroid Build Coastguard Worker    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
326*9880d681SAndroid Build Coastguard Worker  endif()
327*9880d681SAndroid Build Coastguard Workerendif()
328*9880d681SAndroid Build Coastguard Worker
329*9880d681SAndroid Build Coastguard Workercheck_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
330*9880d681SAndroid Build Coastguard Worker
331*9880d681SAndroid Build Coastguard Workerset(USE_NO_MAYBE_UNINITIALIZED 0)
332*9880d681SAndroid Build Coastguard Workerset(USE_NO_UNINITIALIZED 0)
333*9880d681SAndroid Build Coastguard Worker
334*9880d681SAndroid Build Coastguard Worker# Disable gcc's potentially uninitialized use analysis as it presents lots of
335*9880d681SAndroid Build Coastguard Worker# false positives.
336*9880d681SAndroid Build Coastguard Workerif (CMAKE_COMPILER_IS_GNUCXX)
337*9880d681SAndroid Build Coastguard Worker  check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
338*9880d681SAndroid Build Coastguard Worker  if (HAS_MAYBE_UNINITIALIZED)
339*9880d681SAndroid Build Coastguard Worker    set(USE_NO_MAYBE_UNINITIALIZED 1)
340*9880d681SAndroid Build Coastguard Worker  else()
341*9880d681SAndroid Build Coastguard Worker    # Only recent versions of gcc make the distinction between -Wuninitialized
342*9880d681SAndroid Build Coastguard Worker    # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
343*9880d681SAndroid Build Coastguard Worker    # turn off all uninitialized use warnings.
344*9880d681SAndroid Build Coastguard Worker    check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
345*9880d681SAndroid Build Coastguard Worker    set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
346*9880d681SAndroid Build Coastguard Worker  endif()
347*9880d681SAndroid Build Coastguard Workerendif()
348*9880d681SAndroid Build Coastguard Worker
349*9880d681SAndroid Build Coastguard Worker# By default, we target the host, but this can be overridden at CMake
350*9880d681SAndroid Build Coastguard Worker# invocation time.
351*9880d681SAndroid Build Coastguard Workerinclude(GetHostTriple)
352*9880d681SAndroid Build Coastguard Workerget_host_triple(LLVM_INFERRED_HOST_TRIPLE)
353*9880d681SAndroid Build Coastguard Worker
354*9880d681SAndroid Build Coastguard Workerset(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
355*9880d681SAndroid Build Coastguard Worker    "Host on which LLVM binaries will run")
356*9880d681SAndroid Build Coastguard Worker
357*9880d681SAndroid Build Coastguard Worker# Determine the native architecture.
358*9880d681SAndroid Build Coastguard Workerstring(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
359*9880d681SAndroid Build Coastguard Workerif( LLVM_NATIVE_ARCH STREQUAL "host" )
360*9880d681SAndroid Build Coastguard Worker  string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
361*9880d681SAndroid Build Coastguard Workerendif ()
362*9880d681SAndroid Build Coastguard Worker
363*9880d681SAndroid Build Coastguard Workerif (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
364*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH X86)
365*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH STREQUAL "x86")
366*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH X86)
367*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
368*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH X86)
369*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
370*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH X86)
371*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "sparc")
372*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH Sparc)
373*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
374*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH PowerPC)
375*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
376*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH AArch64)
377*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "arm64")
378*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH AArch64)
379*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "arm")
380*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH ARM)
381*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "mips")
382*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH Mips)
383*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "xcore")
384*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH XCore)
385*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "msp430")
386*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH MSP430)
387*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
388*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH Hexagon)
389*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "s390x")
390*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH SystemZ)
391*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
392*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH WebAssembly)
393*9880d681SAndroid Build Coastguard Workerelseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
394*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ARCH WebAssembly)
395*9880d681SAndroid Build Coastguard Workerelse ()
396*9880d681SAndroid Build Coastguard Worker  message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
397*9880d681SAndroid Build Coastguard Workerendif ()
398*9880d681SAndroid Build Coastguard Worker
399*9880d681SAndroid Build Coastguard Worker# If build targets includes "host", then replace with native architecture.
400*9880d681SAndroid Build Coastguard Workerlist(FIND LLVM_TARGETS_TO_BUILD "host" idx)
401*9880d681SAndroid Build Coastguard Workerif( NOT idx LESS 0 )
402*9880d681SAndroid Build Coastguard Worker  list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
403*9880d681SAndroid Build Coastguard Worker  list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
404*9880d681SAndroid Build Coastguard Worker  list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
405*9880d681SAndroid Build Coastguard Workerendif()
406*9880d681SAndroid Build Coastguard Worker
407*9880d681SAndroid Build Coastguard Workerlist(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
408*9880d681SAndroid Build Coastguard Workerif (NATIVE_ARCH_IDX EQUAL -1)
409*9880d681SAndroid Build Coastguard Worker  message(STATUS
410*9880d681SAndroid Build Coastguard Worker    "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
411*9880d681SAndroid Build Coastguard Workerelse ()
412*9880d681SAndroid Build Coastguard Worker  message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
413*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
414*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
415*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
416*9880d681SAndroid Build Coastguard Worker  set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
417*9880d681SAndroid Build Coastguard Worker
418*9880d681SAndroid Build Coastguard Worker  # We don't have an ASM parser for all architectures yet.
419*9880d681SAndroid Build Coastguard Worker  if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
420*9880d681SAndroid Build Coastguard Worker    set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
421*9880d681SAndroid Build Coastguard Worker  endif ()
422*9880d681SAndroid Build Coastguard Worker
423*9880d681SAndroid Build Coastguard Worker  # We don't have an disassembler for all architectures yet.
424*9880d681SAndroid Build Coastguard Worker  if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
425*9880d681SAndroid Build Coastguard Worker    set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
426*9880d681SAndroid Build Coastguard Worker  endif ()
427*9880d681SAndroid Build Coastguard Workerendif ()
428*9880d681SAndroid Build Coastguard Worker
429*9880d681SAndroid Build Coastguard Workerif( MINGW )
430*9880d681SAndroid Build Coastguard Worker  set(HAVE_LIBPSAPI 1)
431*9880d681SAndroid Build Coastguard Worker  set(HAVE_LIBSHELL32 1)
432*9880d681SAndroid Build Coastguard Worker  # TODO: Check existence of libraries.
433*9880d681SAndroid Build Coastguard Worker  #   include(CheckLibraryExists)
434*9880d681SAndroid Build Coastguard Workerendif( MINGW )
435*9880d681SAndroid Build Coastguard Worker
436*9880d681SAndroid Build Coastguard Workerif (NOT HAVE_STRTOLL)
437*9880d681SAndroid Build Coastguard Worker  # Use _strtoi64 if strtoll is not available.
438*9880d681SAndroid Build Coastguard Worker  check_symbol_exists(_strtoi64 stdlib.h have_strtoi64)
439*9880d681SAndroid Build Coastguard Worker  if (have_strtoi64)
440*9880d681SAndroid Build Coastguard Worker    set(HAVE_STRTOLL 1)
441*9880d681SAndroid Build Coastguard Worker    set(strtoll "_strtoi64")
442*9880d681SAndroid Build Coastguard Worker    set(strtoull "_strtoui64")
443*9880d681SAndroid Build Coastguard Worker  endif ()
444*9880d681SAndroid Build Coastguard Workerendif ()
445*9880d681SAndroid Build Coastguard Worker
446*9880d681SAndroid Build Coastguard Workerif( MSVC )
447*9880d681SAndroid Build Coastguard Worker  set(SHLIBEXT ".lib")
448*9880d681SAndroid Build Coastguard Worker  set(stricmp "_stricmp")
449*9880d681SAndroid Build Coastguard Worker  set(strdup "_strdup")
450*9880d681SAndroid Build Coastguard Worker
451*9880d681SAndroid Build Coastguard Worker  # See if the DIA SDK is available and usable.
452*9880d681SAndroid Build Coastguard Worker  set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
453*9880d681SAndroid Build Coastguard Worker
454*9880d681SAndroid Build Coastguard Worker  # Due to a bug in MSVC 2013's installation software, it is possible
455*9880d681SAndroid Build Coastguard Worker  # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
456*9880d681SAndroid Build Coastguard Worker  # install directory.  If this happens, the installation is corrupt
457*9880d681SAndroid Build Coastguard Worker  # and there's nothing we can do.  It happens with enough frequency
458*9880d681SAndroid Build Coastguard Worker  # though that we should handle it.  We do so by simply checking that
459*9880d681SAndroid Build Coastguard Worker  # the DIA SDK folder exists.  Should this happen you will need to
460*9880d681SAndroid Build Coastguard Worker  # uninstall VS 2012 and then re-install VS 2013.
461*9880d681SAndroid Build Coastguard Worker  if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
462*9880d681SAndroid Build Coastguard Worker    set(HAVE_DIA_SDK 1)
463*9880d681SAndroid Build Coastguard Worker  else()
464*9880d681SAndroid Build Coastguard Worker    set(HAVE_DIA_SDK 0)
465*9880d681SAndroid Build Coastguard Worker  endif()
466*9880d681SAndroid Build Coastguard Workerelse()
467*9880d681SAndroid Build Coastguard Worker  set(HAVE_DIA_SDK 0)
468*9880d681SAndroid Build Coastguard Workerendif( MSVC )
469*9880d681SAndroid Build Coastguard Worker
470*9880d681SAndroid Build Coastguard Worker# FIXME: Signal handler return type, currently hardcoded to 'void'
471*9880d681SAndroid Build Coastguard Workerset(RETSIGTYPE void)
472*9880d681SAndroid Build Coastguard Worker
473*9880d681SAndroid Build Coastguard Workerif( LLVM_ENABLE_THREADS )
474*9880d681SAndroid Build Coastguard Worker  # Check if threading primitives aren't supported on this platform
475*9880d681SAndroid Build Coastguard Worker  if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
476*9880d681SAndroid Build Coastguard Worker    set(LLVM_ENABLE_THREADS 0)
477*9880d681SAndroid Build Coastguard Worker  endif()
478*9880d681SAndroid Build Coastguard Workerendif()
479*9880d681SAndroid Build Coastguard Worker
480*9880d681SAndroid Build Coastguard Workerif( LLVM_ENABLE_THREADS )
481*9880d681SAndroid Build Coastguard Worker  message(STATUS "Threads enabled.")
482*9880d681SAndroid Build Coastguard Workerelse( LLVM_ENABLE_THREADS )
483*9880d681SAndroid Build Coastguard Worker  message(STATUS "Threads disabled.")
484*9880d681SAndroid Build Coastguard Workerendif()
485*9880d681SAndroid Build Coastguard Worker
486*9880d681SAndroid Build Coastguard Workerif (LLVM_ENABLE_ZLIB )
487*9880d681SAndroid Build Coastguard Worker  # Check if zlib is available in the system.
488*9880d681SAndroid Build Coastguard Worker  if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
489*9880d681SAndroid Build Coastguard Worker    set(LLVM_ENABLE_ZLIB 0)
490*9880d681SAndroid Build Coastguard Worker  endif()
491*9880d681SAndroid Build Coastguard Workerendif()
492*9880d681SAndroid Build Coastguard Worker
493*9880d681SAndroid Build Coastguard Workerset(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
494*9880d681SAndroid Build Coastguard Worker
495*9880d681SAndroid Build Coastguard Workerif (LLVM_ENABLE_DOXYGEN)
496*9880d681SAndroid Build Coastguard Worker  message(STATUS "Doxygen enabled.")
497*9880d681SAndroid Build Coastguard Worker  find_package(Doxygen REQUIRED)
498*9880d681SAndroid Build Coastguard Worker
499*9880d681SAndroid Build Coastguard Worker  if (DOXYGEN_FOUND)
500*9880d681SAndroid Build Coastguard Worker    # If we find doxygen and we want to enable doxygen by default create a
501*9880d681SAndroid Build Coastguard Worker    # global aggregate doxygen target for generating llvm and any/all
502*9880d681SAndroid Build Coastguard Worker    # subprojects doxygen documentation.
503*9880d681SAndroid Build Coastguard Worker    if (LLVM_BUILD_DOCS)
504*9880d681SAndroid Build Coastguard Worker      add_custom_target(doxygen ALL)
505*9880d681SAndroid Build Coastguard Worker    endif()
506*9880d681SAndroid Build Coastguard Worker
507*9880d681SAndroid Build Coastguard Worker    option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
508*9880d681SAndroid Build Coastguard Worker    if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
509*9880d681SAndroid Build Coastguard Worker      set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.")
510*9880d681SAndroid Build Coastguard Worker      set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
511*9880d681SAndroid Build Coastguard Worker    endif()
512*9880d681SAndroid Build Coastguard Worker  endif()
513*9880d681SAndroid Build Coastguard Workerelse()
514*9880d681SAndroid Build Coastguard Worker  message(STATUS "Doxygen disabled.")
515*9880d681SAndroid Build Coastguard Workerendif()
516*9880d681SAndroid Build Coastguard Worker
517*9880d681SAndroid Build Coastguard Workerif (LLVM_ENABLE_SPHINX)
518*9880d681SAndroid Build Coastguard Worker  message(STATUS "Sphinx enabled.")
519*9880d681SAndroid Build Coastguard Worker  find_package(Sphinx REQUIRED)
520*9880d681SAndroid Build Coastguard Worker  if (LLVM_BUILD_DOCS)
521*9880d681SAndroid Build Coastguard Worker    add_custom_target(sphinx ALL)
522*9880d681SAndroid Build Coastguard Worker  endif()
523*9880d681SAndroid Build Coastguard Workerelse()
524*9880d681SAndroid Build Coastguard Worker  message(STATUS "Sphinx disabled.")
525*9880d681SAndroid Build Coastguard Workerendif()
526*9880d681SAndroid Build Coastguard Worker
527*9880d681SAndroid Build Coastguard Workerset(LLVM_BINDINGS "")
528*9880d681SAndroid Build Coastguard Workerif(WIN32)
529*9880d681SAndroid Build Coastguard Worker  message(STATUS "Go bindings disabled.")
530*9880d681SAndroid Build Coastguard Workerelse()
531*9880d681SAndroid Build Coastguard Worker  find_program(GO_EXECUTABLE NAMES go DOC "go executable")
532*9880d681SAndroid Build Coastguard Worker  if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND")
533*9880d681SAndroid Build Coastguard Worker    message(STATUS "Go bindings disabled.")
534*9880d681SAndroid Build Coastguard Worker  else()
535*9880d681SAndroid Build Coastguard Worker    execute_process(COMMAND ${GO_EXECUTABLE} run ${PROJECT_SOURCE_DIR}/bindings/go/conftest.go
536*9880d681SAndroid Build Coastguard Worker                    RESULT_VARIABLE GO_CONFTEST)
537*9880d681SAndroid Build Coastguard Worker    if(GO_CONFTEST STREQUAL "0")
538*9880d681SAndroid Build Coastguard Worker      set(LLVM_BINDINGS "${LLVM_BINDINGS} go")
539*9880d681SAndroid Build Coastguard Worker      message(STATUS "Go bindings enabled.")
540*9880d681SAndroid Build Coastguard Worker    else()
541*9880d681SAndroid Build Coastguard Worker      message(STATUS "Go bindings disabled, need at least Go 1.2.")
542*9880d681SAndroid Build Coastguard Worker    endif()
543*9880d681SAndroid Build Coastguard Worker  endif()
544*9880d681SAndroid Build Coastguard Workerendif()
545*9880d681SAndroid Build Coastguard Worker
546*9880d681SAndroid Build Coastguard Workerfind_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker")
547*9880d681SAndroid Build Coastguard Workerset(LLVM_BINUTILS_INCDIR "" CACHE PATH
548*9880d681SAndroid Build Coastguard Worker	"PATH to binutils/include containing plugin-api.h for gold plugin.")
549*9880d681SAndroid Build Coastguard Worker
550*9880d681SAndroid Build Coastguard Workerif(APPLE)
551*9880d681SAndroid Build Coastguard Worker  find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker")
552*9880d681SAndroid Build Coastguard Workerendif()
553*9880d681SAndroid Build Coastguard Worker
554*9880d681SAndroid Build Coastguard Workerinclude(FindOCaml)
555*9880d681SAndroid Build Coastguard Workerinclude(AddOCaml)
556*9880d681SAndroid Build Coastguard Workerif(WIN32)
557*9880d681SAndroid Build Coastguard Worker  message(STATUS "OCaml bindings disabled.")
558*9880d681SAndroid Build Coastguard Workerelse()
559*9880d681SAndroid Build Coastguard Worker  find_package(OCaml)
560*9880d681SAndroid Build Coastguard Worker  if( NOT OCAML_FOUND )
561*9880d681SAndroid Build Coastguard Worker    message(STATUS "OCaml bindings disabled.")
562*9880d681SAndroid Build Coastguard Worker  else()
563*9880d681SAndroid Build Coastguard Worker    if( OCAML_VERSION VERSION_LESS "4.00.0" )
564*9880d681SAndroid Build Coastguard Worker      message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.")
565*9880d681SAndroid Build Coastguard Worker    else()
566*9880d681SAndroid Build Coastguard Worker      find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL)
567*9880d681SAndroid Build Coastguard Worker      if( HAVE_OCAML_CTYPES )
568*9880d681SAndroid Build Coastguard Worker        message(STATUS "OCaml bindings enabled.")
569*9880d681SAndroid Build Coastguard Worker        find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
570*9880d681SAndroid Build Coastguard Worker        set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
571*9880d681SAndroid Build Coastguard Worker      else()
572*9880d681SAndroid Build Coastguard Worker        message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
573*9880d681SAndroid Build Coastguard Worker      endif()
574*9880d681SAndroid Build Coastguard Worker    endif()
575*9880d681SAndroid Build Coastguard Worker  endif()
576*9880d681SAndroid Build Coastguard Workerendif()
577*9880d681SAndroid Build Coastguard Worker
578*9880d681SAndroid Build Coastguard Workerstring(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")
579