Oscar Fuentes | 325610b | 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 | 9c091a48 | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 6 | include(CheckIncludeFile) |
| 7 | include(CheckLibraryExists) |
| 8 | include(CheckSymbolExists) |
| 9 | include(CheckFunctionExists) |
Argyrios Kyrtzidis | 802db56 | 2018-11-26 00:03:39 +0000 | [diff] [blame] | 10 | include(CheckStructHasMember) |
Juergen Ributzka | 0e3a936 | 2017-08-29 00:34:56 +0000 | [diff] [blame] | 11 | include(CheckCCompilerFlag) |
Douglas Gregor | 9c091a48 | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 12 | |
Reid Kleckner | 06ff4ba | 2016-03-02 16:42:56 +0000 | [diff] [blame] | 13 | include(CheckCompilerVersion) |
Jordan Rose | 1b7969e | 2014-02-05 00:02:37 +0000 | [diff] [blame] | 14 | include(HandleLLVMStdlib) |
| 15 | |
Renato Golin | 59e23fa | 2016-02-26 17:01:45 +0000 | [diff] [blame] | 16 | if( UNIX AND NOT (BEOS OR HAIKU) ) |
Oscar Fuentes | a447cfe | 2009-11-12 05:36:09 +0000 | [diff] [blame] | 17 | # Used by check_symbol_exists: |
Don Hinton | e40169c | 2017-12-25 01:23:09 +0000 | [diff] [blame] | 18 | list(APPEND CMAKE_REQUIRED_LIBRARIES "m") |
Oscar Fuentes | a447cfe | 2009-11-12 05:36:09 +0000 | [diff] [blame] | 19 | endif() |
Viktor Kutuzov | d97cbff | 2014-04-09 11:43:34 +0000 | [diff] [blame] | 20 | # x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly. |
| 21 | if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND |
| 22 | CMAKE_SIZEOF_VOID_P EQUAL 8 ) |
| 23 | list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt") |
| 24 | endif() |
Oscar Fuentes | a447cfe | 2009-11-12 05:36:09 +0000 | [diff] [blame] | 25 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 26 | # include checks |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 27 | check_include_file(dlfcn.h HAVE_DLFCN_H) |
| 28 | check_include_file(errno.h HAVE_ERRNO_H) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 29 | check_include_file(fcntl.h HAVE_FCNTL_H) |
Alexey Samsonov | fcc00a1 | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 30 | check_include_file(link.h HAVE_LINK_H) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 31 | check_include_file(malloc.h HAVE_MALLOC_H) |
| 32 | check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) |
Oscar Fuentes | 325610b | 2011-02-04 05:40:04 +0000 | [diff] [blame] | 33 | if( NOT PURE_WINDOWS ) |
Oscar Fuentes | 20f1714 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 34 | check_include_file(pthread.h HAVE_PTHREAD_H) |
| 35 | endif() |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 36 | check_include_file(signal.h HAVE_SIGNAL_H) |
Douglas Gregor | 0174674 | 2009-05-11 18:05:52 +0000 | [diff] [blame] | 37 | check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 38 | check_include_file(sys/mman.h HAVE_SYS_MMAN_H) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 39 | check_include_file(sys/param.h HAVE_SYS_PARAM_H) |
| 40 | check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) |
| 41 | check_include_file(sys/stat.h HAVE_SYS_STAT_H) |
| 42 | check_include_file(sys/time.h HAVE_SYS_TIME_H) |
Jeroen Ketema | e655757 | 2016-04-07 08:36:13 +0000 | [diff] [blame] | 43 | check_include_file(sys/types.h HAVE_SYS_TYPES_H) |
Douglas Gregor | 071d73d | 2009-05-18 17:21:34 +0000 | [diff] [blame] | 44 | check_include_file(termios.h HAVE_TERMIOS_H) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 45 | check_include_file(unistd.h HAVE_UNISTD_H) |
Jeffrey Yasskin | f28411f | 2010-03-15 04:57:55 +0000 | [diff] [blame] | 46 | check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H) |
Alexey Samsonov | ee03c94 | 2013-04-23 08:28:39 +0000 | [diff] [blame] | 47 | check_include_file(zlib.h HAVE_ZLIB_H) |
Oscar Fuentes | c141acc | 2010-09-17 20:30:48 +0000 | [diff] [blame] | 48 | check_include_file(fenv.h HAVE_FENV_H) |
Joerg Sonnenberger | f9a7132 | 2013-03-25 13:13:33 +0000 | [diff] [blame] | 49 | check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT) |
| 50 | check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT) |
| 51 | |
Oscar Fuentes | 3c00a83 | 2011-01-17 16:35:14 +0000 | [diff] [blame] | 52 | check_include_file(mach/mach.h HAVE_MACH_MACH_H) |
Chris Bieneman | b91ff6d | 2015-01-30 00:10:43 +0000 | [diff] [blame] | 53 | check_include_file(histedit.h HAVE_HISTEDIT_H) |
Chris Bieneman | b7e5e7d | 2016-12-07 18:53:04 +0000 | [diff] [blame] | 54 | check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H) |
Chris Bieneman | c14b21a | 2016-12-07 20:55:38 +0000 | [diff] [blame] | 55 | if(APPLE) |
| 56 | include(CheckCSourceCompiles) |
| 57 | CHECK_C_SOURCE_COMPILES(" |
| 58 | static const char *__crashreporter_info__ = 0; |
| 59 | asm(\".desc ___crashreporter_info__, 0x10\"); |
| 60 | int main() { return 0; }" |
| 61 | HAVE_CRASHREPORTER_INFO) |
| 62 | endif() |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 63 | |
Michal Gorny | 39b10e9 | 2017-02-22 18:09:15 +0000 | [diff] [blame] | 64 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") |
| 65 | check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H) |
| 66 | if(NOT HAVE_LINUX_MAGIC_H) |
| 67 | # older kernels use split files |
| 68 | check_include_file(linux/nfs_fs.h HAVE_LINUX_NFS_FS_H) |
| 69 | check_include_file(linux/smb.h HAVE_LINUX_SMB_H) |
| 70 | endif() |
| 71 | endif() |
| 72 | |
Oscar Fuentes | d413c01 | 2009-05-06 14:40:37 +0000 | [diff] [blame] | 73 | # library checks |
Oscar Fuentes | 325610b | 2011-02-04 05:40:04 +0000 | [diff] [blame] | 74 | if( NOT PURE_WINDOWS ) |
Oscar Fuentes | 20f1714 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 75 | check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) |
Evgeniy Stepanov | 68d92bd | 2012-09-04 09:14:45 +0000 | [diff] [blame] | 76 | if (HAVE_LIBPTHREAD) |
| 77 | check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC) |
| 78 | check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) |
| 79 | check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) |
| 80 | else() |
| 81 | # this could be Android |
| 82 | check_library_exists(c pthread_create "" PTHREAD_IN_LIBC) |
| 83 | if (PTHREAD_IN_LIBC) |
| 84 | check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC) |
| 85 | check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) |
| 86 | check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) |
| 87 | endif() |
| 88 | endif() |
Oscar Fuentes | 20f1714 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 89 | check_library_exists(dl dlopen "" HAVE_LIBDL) |
Chandler Carruth | 73c35d8 | 2013-01-04 23:19:55 +0000 | [diff] [blame] | 90 | check_library_exists(rt clock_gettime "" HAVE_LIBRT) |
Clement Courbet | 88fe9bc | 2018-04-05 07:35:28 +0000 | [diff] [blame] | 91 | endif() |
| 92 | |
| 93 | # Check for libpfm. |
Clement Courbet | e7bb73e | 2018-04-11 07:39:00 +0000 | [diff] [blame] | 94 | include(FindLibpfm) |
Reid Kleckner | e96fd6d | 2015-11-19 00:05:21 +0000 | [diff] [blame] | 95 | |
Rafael Espindola | 93ed620 | 2016-03-01 15:54:40 +0000 | [diff] [blame] | 96 | if(HAVE_LIBPTHREAD) |
Artem Belevich | 1e67d66 | 2016-06-21 19:34:40 +0000 | [diff] [blame] | 97 | # We want to find pthreads library and at the moment we do want to |
| 98 | # have it reported as '-l<lib>' instead of '-pthread'. |
| 99 | # TODO: switch to -pthread once the rest of the build system can deal with it. |
| 100 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 101 | set(THREADS_HAVE_PTHREAD_ARG Off) |
| 102 | find_package(Threads REQUIRED) |
Eric Fiselier | a61fc42 | 2017-02-10 01:59:20 +0000 | [diff] [blame] | 103 | set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) |
Rafael Espindola | 93ed620 | 2016-03-01 15:54:40 +0000 | [diff] [blame] | 104 | endif() |
| 105 | |
Pavel Labath | fd8ab36 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 106 | # Don't look for these libraries if we're using MSan, since uninstrumented third |
| 107 | # party code may call MSan interceptors like strlen, leading to false positives. |
| 108 | if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") |
| 109 | set(HAVE_LIBZ 0) |
| 110 | if(LLVM_ENABLE_ZLIB) |
| 111 | foreach(library z zlib_static zlib) |
Pavel Labath | 3f2a29c | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 112 | string(TOUPPER ${library} library_suffix) |
Pavel Labath | fd8ab36 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 113 | check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix}) |
| 114 | if(HAVE_LIBZ_${library_suffix}) |
| 115 | set(HAVE_LIBZ 1) |
| 116 | set(ZLIB_LIBRARIES "${library}") |
Pavel Labath | 3f2a29c | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 117 | break() |
Pavel Labath | 2f1bcfe | 2017-12-01 11:41:07 +0000 | [diff] [blame] | 118 | endif() |
Pavel Labath | 3f2a29c | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 119 | endforeach() |
Pavel Labath | 3f2a29c | 2017-12-04 16:46:20 +0000 | [diff] [blame] | 120 | endif() |
| 121 | |
Pavel Labath | fd8ab36 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 122 | # Don't look for these libraries on Windows. |
| 123 | if (NOT PURE_WINDOWS) |
| 124 | # Skip libedit if using ASan as it contains memory leaks. |
| 125 | if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*") |
| 126 | check_library_exists(edit el_init "" HAVE_LIBEDIT) |
| 127 | else() |
| 128 | set(HAVE_LIBEDIT 0) |
| 129 | endif() |
| 130 | if(LLVM_ENABLE_TERMINFO) |
| 131 | set(HAVE_TERMINFO 0) |
Kamil Rytarowski | 8f78249 | 2018-11-18 12:13:51 +0000 | [diff] [blame] | 132 | foreach(library terminfo tinfo curses ncurses ncursesw) |
Pavel Labath | fd8ab36 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 133 | string(TOUPPER ${library} library_suffix) |
| 134 | check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix}) |
| 135 | if(HAVE_TERMINFO_${library_suffix}) |
| 136 | set(HAVE_TERMINFO 1) |
| 137 | set(TERMINFO_LIBS "${library}") |
| 138 | break() |
| 139 | endif() |
| 140 | endforeach() |
| 141 | else() |
| 142 | set(HAVE_TERMINFO 0) |
| 143 | endif() |
| 144 | |
| 145 | find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c) |
| 146 | set(LLVM_LIBXML2_ENABLED 0) |
| 147 | set(LIBXML2_FOUND 0) |
| 148 | if((LLVM_ENABLE_LIBXML2) AND ((CMAKE_SYSTEM_NAME MATCHES "Linux") AND (ICONV_LIBRARY_PATH) OR APPLE)) |
| 149 | find_package(LibXml2) |
| 150 | if (LIBXML2_FOUND) |
| 151 | set(LLVM_LIBXML2_ENABLED 1) |
Bruno Cardoso Lopes | 7d3355e | 2018-06-14 18:19:54 +0000 | [diff] [blame] | 152 | if ((CMAKE_OSX_SYSROOT) AND (EXISTS ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})) |
| 153 | include_directories(${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}) |
| 154 | else() |
| 155 | include_directories(${LIBXML2_INCLUDE_DIR}) |
| 156 | endif() |
Pavel Labath | fd8ab36 | 2017-12-05 10:24:15 +0000 | [diff] [blame] | 157 | set(LIBXML2_LIBS "xml2") |
| 158 | endif() |
Eric Beckmann | c152744 | 2017-07-20 21:42:04 +0000 | [diff] [blame] | 159 | endif() |
| 160 | endif() |
Oscar Fuentes | 20f1714 | 2009-11-05 18:57:56 +0000 | [diff] [blame] | 161 | endif() |
Oscar Fuentes | d413c01 | 2009-05-06 14:40:37 +0000 | [diff] [blame] | 162 | |
Hans Wennborg | e144f87 | 2017-11-14 22:32:49 +0000 | [diff] [blame] | 163 | if (LLVM_ENABLE_LIBXML2 STREQUAL "FORCE_ON" AND NOT LLVM_LIBXML2_ENABLED) |
| 164 | message(FATAL_ERROR "Failed to congifure libxml2") |
| 165 | endif() |
| 166 | |
Kevin Enderby | 866cdd5 | 2016-05-23 21:34:12 +0000 | [diff] [blame] | 167 | check_library_exists(xar xar_open "" HAVE_LIBXAR) |
| 168 | if(HAVE_LIBXAR) |
| 169 | set(XAR_LIB xar) |
| 170 | endif() |
| 171 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 172 | # function checks |
Todd Fiala | 9cd9208 | 2014-02-05 05:04:36 +0000 | [diff] [blame] | 173 | check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM) |
Ed Maste | 944d939 | 2017-04-12 13:51:00 +0000 | [diff] [blame] | 174 | find_package(Backtrace) |
| 175 | set(HAVE_BACKTRACE ${Backtrace_FOUND}) |
| 176 | set(BACKTRACE_HEADER ${Backtrace_HEADER}) |
Juergen Ributzka | 0e3a936 | 2017-08-29 00:34:56 +0000 | [diff] [blame] | 177 | |
| 178 | # Prevent check_symbol_exists from using API that is not supported for a given |
| 179 | # deployment target. |
| 180 | check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW") |
| 181 | if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW) |
| 182 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new") |
| 183 | endif() |
| 184 | |
Joerg Sonnenberger | 422655d | 2016-09-29 21:07:57 +0000 | [diff] [blame] | 185 | check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 186 | check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) |
Joerg Sonnenberger | d72397a | 2016-09-29 21:18:05 +0000 | [diff] [blame] | 187 | check_symbol_exists(sysconf unistd.h HAVE_SYSCONF) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 188 | check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE) |
| 189 | check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT) |
Ted Kremenek | cf98592 | 2011-12-23 01:31:45 +0000 | [diff] [blame] | 190 | check_symbol_exists(isatty unistd.h HAVE_ISATTY) |
Eric Christopher | c589a5f | 2013-07-04 01:10:38 +0000 | [diff] [blame] | 191 | check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS) |
| 192 | check_symbol_exists(futimes sys/time.h HAVE_FUTIMES) |
Rafael Espindola | 75cca7a | 2016-07-19 20:19:56 +0000 | [diff] [blame] | 193 | check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE) |
Vitaly Buka | 744b8ba | 2016-08-25 03:44:36 +0000 | [diff] [blame] | 194 | # AddressSanitizer conflicts with lib/Support/Unix/Signals.inc |
Bob Wilson | 80617ba | 2017-01-06 02:26:30 +0000 | [diff] [blame] | 195 | # Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it |
| 196 | # (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind |
| 197 | # past the signal handler after an assertion failure (rdar://29866587). |
| 198 | if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE ) |
Richard Smith | b074e28 | 2016-05-20 21:26:00 +0000 | [diff] [blame] | 199 | check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK) |
| 200 | endif() |
Peter Collingbourne | 4b3d007 | 2016-12-09 05:20:43 +0000 | [diff] [blame] | 201 | set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE") |
| 202 | check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64) |
| 203 | set(CMAKE_REQUIRED_DEFINITIONS "") |
Davide Italiano | d6f86b8 | 2015-02-19 07:27:14 +0000 | [diff] [blame] | 204 | check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 205 | check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) |
Douglas Gregor | ef23d71 | 2009-06-04 17:22:52 +0000 | [diff] [blame] | 206 | check_symbol_exists(malloc_zone_statistics malloc/malloc.h |
| 207 | HAVE_MALLOC_ZONE_STATISTICS) |
Oscar Fuentes | 006bfeb | 2011-01-13 19:17:28 +0000 | [diff] [blame] | 208 | check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT) |
Benjamin Kramer | 5745fbc | 2011-11-22 12:31:53 +0000 | [diff] [blame] | 209 | check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN) |
| 210 | check_symbol_exists(pread unistd.h HAVE_PREAD) |
Alexey Samsonov | 19a5472 | 2013-08-26 18:11:25 +0000 | [diff] [blame] | 211 | check_symbol_exists(realpath stdlib.h HAVE_REALPATH) |
Edward O'Callaghan | a2c7535 | 2009-10-05 23:05:32 +0000 | [diff] [blame] | 212 | check_symbol_exists(sbrk unistd.h HAVE_SBRK) |
Jeffrey Yasskin | ed1c0ff | 2009-07-01 18:11:20 +0000 | [diff] [blame] | 213 | check_symbol_exists(strerror string.h HAVE_STRERROR) |
| 214 | check_symbol_exists(strerror_r string.h HAVE_STRERROR_R) |
NAKAMURA Takumi | e29b0ac | 2011-02-09 04:18:48 +0000 | [diff] [blame] | 215 | check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S) |
Jeffrey Yasskin | b7a8d40 | 2009-09-25 21:07:20 +0000 | [diff] [blame] | 216 | check_symbol_exists(setenv stdlib.h HAVE_SETENV) |
Oscar Fuentes | 325610b | 2011-02-04 05:40:04 +0000 | [diff] [blame] | 217 | if( PURE_WINDOWS ) |
Michael J. Spencer | db04b39 | 2010-12-03 18:48:56 +0000 | [diff] [blame] | 218 | check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S) |
NAKAMURA Takumi | 1f6832a | 2011-02-05 15:11:53 +0000 | [diff] [blame] | 219 | |
| 220 | check_function_exists(_alloca HAVE__ALLOCA) |
| 221 | check_function_exists(__alloca HAVE___ALLOCA) |
| 222 | check_function_exists(__chkstk HAVE___CHKSTK) |
NAKAMURA Takumi | d379c6b | 2015-01-30 13:01:19 +0000 | [diff] [blame] | 223 | check_function_exists(__chkstk_ms HAVE___CHKSTK_MS) |
NAKAMURA Takumi | 1f6832a | 2011-02-05 15:11:53 +0000 | [diff] [blame] | 224 | check_function_exists(___chkstk HAVE____CHKSTK) |
NAKAMURA Takumi | d379c6b | 2015-01-30 13:01:19 +0000 | [diff] [blame] | 225 | check_function_exists(___chkstk_ms HAVE____CHKSTK_MS) |
NAKAMURA Takumi | 1f6832a | 2011-02-05 15:11:53 +0000 | [diff] [blame] | 226 | |
| 227 | check_function_exists(__ashldi3 HAVE___ASHLDI3) |
| 228 | check_function_exists(__ashrdi3 HAVE___ASHRDI3) |
| 229 | check_function_exists(__divdi3 HAVE___DIVDI3) |
| 230 | check_function_exists(__fixdfdi HAVE___FIXDFDI) |
| 231 | check_function_exists(__fixsfdi HAVE___FIXSFDI) |
| 232 | check_function_exists(__floatdidf HAVE___FLOATDIDF) |
| 233 | check_function_exists(__lshrdi3 HAVE___LSHRDI3) |
| 234 | check_function_exists(__moddi3 HAVE___MODDI3) |
| 235 | check_function_exists(__udivdi3 HAVE___UDIVDI3) |
| 236 | check_function_exists(__umoddi3 HAVE___UMODDI3) |
| 237 | |
| 238 | check_function_exists(__main HAVE___MAIN) |
| 239 | check_function_exists(__cmpdi2 HAVE___CMPDI2) |
Michael J. Spencer | db04b39 | 2010-12-03 18:48:56 +0000 | [diff] [blame] | 240 | endif() |
Oscar Fuentes | 78e2074 | 2011-01-31 18:25:25 +0000 | [diff] [blame] | 241 | if( HAVE_DLFCN_H ) |
| 242 | if( HAVE_LIBDL ) |
| 243 | list(APPEND CMAKE_REQUIRED_LIBRARIES dl) |
| 244 | endif() |
Oscar Fuentes | 3c00a83 | 2011-01-17 16:35:14 +0000 | [diff] [blame] | 245 | check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN) |
Omair Javaid | 367ed08 | 2017-02-02 01:17:49 +0000 | [diff] [blame] | 246 | check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR) |
Oscar Fuentes | 78e2074 | 2011-01-31 18:25:25 +0000 | [diff] [blame] | 247 | if( HAVE_LIBDL ) |
| 248 | list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl) |
| 249 | endif() |
Oscar Fuentes | 3c00a83 | 2011-01-17 16:35:14 +0000 | [diff] [blame] | 250 | endif() |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 251 | |
Argyrios Kyrtzidis | 802db56 | 2018-11-26 00:03:39 +0000 | [diff] [blame] | 252 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec |
| 253 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) |
| 254 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec |
| 255 | "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) |
| 256 | |
Oscar Fuentes | 9a0107d | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 257 | check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) |
| 258 | if( LLVM_USING_GLIBC ) |
Serge Pavlov | bbcc0db | 2017-03-21 04:03:24 +0000 | [diff] [blame] | 259 | add_definitions( -D_GNU_SOURCE ) |
Rafael Espindola | a72e2a9 | 2017-10-04 20:27:01 +0000 | [diff] [blame] | 260 | list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") |
Oscar Fuentes | 9a0107d | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 261 | endif() |
Krzysztof Parzyszek | 2b46554 | 2017-03-03 21:53:12 +0000 | [diff] [blame] | 262 | # This check requires _GNU_SOURCE |
Rafael Espindola | a72e2a9 | 2017-10-04 20:27:01 +0000 | [diff] [blame] | 263 | check_symbol_exists(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY) |
| 264 | check_symbol_exists(CPU_COUNT sched.h HAVE_CPU_COUNT) |
Pavel Labath | 646d5bb | 2018-04-18 13:13:27 +0000 | [diff] [blame] | 265 | if (NOT PURE_WINDOWS) |
| 266 | if (LLVM_PTHREAD_LIB) |
| 267 | list(APPEND CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB}) |
| 268 | endif() |
| 269 | check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP) |
| 270 | check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP) |
| 271 | if (LLVM_PTHREAD_LIB) |
| 272 | list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB}) |
| 273 | endif() |
Krzysztof Parzyszek | 2b46554 | 2017-03-03 21:53:12 +0000 | [diff] [blame] | 274 | endif() |
Oscar Fuentes | 9a0107d | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 275 | |
Oscar Fuentes | b5b10c2 | 2009-11-05 19:03:26 +0000 | [diff] [blame] | 276 | # available programs checks |
Oscar Fuentes | 6a660d4 | 2009-11-09 15:26:40 +0000 | [diff] [blame] | 277 | function(llvm_find_program name) |
| 278 | string(TOUPPER ${name} NAME) |
Tobias Grosser | f3a83d6 | 2011-02-27 04:11:05 +0000 | [diff] [blame] | 279 | string(REGEX REPLACE "\\." "_" NAME ${NAME}) |
Matt Arsenault | cffecb4 | 2013-07-08 20:24:49 +0000 | [diff] [blame] | 280 | |
| 281 | find_program(LLVM_PATH_${NAME} NAMES ${ARGV}) |
Oscar Fuentes | 6a660d4 | 2009-11-09 15:26:40 +0000 | [diff] [blame] | 282 | mark_as_advanced(LLVM_PATH_${NAME}) |
| 283 | if(LLVM_PATH_${NAME}) |
| 284 | set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?") |
| 285 | mark_as_advanced(HAVE_${NAME}) |
| 286 | else(LLVM_PATH_${NAME}) |
| 287 | set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?") |
Oscar Fuentes | 6a660d4 | 2009-11-09 15:26:40 +0000 | [diff] [blame] | 288 | endif(LLVM_PATH_${NAME}) |
| 289 | endfunction() |
| 290 | |
Alp Toker | 04de60e | 2014-06-02 01:40:04 +0000 | [diff] [blame] | 291 | if (LLVM_ENABLE_DOXYGEN) |
| 292 | llvm_find_program(dot) |
| 293 | endif () |
Oscar Fuentes | b5b10c2 | 2009-11-05 19:03:26 +0000 | [diff] [blame] | 294 | |
Oscar Fuentes | 5969379 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 295 | if( LLVM_ENABLE_FFI ) |
| 296 | find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR}) |
Josh Klontz | a9ee302 | 2014-08-08 14:32:56 +0000 | [diff] [blame] | 297 | if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" ) |
Oscar Fuentes | 5969379 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 298 | set(FFI_HEADER ffi.h CACHE INTERNAL "") |
| 299 | set(HAVE_FFI_H 1 CACHE INTERNAL "") |
| 300 | else() |
| 301 | find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR}) |
Josh Klontz | a9ee302 | 2014-08-08 14:32:56 +0000 | [diff] [blame] | 302 | if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" ) |
Oscar Fuentes | 5969379 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 303 | set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "") |
| 304 | set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "") |
| 305 | endif() |
| 306 | endif() |
| 307 | |
| 308 | if( NOT FFI_HEADER ) |
| 309 | message(FATAL_ERROR "libffi includes are not found.") |
| 310 | endif() |
| 311 | |
| 312 | find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR}) |
| 313 | if( NOT FFI_LIBRARY_PATH ) |
| 314 | message(FATAL_ERROR "libffi is not found.") |
| 315 | endif() |
| 316 | |
| 317 | list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH}) |
| 318 | list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH}) |
| 319 | check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL) |
| 320 | list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH}) |
| 321 | list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH}) |
Oscar Fuentes | 0b7bc77 | 2011-04-02 13:21:12 +0000 | [diff] [blame] | 322 | else() |
| 323 | unset(HAVE_FFI_FFI_H CACHE) |
| 324 | unset(HAVE_FFI_H CACHE) |
| 325 | unset(HAVE_FFI_CALL CACHE) |
Oscar Fuentes | 5969379 | 2011-01-21 15:42:54 +0000 | [diff] [blame] | 326 | endif( LLVM_ENABLE_FFI ) |
| 327 | |
Eric Christopher | 627445f | 2011-09-19 20:43:23 +0000 | [diff] [blame] | 328 | # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported. |
Xerxes Ranby | 6215c62 | 2009-07-17 19:22:41 +0000 | [diff] [blame] | 329 | include(CheckAtomic) |
| 330 | |
Oscar Fuentes | 111fd9c | 2011-01-15 13:35:37 +0000 | [diff] [blame] | 331 | if( LLVM_ENABLE_PIC ) |
| 332 | set(ENABLE_PIC 1) |
| 333 | else() |
| 334 | set(ENABLE_PIC 0) |
Chris Bieneman | f92fdc8 | 2015-11-24 08:04:59 +0000 | [diff] [blame] | 335 | check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG) |
| 336 | if(SUPPORTS_NO_PIE_FLAG) |
Pavel Labath | 1b6b889 | 2015-11-24 09:46:01 +0000 | [diff] [blame] | 337 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") |
Chris Bieneman | f92fdc8 | 2015-11-24 08:04:59 +0000 | [diff] [blame] | 338 | endif() |
Oscar Fuentes | 111fd9c | 2011-01-15 13:35:37 +0000 | [diff] [blame] | 339 | endif() |
Oscar Fuentes | 2c5e0b8 | 2011-01-09 14:34:39 +0000 | [diff] [blame] | 340 | |
Chandler Carruth | 2ff6bc0 | 2017-01-06 23:16:00 +0000 | [diff] [blame] | 341 | check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG) |
| 342 | check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments" |
| 343 | SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG) |
Michael J. Spencer | 1cade33 | 2010-10-07 18:12:54 +0000 | [diff] [blame] | 344 | |
Edwin Vane | 4b5dbaa | 2013-02-04 02:32:44 +0000 | [diff] [blame] | 345 | set(USE_NO_MAYBE_UNINITIALIZED 0) |
| 346 | set(USE_NO_UNINITIALIZED 0) |
| 347 | |
| 348 | # Disable gcc's potentially uninitialized use analysis as it presents lots of |
| 349 | # false positives. |
| 350 | if (CMAKE_COMPILER_IS_GNUCXX) |
| 351 | check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED) |
| 352 | if (HAS_MAYBE_UNINITIALIZED) |
| 353 | set(USE_NO_MAYBE_UNINITIALIZED 1) |
| 354 | else() |
| 355 | # Only recent versions of gcc make the distinction between -Wuninitialized |
| 356 | # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just |
| 357 | # turn off all uninitialized use warnings. |
| 358 | check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED) |
| 359 | set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED}) |
| 360 | endif() |
| 361 | endif() |
| 362 | |
Sebastian Pop | 9469dd3 | 2012-08-08 18:04:45 +0000 | [diff] [blame] | 363 | # By default, we target the host, but this can be overridden at CMake |
| 364 | # invocation time. |
Tim Northover | d66ad6c | 2013-05-04 07:36:23 +0000 | [diff] [blame] | 365 | include(GetHostTriple) |
| 366 | get_host_triple(LLVM_INFERRED_HOST_TRIPLE) |
| 367 | |
| 368 | set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING |
| 369 | "Host on which LLVM binaries will run") |
Daniel Dunbar | e9b88e4 | 2009-11-07 23:52:20 +0000 | [diff] [blame] | 370 | |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 371 | # Determine the native architecture. |
Oscar Fuentes | a9ff139 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 372 | string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH) |
| 373 | if( LLVM_NATIVE_ARCH STREQUAL "host" ) |
Chandler Carruth | 9136f21 | 2012-01-24 18:00:44 +0000 | [diff] [blame] | 374 | string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE}) |
Oscar Fuentes | a9ff139 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 375 | endif () |
| 376 | |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 377 | if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86") |
| 378 | set(LLVM_NATIVE_ARCH X86) |
Oscar Fuentes | a9ff139 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 379 | elseif (LLVM_NATIVE_ARCH STREQUAL "x86") |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 380 | set(LLVM_NATIVE_ARCH X86) |
Oscar Fuentes | a9ff139 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 381 | elseif (LLVM_NATIVE_ARCH STREQUAL "amd64") |
| 382 | set(LLVM_NATIVE_ARCH X86) |
| 383 | elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64") |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 384 | set(LLVM_NATIVE_ARCH X86) |
| 385 | elseif (LLVM_NATIVE_ARCH MATCHES "sparc") |
| 386 | set(LLVM_NATIVE_ARCH Sparc) |
| 387 | elseif (LLVM_NATIVE_ARCH MATCHES "powerpc") |
| 388 | set(LLVM_NATIVE_ARCH PowerPC) |
Tim Northover | bd121f5 | 2013-05-04 20:13:52 +0000 | [diff] [blame] | 389 | elseif (LLVM_NATIVE_ARCH MATCHES "aarch64") |
| 390 | set(LLVM_NATIVE_ARCH AArch64) |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 391 | elseif (LLVM_NATIVE_ARCH MATCHES "arm64") |
Tim Northover | 29f94c7 | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 392 | set(LLVM_NATIVE_ARCH AArch64) |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 393 | elseif (LLVM_NATIVE_ARCH MATCHES "arm") |
| 394 | set(LLVM_NATIVE_ARCH ARM) |
| 395 | elseif (LLVM_NATIVE_ARCH MATCHES "mips") |
| 396 | set(LLVM_NATIVE_ARCH Mips) |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 397 | elseif (LLVM_NATIVE_ARCH MATCHES "xcore") |
| 398 | set(LLVM_NATIVE_ARCH XCore) |
| 399 | elseif (LLVM_NATIVE_ARCH MATCHES "msp430") |
| 400 | set(LLVM_NATIVE_ARCH MSP430) |
Sebastian Pop | 974e12b | 2012-08-20 19:56:49 +0000 | [diff] [blame] | 401 | elseif (LLVM_NATIVE_ARCH MATCHES "hexagon") |
| 402 | set(LLVM_NATIVE_ARCH Hexagon) |
Ulrich Weigand | 735ab83 | 2013-05-06 16:22:34 +0000 | [diff] [blame] | 403 | elseif (LLVM_NATIVE_ARCH MATCHES "s390x") |
| 404 | set(LLVM_NATIVE_ARCH SystemZ) |
Dan Gohman | a743413 | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 405 | elseif (LLVM_NATIVE_ARCH MATCHES "wasm32") |
| 406 | set(LLVM_NATIVE_ARCH WebAssembly) |
| 407 | elseif (LLVM_NATIVE_ARCH MATCHES "wasm64") |
| 408 | set(LLVM_NATIVE_ARCH WebAssembly) |
Azharuddin Mohammed | 3ca92f8 | 2018-03-13 17:04:33 +0000 | [diff] [blame] | 409 | elseif (LLVM_NATIVE_ARCH MATCHES "riscv32") |
| 410 | set(LLVM_NATIVE_ARCH RISCV) |
| 411 | elseif (LLVM_NATIVE_ARCH MATCHES "riscv64") |
| 412 | set(LLVM_NATIVE_ARCH RISCV) |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 413 | else () |
Oscar Fuentes | db3480c | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 414 | message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}") |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 415 | endif () |
Michael J. Spencer | c8417d7 | 2010-09-24 09:00:56 +0000 | [diff] [blame] | 416 | |
Andy Gibbs | 84bb3a2 | 2013-06-26 07:57:53 +0000 | [diff] [blame] | 417 | # If build targets includes "host", then replace with native architecture. |
| 418 | list(FIND LLVM_TARGETS_TO_BUILD "host" idx) |
| 419 | if( NOT idx LESS 0 ) |
| 420 | list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx}) |
| 421 | list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH}) |
| 422 | list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) |
| 423 | endif() |
| 424 | |
Oscar Fuentes | db3480c | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 425 | list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX) |
| 426 | if (NATIVE_ARCH_IDX EQUAL -1) |
| 427 | message(STATUS |
| 428 | "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code") |
| 429 | else () |
| 430 | message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}") |
| 431 | set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target) |
| 432 | set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo) |
Evan Cheng | e78085a | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 433 | set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC) |
Oscar Fuentes | db3480c | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 434 | set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter) |
Chandler Carruth | 0c5fc0c | 2011-12-09 03:31:58 +0000 | [diff] [blame] | 435 | |
| 436 | # We don't have an ASM parser for all architectures yet. |
Vassil Vassilev | 62bc287 | 2016-06-11 17:20:53 +0000 | [diff] [blame] | 437 | if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt) |
Chandler Carruth | 0c5fc0c | 2011-12-09 03:31:58 +0000 | [diff] [blame] | 438 | set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser) |
| 439 | endif () |
Eric Christopher | c4b2271 | 2012-03-26 21:56:56 +0000 | [diff] [blame] | 440 | |
| 441 | # We don't have an disassembler for all architectures yet. |
Vassil Vassilev | 62bc287 | 2016-06-11 17:20:53 +0000 | [diff] [blame] | 442 | if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt) |
Eric Christopher | c4b2271 | 2012-03-26 21:56:56 +0000 | [diff] [blame] | 443 | set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler) |
| 444 | endif () |
Oscar Fuentes | db3480c | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 445 | endif () |
Douglas Gregor | e9d683b | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 446 | |
Oscar Fuentes | de98db3 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 447 | if( MSVC ) |
Oscar Fuentes | de98db3 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 448 | set(SHLIBEXT ".lib") |
Oscar Fuentes | de98db3 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 449 | set(stricmp "_stricmp") |
| 450 | set(strdup "_strdup") |
Zachary Turner | e20fe23 | 2015-02-10 05:04:25 +0000 | [diff] [blame] | 451 | |
| 452 | # See if the DIA SDK is available and usable. |
| 453 | set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK") |
| 454 | |
| 455 | # Due to a bug in MSVC 2013's installation software, it is possible |
| 456 | # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012 |
| 457 | # install directory. If this happens, the installation is corrupt |
| 458 | # and there's nothing we can do. It happens with enough frequency |
| 459 | # though that we should handle it. We do so by simply checking that |
| 460 | # the DIA SDK folder exists. Should this happen you will need to |
| 461 | # uninstall VS 2012 and then re-install VS 2013. |
| 462 | if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR}) |
| 463 | set(HAVE_DIA_SDK 1) |
| 464 | else() |
| 465 | set(HAVE_DIA_SDK 0) |
| 466 | endif() |
Michal Gorny | a50b783 | 2017-01-02 18:19:35 +0000 | [diff] [blame] | 467 | |
| 468 | option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available." |
| 469 | ${HAVE_DIA_SDK}) |
| 470 | |
| 471 | if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK) |
| 472 | 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.") |
| 473 | endif() |
Zachary Turner | 69fadae | 2015-02-22 07:13:52 +0000 | [diff] [blame] | 474 | else() |
Michal Gorny | a50b783 | 2017-01-02 18:19:35 +0000 | [diff] [blame] | 475 | set(LLVM_ENABLE_DIA_SDK 0) |
Oscar Fuentes | de98db3 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 476 | endif( MSVC ) |
| 477 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 478 | # FIXME: Signal handler return type, currently hardcoded to 'void' |
| 479 | set(RETSIGTYPE void) |
| 480 | |
Oscar Fuentes | 4b44283 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 481 | if( LLVM_ENABLE_THREADS ) |
Dylan Noblesmith | 08b73a3 | 2011-11-28 00:48:58 +0000 | [diff] [blame] | 482 | # Check if threading primitives aren't supported on this platform |
| 483 | if( NOT HAVE_PTHREAD_H AND NOT WIN32 ) |
| 484 | set(LLVM_ENABLE_THREADS 0) |
Oscar Fuentes | 4b44283 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 485 | endif() |
| 486 | endif() |
| 487 | |
Dylan Noblesmith | 08b73a3 | 2011-11-28 00:48:58 +0000 | [diff] [blame] | 488 | if( LLVM_ENABLE_THREADS ) |
Oscar Fuentes | 4b44283 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 489 | message(STATUS "Threads enabled.") |
Dylan Noblesmith | 08b73a3 | 2011-11-28 00:48:58 +0000 | [diff] [blame] | 490 | else( LLVM_ENABLE_THREADS ) |
Oscar Fuentes | 4b44283 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 491 | message(STATUS "Threads disabled.") |
| 492 | endif() |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 493 | |
Alexey Samsonov | ee03c94 | 2013-04-23 08:28:39 +0000 | [diff] [blame] | 494 | if (LLVM_ENABLE_ZLIB ) |
| 495 | # Check if zlib is available in the system. |
| 496 | if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ ) |
| 497 | set(LLVM_ENABLE_ZLIB 0) |
| 498 | endif() |
| 499 | endif() |
| 500 | |
Michael Gottesman | 5b83d0c | 2013-08-24 07:25:21 +0000 | [diff] [blame] | 501 | if (LLVM_ENABLE_DOXYGEN) |
| 502 | message(STATUS "Doxygen enabled.") |
Dan Liew | 859530f | 2014-04-28 09:10:05 +0000 | [diff] [blame] | 503 | find_package(Doxygen REQUIRED) |
Michael Gottesman | b7cb635 | 2013-08-28 20:28:32 +0000 | [diff] [blame] | 504 | |
| 505 | if (DOXYGEN_FOUND) |
| 506 | # If we find doxygen and we want to enable doxygen by default create a |
| 507 | # global aggregate doxygen target for generating llvm and any/all |
| 508 | # subprojects doxygen documentation. |
| 509 | if (LLVM_BUILD_DOCS) |
| 510 | add_custom_target(doxygen ALL) |
| 511 | endif() |
Michael Gottesman | 4cff093 | 2013-08-28 21:55:26 +0000 | [diff] [blame] | 512 | |
| 513 | option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF) |
| 514 | if (LLVM_DOXYGEN_EXTERNAL_SEARCH) |
Saleem Abdulrasool | 994d771 | 2015-07-24 01:14:25 +0000 | [diff] [blame] | 515 | set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.") |
Michael Gottesman | 4cff093 | 2013-08-28 21:55:26 +0000 | [diff] [blame] | 516 | set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings") |
| 517 | endif() |
Michael Gottesman | b7cb635 | 2013-08-28 20:28:32 +0000 | [diff] [blame] | 518 | endif() |
Michael Gottesman | 5b83d0c | 2013-08-24 07:25:21 +0000 | [diff] [blame] | 519 | else() |
| 520 | message(STATUS "Doxygen disabled.") |
| 521 | endif() |
Reid Kleckner | 4c464de | 2014-04-18 21:45:25 +0000 | [diff] [blame] | 522 | |
Peter Collingbourne | 798ace2 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 523 | set(LLVM_BINDINGS "") |
Vassil Vassilev | 04e4adf | 2018-05-20 08:37:54 +0000 | [diff] [blame] | 524 | find_program(GO_EXECUTABLE NAMES go DOC "go executable") |
| 525 | if(WIN32 OR NOT LLVM_ENABLE_BINDINGS) |
Peter Collingbourne | 798ace2 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 526 | message(STATUS "Go bindings disabled.") |
| 527 | else() |
Peter Collingbourne | bdc3a5b | 2014-10-23 02:33:23 +0000 | [diff] [blame] | 528 | if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND") |
| 529 | message(STATUS "Go bindings disabled.") |
Peter Collingbourne | 798ace2 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 530 | else() |
Vassil Vassilev | 62bc287 | 2016-06-11 17:20:53 +0000 | [diff] [blame] | 531 | execute_process(COMMAND ${GO_EXECUTABLE} run ${PROJECT_SOURCE_DIR}/bindings/go/conftest.go |
Peter Collingbourne | bdc3a5b | 2014-10-23 02:33:23 +0000 | [diff] [blame] | 532 | RESULT_VARIABLE GO_CONFTEST) |
| 533 | if(GO_CONFTEST STREQUAL "0") |
| 534 | set(LLVM_BINDINGS "${LLVM_BINDINGS} go") |
| 535 | message(STATUS "Go bindings enabled.") |
| 536 | else() |
| 537 | message(STATUS "Go bindings disabled, need at least Go 1.2.") |
| 538 | endif() |
Peter Collingbourne | 798ace2 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 539 | endif() |
| 540 | endif() |
Peter Zotov | a0a26f2 | 2014-12-01 19:50:23 +0000 | [diff] [blame] | 541 | |
Niels Ole Salscheider | 16b7c0f | 2015-05-01 11:58:30 +0000 | [diff] [blame] | 542 | 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 | 077908a | 2015-04-27 21:08:47 +0000 | [diff] [blame] | 543 | set(LLVM_BINUTILS_INCDIR "" CACHE PATH |
| 544 | "PATH to binutils/include containing plugin-api.h for gold plugin.") |
Chandler Carruth | 15db818 | 2015-02-14 09:43:57 +0000 | [diff] [blame] | 545 | |
Bruno Cardoso Lopes | 98a069f | 2016-07-26 18:09:23 +0000 | [diff] [blame] | 546 | if(CMAKE_HOST_APPLE AND APPLE) |
Matthias Braun | 4f013f8a | 2017-02-11 00:14:01 +0000 | [diff] [blame] | 547 | if(NOT CMAKE_XCRUN) |
| 548 | find_program(CMAKE_XCRUN NAMES xcrun) |
| 549 | endif() |
Bruno Cardoso Lopes | 98a069f | 2016-07-26 18:09:23 +0000 | [diff] [blame] | 550 | if(CMAKE_XCRUN) |
| 551 | execute_process(COMMAND ${CMAKE_XCRUN} -find ld |
| 552 | OUTPUT_VARIABLE LD64_EXECUTABLE |
| 553 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 554 | else() |
| 555 | find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker") |
| 556 | endif() |
| 557 | |
| 558 | if(LD64_EXECUTABLE) |
| 559 | set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable") |
| 560 | message(STATUS "Found ld64 - ${LD64_EXECUTABLE}") |
| 561 | endif() |
Peter Collingbourne | aa01400 | 2015-03-19 23:55:38 +0000 | [diff] [blame] | 562 | endif() |
| 563 | |
Peter Zotov | d02e8e5 | 2016-09-05 01:42:22 +0000 | [diff] [blame] | 564 | # Keep the version requirements in sync with bindings/ocaml/README.txt. |
Peter Zotov | a0a26f2 | 2014-12-01 19:50:23 +0000 | [diff] [blame] | 565 | include(FindOCaml) |
| 566 | include(AddOCaml) |
Vassil Vassilev | 04e4adf | 2018-05-20 08:37:54 +0000 | [diff] [blame] | 567 | if(WIN32 OR NOT LLVM_ENABLE_BINDINGS) |
Peter Zotov | a0a26f2 | 2014-12-01 19:50:23 +0000 | [diff] [blame] | 568 | message(STATUS "OCaml bindings disabled.") |
| 569 | else() |
| 570 | find_package(OCaml) |
| 571 | if( NOT OCAML_FOUND ) |
| 572 | message(STATUS "OCaml bindings disabled.") |
| 573 | else() |
| 574 | if( OCAML_VERSION VERSION_LESS "4.00.0" ) |
| 575 | message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.") |
| 576 | else() |
Peter Zotov | b9fec3e | 2015-06-27 14:32:30 +0000 | [diff] [blame] | 577 | find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL) |
Peter Zotov | 0245b12 | 2014-12-03 03:39:01 +0000 | [diff] [blame] | 578 | if( HAVE_OCAML_CTYPES ) |
| 579 | message(STATUS "OCaml bindings enabled.") |
| 580 | find_ocamlfind_package(oUnit VERSION 2 OPTIONAL) |
| 581 | set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml") |
Michal Gorny | a7d748b | 2016-09-30 18:34:23 +0000 | [diff] [blame] | 582 | |
| 583 | set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING |
| 584 | "Install directory for LLVM OCaml packages") |
Peter Zotov | 0245b12 | 2014-12-03 03:39:01 +0000 | [diff] [blame] | 585 | else() |
Peter Zotov | b9fec3e | 2015-06-27 14:32:30 +0000 | [diff] [blame] | 586 | message(STATUS "OCaml bindings disabled, need ctypes >=0.4.") |
Peter Zotov | 0245b12 | 2014-12-03 03:39:01 +0000 | [diff] [blame] | 587 | endif() |
Peter Zotov | a0a26f2 | 2014-12-01 19:50:23 +0000 | [diff] [blame] | 588 | endif() |
| 589 | endif() |
| 590 | endif() |
| 591 | |
| 592 | string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}") |
Adam Nemet | d3ee065 | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 593 | |
| 594 | function(find_python_module module) |
Jonas Hahnfeld | b24a45d | 2018-01-02 17:53:08 +0000 | [diff] [blame] | 595 | string(REPLACE "." "_" module_name ${module}) |
| 596 | string(TOUPPER ${module_name} module_upper) |
Adam Nemet | d3ee065 | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 597 | set(FOUND_VAR PY_${module_upper}_FOUND) |
| 598 | |
| 599 | execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}" |
| 600 | RESULT_VARIABLE status |
| 601 | ERROR_QUIET) |
| 602 | |
| 603 | if(status) |
| 604 | set(${FOUND_VAR} 0 PARENT_SCOPE) |
| 605 | message(STATUS "Could NOT find Python module ${module}") |
| 606 | else() |
| 607 | set(${FOUND_VAR} 1 PARENT_SCOPE) |
| 608 | message(STATUS "Found Python module ${module}") |
| 609 | endif() |
| 610 | endfunction() |
| 611 | |
| 612 | set (PYTHON_MODULES |
| 613 | pygments |
Jonas Hahnfeld | b24a45d | 2018-01-02 17:53:08 +0000 | [diff] [blame] | 614 | # Some systems still don't have pygments.lexers.c_cpp which was introduced in |
| 615 | # version 2.0 in 2014... |
| 616 | pygments.lexers.c_cpp |
Adam Nemet | d3ee065 | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 617 | yaml |
| 618 | ) |
| 619 | foreach(module ${PYTHON_MODULES}) |
| 620 | find_python_module(${module}) |
| 621 | endforeach() |
| 622 | |
Jonas Hahnfeld | b24a45d | 2018-01-02 17:53:08 +0000 | [diff] [blame] | 623 | if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND) |
Adam Nemet | d3ee065 | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 624 | set (LLVM_HAVE_OPT_VIEWER_MODULES 1) |
| 625 | else() |
| 626 | set (LLVM_HAVE_OPT_VIEWER_MODULES 0) |
| 627 | endif() |