blob: 9c4658eb22a2af45ddf3afc83847b78088a497c8 [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
Reid Kleckner9fac19f2016-03-02 16:42:56 +000014include(CheckCompilerVersion)
Jordan Rose31c5b7b2014-02-05 00:02:37 +000015include(HandleLLVMStdlib)
16
Renato Golin9590c532016-02-26 17:01:45 +000017if( UNIX AND NOT (BEOS OR HAIKU) )
Oscar Fuentesd533e1d2009-11-12 05:36:09 +000018 # Used by check_symbol_exists:
19 set(CMAKE_REQUIRED_LIBRARIES m)
20endif()
Viktor Kutuzov6bd32292014-04-09 11:43:34 +000021# x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.
22if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND
23 CMAKE_SIZEOF_VOID_P EQUAL 8 )
24 list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt")
25endif()
Oscar Fuentesd533e1d2009-11-12 05:36:09 +000026
Douglas Gregorf99626e2009-10-01 17:25:36 +000027# Helper macros and functions
28macro(add_cxx_include result files)
29 set(${result} "")
30 foreach (file_name ${files})
31 set(${result} "${${result}}#include<${file_name}>\n")
32 endforeach()
33endmacro(add_cxx_include files result)
34
35function(check_type_exists type files variable)
36 add_cxx_include(includes "${files}")
37 CHECK_CXX_SOURCE_COMPILES("
38 ${includes} ${type} typeVar;
39 int main() {
40 return 0;
41 }
42 " ${variable})
43endfunction()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000044
45# include checks
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000046check_include_file(dirent.h HAVE_DIRENT_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000047check_include_file(dlfcn.h HAVE_DLFCN_H)
48check_include_file(errno.h HAVE_ERRNO_H)
49check_include_file(execinfo.h HAVE_EXECINFO_H)
50check_include_file(fcntl.h HAVE_FCNTL_H)
51check_include_file(inttypes.h HAVE_INTTYPES_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)
Jeroen Ketemaa6897212016-04-07 08:36:13 +000069check_include_file(sys/types.h HAVE_SYS_TYPES_H)
Oscar Fuentesed27ead2011-02-03 04:23:07 +000070check_include_file(sys/uio.h HAVE_SYS_UIO_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)
Jeffrey Yasskin3ddd88f2010-03-15 04:57:55 +000073check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
Alexey Samsonov2fb337e2013-04-23 08:28:39 +000074check_include_file(zlib.h HAVE_ZLIB_H)
Oscar Fuentesbcc8b2f2010-09-17 20:30:48 +000075check_include_file(fenv.h HAVE_FENV_H)
Joerg Sonnenberger8a1177f2013-03-25 13:13:33 +000076check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
77check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
78
Oscar Fuentese65ed1c2011-01-17 16:35:14 +000079check_include_file(mach/mach.h HAVE_MACH_MACH_H)
Chris Bienemanb2d71492015-01-30 00:10:43 +000080check_include_file(histedit.h HAVE_HISTEDIT_H)
Chris Bienemandf11f532016-12-07 18:53:04 +000081check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000082
Oscar Fuentesa6e20062009-05-06 14:40:37 +000083# library checks
Oscar Fuentes2761c7a2011-02-04 05:40:04 +000084if( NOT PURE_WINDOWS )
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +000085 check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
Evgeniy Stepanovc439a422012-09-04 09:14:45 +000086 if (HAVE_LIBPTHREAD)
87 check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
88 check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
89 check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
90 else()
91 # this could be Android
92 check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)
93 if (PTHREAD_IN_LIBC)
94 check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
95 check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
96 check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
97 endif()
98 endif()
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +000099 check_library_exists(dl dlopen "" HAVE_LIBDL)
Chandler Carruthef7f9682013-01-04 23:19:55 +0000100 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
Reid Kleckner61bc3562015-11-19 00:05:21 +0000101endif()
102
Rafael Espindola5cd721a2016-03-01 15:54:40 +0000103if(HAVE_LIBPTHREAD)
Artem Belevichdf7103d2016-06-21 19:34:40 +0000104 # We want to find pthreads library and at the moment we do want to
105 # have it reported as '-l<lib>' instead of '-pthread'.
106 # TODO: switch to -pthread once the rest of the build system can deal with it.
107 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
108 set(THREADS_HAVE_PTHREAD_ARG Off)
109 find_package(Threads REQUIRED)
110 set(PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
Rafael Espindola5cd721a2016-03-01 15:54:40 +0000111endif()
112
Reid Kleckner61bc3562015-11-19 00:05:21 +0000113# Don't look for these libraries on Windows. Also don't look for them if we're
Etienne Bergerona15c90e2016-09-21 17:15:23 +0000114# using MSan, since uninstrumented third party code may call MSan interceptors
Reid Kleckner61bc3562015-11-19 00:05:21 +0000115# like strlen, leading to false positives.
116if( NOT PURE_WINDOWS AND NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
Alexey Samsonov068fc8a2013-04-23 10:17:34 +0000117 if (LLVM_ENABLE_ZLIB)
118 check_library_exists(z compress2 "" HAVE_LIBZ)
119 else()
120 set(HAVE_LIBZ 0)
121 endif()
Chandler Carruth75e01062016-08-20 07:05:13 +0000122 # Skip libedit if using ASan as it contains memory leaks.
Yichao Yu4497a282016-11-18 01:25:49 +0000123 if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")
Chris Bienemanb2d71492015-01-30 00:10:43 +0000124 check_library_exists(edit el_init "" HAVE_LIBEDIT)
Yichao Yu4497a282016-11-18 01:25:49 +0000125 else()
126 set(HAVE_LIBEDIT 0)
Chris Bienemanb2d71492015-01-30 00:10:43 +0000127 endif()
Chandler Carruth91219852013-08-12 10:40:11 +0000128 if(LLVM_ENABLE_TERMINFO)
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000129 set(HAVE_TERMINFO 0)
Joerg Sonnenberger4e5a3992013-08-17 11:06:00 +0000130 foreach(library tinfo terminfo curses ncurses ncursesw)
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000131 string(TOUPPER ${library} library_suffix)
132 check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
133 if(HAVE_TERMINFO_${library_suffix})
134 set(HAVE_TERMINFO 1)
135 set(TERMINFO_LIBS "${library}")
136 break()
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000137 endif()
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000138 endforeach()
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000139 else()
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000140 set(HAVE_TERMINFO 0)
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000141 endif()
Oscar Fuentes1a0bfb62009-11-05 18:57:56 +0000142endif()
Oscar Fuentesa6e20062009-05-06 14:40:37 +0000143
Kevin Enderby9873e2c2016-05-23 21:34:12 +0000144check_library_exists(xar xar_open "" HAVE_LIBXAR)
145if(HAVE_LIBXAR)
146 set(XAR_LIB xar)
147endif()
148
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000149# function checks
Todd Fiala4ccfe392014-02-05 05:04:36 +0000150check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
Benjamin Kramerd02949b2012-09-01 20:50:18 +0000151check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
Joerg Sonnenberger5c505392016-09-29 21:07:57 +0000152check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000153check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
Joerg Sonnenberger4b2a79e2016-09-29 21:18:05 +0000154check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000155check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
156check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
Ted Kremenek6ea1b762011-12-23 01:31:45 +0000157check_symbol_exists(isatty unistd.h HAVE_ISATTY)
Eric Christophera24dc7f2013-07-04 01:10:38 +0000158check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
159check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
Rafael Espindola3816c532016-07-19 20:19:56 +0000160check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE)
Vitaly Bukad44b7632016-08-25 03:44:36 +0000161# AddressSanitizer conflicts with lib/Support/Unix/Signals.inc
Vitaly Bukad2124562016-08-25 03:32:49 +0000162if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")
Richard Smithabab5d22016-05-20 21:26:00 +0000163 check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
164endif()
Oscar Fuentesed27ead2011-02-03 04:23:07 +0000165if( HAVE_SYS_UIO_H )
166 check_symbol_exists(writev sys/uio.h HAVE_WRITEV)
167endif()
Davide Italianofaafae32015-02-19 07:27:14 +0000168check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000169check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
Douglas Gregor60dd76f2009-06-04 17:22:52 +0000170check_symbol_exists(malloc_zone_statistics malloc/malloc.h
171 HAVE_MALLOC_ZONE_STATISTICS)
Benjamin Kramerc1ba4c22009-10-28 18:37:31 +0000172check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
173check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
174check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
Oscar Fuentes0a1b6b82011-01-13 19:17:28 +0000175check_symbol_exists(getcwd unistd.h HAVE_GETCWD)
176check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
177check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
Benjamin Kramere1effb02011-11-22 12:31:53 +0000178check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
179check_symbol_exists(pread unistd.h HAVE_PREAD)
Alexey Samsonov30c0ecc2013-08-26 18:11:25 +0000180check_symbol_exists(realpath stdlib.h HAVE_REALPATH)
Edward O'Callaghan655314e2009-10-05 23:05:32 +0000181check_symbol_exists(sbrk unistd.h HAVE_SBRK)
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000182check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
Jeffrey Yasskin1a933302009-07-01 18:11:20 +0000183check_symbol_exists(strerror string.h HAVE_STRERROR)
184check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
NAKAMURA Takumi189111802011-02-09 04:18:48 +0000185check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
Jeffrey Yasskin14a5cc52009-09-25 21:07:20 +0000186check_symbol_exists(setenv stdlib.h HAVE_SETENV)
Oscar Fuentes2761c7a2011-02-04 05:40:04 +0000187if( PURE_WINDOWS )
Michael J. Spencerca242f22010-12-03 18:48:56 +0000188 check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
NAKAMURA Takumi03a541f2011-02-05 15:11:53 +0000189
190 check_function_exists(_alloca HAVE__ALLOCA)
191 check_function_exists(__alloca HAVE___ALLOCA)
192 check_function_exists(__chkstk HAVE___CHKSTK)
NAKAMURA Takumi78855072015-01-30 13:01:19 +0000193 check_function_exists(__chkstk_ms HAVE___CHKSTK_MS)
NAKAMURA Takumi03a541f2011-02-05 15:11:53 +0000194 check_function_exists(___chkstk HAVE____CHKSTK)
NAKAMURA Takumi78855072015-01-30 13:01:19 +0000195 check_function_exists(___chkstk_ms HAVE____CHKSTK_MS)
NAKAMURA Takumi03a541f2011-02-05 15:11:53 +0000196
197 check_function_exists(__ashldi3 HAVE___ASHLDI3)
198 check_function_exists(__ashrdi3 HAVE___ASHRDI3)
199 check_function_exists(__divdi3 HAVE___DIVDI3)
200 check_function_exists(__fixdfdi HAVE___FIXDFDI)
201 check_function_exists(__fixsfdi HAVE___FIXSFDI)
202 check_function_exists(__floatdidf HAVE___FLOATDIDF)
203 check_function_exists(__lshrdi3 HAVE___LSHRDI3)
204 check_function_exists(__moddi3 HAVE___MODDI3)
205 check_function_exists(__udivdi3 HAVE___UDIVDI3)
206 check_function_exists(__umoddi3 HAVE___UMODDI3)
207
208 check_function_exists(__main HAVE___MAIN)
209 check_function_exists(__cmpdi2 HAVE___CMPDI2)
Michael J. Spencerca242f22010-12-03 18:48:56 +0000210endif()
Oscar Fuentese866c412011-01-31 18:25:25 +0000211if( HAVE_DLFCN_H )
212 if( HAVE_LIBDL )
213 list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
214 endif()
Oscar Fuentese65ed1c2011-01-17 16:35:14 +0000215 check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
Oscar Fuentese866c412011-01-31 18:25:25 +0000216 if( HAVE_LIBDL )
217 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
218 endif()
Oscar Fuentese65ed1c2011-01-17 16:35:14 +0000219endif()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000220
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000221check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
222if( LLVM_USING_GLIBC )
223 add_llvm_definitions( -D_GNU_SOURCE )
224endif()
225
Reid Kleckner37f69de2013-07-26 16:54:23 +0000226set(headers "sys/types.h")
Douglas Gregorf99626e2009-10-01 17:25:36 +0000227
228if (HAVE_INTTYPES_H)
229 set(headers ${headers} "inttypes.h")
230endif()
231
232if (HAVE_STDINT_H)
233 set(headers ${headers} "stdint.h")
234endif()
235
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000236check_type_exists(int64_t "${headers}" HAVE_INT64_T)
Douglas Gregorf99626e2009-10-01 17:25:36 +0000237check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
238check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
239
Oscar Fuentes17feb2a2009-11-05 19:03:26 +0000240# available programs checks
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000241function(llvm_find_program name)
242 string(TOUPPER ${name} NAME)
Tobias Grosser1b4f9402011-02-27 04:11:05 +0000243 string(REGEX REPLACE "\\." "_" NAME ${NAME})
Matt Arsenault90962172013-07-08 20:24:49 +0000244
245 find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000246 mark_as_advanced(LLVM_PATH_${NAME})
247 if(LLVM_PATH_${NAME})
248 set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
249 mark_as_advanced(HAVE_${NAME})
250 else(LLVM_PATH_${NAME})
251 set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
Oscar Fuentesde8f4312009-11-09 15:26:40 +0000252 endif(LLVM_PATH_${NAME})
253endfunction()
254
Alp Toker125be842014-06-02 01:40:04 +0000255if (LLVM_ENABLE_DOXYGEN)
256 llvm_find_program(dot)
257endif ()
Oscar Fuentes17feb2a2009-11-05 19:03:26 +0000258
Oscar Fuentes64955952011-01-21 15:42:54 +0000259if( LLVM_ENABLE_FFI )
260 find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
Josh Klontzda295e92014-08-08 14:32:56 +0000261 if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" )
Oscar Fuentes64955952011-01-21 15:42:54 +0000262 set(FFI_HEADER ffi.h CACHE INTERNAL "")
263 set(HAVE_FFI_H 1 CACHE INTERNAL "")
264 else()
265 find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
Josh Klontzda295e92014-08-08 14:32:56 +0000266 if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" )
Oscar Fuentes64955952011-01-21 15:42:54 +0000267 set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
268 set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
269 endif()
270 endif()
271
272 if( NOT FFI_HEADER )
273 message(FATAL_ERROR "libffi includes are not found.")
274 endif()
275
276 find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
277 if( NOT FFI_LIBRARY_PATH )
278 message(FATAL_ERROR "libffi is not found.")
279 endif()
280
281 list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
282 list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
283 check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
284 list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
285 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
Oscar Fuentesf2ab9282011-04-02 13:21:12 +0000286else()
287 unset(HAVE_FFI_FFI_H CACHE)
288 unset(HAVE_FFI_H CACHE)
289 unset(HAVE_FFI_CALL CACHE)
Oscar Fuentes64955952011-01-21 15:42:54 +0000290endif( LLVM_ENABLE_FFI )
291
Eric Christopher4418a602011-09-19 20:43:23 +0000292# Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
Xerxes Ranby64c6d422009-07-17 19:22:41 +0000293include(CheckAtomic)
294
Oscar Fuentes25ac8302011-01-15 13:35:37 +0000295if( LLVM_ENABLE_PIC )
296 set(ENABLE_PIC 1)
297else()
298 set(ENABLE_PIC 0)
Chris Bieneman7494dc52015-11-24 08:04:59 +0000299 check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG)
300 if(SUPPORTS_NO_PIE_FLAG)
Pavel Labathe3af0262015-11-24 09:46:01 +0000301 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
Chris Bieneman7494dc52015-11-24 08:04:59 +0000302 endif()
Oscar Fuentes25ac8302011-01-15 13:35:37 +0000303endif()
Oscar Fuentesedfc1842011-01-09 14:34:39 +0000304
Michael J. Spencer33a390e2010-10-07 18:12:54 +0000305check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
306
Edwin Vanea9c5bb32013-02-04 02:32:44 +0000307set(USE_NO_MAYBE_UNINITIALIZED 0)
308set(USE_NO_UNINITIALIZED 0)
309
310# Disable gcc's potentially uninitialized use analysis as it presents lots of
311# false positives.
312if (CMAKE_COMPILER_IS_GNUCXX)
313 check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
314 if (HAS_MAYBE_UNINITIALIZED)
315 set(USE_NO_MAYBE_UNINITIALIZED 1)
316 else()
317 # Only recent versions of gcc make the distinction between -Wuninitialized
318 # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
319 # turn off all uninitialized use warnings.
320 check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
321 set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
322 endif()
323endif()
324
Sebastian Pop82622dc2012-08-08 18:04:45 +0000325# By default, we target the host, but this can be overridden at CMake
326# invocation time.
Tim Northoverfee13d12013-05-04 07:36:23 +0000327include(GetHostTriple)
328get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
329
330set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
331 "Host on which LLVM binaries will run")
Daniel Dunbarc0fd8a42009-11-07 23:52:20 +0000332
Douglas Gregor3def8472009-06-17 17:01:56 +0000333# Determine the native architecture.
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000334string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
335if( LLVM_NATIVE_ARCH STREQUAL "host" )
Chandler Carruthbeb3e7e2012-01-24 18:00:44 +0000336 string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000337endif ()
338
Douglas Gregor3def8472009-06-17 17:01:56 +0000339if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
340 set(LLVM_NATIVE_ARCH X86)
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000341elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
Douglas Gregor3def8472009-06-17 17:01:56 +0000342 set(LLVM_NATIVE_ARCH X86)
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000343elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
344 set(LLVM_NATIVE_ARCH X86)
345elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
Douglas Gregor3def8472009-06-17 17:01:56 +0000346 set(LLVM_NATIVE_ARCH X86)
347elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
348 set(LLVM_NATIVE_ARCH Sparc)
349elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
350 set(LLVM_NATIVE_ARCH PowerPC)
Tim Northovera958a572013-05-04 20:13:52 +0000351elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
352 set(LLVM_NATIVE_ARCH AArch64)
Tim Northover00ed9962014-03-29 10:18:08 +0000353elseif (LLVM_NATIVE_ARCH MATCHES "arm64")
Tim Northover3b0846e2014-05-24 12:50:23 +0000354 set(LLVM_NATIVE_ARCH AArch64)
Douglas Gregor3def8472009-06-17 17:01:56 +0000355elseif (LLVM_NATIVE_ARCH MATCHES "arm")
356 set(LLVM_NATIVE_ARCH ARM)
357elseif (LLVM_NATIVE_ARCH MATCHES "mips")
358 set(LLVM_NATIVE_ARCH Mips)
Douglas Gregor3def8472009-06-17 17:01:56 +0000359elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
360 set(LLVM_NATIVE_ARCH XCore)
361elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
362 set(LLVM_NATIVE_ARCH MSP430)
Sebastian Pop8f4aec42012-08-20 19:56:49 +0000363elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
364 set(LLVM_NATIVE_ARCH Hexagon)
Ulrich Weigand1ceebf62013-05-06 16:22:34 +0000365elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
366 set(LLVM_NATIVE_ARCH SystemZ)
Dan Gohman10e730a2015-06-29 23:51:55 +0000367elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
368 set(LLVM_NATIVE_ARCH WebAssembly)
369elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
370 set(LLVM_NATIVE_ARCH WebAssembly)
Douglas Gregor3def8472009-06-17 17:01:56 +0000371else ()
Oscar Fuentes465f9362011-03-23 17:42:13 +0000372 message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
Douglas Gregor3def8472009-06-17 17:01:56 +0000373endif ()
Michael J. Spencer1444f472010-09-24 09:00:56 +0000374
Andy Gibbsf5dede12013-06-26 07:57:53 +0000375# If build targets includes "host", then replace with native architecture.
376list(FIND LLVM_TARGETS_TO_BUILD "host" idx)
377if( NOT idx LESS 0 )
378 list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
379 list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
380 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
381endif()
382
Oscar Fuentes465f9362011-03-23 17:42:13 +0000383list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
384if (NATIVE_ARCH_IDX EQUAL -1)
385 message(STATUS
386 "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
387else ()
388 message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
389 set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
390 set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
Evan Cheng8c886a42011-07-22 21:58:54 +0000391 set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
Oscar Fuentes465f9362011-03-23 17:42:13 +0000392 set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
Chandler Carruth98e642d2011-12-09 03:31:58 +0000393
394 # We don't have an ASM parser for all architectures yet.
Vassil Vassileve2d8a402016-06-11 17:20:53 +0000395 if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
Chandler Carruth98e642d2011-12-09 03:31:58 +0000396 set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
397 endif ()
Eric Christopher56079c12012-03-26 21:56:56 +0000398
399 # We don't have an disassembler for all architectures yet.
Vassil Vassileve2d8a402016-06-11 17:20:53 +0000400 if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
Eric Christopher56079c12012-03-26 21:56:56 +0000401 set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
402 endif ()
Oscar Fuentes465f9362011-03-23 17:42:13 +0000403endif ()
Douglas Gregor3def8472009-06-17 17:01:56 +0000404
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000405if( MINGW )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000406 set(HAVE_LIBPSAPI 1)
David Majnemer61eae2e2013-10-07 01:00:07 +0000407 set(HAVE_LIBSHELL32 1)
Oscar Fuentes2500aae2008-10-29 02:33:15 +0000408 # TODO: Check existence of libraries.
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000409 # include(CheckLibraryExists)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000410endif( MINGW )
411
Reid Klecknera3ae94e2013-08-07 00:29:15 +0000412if (NOT HAVE_STRTOLL)
413 # Use _strtoi64 if strtoll is not available.
414 check_symbol_exists(_strtoi64 stdlib.h have_strtoi64)
415 if (have_strtoi64)
416 set(HAVE_STRTOLL 1)
417 set(strtoll "_strtoi64")
418 set(strtoull "_strtoui64")
419 endif ()
420endif ()
421
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000422if( MSVC )
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000423 set(SHLIBEXT ".lib")
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000424 set(stricmp "_stricmp")
425 set(strdup "_strdup")
Zachary Turner733b8492015-02-10 05:04:25 +0000426
427 # See if the DIA SDK is available and usable.
428 set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
429
430 # Due to a bug in MSVC 2013's installation software, it is possible
431 # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
432 # install directory. If this happens, the installation is corrupt
433 # and there's nothing we can do. It happens with enough frequency
434 # though that we should handle it. We do so by simply checking that
435 # the DIA SDK folder exists. Should this happen you will need to
436 # uninstall VS 2012 and then re-install VS 2013.
437 if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
438 set(HAVE_DIA_SDK 1)
439 else()
440 set(HAVE_DIA_SDK 0)
441 endif()
Zachary Turner3ddf94e2015-02-22 07:13:52 +0000442else()
443 set(HAVE_DIA_SDK 0)
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000444endif( MSVC )
445
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000446# FIXME: Signal handler return type, currently hardcoded to 'void'
447set(RETSIGTYPE void)
448
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000449if( LLVM_ENABLE_THREADS )
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000450 # Check if threading primitives aren't supported on this platform
451 if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
452 set(LLVM_ENABLE_THREADS 0)
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000453 endif()
454endif()
455
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000456if( LLVM_ENABLE_THREADS )
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000457 message(STATUS "Threads enabled.")
Dylan Noblesmithefddf202011-11-28 00:48:58 +0000458else( LLVM_ENABLE_THREADS )
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000459 message(STATUS "Threads disabled.")
460endif()
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000461
Alexey Samsonov2fb337e2013-04-23 08:28:39 +0000462if (LLVM_ENABLE_ZLIB )
463 # Check if zlib is available in the system.
464 if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
465 set(LLVM_ENABLE_ZLIB 0)
466 endif()
467endif()
468
Oscar Fuentes2b1077f2010-08-08 04:32:21 +0000469set(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
Michael Gottesman4d35b902013-08-24 07:25:21 +0000470
471if (LLVM_ENABLE_DOXYGEN)
472 message(STATUS "Doxygen enabled.")
Dan Liewf8542952014-04-28 09:10:05 +0000473 find_package(Doxygen REQUIRED)
Michael Gottesman9cc5a452013-08-28 20:28:32 +0000474
475 if (DOXYGEN_FOUND)
476 # If we find doxygen and we want to enable doxygen by default create a
477 # global aggregate doxygen target for generating llvm and any/all
478 # subprojects doxygen documentation.
479 if (LLVM_BUILD_DOCS)
480 add_custom_target(doxygen ALL)
481 endif()
Michael Gottesman406525d2013-08-28 21:55:26 +0000482
483 option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
484 if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
Saleem Abdulrasoolf95da492015-07-24 01:14:25 +0000485 set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.")
Michael Gottesman406525d2013-08-28 21:55:26 +0000486 set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
487 endif()
Michael Gottesman9cc5a452013-08-28 20:28:32 +0000488 endif()
Michael Gottesman4d35b902013-08-24 07:25:21 +0000489else()
490 message(STATUS "Doxygen disabled.")
491endif()
Reid Kleckner9f5eb632014-04-18 21:45:25 +0000492
493if (LLVM_ENABLE_SPHINX)
494 message(STATUS "Sphinx enabled.")
495 find_package(Sphinx REQUIRED)
496 if (LLVM_BUILD_DOCS)
497 add_custom_target(sphinx ALL)
498 endif()
499else()
500 message(STATUS "Sphinx disabled.")
501endif()
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000502
503set(LLVM_BINDINGS "")
Peter Collingbourne244ecf52014-10-23 02:33:23 +0000504if(WIN32)
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000505 message(STATUS "Go bindings disabled.")
506else()
Peter Collingbourne244ecf52014-10-23 02:33:23 +0000507 find_program(GO_EXECUTABLE NAMES go DOC "go executable")
508 if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND")
509 message(STATUS "Go bindings disabled.")
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000510 else()
Vassil Vassileve2d8a402016-06-11 17:20:53 +0000511 execute_process(COMMAND ${GO_EXECUTABLE} run ${PROJECT_SOURCE_DIR}/bindings/go/conftest.go
Peter Collingbourne244ecf52014-10-23 02:33:23 +0000512 RESULT_VARIABLE GO_CONFTEST)
513 if(GO_CONFTEST STREQUAL "0")
514 set(LLVM_BINDINGS "${LLVM_BINDINGS} go")
515 message(STATUS "Go bindings enabled.")
516 else()
517 message(STATUS "Go bindings disabled, need at least Go 1.2.")
518 endif()
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000519 endif()
520endif()
Peter Zotovb20073c2014-12-01 19:50:23 +0000521
Niels Ole Salscheiderb0e3c342015-05-01 11:58:30 +0000522find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker")
Rafael Espindola6b279992015-04-27 21:08:47 +0000523set(LLVM_BINUTILS_INCDIR "" CACHE PATH
524 "PATH to binutils/include containing plugin-api.h for gold plugin.")
Chandler Carruthedd92942015-02-14 09:43:57 +0000525
Bruno Cardoso Lopesf8df4d12016-07-26 18:09:23 +0000526if(CMAKE_HOST_APPLE AND APPLE)
527 if(CMAKE_XCRUN)
528 execute_process(COMMAND ${CMAKE_XCRUN} -find ld
529 OUTPUT_VARIABLE LD64_EXECUTABLE
530 OUTPUT_STRIP_TRAILING_WHITESPACE)
531 else()
532 find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker")
533 endif()
534
535 if(LD64_EXECUTABLE)
536 set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable")
537 message(STATUS "Found ld64 - ${LD64_EXECUTABLE}")
538 endif()
Peter Collingbournebbdc26b2015-03-19 23:55:38 +0000539endif()
540
Peter Zotove9dd46f2016-09-05 01:42:22 +0000541# Keep the version requirements in sync with bindings/ocaml/README.txt.
Peter Zotovb20073c2014-12-01 19:50:23 +0000542include(FindOCaml)
543include(AddOCaml)
544if(WIN32)
545 message(STATUS "OCaml bindings disabled.")
546else()
547 find_package(OCaml)
548 if( NOT OCAML_FOUND )
549 message(STATUS "OCaml bindings disabled.")
550 else()
551 if( OCAML_VERSION VERSION_LESS "4.00.0" )
552 message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.")
553 else()
Peter Zotov8c7e29d2015-06-27 14:32:30 +0000554 find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL)
Peter Zotovfcefcf92014-12-03 03:39:01 +0000555 if( HAVE_OCAML_CTYPES )
556 message(STATUS "OCaml bindings enabled.")
557 find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
558 set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
Michal Gornyb002f632016-09-30 18:34:23 +0000559
560 set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING
561 "Install directory for LLVM OCaml packages")
Peter Zotovfcefcf92014-12-03 03:39:01 +0000562 else()
Peter Zotov8c7e29d2015-06-27 14:32:30 +0000563 message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
Peter Zotovfcefcf92014-12-03 03:39:01 +0000564 endif()
Peter Zotovb20073c2014-12-01 19:50:23 +0000565 endif()
566 endif()
567endif()
568
569string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")