1if( WIN32 AND NOT CYGWIN ) 2 # We consider Cygwin as another Unix 3 set(PURE_WINDOWS 1) 4endif() 5 6include(CheckIncludeFile) 7include(CheckLibraryExists) 8include(CheckSymbolExists) 9include(CheckCXXSymbolExists) 10include(CheckFunctionExists) 11include(CheckStructHasMember) 12include(CheckCCompilerFlag) 13include(CMakePushCheckState) 14 15include(CheckCompilerVersion) 16include(CheckProblematicConfigurations) 17include(HandleLLVMStdlib) 18 19if( UNIX AND NOT (APPLE OR BEOS OR HAIKU) ) 20 # Used by check_symbol_exists: 21 list(APPEND CMAKE_REQUIRED_LIBRARIES "m") 22endif() 23# x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly. 24if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND 25 CMAKE_SIZEOF_VOID_P EQUAL 8 ) 26 list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt") 27endif() 28 29# Do checks with _XOPEN_SOURCE and large-file API on AIX, because we will build 30# with those too. 31if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") 32 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_XOPEN_SOURCE=700") 33 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_LARGE_FILE_API") 34endif() 35 36# Do checks with _FILE_OFFSET_BITS=64 on Solaris, because we will build 37# with those too. 38if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") 39 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64") 40endif() 41 42# include checks 43check_include_file(dlfcn.h HAVE_DLFCN_H) 44check_include_file(errno.h HAVE_ERRNO_H) 45check_include_file(fcntl.h HAVE_FCNTL_H) 46check_include_file(link.h HAVE_LINK_H) 47check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) 48if( NOT PURE_WINDOWS ) 49 check_include_file(pthread.h HAVE_PTHREAD_H) 50endif() 51check_include_file(signal.h HAVE_SIGNAL_H) 52check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) 53check_include_file(sys/mman.h HAVE_SYS_MMAN_H) 54check_include_file(sys/param.h HAVE_SYS_PARAM_H) 55check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) 56check_include_file(sys/stat.h HAVE_SYS_STAT_H) 57check_include_file(sys/time.h HAVE_SYS_TIME_H) 58check_include_file(sys/types.h HAVE_SYS_TYPES_H) 59check_include_file(sysexits.h HAVE_SYSEXITS_H) 60check_include_file(termios.h HAVE_TERMIOS_H) 61check_include_file(unistd.h HAVE_UNISTD_H) 62check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H) 63check_include_file(fenv.h HAVE_FENV_H) 64check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT) 65check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT) 66 67check_include_file(mach/mach.h HAVE_MACH_MACH_H) 68check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H) 69if(APPLE) 70 include(CheckCSourceCompiles) 71 CHECK_C_SOURCE_COMPILES(" 72 static const char *__crashreporter_info__ = 0; 73 asm(\".desc ___crashreporter_info__, 0x10\"); 74 int main(void) { return 0; }" 75 HAVE_CRASHREPORTER_INFO) 76endif() 77 78if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 79 check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H) 80 if(NOT HAVE_LINUX_MAGIC_H) 81 # older kernels use split files 82 check_include_file(linux/nfs_fs.h HAVE_LINUX_NFS_FS_H) 83 check_include_file(linux/smb.h HAVE_LINUX_SMB_H) 84 endif() 85endif() 86 87# library checks 88if( NOT PURE_WINDOWS ) 89 check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) 90 if (HAVE_LIBPTHREAD) 91 check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) 92 check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) 93 else() 94 # this could be Android 95 check_library_exists(c pthread_create "" PTHREAD_IN_LIBC) 96 if (PTHREAD_IN_LIBC) 97 check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) 98 check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK) 99 endif() 100 endif() 101 check_library_exists(dl dlopen "" HAVE_LIBDL) 102 check_library_exists(rt clock_gettime "" HAVE_LIBRT) 103endif() 104 105# Check for libpfm. 106include(FindLibpfm) 107 108if(HAVE_LIBPTHREAD) 109 # We want to find pthreads library and at the moment we do want to 110 # have it reported as '-l<lib>' instead of '-pthread'. 111 # TODO: switch to -pthread once the rest of the build system can deal with it. 112 set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 113 set(THREADS_HAVE_PTHREAD_ARG Off) 114 find_package(Threads REQUIRED) 115 set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) 116endif() 117 118if(LLVM_ENABLE_ZLIB) 119 if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON) 120 find_package(ZLIB REQUIRED) 121 elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") 122 find_package(ZLIB) 123 endif() 124 if(ZLIB_FOUND) 125 # Check if zlib we found is usable; for example, we may have found a 32-bit 126 # library on a 64-bit system which would result in a link-time failure. 127 cmake_push_check_state() 128 list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS}) 129 list(APPEND CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY}) 130 check_symbol_exists(compress2 zlib.h HAVE_ZLIB) 131 cmake_pop_check_state() 132 if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON AND NOT HAVE_ZLIB) 133 message(FATAL_ERROR "Failed to configure zlib") 134 endif() 135 endif() 136 set(LLVM_ENABLE_ZLIB "${HAVE_ZLIB}") 137else() 138 set(LLVM_ENABLE_ZLIB 0) 139endif() 140 141set(zstd_FOUND 0) 142if(LLVM_ENABLE_ZSTD) 143 if(LLVM_ENABLE_ZSTD STREQUAL FORCE_ON) 144 find_package(zstd REQUIRED) 145 if(NOT zstd_FOUND) 146 message(FATAL_ERROR "Failed to configure zstd, but LLVM_ENABLE_ZSTD is FORCE_ON") 147 endif() 148 elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") 149 find_package(zstd QUIET) 150 endif() 151endif() 152set(LLVM_ENABLE_ZSTD ${zstd_FOUND}) 153 154if(LLVM_ENABLE_LIBXML2) 155 if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON) 156 find_package(LibXml2 REQUIRED) 157 elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") 158 find_package(LibXml2) 159 endif() 160 if(LibXml2_FOUND) 161 # Check if libxml2 we found is usable; for example, we may have found a 32-bit 162 # library on a 64-bit system which would result in a link-time failure. 163 cmake_push_check_state() 164 list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIRS}) 165 list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBXML2_LIBRARIES}) 166 list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LIBXML2_DEFINITIONS}) 167 check_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2) 168 cmake_pop_check_state() 169 if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON AND NOT HAVE_LIBXML2) 170 message(FATAL_ERROR "Failed to configure libxml2") 171 endif() 172 endif() 173 set(LLVM_ENABLE_LIBXML2 "${HAVE_LIBXML2}") 174endif() 175 176if(LLVM_ENABLE_CURL) 177 if(LLVM_ENABLE_CURL STREQUAL FORCE_ON) 178 find_package(CURL REQUIRED) 179 else() 180 find_package(CURL) 181 endif() 182 if(CURL_FOUND) 183 # Check if curl we found is usable; for example, we may have found a 32-bit 184 # library on a 64-bit system which would result in a link-time failure. 185 cmake_push_check_state() 186 list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::libcurl) 187 check_symbol_exists(curl_easy_init curl/curl.h HAVE_CURL) 188 cmake_pop_check_state() 189 if(LLVM_ENABLE_CURL STREQUAL FORCE_ON AND NOT HAVE_CURL) 190 message(FATAL_ERROR "Failed to configure curl") 191 endif() 192 endif() 193 set(LLVM_ENABLE_CURL "${HAVE_CURL}") 194endif() 195 196if(LLVM_ENABLE_HTTPLIB) 197 if(LLVM_ENABLE_HTTPLIB STREQUAL FORCE_ON) 198 find_package(httplib REQUIRED) 199 else() 200 find_package(httplib) 201 endif() 202 if(HTTPLIB_FOUND) 203 # Check if the "httplib" we found is usable; for example there may be another 204 # library with the same name. 205 cmake_push_check_state() 206 list(APPEND CMAKE_REQUIRED_LIBRARIES ${HTTPLIB_LIBRARY}) 207 check_cxx_symbol_exists(CPPHTTPLIB_HTTPLIB_H ${HTTPLIB_HEADER_PATH} HAVE_HTTPLIB) 208 cmake_pop_check_state() 209 if(LLVM_ENABLE_HTTPLIB STREQUAL FORCE_ON AND NOT HAVE_HTTPLIB) 210 message(FATAL_ERROR "Failed to configure cpp-httplib") 211 endif() 212 endif() 213 set(LLVM_ENABLE_HTTPLIB "${HAVE_HTTPLIB}") 214endif() 215 216# Don't look for these libraries if we're using MSan, since uninstrumented third 217# party code may call MSan interceptors like strlen, leading to false positives. 218if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*") 219 # Don't look for these libraries on Windows. 220 if (NOT PURE_WINDOWS) 221 # Skip libedit if using ASan as it contains memory leaks. 222 if (LLVM_ENABLE_LIBEDIT AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*") 223 find_package(LibEdit) 224 set(HAVE_LIBEDIT ${LibEdit_FOUND}) 225 else() 226 set(HAVE_LIBEDIT 0) 227 endif() 228 if(LLVM_ENABLE_TERMINFO) 229 if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON) 230 find_package(Terminfo REQUIRED) 231 else() 232 find_package(Terminfo) 233 endif() 234 set(LLVM_ENABLE_TERMINFO "${Terminfo_FOUND}") 235 endif() 236 else() 237 set(LLVM_ENABLE_TERMINFO 0) 238 endif() 239else() 240 set(LLVM_ENABLE_TERMINFO 0) 241endif() 242 243check_library_exists(xar xar_open "" LLVM_HAVE_LIBXAR) 244if(LLVM_HAVE_LIBXAR) 245 message(STATUS "The xar file format has been deprecated: LLVM_HAVE_LIBXAR might be removed in the future.") 246 # The xar file format has been deprecated since macOS 12.0. 247 if (CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 12) 248 set(LLVM_HAVE_LIBXAR 0) 249 else() 250 set(XAR_LIB xar) 251 endif() 252endif() 253 254# function checks 255check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM) 256find_package(Backtrace) 257set(HAVE_BACKTRACE ${Backtrace_FOUND}) 258set(BACKTRACE_HEADER ${Backtrace_HEADER}) 259 260# Prevent check_symbol_exists from using API that is not supported for a given 261# deployment target. 262check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW") 263if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW) 264 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new") 265endif() 266 267# Determine whether we can register EH tables. 268check_symbol_exists(__register_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_REGISTER_FRAME) 269check_symbol_exists(__deregister_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_DEREGISTER_FRAME) 270check_symbol_exists(__unw_add_dynamic_fde "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_UNW_ADD_DYNAMIC_FDE) 271 272check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE) 273check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) 274check_symbol_exists(sysconf unistd.h HAVE_SYSCONF) 275check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE) 276check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT) 277check_symbol_exists(isatty unistd.h HAVE_ISATTY) 278check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS) 279check_symbol_exists(futimes sys/time.h HAVE_FUTIMES) 280# AddressSanitizer conflicts with lib/Support/Unix/Signals.inc 281# Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it 282# (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind 283# past the signal handler after an assertion failure (rdar://29866587). 284if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE ) 285 check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK) 286endif() 287check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL) 288check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) 289check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2) 290check_symbol_exists(malloc_zone_statistics malloc/malloc.h 291 HAVE_MALLOC_ZONE_STATISTICS) 292check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT) 293check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN) 294check_symbol_exists(pread unistd.h HAVE_PREAD) 295check_symbol_exists(sbrk unistd.h HAVE_SBRK) 296check_symbol_exists(strerror string.h HAVE_STRERROR) 297check_symbol_exists(strerror_r string.h HAVE_STRERROR_R) 298check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S) 299check_symbol_exists(setenv stdlib.h HAVE_SETENV) 300if( PURE_WINDOWS ) 301 check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S) 302 303 check_function_exists(_alloca HAVE__ALLOCA) 304 check_function_exists(__alloca HAVE___ALLOCA) 305 check_function_exists(__chkstk HAVE___CHKSTK) 306 check_function_exists(__chkstk_ms HAVE___CHKSTK_MS) 307 check_function_exists(___chkstk HAVE____CHKSTK) 308 check_function_exists(___chkstk_ms HAVE____CHKSTK_MS) 309 310 check_function_exists(__ashldi3 HAVE___ASHLDI3) 311 check_function_exists(__ashrdi3 HAVE___ASHRDI3) 312 check_function_exists(__divdi3 HAVE___DIVDI3) 313 check_function_exists(__fixdfdi HAVE___FIXDFDI) 314 check_function_exists(__fixsfdi HAVE___FIXSFDI) 315 check_function_exists(__floatdidf HAVE___FLOATDIDF) 316 check_function_exists(__lshrdi3 HAVE___LSHRDI3) 317 check_function_exists(__moddi3 HAVE___MODDI3) 318 check_function_exists(__udivdi3 HAVE___UDIVDI3) 319 check_function_exists(__umoddi3 HAVE___UMODDI3) 320 321 check_function_exists(__main HAVE___MAIN) 322 check_function_exists(__cmpdi2 HAVE___CMPDI2) 323endif() 324 325CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec 326 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) 327if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") 328# The st_mtim.tv_nsec member of a `stat` structure is not reliable on some AIX 329# environments. 330 set(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 0) 331else() 332 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec 333 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) 334endif() 335 336check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) 337if( LLVM_USING_GLIBC ) 338 add_compile_definitions(_GNU_SOURCE) 339 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") 340# enable 64bit off_t on 32bit systems using glibc 341 if (CMAKE_SIZEOF_VOID_P EQUAL 4) 342 add_compile_definitions(_FILE_OFFSET_BITS=64) 343 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64") 344 endif() 345endif() 346 347# This check requires _GNU_SOURCE. 348if (NOT PURE_WINDOWS) 349 if (LLVM_PTHREAD_LIB) 350 list(APPEND CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB}) 351 endif() 352 check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP) 353 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP) 354 if (LLVM_PTHREAD_LIB) 355 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB}) 356 endif() 357endif() 358 359# This check requires _GNU_SOURCE. 360if( HAVE_DLFCN_H ) 361 if( HAVE_LIBDL ) 362 list(APPEND CMAKE_REQUIRED_LIBRARIES dl) 363 endif() 364 check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN) 365 check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR) 366 if( HAVE_LIBDL ) 367 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl) 368 endif() 369endif() 370 371# available programs checks 372function(llvm_find_program name) 373 string(TOUPPER ${name} NAME) 374 string(REGEX REPLACE "\\." "_" NAME ${NAME}) 375 376 find_program(LLVM_PATH_${NAME} NAMES ${ARGV}) 377 mark_as_advanced(LLVM_PATH_${NAME}) 378 if(LLVM_PATH_${NAME}) 379 set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?") 380 mark_as_advanced(HAVE_${NAME}) 381 else(LLVM_PATH_${NAME}) 382 set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?") 383 endif(LLVM_PATH_${NAME}) 384endfunction() 385 386if (LLVM_ENABLE_DOXYGEN) 387 llvm_find_program(dot) 388endif () 389 390if(LLVM_ENABLE_FFI) 391 set(FFI_REQUIRE_INCLUDE On) 392 if(LLVM_ENABLE_FFI STREQUAL FORCE_ON) 393 find_package(FFI REQUIRED) 394 else() 395 find_package(FFI) 396 endif() 397 set(LLVM_ENABLE_FFI "${FFI_FOUND}") 398else() 399 unset(HAVE_FFI_FFI_H CACHE) 400 unset(HAVE_FFI_H CACHE) 401 unset(HAVE_FFI_CALL CACHE) 402endif() 403 404check_symbol_exists(proc_pid_rusage "libproc.h" HAVE_PROC_PID_RUSAGE) 405 406# Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported. 407include(CheckAtomic) 408 409if( LLVM_ENABLE_PIC ) 410 set(ENABLE_PIC 1) 411else() 412 set(ENABLE_PIC 0) 413 check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG) 414 if(SUPPORTS_NO_PIE_FLAG) 415 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") 416 endif() 417endif() 418 419check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG) 420check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments" 421 SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG) 422 423set(USE_NO_MAYBE_UNINITIALIZED 0) 424set(USE_NO_UNINITIALIZED 0) 425 426# Disable gcc's potentially uninitialized use analysis as it presents lots of 427# false positives. 428if (CMAKE_COMPILER_IS_GNUCXX) 429 check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED) 430 if (HAS_MAYBE_UNINITIALIZED) 431 set(USE_NO_MAYBE_UNINITIALIZED 1) 432 else() 433 # Only recent versions of gcc make the distinction between -Wuninitialized 434 # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just 435 # turn off all uninitialized use warnings. 436 check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED) 437 set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED}) 438 endif() 439endif() 440 441# By default, we target the host, but this can be overridden at CMake 442# invocation time. 443include(GetHostTriple) 444get_host_triple(LLVM_INFERRED_HOST_TRIPLE) 445 446set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING 447 "Host on which LLVM binaries will run") 448 449# Determine the native architecture. 450string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH) 451if( LLVM_NATIVE_ARCH STREQUAL "host" ) 452 string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE}) 453endif () 454 455if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86") 456 set(LLVM_NATIVE_ARCH X86) 457elseif (LLVM_NATIVE_ARCH STREQUAL "x86") 458 set(LLVM_NATIVE_ARCH X86) 459elseif (LLVM_NATIVE_ARCH STREQUAL "amd64") 460 set(LLVM_NATIVE_ARCH X86) 461elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64") 462 set(LLVM_NATIVE_ARCH X86) 463elseif (LLVM_NATIVE_ARCH MATCHES "sparc") 464 set(LLVM_NATIVE_ARCH Sparc) 465elseif (LLVM_NATIVE_ARCH MATCHES "powerpc") 466 set(LLVM_NATIVE_ARCH PowerPC) 467elseif (LLVM_NATIVE_ARCH MATCHES "ppc64le") 468 set(LLVM_NATIVE_ARCH PowerPC) 469elseif (LLVM_NATIVE_ARCH MATCHES "aarch64") 470 set(LLVM_NATIVE_ARCH AArch64) 471elseif (LLVM_NATIVE_ARCH MATCHES "arm64") 472 set(LLVM_NATIVE_ARCH AArch64) 473elseif (LLVM_NATIVE_ARCH MATCHES "arm") 474 set(LLVM_NATIVE_ARCH ARM) 475elseif (LLVM_NATIVE_ARCH MATCHES "avr") 476 set(LLVM_NATIVE_ARCH AVR) 477elseif (LLVM_NATIVE_ARCH MATCHES "mips") 478 set(LLVM_NATIVE_ARCH Mips) 479elseif (LLVM_NATIVE_ARCH MATCHES "xcore") 480 set(LLVM_NATIVE_ARCH XCore) 481elseif (LLVM_NATIVE_ARCH MATCHES "msp430") 482 set(LLVM_NATIVE_ARCH MSP430) 483elseif (LLVM_NATIVE_ARCH MATCHES "hexagon") 484 set(LLVM_NATIVE_ARCH Hexagon) 485elseif (LLVM_NATIVE_ARCH MATCHES "s390x") 486 set(LLVM_NATIVE_ARCH SystemZ) 487elseif (LLVM_NATIVE_ARCH MATCHES "wasm32") 488 set(LLVM_NATIVE_ARCH WebAssembly) 489elseif (LLVM_NATIVE_ARCH MATCHES "wasm64") 490 set(LLVM_NATIVE_ARCH WebAssembly) 491elseif (LLVM_NATIVE_ARCH MATCHES "riscv32") 492 set(LLVM_NATIVE_ARCH RISCV) 493elseif (LLVM_NATIVE_ARCH MATCHES "riscv64") 494 set(LLVM_NATIVE_ARCH RISCV) 495elseif (LLVM_NATIVE_ARCH STREQUAL "m68k") 496 set(LLVM_NATIVE_ARCH M68k) 497elseif (LLVM_NATIVE_ARCH MATCHES "loongarch") 498 set(LLVM_NATIVE_ARCH LoongArch) 499else () 500 message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}") 501endif () 502 503# If build targets includes "host" or "Native", then replace with native architecture. 504foreach (NATIVE_KEYWORD host Native) 505 list(FIND LLVM_TARGETS_TO_BUILD ${NATIVE_KEYWORD} idx) 506 if( NOT idx LESS 0 ) 507 list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx}) 508 list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH}) 509 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) 510 endif() 511endforeach() 512 513if (NOT ${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD) 514 message(STATUS 515 "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code") 516else () 517 message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}") 518 set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target) 519 set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo) 520 set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC) 521 set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter) 522 523 # We don't have an ASM parser for all architectures yet. 524 if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt) 525 set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser) 526 endif () 527 528 # We don't have an disassembler for all architectures yet. 529 if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt) 530 set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler) 531 endif () 532endif () 533 534if( MSVC ) 535 set(SHLIBEXT ".lib") 536 set(stricmp "_stricmp") 537 set(strdup "_strdup") 538 539 # Allow setting clang-cl's /winsysroot flag. 540 set(LLVM_WINSYSROOT "" CACHE STRING 541 "If set, argument to clang-cl's /winsysroot") 542 543 if (LLVM_WINSYSROOT) 544 set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH 545 "Path to the DIA SDK") 546 else() 547 set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH 548 "Path to the DIA SDK") 549 endif() 550 551 # See if the DIA SDK is available and usable. 552 # Due to a bug in MSVC 2013's installation software, it is possible 553 # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012 554 # install directory. If this happens, the installation is corrupt 555 # and there's nothing we can do. It happens with enough frequency 556 # though that we should handle it. We do so by simply checking that 557 # the DIA SDK folder exists. Should this happen you will need to 558 # uninstall VS 2012 and then re-install VS 2013. 559 if (IS_DIRECTORY "${MSVC_DIA_SDK_DIR}") 560 set(HAVE_DIA_SDK 1) 561 else() 562 set(HAVE_DIA_SDK 0) 563 endif() 564 565 option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available." 566 ${HAVE_DIA_SDK}) 567 568 if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK) 569 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.") 570 endif() 571else() 572 set(LLVM_ENABLE_DIA_SDK 0) 573endif( MSVC ) 574 575if( LLVM_ENABLE_THREADS ) 576 # Check if threading primitives aren't supported on this platform 577 if( NOT HAVE_PTHREAD_H AND NOT WIN32 ) 578 set(LLVM_ENABLE_THREADS 0) 579 endif() 580endif() 581 582if( LLVM_ENABLE_THREADS ) 583 message(STATUS "Threads enabled.") 584else( LLVM_ENABLE_THREADS ) 585 message(STATUS "Threads disabled.") 586endif() 587 588if (LLVM_ENABLE_DOXYGEN) 589 message(STATUS "Doxygen enabled.") 590 find_package(Doxygen REQUIRED) 591 592 if (DOXYGEN_FOUND) 593 # If we find doxygen and we want to enable doxygen by default create a 594 # global aggregate doxygen target for generating llvm and any/all 595 # subprojects doxygen documentation. 596 if (LLVM_BUILD_DOCS) 597 add_custom_target(doxygen ALL) 598 endif() 599 600 option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF) 601 if (LLVM_DOXYGEN_EXTERNAL_SEARCH) 602 set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.") 603 set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings") 604 endif() 605 endif() 606else() 607 message(STATUS "Doxygen disabled.") 608endif() 609 610find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker") 611set(LLVM_BINUTILS_INCDIR "" CACHE PATH 612 "PATH to binutils/include containing plugin-api.h for gold plugin.") 613 614if(CMAKE_GENERATOR MATCHES "Ninja") 615 execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version 616 OUTPUT_VARIABLE NINJA_VERSION 617 OUTPUT_STRIP_TRAILING_WHITESPACE) 618 set(NINJA_VERSION ${NINJA_VERSION} CACHE STRING "Ninja version number" FORCE) 619 message(STATUS "Ninja version: ${NINJA_VERSION}") 620endif() 621 622if(CMAKE_GENERATOR MATCHES "Ninja" AND 623 NOT "${NINJA_VERSION}" VERSION_LESS "1.9.0" AND 624 CMAKE_HOST_APPLE AND CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER "15.6.0") 625 set(LLVM_TOUCH_STATIC_LIBRARIES ON) 626endif() 627 628if(CMAKE_HOST_APPLE AND APPLE) 629 if(NOT LD64_EXECUTABLE) 630 if(NOT CMAKE_XCRUN) 631 find_program(CMAKE_XCRUN NAMES xcrun) 632 endif() 633 if(CMAKE_XCRUN) 634 execute_process(COMMAND ${CMAKE_XCRUN} -find ld 635 OUTPUT_VARIABLE LD64_EXECUTABLE 636 OUTPUT_STRIP_TRAILING_WHITESPACE) 637 else() 638 find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker") 639 endif() 640 endif() 641 642 if(LD64_EXECUTABLE) 643 set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable") 644 message(STATUS "Found ld64 - ${LD64_EXECUTABLE}") 645 endif() 646endif() 647 648# Keep the version requirements in sync with bindings/ocaml/README.txt. 649set(LLVM_BINDINGS "") 650include(FindOCaml) 651include(AddOCaml) 652if(WIN32 OR NOT LLVM_ENABLE_BINDINGS) 653 message(STATUS "OCaml bindings disabled.") 654else() 655 find_package(OCaml) 656 if( NOT OCAML_FOUND ) 657 message(STATUS "OCaml bindings disabled.") 658 else() 659 if( OCAML_VERSION VERSION_LESS "4.00.0" ) 660 message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.") 661 else() 662 find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL) 663 if( HAVE_OCAML_CTYPES ) 664 message(STATUS "OCaml bindings enabled.") 665 set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml") 666 667 set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING 668 "Install directory for LLVM OCaml packages") 669 else() 670 message(STATUS "OCaml bindings disabled, need ctypes >=0.4.") 671 endif() 672 endif() 673 endif() 674endif() 675 676string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}") 677 678function(find_python_module module) 679 string(REPLACE "." "_" module_name ${module}) 680 string(TOUPPER ${module_name} module_upper) 681 set(FOUND_VAR PY_${module_upper}_FOUND) 682 if (DEFINED ${FOUND_VAR}) 683 return() 684 endif() 685 686 execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import ${module}" 687 RESULT_VARIABLE status 688 ERROR_QUIET) 689 690 if(status) 691 set(${FOUND_VAR} OFF CACHE BOOL "Failed to find python module '${module}'") 692 message(STATUS "Could NOT find Python module ${module}") 693 else() 694 set(${FOUND_VAR} ON CACHE BOOL "Found python module '${module}'") 695 message(STATUS "Found Python module ${module}") 696 endif() 697endfunction() 698 699set (PYTHON_MODULES 700 pygments 701 # Some systems still don't have pygments.lexers.c_cpp which was introduced in 702 # version 2.0 in 2014... 703 pygments.lexers.c_cpp 704 yaml 705 ) 706foreach(module ${PYTHON_MODULES}) 707 find_python_module(${module}) 708endforeach() 709 710if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND) 711 set (LLVM_HAVE_OPT_VIEWER_MODULES 1) 712else() 713 set (LLVM_HAVE_OPT_VIEWER_MODULES 0) 714endif() 715 716function(llvm_get_host_prefixes_and_suffixes) 717 # Not all platform files will set these variables (relying on them being 718 # implicitly empty if they're unset), so unset the variables before including 719 # the platform file, to prevent any values from the target system leaking. 720 unset(CMAKE_STATIC_LIBRARY_PREFIX) 721 unset(CMAKE_STATIC_LIBRARY_SUFFIX) 722 unset(CMAKE_SHARED_LIBRARY_PREFIX) 723 unset(CMAKE_SHARED_LIBRARY_SUFFIX) 724 unset(CMAKE_IMPORT_LIBRARY_PREFIX) 725 unset(CMAKE_IMPORT_LIBRARY_SUFFIX) 726 unset(CMAKE_EXECUTABLE_SUFFIX) 727 unset(CMAKE_LINK_LIBRARY_SUFFIX) 728 include(Platform/${CMAKE_HOST_SYSTEM_NAME} OPTIONAL RESULT_VARIABLE _includedFile) 729 if (_includedFile) 730 set(LLVM_HOST_STATIC_LIBRARY_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX} PARENT_SCOPE) 731 set(LLVM_HOST_STATIC_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX} PARENT_SCOPE) 732 set(LLVM_HOST_SHARED_LIBRARY_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX} PARENT_SCOPE) 733 set(LLVM_HOST_SHARED_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX} PARENT_SCOPE) 734 set(LLVM_HOST_IMPORT_LIBRARY_PREFIX ${CMAKE_IMPORT_LIBRARY_PREFIX} PARENT_SCOPE) 735 set(LLVM_HOST_IMPORT_LIBRARY_SUFFIX ${CMAKE_IMPORT_LIBRARY_SUFFIX} PARENT_SCOPE) 736 set(LLVM_HOST_EXECUTABLE_SUFFIX ${CMAKE_EXECUTABLE_SUFFIX} PARENT_SCOPE) 737 set(LLVM_HOST_LINK_LIBRARY_SUFFIX ${CMAKE_LINK_LIBRARY_SUFFIX} PARENT_SCOPE) 738 endif() 739endfunction() 740 741llvm_get_host_prefixes_and_suffixes() 742