Oscar Fuentes | 2761c7a | 2011-02-04 05:40:04 +0000 | [diff] [blame] | 1 | if( WIN32 AND NOT CYGWIN ) |
| 2 | # We consider Cygwin as another Unix |
| 3 | set(PURE_WINDOWS 1) |
| 4 | endif() |
| 5 | |
Douglas Gregor | f99626e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 6 | include(CheckIncludeFile) |
Benjamin Kramer | ff2be22 | 2013-05-03 14:48:29 +0000 | [diff] [blame] | 7 | include(CheckIncludeFileCXX) |
Douglas Gregor | f99626e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 8 | include(CheckLibraryExists) |
| 9 | include(CheckSymbolExists) |
| 10 | include(CheckFunctionExists) |
Juergen Ributzka | c0fc219 | 2017-08-29 00:34:56 +0000 | [diff] [blame] | 11 | include(CheckCCompilerFlag) |
Douglas Gregor | f99626e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 12 | include(CheckCXXSourceCompiles) |
Michael J. Spencer | b550b66 | 2010-10-21 20:28:21 +0000 | [diff] [blame] | 13 | include(TestBigEndian) |
Douglas Gregor | f99626e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 14 | |
Reid Kleckner | 9fac19f | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 15 | include(CheckCompilerVersion) |
Jordan Rose | 31c5b7b | 2014-02-05 00:02:37 +0000 | [diff] [blame] | 16 | include(HandleLLVMStdlib) |
| 17 | |
Renato Golin | 9590c53 | 2016-02-26 17:01:45 +0000 | [diff] [blame] | 18 | if( UNIX AND NOT (BEOS OR HAIKU) ) |
Oscar Fuentes | d533e1d | 2009-11-12 05:36:09 +0000 | [diff] [blame] | 19 | # Used by check_symbol_exists: |
Don Hinton | 3a5a48b | 2017-12-25 01:23:09 +0000 | [diff] [blame] | 20 | list(APPEND CMAKE_REQUIRED_LIBRARIES "m") |
Oscar Fuentes | d533e1d | 2009-11-12 05:36:09 +0000 | [diff] [blame] | 21 | endif() |
Viktor Kutuzov | 6bd3229 | 2014-04-09 11:43:34 +0000 | [diff] [blame] | 22 | # x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly. |
| 23 | if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND |
| 24 | CMAKE_SIZEOF_VOID_P EQUAL 8 ) |
| 25 | list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt") |
| 26 | endif() |
Oscar Fuentes | d533e1d | 2009-11-12 05:36:09 +0000 | [diff] [blame] | 27 | |
Douglas Gregor | f99626e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 28 | # Helper macros and functions |
| 29 | macro(add_cxx_include result files) |
| 30 | set(${result} "") |
| 31 | foreach (file_name ${files}) |
| 32 | set(${result} "${${result}}#include<${file_name}>\n") |
| 33 | endforeach() |
| 34 | endmacro(add_cxx_include files result) |
| 35 | |
| 36 | function(check_type_exists type files variable) |
| 37 | add_cxx_include(includes "${files}") |
| 38 | CHECK_CXX_SOURCE_COMPILES(" |
| 39 | ${includes} ${type} typeVar; |
| 40 | int main() { |
| 41 | return 0; |
| 42 | } |
| 43 | " ${variable}) |
| 44 | endfunction() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 45 | |
| 46 | # include checks |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 47 | check_include_file(dirent.h HAVE_DIRENT_H) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 48 | check_include_file(dlfcn.h HAVE_DLFCN_H) |
| 49 | check_include_file(errno.h HAVE_ERRNO_H) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 50 | check_include_file(fcntl.h HAVE_FCNTL_H) |
| 51 | check_include_file(inttypes.h HAVE_INTTYPES_H) |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 52 | check_include_file(link.h HAVE_LINK_H) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 53 | check_include_file(malloc.h HAVE_MALLOC_H) |
| 54 | check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 55 | check_include_file(ndir.h HAVE_NDIR_H) |
Oscar Fuentes | 2761c7a | 2011-02-04 05:40:04 +0000 | [diff] [blame] | 56 | if( NOT PURE_WINDOWS ) |
Oscar Fuentes | 1a0bfb6 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 57 | check_include_file(pthread.h HAVE_PTHREAD_H) |
| 58 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 59 | check_include_file(signal.h HAVE_SIGNAL_H) |
| 60 | check_include_file(stdint.h HAVE_STDINT_H) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 61 | check_include_file(sys/dir.h HAVE_SYS_DIR_H) |
Douglas Gregor | 1543661 | 2009-05-11 18:05:52 +0000 | [diff] [blame] | 62 | check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 63 | check_include_file(sys/mman.h HAVE_SYS_MMAN_H) |
| 64 | check_include_file(sys/ndir.h HAVE_SYS_NDIR_H) |
| 65 | check_include_file(sys/param.h HAVE_SYS_PARAM_H) |
| 66 | check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) |
| 67 | check_include_file(sys/stat.h HAVE_SYS_STAT_H) |
| 68 | check_include_file(sys/time.h HAVE_SYS_TIME_H) |
Jeroen Ketema | a689721 | 2016-04-07 08:36:13 +0000 | [diff] [blame] | 69 | check_include_file(sys/types.h HAVE_SYS_TYPES_H) |
Oscar Fuentes | ed27ead | 2011-02-03 04:23:07 +0000 | [diff] [blame] | 70 | check_include_file(sys/uio.h HAVE_SYS_UIO_H) |
Douglas Gregor | b81294d | 2009-05-18 17:21:34 +0000 | [diff] [blame] | 71 | check_include_file(termios.h HAVE_TERMIOS_H) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 72 | check_include_file(unistd.h HAVE_UNISTD_H) |
Jeffrey Yasskin | 3ddd88f | 2010-03-15 04:57:55 +0000 | [diff] [blame] | 73 | check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H) |
Alexey Samsonov | 2fb337e | 2013-04-23 08:28:39 +0000 | [diff] [blame] | 74 | check_include_file(zlib.h HAVE_ZLIB_H) |
Oscar Fuentes | bcc8b2f | 2010-09-17 20:30:48 +0000 | [diff] [blame] | 75 | check_include_file(fenv.h HAVE_FENV_H) |
Joerg Sonnenberger | 8a1177f | 2013-03-25 13:13:33 +0000 | [diff] [blame] | 76 | check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT) |
| 77 | check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT) |
| 78 | |
Oscar Fuentes | e65ed1c | 2011-01-17 16:35:14 +0000 | [diff] [blame] | 79 | check_include_file(mach/mach.h HAVE_MACH_MACH_H) |
Chris Bieneman | b2d7149 | 2015-01-30 00:10:43 +0000 | [diff] [blame] | 80 | check_include_file(histedit.h HAVE_HISTEDIT_H) |
Chris Bieneman | df11f53 | 2016-12-07 18:53:04 +0000 | [diff] [blame] | 81 | check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H) |
Chris Bieneman | bb41361 | 2016-12-07 20:55:38 +0000 | [diff] [blame] | 82 | if(APPLE) |
| 83 | include(CheckCSourceCompiles) |
| 84 | CHECK_C_SOURCE_COMPILES(" |
| 85 | static const char *__crashreporter_info__ = 0; |
| 86 | asm(\".desc ___crashreporter_info__, 0x10\"); |
| 87 | int main() { return 0; }" |
| 88 | HAVE_CRASHREPORTER_INFO) |
| 89 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 90 | |
Michal Gorny | 5ddd2a5 | 2017-02-22 18:09:15 +0000 | [diff] [blame] | 91 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") |
| 92 | check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H) |
| 93 | if(NOT HAVE_LINUX_MAGIC_H) |
| 94 | # older kernels use split files |
| 95 | check_include_file(linux/nfs_fs.h HAVE_LINUX_NFS_FS_H) |
| 96 | check_include_file(linux/smb.h HAVE_LINUX_SMB_H) |
| 97 | endif() |
| 98 | endif() |
| 99 | |
Oscar Fuentes | a6e2006 | 2009-05-06 14:40:37 +0000 | [diff] [blame] | 100 | # library checks |
Oscar Fuentes | 2761c7a | 2011-02-04 05:40:04 +0000 | [diff] [blame] | 101 | if( NOT PURE_WINDOWS ) |
Oscar Fuentes | 1a0bfb6 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 102 | check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) |
Evgeniy Stepanov | c439a42 | 2012-09-04 09:14:45 +0000 | [diff] [blame] | 103 | if (HAVE_LIBPTHREAD) |
| 104 | check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC) |
| 105 | check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) |
| 106 | check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) |
| 107 | else() |
| 108 | # this could be Android |
| 109 | check_library_exists(c pthread_create "" PTHREAD_IN_LIBC) |
| 110 | if (PTHREAD_IN_LIBC) |
| 111 | check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC) |
| 112 | check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) |
| 113 | check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) |
| 114 | endif() |
| 115 | endif() |
Oscar Fuentes | 1a0bfb6 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 116 | check_library_exists(dl dlopen "" HAVE_LIBDL) |
Chandler Carruth | ef7f968 | 2013-01-04 23:19:55 +0000 | [diff] [blame] | 117 | check_library_exists(rt clock_gettime "" HAVE_LIBRT) |
Reid Kleckner | 61bc356 | 2015-11-19 00:05:21 +0000 | [diff] [blame] | 118 | endif() |
| 119 | |
Rafael Espindola | 5cd721a | 2016-03-01 15:54:40 +0000 | [diff] [blame] | 120 | if(HAVE_LIBPTHREAD) |
Artem Belevich | df7103d | 2016-06-21 19:34:40 +0000 | [diff] [blame] | 121 | # We want to find pthreads library and at the moment we do want to |
| 122 | # have it reported as '-l<lib>' instead of '-pthread'. |
| 123 | # TODO: switch to -pthread once the rest of the build system can deal with it. |
| 124 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 125 | set(THREADS_HAVE_PTHREAD_ARG Off) |
| 126 | find_package(Threads REQUIRED) |
Eric Fiselier | 87c87f4 | 2017-02-10 01:59:20 +0000 | [diff] [blame] | 127 | set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) |
Rafael Espindola | 5cd721a | 2016-03-01 15:54:40 +0000 | [diff] [blame] | 128 | endif() |
| 129 | |
Pavel Labath | 2da3397 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 130 | # Don't look for these libraries if we're using MSan, since uninstrumented third |
| 131 | # party code may call MSan interceptors like strlen, leading to false positives. |
| 132 | if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") |
| 133 | set(HAVE_LIBZ 0) |
| 134 | if(LLVM_ENABLE_ZLIB) |
| 135 | foreach(library z zlib_static zlib) |
Pavel Labath | f2fdc18 | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 136 | string(TOUPPER ${library} library_suffix) |
Pavel Labath | 2da3397 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 137 | check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix}) |
| 138 | if(HAVE_LIBZ_${library_suffix}) |
| 139 | set(HAVE_LIBZ 1) |
| 140 | set(ZLIB_LIBRARIES "${library}") |
Pavel Labath | f2fdc18 | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 141 | break() |
Pavel Labath | 11ce6e6 | 2017-12-01 11:41:07 +0000 | [diff] [blame] | 142 | endif() |
Pavel Labath | f2fdc18 | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 143 | endforeach() |
Pavel Labath | f2fdc18 | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 144 | endif() |
| 145 | |
Pavel Labath | 2da3397 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 146 | # Don't look for these libraries on Windows. |
| 147 | if (NOT PURE_WINDOWS) |
| 148 | # Skip libedit if using ASan as it contains memory leaks. |
| 149 | if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*") |
| 150 | check_library_exists(edit el_init "" HAVE_LIBEDIT) |
| 151 | else() |
| 152 | set(HAVE_LIBEDIT 0) |
| 153 | endif() |
| 154 | if(LLVM_ENABLE_TERMINFO) |
| 155 | set(HAVE_TERMINFO 0) |
| 156 | foreach(library tinfo terminfo curses ncurses ncursesw) |
| 157 | string(TOUPPER ${library} library_suffix) |
| 158 | check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix}) |
| 159 | if(HAVE_TERMINFO_${library_suffix}) |
| 160 | set(HAVE_TERMINFO 1) |
| 161 | set(TERMINFO_LIBS "${library}") |
| 162 | break() |
| 163 | endif() |
| 164 | endforeach() |
| 165 | else() |
| 166 | set(HAVE_TERMINFO 0) |
| 167 | endif() |
| 168 | |
| 169 | find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c) |
| 170 | set(LLVM_LIBXML2_ENABLED 0) |
| 171 | set(LIBXML2_FOUND 0) |
| 172 | if((LLVM_ENABLE_LIBXML2) AND ((CMAKE_SYSTEM_NAME MATCHES "Linux") AND (ICONV_LIBRARY_PATH) OR APPLE)) |
| 173 | find_package(LibXml2) |
| 174 | if (LIBXML2_FOUND) |
| 175 | set(LLVM_LIBXML2_ENABLED 1) |
| 176 | include_directories(${LIBXML2_INCLUDE_DIR}) |
| 177 | set(LIBXML2_LIBS "xml2") |
| 178 | endif() |
Eric Beckmann | 7d50c389 | 2017-07-20 21:42:04 +0000 | [diff] [blame] | 179 | endif() |
| 180 | endif() |
Oscar Fuentes | 1a0bfb6 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 181 | endif() |
Oscar Fuentes | a6e2006 | 2009-05-06 14:40:37 +0000 | [diff] [blame] | 182 | |
Hans Wennborg | 88e6e18 | 2017-11-14 22:32:49 +0000 | [diff] [blame] | 183 | if (LLVM_ENABLE_LIBXML2 STREQUAL "FORCE_ON" AND NOT LLVM_LIBXML2_ENABLED) |
| 184 | message(FATAL_ERROR "Failed to congifure libxml2") |
| 185 | endif() |
| 186 | |
Kevin Enderby | 9873e2c | 2016-05-23 21:34:12 +0000 | [diff] [blame] | 187 | check_library_exists(xar xar_open "" HAVE_LIBXAR) |
| 188 | if(HAVE_LIBXAR) |
| 189 | set(XAR_LIB xar) |
| 190 | endif() |
| 191 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 192 | # function checks |
Todd Fiala | 4ccfe39 | 2014-02-05 05:04:36 +0000 | [diff] [blame] | 193 | check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM) |
Ed Maste | e544379 | 2017-04-12 13:51:00 +0000 | [diff] [blame] | 194 | find_package(Backtrace) |
| 195 | set(HAVE_BACKTRACE ${Backtrace_FOUND}) |
| 196 | set(BACKTRACE_HEADER ${Backtrace_HEADER}) |
Juergen Ributzka | c0fc219 | 2017-08-29 00:34:56 +0000 | [diff] [blame] | 197 | |
| 198 | # Prevent check_symbol_exists from using API that is not supported for a given |
| 199 | # deployment target. |
| 200 | check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW") |
| 201 | if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW) |
| 202 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new") |
| 203 | endif() |
| 204 | |
Joerg Sonnenberger | 5c50539 | 2016-09-29 21:07:57 +0000 | [diff] [blame] | 205 | check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 206 | check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) |
Joerg Sonnenberger | 4b2a79e | 2016-09-29 21:18:05 +0000 | [diff] [blame] | 207 | check_symbol_exists(sysconf unistd.h HAVE_SYSCONF) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 208 | check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE) |
| 209 | check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT) |
Ted Kremenek | 6ea1b76 | 2011-12-23 01:31:45 +0000 | [diff] [blame] | 210 | check_symbol_exists(isatty unistd.h HAVE_ISATTY) |
Eric Christopher | a24dc7f | 2013-07-04 01:10:38 +0000 | [diff] [blame] | 211 | check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS) |
| 212 | check_symbol_exists(futimes sys/time.h HAVE_FUTIMES) |
Rafael Espindola | 3816c53 | 2016-07-19 20:19:56 +0000 | [diff] [blame] | 213 | check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE) |
Vitaly Buka | d44b763 | 2016-08-25 03:44:36 +0000 | [diff] [blame] | 214 | # AddressSanitizer conflicts with lib/Support/Unix/Signals.inc |
Bob Wilson | d39ead4 | 2017-01-06 02:26:30 +0000 | [diff] [blame] | 215 | # Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it |
| 216 | # (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind |
| 217 | # past the signal handler after an assertion failure (rdar://29866587). |
| 218 | if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE ) |
Richard Smith | abab5d2 | 2016-05-20 21:26:00 +0000 | [diff] [blame] | 219 | check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK) |
| 220 | endif() |
Oscar Fuentes | ed27ead | 2011-02-03 04:23:07 +0000 | [diff] [blame] | 221 | if( HAVE_SYS_UIO_H ) |
| 222 | check_symbol_exists(writev sys/uio.h HAVE_WRITEV) |
| 223 | endif() |
Peter Collingbourne | 8db7e5e | 2016-12-09 05:20:43 +0000 | [diff] [blame] | 224 | set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE") |
| 225 | check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64) |
| 226 | set(CMAKE_REQUIRED_DEFINITIONS "") |
Davide Italiano | faafae3 | 2015-02-19 07:27:14 +0000 | [diff] [blame] | 227 | check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 228 | check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) |
Douglas Gregor | 60dd76f | 2009-06-04 17:22:52 +0000 | [diff] [blame] | 229 | check_symbol_exists(malloc_zone_statistics malloc/malloc.h |
| 230 | HAVE_MALLOC_ZONE_STATISTICS) |
Benjamin Kramer | c1ba4c2 | 2009-10-28 18:37:31 +0000 | [diff] [blame] | 231 | check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP) |
| 232 | check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP) |
| 233 | check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP) |
Oscar Fuentes | 0a1b6b8 | 2011-01-13 19:17:28 +0000 | [diff] [blame] | 234 | check_symbol_exists(getcwd unistd.h HAVE_GETCWD) |
| 235 | check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY) |
| 236 | check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT) |
Benjamin Kramer | e1effb0 | 2011-11-22 12:31:53 +0000 | [diff] [blame] | 237 | check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN) |
| 238 | check_symbol_exists(pread unistd.h HAVE_PREAD) |
Alexey Samsonov | 30c0ecc | 2013-08-26 18:11:25 +0000 | [diff] [blame] | 239 | check_symbol_exists(realpath stdlib.h HAVE_REALPATH) |
Edward O'Callaghan | 655314e | 2009-10-05 23:05:32 +0000 | [diff] [blame] | 240 | check_symbol_exists(sbrk unistd.h HAVE_SBRK) |
Oscar Fuentes | a9ac909 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 241 | check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) |
Jeffrey Yasskin | 1a93330 | 2009-07-01 18:11:20 +0000 | [diff] [blame] | 242 | check_symbol_exists(strerror string.h HAVE_STRERROR) |
| 243 | check_symbol_exists(strerror_r string.h HAVE_STRERROR_R) |
NAKAMURA Takumi | 18911180 | 2011-02-09 04:18:48 +0000 | [diff] [blame] | 244 | check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S) |
Jeffrey Yasskin | 14a5cc5 | 2009-09-25 21:07:20 +0000 | [diff] [blame] | 245 | check_symbol_exists(setenv stdlib.h HAVE_SETENV) |
Oscar Fuentes | 2761c7a | 2011-02-04 05:40:04 +0000 | [diff] [blame] | 246 | if( PURE_WINDOWS ) |
Michael J. Spencer | ca242f2 | 2010-12-03 18:48:56 +0000 | [diff] [blame] | 247 | check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S) |
NAKAMURA Takumi | 03a541f | 2011-02-05 15:11:53 +0000 | [diff] [blame] | 248 | |
| 249 | check_function_exists(_alloca HAVE__ALLOCA) |
| 250 | check_function_exists(__alloca HAVE___ALLOCA) |
| 251 | check_function_exists(__chkstk HAVE___CHKSTK) |
NAKAMURA Takumi | 7885507 | 2015-01-30 13:01:19 +0000 | [diff] [blame] | 252 | check_function_exists(__chkstk_ms HAVE___CHKSTK_MS) |
NAKAMURA Takumi | 03a541f | 2011-02-05 15:11:53 +0000 | [diff] [blame] | 253 | check_function_exists(___chkstk HAVE____CHKSTK) |
NAKAMURA Takumi | 7885507 | 2015-01-30 13:01:19 +0000 | [diff] [blame] | 254 | check_function_exists(___chkstk_ms HAVE____CHKSTK_MS) |
NAKAMURA Takumi | 03a541f | 2011-02-05 15:11:53 +0000 | [diff] [blame] | 255 | |
| 256 | check_function_exists(__ashldi3 HAVE___ASHLDI3) |
| 257 | check_function_exists(__ashrdi3 HAVE___ASHRDI3) |
| 258 | check_function_exists(__divdi3 HAVE___DIVDI3) |
| 259 | check_function_exists(__fixdfdi HAVE___FIXDFDI) |
| 260 | check_function_exists(__fixsfdi HAVE___FIXSFDI) |
| 261 | check_function_exists(__floatdidf HAVE___FLOATDIDF) |
| 262 | check_function_exists(__lshrdi3 HAVE___LSHRDI3) |
| 263 | check_function_exists(__moddi3 HAVE___MODDI3) |
| 264 | check_function_exists(__udivdi3 HAVE___UDIVDI3) |
| 265 | check_function_exists(__umoddi3 HAVE___UMODDI3) |
| 266 | |
| 267 | check_function_exists(__main HAVE___MAIN) |
| 268 | check_function_exists(__cmpdi2 HAVE___CMPDI2) |
Michael J. Spencer | ca242f2 | 2010-12-03 18:48:56 +0000 | [diff] [blame] | 269 | endif() |
Oscar Fuentes | e866c41 | 2011-01-31 18:25:25 +0000 | [diff] [blame] | 270 | if( HAVE_DLFCN_H ) |
| 271 | if( HAVE_LIBDL ) |
| 272 | list(APPEND CMAKE_REQUIRED_LIBRARIES dl) |
| 273 | endif() |
Oscar Fuentes | e65ed1c | 2011-01-17 16:35:14 +0000 | [diff] [blame] | 274 | check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN) |
Omair Javaid | f5d560bc84 | 2017-02-02 01:17:49 +0000 | [diff] [blame] | 275 | check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR) |
Oscar Fuentes | e866c41 | 2011-01-31 18:25:25 +0000 | [diff] [blame] | 276 | if( HAVE_LIBDL ) |
| 277 | list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl) |
| 278 | endif() |
Oscar Fuentes | e65ed1c | 2011-01-17 16:35:14 +0000 | [diff] [blame] | 279 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 280 | |
Oscar Fuentes | bda403b | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 281 | check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) |
| 282 | if( LLVM_USING_GLIBC ) |
Serge Pavlov | 23be945 | 2017-03-21 04:03:24 +0000 | [diff] [blame] | 283 | add_definitions( -D_GNU_SOURCE ) |
Rafael Espindola | 8c0ff95 | 2017-10-04 20:27:01 +0000 | [diff] [blame] | 284 | list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") |
Oscar Fuentes | bda403b | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 285 | endif() |
Krzysztof Parzyszek | 6cf2540 | 2017-03-03 21:53:12 +0000 | [diff] [blame] | 286 | # This check requires _GNU_SOURCE |
Rafael Espindola | 8c0ff95 | 2017-10-04 20:27:01 +0000 | [diff] [blame] | 287 | check_symbol_exists(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY) |
| 288 | check_symbol_exists(CPU_COUNT sched.h HAVE_CPU_COUNT) |
Krzysztof Parzyszek | 6cf2540 | 2017-03-03 21:53:12 +0000 | [diff] [blame] | 289 | if(HAVE_LIBPTHREAD) |
| 290 | check_library_exists(pthread pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP) |
| 291 | check_library_exists(pthread pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP) |
| 292 | elseif(PTHREAD_IN_LIBC) |
| 293 | check_library_exists(c pthread_getname_np "" HAVE_PTHREAD_GETNAME_NP) |
| 294 | check_library_exists(c pthread_setname_np "" HAVE_PTHREAD_SETNAME_NP) |
| 295 | endif() |
Oscar Fuentes | bda403b | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 296 | |
Reid Kleckner | 37f69de | 2013-07-26 16:54:23 +0000 | [diff] [blame] | 297 | set(headers "sys/types.h") |
Douglas Gregor | f99626e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 298 | |
| 299 | if (HAVE_INTTYPES_H) |
| 300 | set(headers ${headers} "inttypes.h") |
| 301 | endif() |
| 302 | |
| 303 | if (HAVE_STDINT_H) |
| 304 | set(headers ${headers} "stdint.h") |
| 305 | endif() |
| 306 | |
Oscar Fuentes | c8cb58e | 2011-01-11 12:31:54 +0000 | [diff] [blame] | 307 | check_type_exists(int64_t "${headers}" HAVE_INT64_T) |
Douglas Gregor | f99626e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 308 | check_type_exists(uint64_t "${headers}" HAVE_UINT64_T) |
| 309 | check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T) |
| 310 | |
Oscar Fuentes | 17feb2a | 2009-11-05 19:03:26 +0000 | [diff] [blame] | 311 | # available programs checks |
Oscar Fuentes | de8f431 | 2009-11-09 15:26:40 +0000 | [diff] [blame] | 312 | function(llvm_find_program name) |
| 313 | string(TOUPPER ${name} NAME) |
Tobias Grosser | 1b4f940 | 2011-02-27 04:11:05 +0000 | [diff] [blame] | 314 | string(REGEX REPLACE "\\." "_" NAME ${NAME}) |
Matt Arsenault | 9096217 | 2013-07-08 20:24:49 +0000 | [diff] [blame] | 315 | |
| 316 | find_program(LLVM_PATH_${NAME} NAMES ${ARGV}) |
Oscar Fuentes | de8f431 | 2009-11-09 15:26:40 +0000 | [diff] [blame] | 317 | mark_as_advanced(LLVM_PATH_${NAME}) |
| 318 | if(LLVM_PATH_${NAME}) |
| 319 | set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?") |
| 320 | mark_as_advanced(HAVE_${NAME}) |
| 321 | else(LLVM_PATH_${NAME}) |
| 322 | set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?") |
Oscar Fuentes | de8f431 | 2009-11-09 15:26:40 +0000 | [diff] [blame] | 323 | endif(LLVM_PATH_${NAME}) |
| 324 | endfunction() |
| 325 | |
Alp Toker | 125be84 | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 326 | if (LLVM_ENABLE_DOXYGEN) |
| 327 | llvm_find_program(dot) |
| 328 | endif () |
Oscar Fuentes | 17feb2a | 2009-11-05 19:03:26 +0000 | [diff] [blame] | 329 | |
Oscar Fuentes | 6495595 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 330 | if( LLVM_ENABLE_FFI ) |
| 331 | find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR}) |
Josh Klontz | da295e9 | 2014-08-08 14:32:56 +0000 | [diff] [blame] | 332 | if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" ) |
Oscar Fuentes | 6495595 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 333 | set(FFI_HEADER ffi.h CACHE INTERNAL "") |
| 334 | set(HAVE_FFI_H 1 CACHE INTERNAL "") |
| 335 | else() |
| 336 | find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR}) |
Josh Klontz | da295e9 | 2014-08-08 14:32:56 +0000 | [diff] [blame] | 337 | if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" ) |
Oscar Fuentes | 6495595 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 338 | set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "") |
| 339 | set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "") |
| 340 | endif() |
| 341 | endif() |
| 342 | |
| 343 | if( NOT FFI_HEADER ) |
| 344 | message(FATAL_ERROR "libffi includes are not found.") |
| 345 | endif() |
| 346 | |
| 347 | find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR}) |
| 348 | if( NOT FFI_LIBRARY_PATH ) |
| 349 | message(FATAL_ERROR "libffi is not found.") |
| 350 | endif() |
| 351 | |
| 352 | list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH}) |
| 353 | list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH}) |
| 354 | check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL) |
| 355 | list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH}) |
| 356 | list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH}) |
Oscar Fuentes | f2ab928 | 2011-04-02 13:21:12 +0000 | [diff] [blame] | 357 | else() |
| 358 | unset(HAVE_FFI_FFI_H CACHE) |
| 359 | unset(HAVE_FFI_H CACHE) |
| 360 | unset(HAVE_FFI_CALL CACHE) |
Oscar Fuentes | 6495595 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 361 | endif( LLVM_ENABLE_FFI ) |
| 362 | |
Eric Christopher | 4418a60 | 2011-09-19 20:43:23 +0000 | [diff] [blame] | 363 | # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported. |
Xerxes Ranby | 64c6d42 | 2009-07-17 19:22:41 +0000 | [diff] [blame] | 364 | include(CheckAtomic) |
| 365 | |
Oscar Fuentes | 25ac830 | 2011-01-15 13:35:37 +0000 | [diff] [blame] | 366 | if( LLVM_ENABLE_PIC ) |
| 367 | set(ENABLE_PIC 1) |
| 368 | else() |
| 369 | set(ENABLE_PIC 0) |
Chris Bieneman | 7494dc5 | 2015-11-24 08:04:59 +0000 | [diff] [blame] | 370 | check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG) |
| 371 | if(SUPPORTS_NO_PIE_FLAG) |
Pavel Labath | e3af026 | 2015-11-24 09:46:01 +0000 | [diff] [blame] | 372 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") |
Chris Bieneman | 7494dc5 | 2015-11-24 08:04:59 +0000 | [diff] [blame] | 373 | endif() |
Oscar Fuentes | 25ac830 | 2011-01-15 13:35:37 +0000 | [diff] [blame] | 374 | endif() |
Oscar Fuentes | edfc184 | 2011-01-09 14:34:39 +0000 | [diff] [blame] | 375 | |
Chandler Carruth | 25657e8 | 2017-01-06 23:16:00 +0000 | [diff] [blame] | 376 | check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG) |
| 377 | check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments" |
| 378 | SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG) |
Michael J. Spencer | 33a390e | 2010-10-07 18:12:54 +0000 | [diff] [blame] | 379 | |
Edwin Vane | a9c5bb3 | 2013-02-04 02:32:44 +0000 | [diff] [blame] | 380 | set(USE_NO_MAYBE_UNINITIALIZED 0) |
| 381 | set(USE_NO_UNINITIALIZED 0) |
| 382 | |
| 383 | # Disable gcc's potentially uninitialized use analysis as it presents lots of |
| 384 | # false positives. |
| 385 | if (CMAKE_COMPILER_IS_GNUCXX) |
| 386 | check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED) |
| 387 | if (HAS_MAYBE_UNINITIALIZED) |
| 388 | set(USE_NO_MAYBE_UNINITIALIZED 1) |
| 389 | else() |
| 390 | # Only recent versions of gcc make the distinction between -Wuninitialized |
| 391 | # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just |
| 392 | # turn off all uninitialized use warnings. |
| 393 | check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED) |
| 394 | set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED}) |
| 395 | endif() |
| 396 | endif() |
| 397 | |
Sebastian Pop | 82622dc | 2012-08-08 18:04:45 +0000 | [diff] [blame] | 398 | # By default, we target the host, but this can be overridden at CMake |
| 399 | # invocation time. |
Tim Northover | fee13d1 | 2013-05-04 07:36:23 +0000 | [diff] [blame] | 400 | include(GetHostTriple) |
| 401 | get_host_triple(LLVM_INFERRED_HOST_TRIPLE) |
| 402 | |
| 403 | set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING |
| 404 | "Host on which LLVM binaries will run") |
Daniel Dunbar | c0fd8a4 | 2009-11-07 23:52:20 +0000 | [diff] [blame] | 405 | |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 406 | # Determine the native architecture. |
Oscar Fuentes | b9a7813 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 407 | string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH) |
| 408 | if( LLVM_NATIVE_ARCH STREQUAL "host" ) |
Chandler Carruth | beb3e7e | 2012-01-24 18:00:44 +0000 | [diff] [blame] | 409 | string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE}) |
Oscar Fuentes | b9a7813 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 410 | endif () |
| 411 | |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 412 | if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86") |
| 413 | set(LLVM_NATIVE_ARCH X86) |
Oscar Fuentes | b9a7813 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 414 | elseif (LLVM_NATIVE_ARCH STREQUAL "x86") |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 415 | set(LLVM_NATIVE_ARCH X86) |
Oscar Fuentes | b9a7813 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 416 | elseif (LLVM_NATIVE_ARCH STREQUAL "amd64") |
| 417 | set(LLVM_NATIVE_ARCH X86) |
| 418 | elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64") |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 419 | set(LLVM_NATIVE_ARCH X86) |
| 420 | elseif (LLVM_NATIVE_ARCH MATCHES "sparc") |
| 421 | set(LLVM_NATIVE_ARCH Sparc) |
| 422 | elseif (LLVM_NATIVE_ARCH MATCHES "powerpc") |
| 423 | set(LLVM_NATIVE_ARCH PowerPC) |
Tim Northover | a958a57 | 2013-05-04 20:13:52 +0000 | [diff] [blame] | 424 | elseif (LLVM_NATIVE_ARCH MATCHES "aarch64") |
| 425 | set(LLVM_NATIVE_ARCH AArch64) |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 426 | elseif (LLVM_NATIVE_ARCH MATCHES "arm64") |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 427 | set(LLVM_NATIVE_ARCH AArch64) |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 428 | elseif (LLVM_NATIVE_ARCH MATCHES "arm") |
| 429 | set(LLVM_NATIVE_ARCH ARM) |
| 430 | elseif (LLVM_NATIVE_ARCH MATCHES "mips") |
| 431 | set(LLVM_NATIVE_ARCH Mips) |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 432 | elseif (LLVM_NATIVE_ARCH MATCHES "xcore") |
| 433 | set(LLVM_NATIVE_ARCH XCore) |
| 434 | elseif (LLVM_NATIVE_ARCH MATCHES "msp430") |
| 435 | set(LLVM_NATIVE_ARCH MSP430) |
Sebastian Pop | 8f4aec4 | 2012-08-20 19:56:49 +0000 | [diff] [blame] | 436 | elseif (LLVM_NATIVE_ARCH MATCHES "hexagon") |
| 437 | set(LLVM_NATIVE_ARCH Hexagon) |
Ulrich Weigand | 1ceebf6 | 2013-05-06 16:22:34 +0000 | [diff] [blame] | 438 | elseif (LLVM_NATIVE_ARCH MATCHES "s390x") |
| 439 | set(LLVM_NATIVE_ARCH SystemZ) |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 440 | elseif (LLVM_NATIVE_ARCH MATCHES "wasm32") |
| 441 | set(LLVM_NATIVE_ARCH WebAssembly) |
| 442 | elseif (LLVM_NATIVE_ARCH MATCHES "wasm64") |
| 443 | set(LLVM_NATIVE_ARCH WebAssembly) |
Azharuddin Mohammed | 8afcd93 | 2018-03-13 17:04:33 +0000 | [diff] [blame^] | 444 | elseif (LLVM_NATIVE_ARCH MATCHES "riscv32") |
| 445 | set(LLVM_NATIVE_ARCH RISCV) |
| 446 | elseif (LLVM_NATIVE_ARCH MATCHES "riscv64") |
| 447 | set(LLVM_NATIVE_ARCH RISCV) |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 448 | else () |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 449 | message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}") |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 450 | endif () |
Michael J. Spencer | 1444f47 | 2010-09-24 09:00:56 +0000 | [diff] [blame] | 451 | |
Andy Gibbs | f5dede1 | 2013-06-26 07:57:53 +0000 | [diff] [blame] | 452 | # If build targets includes "host", then replace with native architecture. |
| 453 | list(FIND LLVM_TARGETS_TO_BUILD "host" idx) |
| 454 | if( NOT idx LESS 0 ) |
| 455 | list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx}) |
| 456 | list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH}) |
| 457 | list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) |
| 458 | endif() |
| 459 | |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 460 | list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX) |
| 461 | if (NATIVE_ARCH_IDX EQUAL -1) |
| 462 | message(STATUS |
| 463 | "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code") |
| 464 | else () |
| 465 | message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}") |
| 466 | set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target) |
| 467 | set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo) |
Evan Cheng | 8c886a4 | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 468 | set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC) |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 469 | set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter) |
Chandler Carruth | 98e642d | 2011-12-09 03:31:58 +0000 | [diff] [blame] | 470 | |
| 471 | # We don't have an ASM parser for all architectures yet. |
Vassil Vassilev | e2d8a40 | 2016-06-11 17:20:53 +0000 | [diff] [blame] | 472 | if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt) |
Chandler Carruth | 98e642d | 2011-12-09 03:31:58 +0000 | [diff] [blame] | 473 | set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser) |
| 474 | endif () |
Eric Christopher | 56079c1 | 2012-03-26 21:56:56 +0000 | [diff] [blame] | 475 | |
| 476 | # We don't have an disassembler for all architectures yet. |
Vassil Vassilev | e2d8a40 | 2016-06-11 17:20:53 +0000 | [diff] [blame] | 477 | if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt) |
Eric Christopher | 56079c1 | 2012-03-26 21:56:56 +0000 | [diff] [blame] | 478 | set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler) |
| 479 | endif () |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 480 | endif () |
Douglas Gregor | 3def847 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 481 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 482 | if( MINGW ) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 483 | set(HAVE_LIBPSAPI 1) |
David Majnemer | 61eae2e | 2013-10-07 01:00:07 +0000 | [diff] [blame] | 484 | set(HAVE_LIBSHELL32 1) |
Oscar Fuentes | 2500aae | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 485 | # TODO: Check existence of libraries. |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 486 | # include(CheckLibraryExists) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 487 | endif( MINGW ) |
| 488 | |
Reid Kleckner | a3ae94e | 2013-08-07 00:29:15 +0000 | [diff] [blame] | 489 | if (NOT HAVE_STRTOLL) |
| 490 | # Use _strtoi64 if strtoll is not available. |
| 491 | check_symbol_exists(_strtoi64 stdlib.h have_strtoi64) |
| 492 | if (have_strtoi64) |
| 493 | set(HAVE_STRTOLL 1) |
| 494 | set(strtoll "_strtoi64") |
| 495 | set(strtoull "_strtoui64") |
| 496 | endif () |
| 497 | endif () |
| 498 | |
Oscar Fuentes | a9ac909 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 499 | if( MSVC ) |
Oscar Fuentes | a9ac909 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 500 | set(SHLIBEXT ".lib") |
Oscar Fuentes | a9ac909 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 501 | set(stricmp "_stricmp") |
| 502 | set(strdup "_strdup") |
Zachary Turner | 733b849 | 2015-02-10 05:04:25 +0000 | [diff] [blame] | 503 | |
| 504 | # See if the DIA SDK is available and usable. |
| 505 | set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK") |
| 506 | |
| 507 | # Due to a bug in MSVC 2013's installation software, it is possible |
| 508 | # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012 |
| 509 | # install directory. If this happens, the installation is corrupt |
| 510 | # and there's nothing we can do. It happens with enough frequency |
| 511 | # though that we should handle it. We do so by simply checking that |
| 512 | # the DIA SDK folder exists. Should this happen you will need to |
| 513 | # uninstall VS 2012 and then re-install VS 2013. |
| 514 | if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR}) |
| 515 | set(HAVE_DIA_SDK 1) |
| 516 | else() |
| 517 | set(HAVE_DIA_SDK 0) |
| 518 | endif() |
Michal Gorny | 89b6f16 | 2017-01-02 18:19:35 +0000 | [diff] [blame] | 519 | |
| 520 | option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available." |
| 521 | ${HAVE_DIA_SDK}) |
| 522 | |
| 523 | if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK) |
| 524 | message(FATAL_ERROR "DIA SDK not found. If you have both VS 2012 and 2013 installed, you may need to uninstall the former and re-install the latter afterwards.") |
| 525 | endif() |
Zachary Turner | 3ddf94e | 2015-02-22 07:13:52 +0000 | [diff] [blame] | 526 | else() |
Michal Gorny | 89b6f16 | 2017-01-02 18:19:35 +0000 | [diff] [blame] | 527 | set(LLVM_ENABLE_DIA_SDK 0) |
Oscar Fuentes | a9ac909 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 528 | endif( MSVC ) |
| 529 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 530 | # FIXME: Signal handler return type, currently hardcoded to 'void' |
| 531 | set(RETSIGTYPE void) |
| 532 | |
Oscar Fuentes | 366fbb7 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 533 | if( LLVM_ENABLE_THREADS ) |
Dylan Noblesmith | efddf20 | 2011-11-28 00:48:58 +0000 | [diff] [blame] | 534 | # Check if threading primitives aren't supported on this platform |
| 535 | if( NOT HAVE_PTHREAD_H AND NOT WIN32 ) |
| 536 | set(LLVM_ENABLE_THREADS 0) |
Oscar Fuentes | 366fbb7 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 537 | endif() |
| 538 | endif() |
| 539 | |
Dylan Noblesmith | efddf20 | 2011-11-28 00:48:58 +0000 | [diff] [blame] | 540 | if( LLVM_ENABLE_THREADS ) |
Oscar Fuentes | 366fbb7 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 541 | message(STATUS "Threads enabled.") |
Dylan Noblesmith | efddf20 | 2011-11-28 00:48:58 +0000 | [diff] [blame] | 542 | else( LLVM_ENABLE_THREADS ) |
Oscar Fuentes | 366fbb7 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 543 | message(STATUS "Threads disabled.") |
| 544 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 545 | |
Alexey Samsonov | 2fb337e | 2013-04-23 08:28:39 +0000 | [diff] [blame] | 546 | if (LLVM_ENABLE_ZLIB ) |
| 547 | # Check if zlib is available in the system. |
| 548 | if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ ) |
| 549 | set(LLVM_ENABLE_ZLIB 0) |
| 550 | endif() |
| 551 | endif() |
| 552 | |
Michael Gottesman | 4d35b90 | 2013-08-24 07:25:21 +0000 | [diff] [blame] | 553 | if (LLVM_ENABLE_DOXYGEN) |
| 554 | message(STATUS "Doxygen enabled.") |
Dan Liew | f854295 | 2014-04-28 09:10:05 +0000 | [diff] [blame] | 555 | find_package(Doxygen REQUIRED) |
Michael Gottesman | 9cc5a45 | 2013-08-28 20:28:32 +0000 | [diff] [blame] | 556 | |
| 557 | if (DOXYGEN_FOUND) |
| 558 | # If we find doxygen and we want to enable doxygen by default create a |
| 559 | # global aggregate doxygen target for generating llvm and any/all |
| 560 | # subprojects doxygen documentation. |
| 561 | if (LLVM_BUILD_DOCS) |
| 562 | add_custom_target(doxygen ALL) |
| 563 | endif() |
Michael Gottesman | 406525d | 2013-08-28 21:55:26 +0000 | [diff] [blame] | 564 | |
| 565 | option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF) |
| 566 | if (LLVM_DOXYGEN_EXTERNAL_SEARCH) |
Saleem Abdulrasool | f95da49 | 2015-07-24 01:14:25 +0000 | [diff] [blame] | 567 | set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.") |
Michael Gottesman | 406525d | 2013-08-28 21:55:26 +0000 | [diff] [blame] | 568 | set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings") |
| 569 | endif() |
Michael Gottesman | 9cc5a45 | 2013-08-28 20:28:32 +0000 | [diff] [blame] | 570 | endif() |
Michael Gottesman | 4d35b90 | 2013-08-24 07:25:21 +0000 | [diff] [blame] | 571 | else() |
| 572 | message(STATUS "Doxygen disabled.") |
| 573 | endif() |
Reid Kleckner | 9f5eb63 | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 574 | |
Peter Collingbourne | 82e3e37 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 575 | set(LLVM_BINDINGS "") |
Peter Collingbourne | 244ecf5 | 2014-10-23 02:33:23 +0000 | [diff] [blame] | 576 | if(WIN32) |
Peter Collingbourne | 82e3e37 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 577 | message(STATUS "Go bindings disabled.") |
| 578 | else() |
Peter Collingbourne | 244ecf5 | 2014-10-23 02:33:23 +0000 | [diff] [blame] | 579 | find_program(GO_EXECUTABLE NAMES go DOC "go executable") |
| 580 | if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND") |
| 581 | message(STATUS "Go bindings disabled.") |
Peter Collingbourne | 82e3e37 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 582 | else() |
Vassil Vassilev | e2d8a40 | 2016-06-11 17:20:53 +0000 | [diff] [blame] | 583 | execute_process(COMMAND ${GO_EXECUTABLE} run ${PROJECT_SOURCE_DIR}/bindings/go/conftest.go |
Peter Collingbourne | 244ecf5 | 2014-10-23 02:33:23 +0000 | [diff] [blame] | 584 | RESULT_VARIABLE GO_CONFTEST) |
| 585 | if(GO_CONFTEST STREQUAL "0") |
| 586 | set(LLVM_BINDINGS "${LLVM_BINDINGS} go") |
| 587 | message(STATUS "Go bindings enabled.") |
| 588 | else() |
| 589 | message(STATUS "Go bindings disabled, need at least Go 1.2.") |
| 590 | endif() |
Peter Collingbourne | 82e3e37 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 591 | endif() |
| 592 | endif() |
Peter Zotov | b20073c | 2014-12-01 19:50:23 +0000 | [diff] [blame] | 593 | |
Niels Ole Salscheider | b0e3c34 | 2015-05-01 11:58:30 +0000 | [diff] [blame] | 594 | find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker") |
Rafael Espindola | 6b27999 | 2015-04-27 21:08:47 +0000 | [diff] [blame] | 595 | set(LLVM_BINUTILS_INCDIR "" CACHE PATH |
| 596 | "PATH to binutils/include containing plugin-api.h for gold plugin.") |
Chandler Carruth | edd9294 | 2015-02-14 09:43:57 +0000 | [diff] [blame] | 597 | |
Bruno Cardoso Lopes | f8df4d1 | 2016-07-26 18:09:23 +0000 | [diff] [blame] | 598 | if(CMAKE_HOST_APPLE AND APPLE) |
Matthias Braun | 59797ec | 2017-02-11 00:14:01 +0000 | [diff] [blame] | 599 | if(NOT CMAKE_XCRUN) |
| 600 | find_program(CMAKE_XCRUN NAMES xcrun) |
| 601 | endif() |
Bruno Cardoso Lopes | f8df4d1 | 2016-07-26 18:09:23 +0000 | [diff] [blame] | 602 | if(CMAKE_XCRUN) |
| 603 | execute_process(COMMAND ${CMAKE_XCRUN} -find ld |
| 604 | OUTPUT_VARIABLE LD64_EXECUTABLE |
| 605 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 606 | else() |
| 607 | find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker") |
| 608 | endif() |
| 609 | |
| 610 | if(LD64_EXECUTABLE) |
| 611 | set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable") |
| 612 | message(STATUS "Found ld64 - ${LD64_EXECUTABLE}") |
| 613 | endif() |
Peter Collingbourne | bbdc26b | 2015-03-19 23:55:38 +0000 | [diff] [blame] | 614 | endif() |
| 615 | |
Peter Zotov | e9dd46f | 2016-09-05 01:42:22 +0000 | [diff] [blame] | 616 | # Keep the version requirements in sync with bindings/ocaml/README.txt. |
Peter Zotov | b20073c | 2014-12-01 19:50:23 +0000 | [diff] [blame] | 617 | include(FindOCaml) |
| 618 | include(AddOCaml) |
| 619 | if(WIN32) |
| 620 | message(STATUS "OCaml bindings disabled.") |
| 621 | else() |
| 622 | find_package(OCaml) |
| 623 | if( NOT OCAML_FOUND ) |
| 624 | message(STATUS "OCaml bindings disabled.") |
| 625 | else() |
| 626 | if( OCAML_VERSION VERSION_LESS "4.00.0" ) |
| 627 | message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.") |
| 628 | else() |
Peter Zotov | 8c7e29d | 2015-06-27 14:32:30 +0000 | [diff] [blame] | 629 | find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL) |
Peter Zotov | fcefcf9 | 2014-12-03 03:39:01 +0000 | [diff] [blame] | 630 | if( HAVE_OCAML_CTYPES ) |
| 631 | message(STATUS "OCaml bindings enabled.") |
| 632 | find_ocamlfind_package(oUnit VERSION 2 OPTIONAL) |
| 633 | set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml") |
Michal Gorny | b002f63 | 2016-09-30 18:34:23 +0000 | [diff] [blame] | 634 | |
| 635 | set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING |
| 636 | "Install directory for LLVM OCaml packages") |
Peter Zotov | fcefcf9 | 2014-12-03 03:39:01 +0000 | [diff] [blame] | 637 | else() |
Peter Zotov | 8c7e29d | 2015-06-27 14:32:30 +0000 | [diff] [blame] | 638 | message(STATUS "OCaml bindings disabled, need ctypes >=0.4.") |
Peter Zotov | fcefcf9 | 2014-12-03 03:39:01 +0000 | [diff] [blame] | 639 | endif() |
Peter Zotov | b20073c | 2014-12-01 19:50:23 +0000 | [diff] [blame] | 640 | endif() |
| 641 | endif() |
| 642 | endif() |
| 643 | |
| 644 | string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}") |
Adam Nemet | 95e0c5f | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 645 | |
| 646 | function(find_python_module module) |
Jonas Hahnfeld | 9e4431f | 2018-01-02 17:53:08 +0000 | [diff] [blame] | 647 | string(REPLACE "." "_" module_name ${module}) |
| 648 | string(TOUPPER ${module_name} module_upper) |
Adam Nemet | 95e0c5f | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 649 | set(FOUND_VAR PY_${module_upper}_FOUND) |
| 650 | |
| 651 | execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}" |
| 652 | RESULT_VARIABLE status |
| 653 | ERROR_QUIET) |
| 654 | |
| 655 | if(status) |
| 656 | set(${FOUND_VAR} 0 PARENT_SCOPE) |
| 657 | message(STATUS "Could NOT find Python module ${module}") |
| 658 | else() |
| 659 | set(${FOUND_VAR} 1 PARENT_SCOPE) |
| 660 | message(STATUS "Found Python module ${module}") |
| 661 | endif() |
| 662 | endfunction() |
| 663 | |
| 664 | set (PYTHON_MODULES |
| 665 | pygments |
Jonas Hahnfeld | 9e4431f | 2018-01-02 17:53:08 +0000 | [diff] [blame] | 666 | # Some systems still don't have pygments.lexers.c_cpp which was introduced in |
| 667 | # version 2.0 in 2014... |
| 668 | pygments.lexers.c_cpp |
Adam Nemet | 95e0c5f | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 669 | yaml |
| 670 | ) |
| 671 | foreach(module ${PYTHON_MODULES}) |
| 672 | find_python_module(${module}) |
| 673 | endforeach() |
| 674 | |
Jonas Hahnfeld | 9e4431f | 2018-01-02 17:53:08 +0000 | [diff] [blame] | 675 | if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND) |
Adam Nemet | 95e0c5f | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 676 | set (LLVM_HAVE_OPT_VIEWER_MODULES 1) |
| 677 | else() |
| 678 | set (LLVM_HAVE_OPT_VIEWER_MODULES 0) |
| 679 | endif() |