blob: fe1d6c9755edec962665a340e959e376db2bc4cf [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()
Viktor Kutuzov6bd32292014-04-09 11:43:34 +000020# x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.
21if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND
22 CMAKE_SIZEOF_VOID_P EQUAL 8 )
23 list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt")
24endif()
Oscar Fuentesd533e1d2009-11-12 05:36:09 +000025
Douglas Gregorf99626e2009-10-01 17:25:36 +000026# Helper macros and functions
27macro(add_cxx_include result files)
28 set(${result} "")
29 foreach (file_name ${files})
30 set(${result} "${${result}}#include<${file_name}>\n")
31 endforeach()
32endmacro(add_cxx_include files result)
33
34function(check_type_exists type files variable)
35 add_cxx_include(includes "${files}")
36 CHECK_CXX_SOURCE_COMPILES("
37 ${includes} ${type} typeVar;
38 int main() {
39 return 0;
40 }
41 " ${variable})
42endfunction()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000043
44# include checks
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000045check_include_file(dirent.h HAVE_DIRENT_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000046check_include_file(dlfcn.h HAVE_DLFCN_H)
47check_include_file(errno.h HAVE_ERRNO_H)
48check_include_file(execinfo.h HAVE_EXECINFO_H)
49check_include_file(fcntl.h HAVE_FCNTL_H)
50check_include_file(inttypes.h HAVE_INTTYPES_H)
51check_include_file(limits.h HAVE_LIMITS_H)
Alexey Samsonov8a584bb2014-10-10 22:06:59 +000052check_include_file(link.h HAVE_LINK_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000053check_include_file(malloc.h HAVE_MALLOC_H)
54check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000055check_include_file(ndir.h HAVE_NDIR_H)
Oscar Fuentes2761c7a2011-02-04 05:40:04 +000056if( NOT PURE_WINDOWS )
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +000057 check_include_file(pthread.h HAVE_PTHREAD_H)
58endif()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000059check_include_file(signal.h HAVE_SIGNAL_H)
60check_include_file(stdint.h HAVE_STDINT_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000061check_include_file(sys/dir.h HAVE_SYS_DIR_H)
Douglas Gregor15436612009-05-11 18:05:52 +000062check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000063check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
64check_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
65check_include_file(sys/param.h HAVE_SYS_PARAM_H)
66check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
67check_include_file(sys/stat.h HAVE_SYS_STAT_H)
68check_include_file(sys/time.h HAVE_SYS_TIME_H)
Oscar Fuentesed27ead2011-02-03 04:23:07 +000069check_include_file(sys/uio.h HAVE_SYS_UIO_H)
Douglas Gregor5f11afc2009-06-05 23:46:34 +000070check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
Douglas Gregorb81294d2009-05-18 17:21:34 +000071check_include_file(termios.h HAVE_TERMIOS_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000072check_include_file(unistd.h HAVE_UNISTD_H)
73check_include_file(utime.h HAVE_UTIME_H)
Jeffrey Yasskin3ddd88f2010-03-15 04:57:55 +000074check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
Alexey Samsonov2fb337e2013-04-23 08:28:39 +000075check_include_file(zlib.h HAVE_ZLIB_H)
Oscar Fuentesbcc8b2f2010-09-17 20:30:48 +000076check_include_file(fenv.h HAVE_FENV_H)
Joerg Sonnenberger8a1177f2013-03-25 13:13:33 +000077check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
78check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
79
Oscar Fuentese65ed1c2011-01-17 16:35:14 +000080check_include_file(mach/mach.h HAVE_MACH_MACH_H)
81check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
Chris Bienemanb2d71492015-01-30 00:10:43 +000082check_include_file(histedit.h HAVE_HISTEDIT_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000083
Rui Ueyama292fb6d2014-10-27 08:16:18 +000084# size_t must be defined before including cxxabi.h on FreeBSD 10.0.
85check_cxx_source_compiles("
86#include <stddef.h>
87#include <cxxabi.h>
88int main() { return 0; }
89" HAVE_CXXABI_H)
90
Oscar Fuentesa6e20062009-05-06 14:40:37 +000091# library checks
Oscar Fuentes2761c7a2011-02-04 05:40:04 +000092if( NOT PURE_WINDOWS )
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +000093 check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
Evgeniy Stepanovc439a422012-09-04 09:14:45 +000094 if (HAVE_LIBPTHREAD)
95 check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
96 check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
97 check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
98 else()
99 # this could be Android
100 check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)
101 if (PTHREAD_IN_LIBC)
102 check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
103 check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
104 check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
105 endif()
106 endif()
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +0000107 check_library_exists(dl dlopen "" HAVE_LIBDL)
Chandler Carruthef7f9682013-01-04 23:19:55 +0000108 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000109 if (LLVM_ENABLE_ZLIB)
110 check_library_exists(z compress2 "" HAVE_LIBZ)
111 else()
112 set(HAVE_LIBZ 0)
113 endif()
Chris Bienemanb2d71492015-01-30 00:10:43 +0000114 if (HAVE_HISTEDIT_H)
115 check_library_exists(edit el_init "" HAVE_LIBEDIT)
116 endif()
Chandler Carruth91219852013-08-12 10:40:11 +0000117 if(LLVM_ENABLE_TERMINFO)
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000118 set(HAVE_TERMINFO 0)
Joerg Sonnenberger4e5a3992013-08-17 11:06:00 +0000119 foreach(library tinfo terminfo curses ncurses ncursesw)
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000120 string(TOUPPER ${library} library_suffix)
121 check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
122 if(HAVE_TERMINFO_${library_suffix})
123 set(HAVE_TERMINFO 1)
124 set(TERMINFO_LIBS "${library}")
125 break()
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000126 endif()
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000127 endforeach()
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000128 else()
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000129 set(HAVE_TERMINFO 0)
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000130 endif()
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +0000131endif()
Oscar Fuentesa6e20062009-05-06 14:40:37 +0000132
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000133# function checks
Todd Fiala4ccfe392014-02-05 05:04:36 +0000134check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
Benjamin Kramerd02949b2012-09-01 20:50:18 +0000135check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000136check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
137check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
138check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
Ted Kremenek6ea1b762011-12-23 01:31:45 +0000139check_symbol_exists(isatty unistd.h HAVE_ISATTY)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000140check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
141check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000142check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000143check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
144check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000145check_symbol_exists(ceilf math.h HAVE_CEILF)
146check_symbol_exists(floorf math.h HAVE_FLOORF)
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000147check_symbol_exists(fmodf math.h HAVE_FMODF)
Jordan Rosecea01ee2013-02-08 23:17:31 +0000148check_symbol_exists(log math.h HAVE_LOG)
149check_symbol_exists(log2 math.h HAVE_LOG2)
150check_symbol_exists(log10 math.h HAVE_LOG10)
151check_symbol_exists(exp math.h HAVE_EXP)
152check_symbol_exists(exp2 math.h HAVE_EXP2)
153check_symbol_exists(exp10 math.h HAVE_EXP10)
Eric Christophera24dc7f2013-07-04 01:10:38 +0000154check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
155check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
Oscar Fuentese866c412011-01-31 18:25:25 +0000156if( HAVE_SETJMP_H )
157 check_symbol_exists(longjmp setjmp.h HAVE_LONGJMP)
158 check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
159 check_symbol_exists(siglongjmp setjmp.h HAVE_SIGLONGJMP)
160 check_symbol_exists(sigsetjmp setjmp.h HAVE_SIGSETJMP)
161endif()
Oscar Fuentesed27ead2011-02-03 04:23:07 +0000162if( HAVE_SYS_UIO_H )
163 check_symbol_exists(writev sys/uio.h HAVE_WRITEV)
164endif()
Oscar Fuentesd533e1d2009-11-12 05:36:09 +0000165check_symbol_exists(nearbyintf math.h HAVE_NEARBYINTF)
Davide Italianofaafae32015-02-19 07:27:14 +0000166check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000167check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
Douglas Gregor60dd76f2009-06-04 17:22:52 +0000168check_symbol_exists(malloc_zone_statistics malloc/malloc.h
169 HAVE_MALLOC_ZONE_STATISTICS)
Benjamin Kramerc1ba4c22009-10-28 18:37:31 +0000170check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
171check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
172check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
Oscar Fuentes0a1b6b82011-01-13 19:17:28 +0000173check_symbol_exists(closedir "sys/types.h;dirent.h" HAVE_CLOSEDIR)
174check_symbol_exists(opendir "sys/types.h;dirent.h" HAVE_OPENDIR)
Oscar Fuentese866c412011-01-31 18:25:25 +0000175check_symbol_exists(readdir "sys/types.h;dirent.h" HAVE_READDIR)
Oscar Fuentes0a1b6b82011-01-13 19:17:28 +0000176check_symbol_exists(getcwd unistd.h HAVE_GETCWD)
177check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
178check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
Benjamin Kramere1effb02011-11-22 12:31:53 +0000179check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
180check_symbol_exists(pread unistd.h HAVE_PREAD)
Alexey Samsonov30c0ecc2013-08-26 18:11:25 +0000181check_symbol_exists(realpath stdlib.h HAVE_REALPATH)
Edward O'Callaghan655314e2009-10-05 23:05:32 +0000182check_symbol_exists(sbrk unistd.h HAVE_SBRK)
Oscar Fuentese866c412011-01-31 18:25:25 +0000183check_symbol_exists(srand48 stdlib.h HAVE_RAND48_SRAND48)
184if( HAVE_RAND48_SRAND48 )
185 check_symbol_exists(lrand48 stdlib.h HAVE_RAND48_LRAND48)
186 if( HAVE_RAND48_LRAND48 )
187 check_symbol_exists(drand48 stdlib.h HAVE_RAND48_DRAND48)
188 if( HAVE_RAND48_DRAND48 )
189 set(HAVE_RAND48 1 CACHE INTERNAL "are srand48/lrand48/drand48 available?")
190 endif()
191 endif()
192endif()
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000193check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
Oscar Fuentese866c412011-01-31 18:25:25 +0000194check_symbol_exists(strtoq stdlib.h HAVE_STRTOQ)
Jeffrey Yasskin1a933302009-07-01 18:11:20 +0000195check_symbol_exists(strerror string.h HAVE_STRERROR)
196check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
NAKAMURA Takumi189111802011-02-09 04:18:48 +0000197check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
Jeffrey Yasskin14a5cc52009-09-25 21:07:20 +0000198check_symbol_exists(setenv stdlib.h HAVE_SETENV)
Oscar Fuentes2761c7a2011-02-04 05:40:04 +0000199if( PURE_WINDOWS )
Michael J. Spencerca242f22010-12-03 18:48:56 +0000200 check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
NAKAMURA Takumi03a541f2011-02-05 15:11:53 +0000201
202 check_function_exists(_alloca HAVE__ALLOCA)
203 check_function_exists(__alloca HAVE___ALLOCA)
204 check_function_exists(__chkstk HAVE___CHKSTK)
NAKAMURA Takumi78855072015-01-30 13:01:19 +0000205 check_function_exists(__chkstk_ms HAVE___CHKSTK_MS)
NAKAMURA Takumi03a541f2011-02-05 15:11:53 +0000206 check_function_exists(___chkstk HAVE____CHKSTK)
NAKAMURA Takumi78855072015-01-30 13:01:19 +0000207 check_function_exists(___chkstk_ms HAVE____CHKSTK_MS)
NAKAMURA Takumi03a541f2011-02-05 15:11:53 +0000208
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)
Michael J. Spencerca242f22010-12-03 18:48:56 +0000222endif()
Oscar Fuentese866c412011-01-31 18:25:25 +0000223if( HAVE_DLFCN_H )
224 if( HAVE_LIBDL )
225 list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
226 endif()
Oscar Fuentese65ed1c2011-01-17 16:35:14 +0000227 check_symbol_exists(dlerror dlfcn.h HAVE_DLERROR)
228 check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
Oscar Fuentese866c412011-01-31 18:25:25 +0000229 if( HAVE_LIBDL )
230 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
231 endif()
Oscar Fuentese65ed1c2011-01-17 16:35:14 +0000232endif()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000233
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000234check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
235if( LLVM_USING_GLIBC )
236 add_llvm_definitions( -D_GNU_SOURCE )
237endif()
238
Reid Kleckner37f69de2013-07-26 16:54:23 +0000239set(headers "sys/types.h")
Douglas Gregorf99626e2009-10-01 17:25:36 +0000240
241if (HAVE_INTTYPES_H)
242 set(headers ${headers} "inttypes.h")
243endif()
244
245if (HAVE_STDINT_H)
246 set(headers ${headers} "stdint.h")
247endif()
248
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000249check_type_exists(int64_t "${headers}" HAVE_INT64_T)
Douglas Gregorf99626e2009-10-01 17:25:36 +0000250check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
251check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
252
Oscar Fuentes17feb2a2009-11-05 19:03:26 +0000253# available programs checks
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000254function(llvm_find_program name)
255 string(TOUPPER ${name} NAME)
Tobias Grosser1b4f9402011-02-27 04:11:05 +0000256 string(REGEX REPLACE "\\." "_" NAME ${NAME})
Matt Arsenault90962172013-07-08 20:24:49 +0000257
258 find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000259 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 ?")
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000265 endif(LLVM_PATH_${NAME})
266endfunction()
267
Alp Toker125be842014-06-02 01:40:04 +0000268if (LLVM_ENABLE_DOXYGEN)
269 llvm_find_program(dot)
270endif ()
Oscar Fuentes17feb2a2009-11-05 19:03:26 +0000271
Oscar Fuentes64955952011-01-21 15:42:54 +0000272if( LLVM_ENABLE_FFI )
273 find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
Josh Klontzda295e92014-08-08 14:32:56 +0000274 if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" )
Oscar Fuentes64955952011-01-21 15:42:54 +0000275 set(FFI_HEADER ffi.h CACHE INTERNAL "")
276 set(HAVE_FFI_H 1 CACHE INTERNAL "")
277 else()
278 find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
Josh Klontzda295e92014-08-08 14:32:56 +0000279 if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" )
Oscar Fuentes64955952011-01-21 15:42:54 +0000280 set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
281 set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
282 endif()
283 endif()
284
285 if( NOT FFI_HEADER )
286 message(FATAL_ERROR "libffi includes are not found.")
287 endif()
288
289 find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
290 if( NOT FFI_LIBRARY_PATH )
291 message(FATAL_ERROR "libffi is not found.")
292 endif()
293
294 list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
295 list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
296 check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
297 list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
298 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
Oscar Fuentesf2ab9282011-04-02 13:21:12 +0000299else()
300 unset(HAVE_FFI_FFI_H CACHE)
301 unset(HAVE_FFI_H CACHE)
302 unset(HAVE_FFI_CALL CACHE)
Oscar Fuentes64955952011-01-21 15:42:54 +0000303endif( LLVM_ENABLE_FFI )
304
Eric Christopher4418a602011-09-19 20:43:23 +0000305# Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
Xerxes Ranby64c6d422009-07-17 19:22:41 +0000306include(CheckAtomic)
307
Oscar Fuentes25ac8302011-01-15 13:35:37 +0000308if( LLVM_ENABLE_PIC )
309 set(ENABLE_PIC 1)
310else()
311 set(ENABLE_PIC 0)
312endif()
Oscar Fuentesedfc1842011-01-09 14:34:39 +0000313
Michael J. Spencer33a390e2010-10-07 18:12:54 +0000314check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
315
Edwin Vanea9c5bb32013-02-04 02:32:44 +0000316set(USE_NO_MAYBE_UNINITIALIZED 0)
317set(USE_NO_UNINITIALIZED 0)
318
319# Disable gcc's potentially uninitialized use analysis as it presents lots of
320# false positives.
321if (CMAKE_COMPILER_IS_GNUCXX)
322 check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
323 if (HAS_MAYBE_UNINITIALIZED)
324 set(USE_NO_MAYBE_UNINITIALIZED 1)
325 else()
326 # Only recent versions of gcc make the distinction between -Wuninitialized
327 # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
328 # turn off all uninitialized use warnings.
329 check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
330 set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
331 endif()
332endif()
333
Sebastian Pop82622dc2012-08-08 18:04:45 +0000334# By default, we target the host, but this can be overridden at CMake
335# invocation time.
Tim Northoverfee13d12013-05-04 07:36:23 +0000336include(GetHostTriple)
337get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
338
339set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
340 "Host on which LLVM binaries will run")
Daniel Dunbarc0fd8a42009-11-07 23:52:20 +0000341
Douglas Gregor3def8472009-06-17 17:01:56 +0000342# Determine the native architecture.
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000343string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
344if( LLVM_NATIVE_ARCH STREQUAL "host" )
Chandler Carruthbeb3e7e2012-01-24 18:00:44 +0000345 string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000346endif ()
347
Douglas Gregor3def8472009-06-17 17:01:56 +0000348if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
349 set(LLVM_NATIVE_ARCH X86)
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000350elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
Douglas Gregor3def8472009-06-17 17:01:56 +0000351 set(LLVM_NATIVE_ARCH X86)
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000352elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
353 set(LLVM_NATIVE_ARCH X86)
354elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
Douglas Gregor3def8472009-06-17 17:01:56 +0000355 set(LLVM_NATIVE_ARCH X86)
356elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
357 set(LLVM_NATIVE_ARCH Sparc)
358elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
359 set(LLVM_NATIVE_ARCH PowerPC)
Tim Northovera958a572013-05-04 20:13:52 +0000360elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
361 set(LLVM_NATIVE_ARCH AArch64)
Tim Northover00ed9962014-03-29 10:18:08 +0000362elseif (LLVM_NATIVE_ARCH MATCHES "arm64")
Tim Northover3b0846e2014-05-24 12:50:23 +0000363 set(LLVM_NATIVE_ARCH AArch64)
Douglas Gregor3def8472009-06-17 17:01:56 +0000364elseif (LLVM_NATIVE_ARCH MATCHES "arm")
365 set(LLVM_NATIVE_ARCH ARM)
366elseif (LLVM_NATIVE_ARCH MATCHES "mips")
367 set(LLVM_NATIVE_ARCH Mips)
Douglas Gregor3def8472009-06-17 17:01:56 +0000368elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
369 set(LLVM_NATIVE_ARCH XCore)
370elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
371 set(LLVM_NATIVE_ARCH MSP430)
Sebastian Pop8f4aec42012-08-20 19:56:49 +0000372elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
373 set(LLVM_NATIVE_ARCH Hexagon)
Ulrich Weigand1ceebf62013-05-06 16:22:34 +0000374elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
375 set(LLVM_NATIVE_ARCH SystemZ)
Douglas Gregor3def8472009-06-17 17:01:56 +0000376else ()
Oscar Fuentes465f9362011-03-23 17:42:13 +0000377 message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
Douglas Gregor3def8472009-06-17 17:01:56 +0000378endif ()
Michael J. Spencer1444f472010-09-24 09:00:56 +0000379
Andy Gibbsf5dede12013-06-26 07:57:53 +0000380# If build targets includes "host", then replace with native architecture.
381list(FIND LLVM_TARGETS_TO_BUILD "host" idx)
382if( NOT idx LESS 0 )
383 list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
384 list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
385 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
386endif()
387
Oscar Fuentes465f9362011-03-23 17:42:13 +0000388list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
389if (NATIVE_ARCH_IDX EQUAL -1)
390 message(STATUS
391 "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
392else ()
393 message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
394 set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
395 set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
Evan Cheng8c886a42011-07-22 21:58:54 +0000396 set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
Oscar Fuentes465f9362011-03-23 17:42:13 +0000397 set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
Chandler Carruth98e642d2011-12-09 03:31:58 +0000398
399 # We don't have an ASM parser for all architectures yet.
400 if (EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
401 set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
402 endif ()
Eric Christopher56079c12012-03-26 21:56:56 +0000403
404 # We don't have an disassembler for all architectures yet.
405 if (EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
406 set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
407 endif ()
Oscar Fuentes465f9362011-03-23 17:42:13 +0000408endif ()
Douglas Gregor3def8472009-06-17 17:01:56 +0000409
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000410if( MINGW )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000411 set(HAVE_LIBIMAGEHLP 1)
412 set(HAVE_LIBPSAPI 1)
David Majnemer61eae2e2013-10-07 01:00:07 +0000413 set(HAVE_LIBSHELL32 1)
Oscar Fuentes2500aae2008-10-29 02:33:15 +0000414 # TODO: Check existence of libraries.
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000415 # include(CheckLibraryExists)
416 # CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
417endif( MINGW )
418
Reid Klecknera3ae94e2013-08-07 00:29:15 +0000419if (NOT HAVE_STRTOLL)
420 # Use _strtoi64 if strtoll is not available.
421 check_symbol_exists(_strtoi64 stdlib.h have_strtoi64)
422 if (have_strtoi64)
423 set(HAVE_STRTOLL 1)
424 set(strtoll "_strtoi64")
425 set(strtoull "_strtoui64")
426 endif ()
427endif ()
428
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000429if( MSVC )
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000430 set(SHLIBEXT ".lib")
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000431 set(stricmp "_stricmp")
432 set(strdup "_strdup")
Zachary Turner733b8492015-02-10 05:04:25 +0000433
434 # See if the DIA SDK is available and usable.
435 set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
436
437 # Due to a bug in MSVC 2013's installation software, it is possible
438 # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
439 # install directory. If this happens, the installation is corrupt
440 # and there's nothing we can do. It happens with enough frequency
441 # though that we should handle it. We do so by simply checking that
442 # the DIA SDK folder exists. Should this happen you will need to
443 # uninstall VS 2012 and then re-install VS 2013.
444 if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
445 set(HAVE_DIA_SDK 1)
446 else()
447 set(HAVE_DIA_SDK 0)
448 endif()
Zachary Turner3ddf94e2015-02-22 07:13:52 +0000449else()
450 set(HAVE_DIA_SDK 0)
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000451endif( MSVC )
452
Zachary Turnera54b7dd2015-02-22 06:47:32 +0000453message("CMake set HAVE_DIA_SDK to ${HAVE_DIA_SDK}")
454
NAKAMURA Takumi4471f822011-05-01 13:29:49 +0000455if( PURE_WINDOWS )
456 CHECK_CXX_SOURCE_COMPILES("
457 #include <windows.h>
458 #include <imagehlp.h>
459 extern \"C\" void foo(PENUMLOADED_MODULES_CALLBACK);
460 extern \"C\" void foo(BOOL(CALLBACK*)(PCSTR,ULONG_PTR,ULONG,PVOID));
461 int main(){return 0;}"
462 HAVE_ELMCB_PCSTR)
463 if( HAVE_ELMCB_PCSTR )
464 set(WIN32_ELMCB_PCSTR "PCSTR")
465 else()
466 set(WIN32_ELMCB_PCSTR "PSTR")
467 endif()
468endif( PURE_WINDOWS )
469
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000470# FIXME: Signal handler return type, currently hardcoded to 'void'
471set(RETSIGTYPE void)
472
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000473if( LLVM_ENABLE_THREADS )
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000474 # Check if threading primitives aren't supported on this platform
475 if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
476 set(LLVM_ENABLE_THREADS 0)
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000477 endif()
478endif()
479
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000480if( LLVM_ENABLE_THREADS )
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000481 message(STATUS "Threads enabled.")
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000482else( LLVM_ENABLE_THREADS )
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000483 message(STATUS "Threads disabled.")
484endif()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000485
Alexey Samsonov2fb337e2013-04-23 08:28:39 +0000486if (LLVM_ENABLE_ZLIB )
487 # Check if zlib is available in the system.
488 if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
489 set(LLVM_ENABLE_ZLIB 0)
490 endif()
491endif()
492
Oscar Fuentes2b1077f2010-08-08 04:32:21 +0000493set(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
Michael Gottesman4d35b902013-08-24 07:25:21 +0000494
495if (LLVM_ENABLE_DOXYGEN)
496 message(STATUS "Doxygen enabled.")
Dan Liewf8542952014-04-28 09:10:05 +0000497 find_package(Doxygen REQUIRED)
Michael Gottesman9cc5a452013-08-28 20:28:32 +0000498
499 if (DOXYGEN_FOUND)
500 # If we find doxygen and we want to enable doxygen by default create a
501 # global aggregate doxygen target for generating llvm and any/all
502 # subprojects doxygen documentation.
503 if (LLVM_BUILD_DOCS)
504 add_custom_target(doxygen ALL)
505 endif()
Michael Gottesman406525d2013-08-28 21:55:26 +0000506
507 option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
508 if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
509 set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external searhc.")
510 set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
511 endif()
Michael Gottesman9cc5a452013-08-28 20:28:32 +0000512 endif()
Michael Gottesman4d35b902013-08-24 07:25:21 +0000513else()
514 message(STATUS "Doxygen disabled.")
515endif()
Reid Kleckner9f5eb632014-04-18 21:45:25 +0000516
517if (LLVM_ENABLE_SPHINX)
518 message(STATUS "Sphinx enabled.")
519 find_package(Sphinx REQUIRED)
520 if (LLVM_BUILD_DOCS)
521 add_custom_target(sphinx ALL)
522 endif()
523else()
524 message(STATUS "Sphinx disabled.")
525endif()
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000526
527set(LLVM_BINDINGS "")
Peter Collingbourne244ecf52014-10-23 02:33:23 +0000528if(WIN32)
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000529 message(STATUS "Go bindings disabled.")
530else()
Peter Collingbourne244ecf52014-10-23 02:33:23 +0000531 find_program(GO_EXECUTABLE NAMES go DOC "go executable")
532 if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND")
533 message(STATUS "Go bindings disabled.")
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000534 else()
Peter Collingbourne244ecf52014-10-23 02:33:23 +0000535 execute_process(COMMAND ${GO_EXECUTABLE} run ${CMAKE_SOURCE_DIR}/bindings/go/conftest.go
536 RESULT_VARIABLE GO_CONFTEST)
537 if(GO_CONFTEST STREQUAL "0")
538 set(LLVM_BINDINGS "${LLVM_BINDINGS} go")
539 message(STATUS "Go bindings enabled.")
540 else()
541 message(STATUS "Go bindings disabled, need at least Go 1.2.")
542 endif()
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000543 endif()
544endif()
Peter Zotovb20073c2014-12-01 19:50:23 +0000545
Chandler Carruthedd92942015-02-14 09:43:57 +0000546find_program(GOLD_EXECUTABLE NAMES ld.gold ld DOC "The gold linker")
547if(GOLD_EXECUTABLE)
548 set(LLVM_BINUTILS_INCDIR "" CACHE PATH
549 "PATH to binutils/include containing plugin-api.h for gold plugin.")
550endif()
551
Peter Zotovb20073c2014-12-01 19:50:23 +0000552include(FindOCaml)
553include(AddOCaml)
554if(WIN32)
555 message(STATUS "OCaml bindings disabled.")
556else()
557 find_package(OCaml)
558 if( NOT OCAML_FOUND )
559 message(STATUS "OCaml bindings disabled.")
560 else()
561 if( OCAML_VERSION VERSION_LESS "4.00.0" )
562 message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.")
563 else()
Peter Zotovfcefcf92014-12-03 03:39:01 +0000564 find_ocamlfind_package(ctypes VERSION 0.3 OPTIONAL)
565 if( HAVE_OCAML_CTYPES )
566 message(STATUS "OCaml bindings enabled.")
567 find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
568 set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
569 else()
570 message(STATUS "OCaml bindings disabled, need ctypes >=0.3.")
571 endif()
Peter Zotovb20073c2014-12-01 19:50:23 +0000572 endif()
573 endif()
574endif()
575
576string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")