blob: c58e5bd97b0dbc0add304d499c92ddec42a2c9c9 [file] [log] [blame]
Oscar Fuentes2761c7a2011-02-04 05:40:04 +00001if( WIN32 AND NOT CYGWIN )
2 # We consider Cygwin as another Unix
3 set(PURE_WINDOWS 1)
4endif()
5
Douglas Gregorf99626e2009-10-01 17:25:36 +00006include(CheckIncludeFile)
Benjamin Kramerff2be222013-05-03 14:48:29 +00007include(CheckIncludeFileCXX)
Douglas Gregorf99626e2009-10-01 17:25:36 +00008include(CheckLibraryExists)
9include(CheckSymbolExists)
10include(CheckFunctionExists)
11include(CheckCXXSourceCompiles)
Michael J. Spencerb550b662010-10-21 20:28:21 +000012include(TestBigEndian)
Douglas Gregorf99626e2009-10-01 17:25:36 +000013
Jordan Rose31c5b7b2014-02-05 00:02:37 +000014include(HandleLLVMStdlib)
15
Nick Lewycky99d71d12010-06-23 06:48:34 +000016if( UNIX AND NOT BEOS )
Oscar Fuentesd533e1d2009-11-12 05:36:09 +000017 # Used by check_symbol_exists:
18 set(CMAKE_REQUIRED_LIBRARIES m)
19endif()
20
Douglas Gregorf99626e2009-10-01 17:25:36 +000021# Helper macros and functions
22macro(add_cxx_include result files)
23 set(${result} "")
24 foreach (file_name ${files})
25 set(${result} "${${result}}#include<${file_name}>\n")
26 endforeach()
27endmacro(add_cxx_include files result)
28
29function(check_type_exists type files variable)
30 add_cxx_include(includes "${files}")
31 CHECK_CXX_SOURCE_COMPILES("
32 ${includes} ${type} typeVar;
33 int main() {
34 return 0;
35 }
36 " ${variable})
37endfunction()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000038
39# include checks
Benjamin Kramerff2be222013-05-03 14:48:29 +000040check_include_file_cxx(cxxabi.h HAVE_CXXABI_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000041check_include_file(dirent.h HAVE_DIRENT_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000042check_include_file(dlfcn.h HAVE_DLFCN_H)
43check_include_file(errno.h HAVE_ERRNO_H)
44check_include_file(execinfo.h HAVE_EXECINFO_H)
45check_include_file(fcntl.h HAVE_FCNTL_H)
46check_include_file(inttypes.h HAVE_INTTYPES_H)
47check_include_file(limits.h HAVE_LIMITS_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000048check_include_file(malloc.h HAVE_MALLOC_H)
49check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000050check_include_file(ndir.h HAVE_NDIR_H)
Oscar Fuentes2761c7a2011-02-04 05:40:04 +000051if( NOT PURE_WINDOWS )
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +000052 check_include_file(pthread.h HAVE_PTHREAD_H)
53endif()
Evgeniy Stepanov130fdcd2013-01-31 09:58:59 +000054check_include_file(sanitizer/msan_interface.h HAVE_SANITIZER_MSAN_INTERFACE_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000055check_include_file(signal.h HAVE_SIGNAL_H)
56check_include_file(stdint.h HAVE_STDINT_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000057check_include_file(sys/dir.h HAVE_SYS_DIR_H)
Douglas Gregor15436612009-05-11 18:05:52 +000058check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000059check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
60check_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
61check_include_file(sys/param.h HAVE_SYS_PARAM_H)
62check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
63check_include_file(sys/stat.h HAVE_SYS_STAT_H)
64check_include_file(sys/time.h HAVE_SYS_TIME_H)
Oscar Fuentesed27ead2011-02-03 04:23:07 +000065check_include_file(sys/uio.h HAVE_SYS_UIO_H)
Douglas Gregor5f11afc2009-06-05 23:46:34 +000066check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
Douglas Gregorb81294d2009-05-18 17:21:34 +000067check_include_file(termios.h HAVE_TERMIOS_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000068check_include_file(unistd.h HAVE_UNISTD_H)
69check_include_file(utime.h HAVE_UTIME_H)
Jeffrey Yasskin3ddd88f2010-03-15 04:57:55 +000070check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
Alexey Samsonov2fb337e2013-04-23 08:28:39 +000071check_include_file(zlib.h HAVE_ZLIB_H)
Oscar Fuentesbcc8b2f2010-09-17 20:30:48 +000072check_include_file(fenv.h HAVE_FENV_H)
Joerg Sonnenberger8a1177f2013-03-25 13:13:33 +000073check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
74check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
75
Oscar Fuentese65ed1c2011-01-17 16:35:14 +000076check_include_file(mach/mach.h HAVE_MACH_MACH_H)
77check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000078
Oscar Fuentesa6e20062009-05-06 14:40:37 +000079# library checks
Oscar Fuentes2761c7a2011-02-04 05:40:04 +000080if( NOT PURE_WINDOWS )
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +000081 check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
Evgeniy Stepanovc439a422012-09-04 09:14:45 +000082 if (HAVE_LIBPTHREAD)
83 check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
84 check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
85 check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
86 else()
87 # this could be Android
88 check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)
89 if (PTHREAD_IN_LIBC)
90 check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
91 check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
92 check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
93 endif()
94 endif()
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +000095 check_library_exists(dl dlopen "" HAVE_LIBDL)
Chandler Carruthef7f9682013-01-04 23:19:55 +000096 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
Alexey Samsonov068fc8a2013-04-23 10:17:34 +000097 if (LLVM_ENABLE_ZLIB)
98 check_library_exists(z compress2 "" HAVE_LIBZ)
99 else()
100 set(HAVE_LIBZ 0)
101 endif()
Peter Collingbournec7d437c2014-01-31 23:46:14 +0000102 check_library_exists(edit el_init "" HAVE_LIBEDIT)
Chandler Carruth91219852013-08-12 10:40:11 +0000103 if(LLVM_ENABLE_TERMINFO)
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000104 set(HAVE_TERMINFO 0)
Joerg Sonnenberger4e5a3992013-08-17 11:06:00 +0000105 foreach(library tinfo terminfo curses ncurses ncursesw)
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000106 string(TOUPPER ${library} library_suffix)
107 check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
108 if(HAVE_TERMINFO_${library_suffix})
109 set(HAVE_TERMINFO 1)
110 set(TERMINFO_LIBS "${library}")
111 break()
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000112 endif()
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000113 endforeach()
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000114 else()
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000115 set(HAVE_TERMINFO 0)
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000116 endif()
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +0000117endif()
Oscar Fuentesa6e20062009-05-06 14:40:37 +0000118
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000119# function checks
Daniel Dunbar407a85e2012-05-05 16:36:16 +0000120check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM)
Benjamin Kramerd02949b2012-09-01 20:50:18 +0000121check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000122check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
123check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
124check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
Ted Kremenek6ea1b762011-12-23 01:31:45 +0000125check_symbol_exists(isatty unistd.h HAVE_ISATTY)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000126check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
127check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000128check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000129check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
130check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000131check_symbol_exists(ceilf math.h HAVE_CEILF)
132check_symbol_exists(floorf math.h HAVE_FLOORF)
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000133check_symbol_exists(fmodf math.h HAVE_FMODF)
Jordan Rosecea01ee2013-02-08 23:17:31 +0000134check_symbol_exists(log math.h HAVE_LOG)
135check_symbol_exists(log2 math.h HAVE_LOG2)
136check_symbol_exists(log10 math.h HAVE_LOG10)
137check_symbol_exists(exp math.h HAVE_EXP)
138check_symbol_exists(exp2 math.h HAVE_EXP2)
139check_symbol_exists(exp10 math.h HAVE_EXP10)
Eric Christophera24dc7f2013-07-04 01:10:38 +0000140check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
141check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
Oscar Fuentese866c412011-01-31 18:25:25 +0000142if( HAVE_SETJMP_H )
143 check_symbol_exists(longjmp setjmp.h HAVE_LONGJMP)
144 check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
145 check_symbol_exists(siglongjmp setjmp.h HAVE_SIGLONGJMP)
146 check_symbol_exists(sigsetjmp setjmp.h HAVE_SIGSETJMP)
147endif()
Oscar Fuentesed27ead2011-02-03 04:23:07 +0000148if( HAVE_SYS_UIO_H )
149 check_symbol_exists(writev sys/uio.h HAVE_WRITEV)
150endif()
Oscar Fuentesd533e1d2009-11-12 05:36:09 +0000151check_symbol_exists(nearbyintf math.h HAVE_NEARBYINTF)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000152check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
Douglas Gregor60dd76f2009-06-04 17:22:52 +0000153check_symbol_exists(malloc_zone_statistics malloc/malloc.h
154 HAVE_MALLOC_ZONE_STATISTICS)
Benjamin Kramerc1ba4c22009-10-28 18:37:31 +0000155check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
156check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
157check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
Oscar Fuentes0a1b6b82011-01-13 19:17:28 +0000158check_symbol_exists(closedir "sys/types.h;dirent.h" HAVE_CLOSEDIR)
159check_symbol_exists(opendir "sys/types.h;dirent.h" HAVE_OPENDIR)
Oscar Fuentese866c412011-01-31 18:25:25 +0000160check_symbol_exists(readdir "sys/types.h;dirent.h" HAVE_READDIR)
Oscar Fuentes0a1b6b82011-01-13 19:17:28 +0000161check_symbol_exists(getcwd unistd.h HAVE_GETCWD)
162check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
163check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
Benjamin Kramere1effb02011-11-22 12:31:53 +0000164check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
165check_symbol_exists(pread unistd.h HAVE_PREAD)
Alexey Samsonov30c0ecc2013-08-26 18:11:25 +0000166check_symbol_exists(realpath stdlib.h HAVE_REALPATH)
Edward O'Callaghan655314e2009-10-05 23:05:32 +0000167check_symbol_exists(sbrk unistd.h HAVE_SBRK)
Oscar Fuentese866c412011-01-31 18:25:25 +0000168check_symbol_exists(srand48 stdlib.h HAVE_RAND48_SRAND48)
169if( HAVE_RAND48_SRAND48 )
170 check_symbol_exists(lrand48 stdlib.h HAVE_RAND48_LRAND48)
171 if( HAVE_RAND48_LRAND48 )
172 check_symbol_exists(drand48 stdlib.h HAVE_RAND48_DRAND48)
173 if( HAVE_RAND48_DRAND48 )
174 set(HAVE_RAND48 1 CACHE INTERNAL "are srand48/lrand48/drand48 available?")
175 endif()
176 endif()
177endif()
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000178check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
Oscar Fuentese866c412011-01-31 18:25:25 +0000179check_symbol_exists(strtoq stdlib.h HAVE_STRTOQ)
Jeffrey Yasskin1a933302009-07-01 18:11:20 +0000180check_symbol_exists(strerror string.h HAVE_STRERROR)
181check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
NAKAMURA Takumi189111802011-02-09 04:18:48 +0000182check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
Jeffrey Yasskin14a5cc52009-09-25 21:07:20 +0000183check_symbol_exists(setenv stdlib.h HAVE_SETENV)
Oscar Fuentes2761c7a2011-02-04 05:40:04 +0000184if( PURE_WINDOWS )
Michael J. Spencerca242f22010-12-03 18:48:56 +0000185 check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
NAKAMURA Takumi03a541f2011-02-05 15:11:53 +0000186
187 check_function_exists(_alloca HAVE__ALLOCA)
188 check_function_exists(__alloca HAVE___ALLOCA)
189 check_function_exists(__chkstk HAVE___CHKSTK)
190 check_function_exists(___chkstk HAVE____CHKSTK)
191
192 check_function_exists(__ashldi3 HAVE___ASHLDI3)
193 check_function_exists(__ashrdi3 HAVE___ASHRDI3)
194 check_function_exists(__divdi3 HAVE___DIVDI3)
195 check_function_exists(__fixdfdi HAVE___FIXDFDI)
196 check_function_exists(__fixsfdi HAVE___FIXSFDI)
197 check_function_exists(__floatdidf HAVE___FLOATDIDF)
198 check_function_exists(__lshrdi3 HAVE___LSHRDI3)
199 check_function_exists(__moddi3 HAVE___MODDI3)
200 check_function_exists(__udivdi3 HAVE___UDIVDI3)
201 check_function_exists(__umoddi3 HAVE___UMODDI3)
202
203 check_function_exists(__main HAVE___MAIN)
204 check_function_exists(__cmpdi2 HAVE___CMPDI2)
Michael J. Spencerca242f22010-12-03 18:48:56 +0000205endif()
Oscar Fuentese866c412011-01-31 18:25:25 +0000206if( HAVE_DLFCN_H )
207 if( HAVE_LIBDL )
208 list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
209 endif()
Oscar Fuentese65ed1c2011-01-17 16:35:14 +0000210 check_symbol_exists(dlerror dlfcn.h HAVE_DLERROR)
211 check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
Oscar Fuentese866c412011-01-31 18:25:25 +0000212 if( HAVE_LIBDL )
213 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
214 endif()
Oscar Fuentese65ed1c2011-01-17 16:35:14 +0000215endif()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000216
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000217check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
218if( LLVM_USING_GLIBC )
219 add_llvm_definitions( -D_GNU_SOURCE )
220endif()
221
Reid Kleckner37f69de2013-07-26 16:54:23 +0000222set(headers "sys/types.h")
Douglas Gregorf99626e2009-10-01 17:25:36 +0000223
224if (HAVE_INTTYPES_H)
225 set(headers ${headers} "inttypes.h")
226endif()
227
228if (HAVE_STDINT_H)
229 set(headers ${headers} "stdint.h")
230endif()
231
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000232check_type_exists(int64_t "${headers}" HAVE_INT64_T)
Douglas Gregorf99626e2009-10-01 17:25:36 +0000233check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
234check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
235
Oscar Fuentes17feb2a2009-11-05 19:03:26 +0000236# available programs checks
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000237function(llvm_find_program name)
238 string(TOUPPER ${name} NAME)
Tobias Grosser1b4f9402011-02-27 04:11:05 +0000239 string(REGEX REPLACE "\\." "_" NAME ${NAME})
Matt Arsenault90962172013-07-08 20:24:49 +0000240
241 find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000242 mark_as_advanced(LLVM_PATH_${NAME})
243 if(LLVM_PATH_${NAME})
244 set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
245 mark_as_advanced(HAVE_${NAME})
246 else(LLVM_PATH_${NAME})
247 set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000248 endif(LLVM_PATH_${NAME})
249endfunction()
250
251llvm_find_program(gv)
252llvm_find_program(circo)
253llvm_find_program(twopi)
254llvm_find_program(neato)
255llvm_find_program(fdp)
256llvm_find_program(dot)
257llvm_find_program(dotty)
Matt Arsenaultfe56cc62013-07-08 20:24:54 +0000258llvm_find_program(xdot xdot.py)
Ted Kremenek12338952012-05-03 21:51:05 +0000259llvm_find_program(Graphviz)
Oscar Fuentes17feb2a2009-11-05 19:03:26 +0000260
Oscar Fuentes64955952011-01-21 15:42:54 +0000261if( LLVM_ENABLE_FFI )
262 find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
263 if( FFI_INCLUDE_PATH )
264 set(FFI_HEADER ffi.h CACHE INTERNAL "")
265 set(HAVE_FFI_H 1 CACHE INTERNAL "")
266 else()
267 find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
268 if( FFI_INCLUDE_PATH )
269 set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
270 set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
271 endif()
272 endif()
273
274 if( NOT FFI_HEADER )
275 message(FATAL_ERROR "libffi includes are not found.")
276 endif()
277
278 find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
279 if( NOT FFI_LIBRARY_PATH )
280 message(FATAL_ERROR "libffi is not found.")
281 endif()
282
283 list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
284 list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
285 check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
286 list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
287 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
Oscar Fuentesf2ab9282011-04-02 13:21:12 +0000288else()
289 unset(HAVE_FFI_FFI_H CACHE)
290 unset(HAVE_FFI_H CACHE)
291 unset(HAVE_FFI_CALL CACHE)
Oscar Fuentes64955952011-01-21 15:42:54 +0000292endif( LLVM_ENABLE_FFI )
293
Eric Christopher4418a602011-09-19 20:43:23 +0000294# Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
Xerxes Ranby64c6d422009-07-17 19:22:41 +0000295include(CheckAtomic)
296
Oscar Fuentes25ac8302011-01-15 13:35:37 +0000297if( LLVM_ENABLE_PIC )
298 set(ENABLE_PIC 1)
299else()
300 set(ENABLE_PIC 0)
301endif()
Oscar Fuentesedfc1842011-01-09 14:34:39 +0000302
NAKAMURA Takumi92eb2542012-12-14 18:30:20 +0000303find_package(LibXml2)
304if (LIBXML2_FOUND)
305 set(CLANG_HAVE_LIBXML 1)
Renato Golin74c652e2013-09-10 14:24:17 +0000306 # When cross-compiling, liblzma is not detected as a dependency for libxml2,
307 # which makes linking c-index-test fail. But for native builds, all libraries
308 # are installed and checked by CMake before Makefiles are generated and everything
309 # works according to the plan. However, if a -llzma is added to native builds,
310 # an additional requirement on the static liblzma.a is required, but will not
311 # be checked by CMake, breaking native compilation.
312 # Since this is only pertinent to cross-compilations, and there's no way CMake
313 # can check for every foreign library on every OS, we add the dep and warn the dev.
Alexey Samsonov9c0748a2013-09-12 08:26:53 +0000314 if ( CMAKE_CROSSCOMPILING )
Renato Golin74c652e2013-09-10 14:24:17 +0000315 if (NOT PC_LIBXML_VERSION VERSION_LESS "2.8.0")
316 message(STATUS "Adding LZMA as a dep to XML2 for cross-compilation, make sure liblzma.a is available.")
317 set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} "-llzma")
318 endif ()
NAKAMURA Takumi72302462013-09-11 09:42:03 +0000319 endif ()
NAKAMURA Takumi92eb2542012-12-14 18:30:20 +0000320endif ()
321
Michael J. Spencer33a390e2010-10-07 18:12:54 +0000322check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
323
Edwin Vanea9c5bb32013-02-04 02:32:44 +0000324set(USE_NO_MAYBE_UNINITIALIZED 0)
325set(USE_NO_UNINITIALIZED 0)
326
327# Disable gcc's potentially uninitialized use analysis as it presents lots of
328# false positives.
329if (CMAKE_COMPILER_IS_GNUCXX)
330 check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
331 if (HAS_MAYBE_UNINITIALIZED)
332 set(USE_NO_MAYBE_UNINITIALIZED 1)
333 else()
334 # Only recent versions of gcc make the distinction between -Wuninitialized
335 # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
336 # turn off all uninitialized use warnings.
337 check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
338 set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
339 endif()
340endif()
341
Sebastian Pop82622dc2012-08-08 18:04:45 +0000342# By default, we target the host, but this can be overridden at CMake
343# invocation time.
Tim Northoverfee13d12013-05-04 07:36:23 +0000344include(GetHostTriple)
345get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
346
347set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
348 "Host on which LLVM binaries will run")
Daniel Dunbarc0fd8a42009-11-07 23:52:20 +0000349
Douglas Gregor3def8472009-06-17 17:01:56 +0000350# Determine the native architecture.
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000351string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
352if( LLVM_NATIVE_ARCH STREQUAL "host" )
Chandler Carruthbeb3e7e2012-01-24 18:00:44 +0000353 string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000354endif ()
355
Douglas Gregor3def8472009-06-17 17:01:56 +0000356if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
357 set(LLVM_NATIVE_ARCH X86)
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000358elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
Douglas Gregor3def8472009-06-17 17:01:56 +0000359 set(LLVM_NATIVE_ARCH X86)
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000360elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
361 set(LLVM_NATIVE_ARCH X86)
362elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
Douglas Gregor3def8472009-06-17 17:01:56 +0000363 set(LLVM_NATIVE_ARCH X86)
364elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
365 set(LLVM_NATIVE_ARCH Sparc)
366elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
367 set(LLVM_NATIVE_ARCH PowerPC)
Tim Northovera958a572013-05-04 20:13:52 +0000368elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
369 set(LLVM_NATIVE_ARCH AArch64)
Douglas Gregor3def8472009-06-17 17:01:56 +0000370elseif (LLVM_NATIVE_ARCH MATCHES "arm")
371 set(LLVM_NATIVE_ARCH ARM)
372elseif (LLVM_NATIVE_ARCH MATCHES "mips")
373 set(LLVM_NATIVE_ARCH Mips)
Douglas Gregor3def8472009-06-17 17:01:56 +0000374elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
375 set(LLVM_NATIVE_ARCH XCore)
376elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
377 set(LLVM_NATIVE_ARCH MSP430)
Sebastian Pop8f4aec42012-08-20 19:56:49 +0000378elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
379 set(LLVM_NATIVE_ARCH Hexagon)
Ulrich Weigand1ceebf62013-05-06 16:22:34 +0000380elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
381 set(LLVM_NATIVE_ARCH SystemZ)
Douglas Gregor3def8472009-06-17 17:01:56 +0000382else ()
Oscar Fuentes465f9362011-03-23 17:42:13 +0000383 message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
Douglas Gregor3def8472009-06-17 17:01:56 +0000384endif ()
Michael J. Spencer1444f472010-09-24 09:00:56 +0000385
Andy Gibbsf5dede12013-06-26 07:57:53 +0000386# If build targets includes "host", then replace with native architecture.
387list(FIND LLVM_TARGETS_TO_BUILD "host" idx)
388if( NOT idx LESS 0 )
389 list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
390 list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
391 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
392endif()
393
Oscar Fuentes465f9362011-03-23 17:42:13 +0000394list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
395if (NATIVE_ARCH_IDX EQUAL -1)
396 message(STATUS
397 "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
398else ()
399 message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
400 set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
401 set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
Evan Cheng8c886a42011-07-22 21:58:54 +0000402 set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
Oscar Fuentes465f9362011-03-23 17:42:13 +0000403 set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
Chandler Carruth98e642d2011-12-09 03:31:58 +0000404
405 # We don't have an ASM parser for all architectures yet.
406 if (EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
407 set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
408 endif ()
Eric Christopher56079c12012-03-26 21:56:56 +0000409
410 # We don't have an disassembler for all architectures yet.
411 if (EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
412 set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
413 endif ()
Oscar Fuentes465f9362011-03-23 17:42:13 +0000414endif ()
Douglas Gregor3def8472009-06-17 17:01:56 +0000415
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000416if( MINGW )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000417 set(HAVE_LIBIMAGEHLP 1)
418 set(HAVE_LIBPSAPI 1)
David Majnemer61eae2e2013-10-07 01:00:07 +0000419 set(HAVE_LIBSHELL32 1)
Oscar Fuentes2500aae2008-10-29 02:33:15 +0000420 # TODO: Check existence of libraries.
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000421 # include(CheckLibraryExists)
422 # CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
423endif( MINGW )
424
Reid Klecknera3ae94e2013-08-07 00:29:15 +0000425if (NOT HAVE_STRTOLL)
426 # Use _strtoi64 if strtoll is not available.
427 check_symbol_exists(_strtoi64 stdlib.h have_strtoi64)
428 if (have_strtoi64)
429 set(HAVE_STRTOLL 1)
430 set(strtoll "_strtoi64")
431 set(strtoull "_strtoui64")
432 endif ()
433endif ()
434
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000435if( MSVC )
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000436 set(SHLIBEXT ".lib")
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000437 set(stricmp "_stricmp")
438 set(strdup "_strdup")
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000439endif( MSVC )
440
NAKAMURA Takumi4471f822011-05-01 13:29:49 +0000441if( PURE_WINDOWS )
442 CHECK_CXX_SOURCE_COMPILES("
443 #include <windows.h>
444 #include <imagehlp.h>
445 extern \"C\" void foo(PENUMLOADED_MODULES_CALLBACK);
446 extern \"C\" void foo(BOOL(CALLBACK*)(PCSTR,ULONG_PTR,ULONG,PVOID));
447 int main(){return 0;}"
448 HAVE_ELMCB_PCSTR)
449 if( HAVE_ELMCB_PCSTR )
450 set(WIN32_ELMCB_PCSTR "PCSTR")
451 else()
452 set(WIN32_ELMCB_PCSTR "PSTR")
453 endif()
454endif( PURE_WINDOWS )
455
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000456# FIXME: Signal handler return type, currently hardcoded to 'void'
457set(RETSIGTYPE void)
458
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000459if( LLVM_ENABLE_THREADS )
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000460 # Check if threading primitives aren't supported on this platform
461 if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
462 set(LLVM_ENABLE_THREADS 0)
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000463 endif()
464endif()
465
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000466if( LLVM_ENABLE_THREADS )
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000467 message(STATUS "Threads enabled.")
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000468else( LLVM_ENABLE_THREADS )
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000469 message(STATUS "Threads disabled.")
470endif()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000471
Alexey Samsonov2fb337e2013-04-23 08:28:39 +0000472if (LLVM_ENABLE_ZLIB )
473 # Check if zlib is available in the system.
474 if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
475 set(LLVM_ENABLE_ZLIB 0)
476 endif()
477endif()
478
Oscar Fuentes2b1077f2010-08-08 04:32:21 +0000479set(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
Michael Gottesman4d35b902013-08-24 07:25:21 +0000480
481if (LLVM_ENABLE_DOXYGEN)
482 message(STATUS "Doxygen enabled.")
483 find_package(Doxygen)
Michael Gottesman9cc5a452013-08-28 20:28:32 +0000484
485 if (DOXYGEN_FOUND)
486 # If we find doxygen and we want to enable doxygen by default create a
487 # global aggregate doxygen target for generating llvm and any/all
488 # subprojects doxygen documentation.
489 if (LLVM_BUILD_DOCS)
490 add_custom_target(doxygen ALL)
491 endif()
Michael Gottesman406525d2013-08-28 21:55:26 +0000492
493 option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
494 if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
495 set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external searhc.")
496 set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
497 endif()
Michael Gottesman9cc5a452013-08-28 20:28:32 +0000498 endif()
Michael Gottesman4d35b902013-08-24 07:25:21 +0000499else()
500 message(STATUS "Doxygen disabled.")
501endif()