1 if( WIN32 AND NOT CYGWIN )
2 # We consider Cygwin as another Unix
6 include(CheckIncludeFile)
7 include(CheckLibraryExists)
8 include(CheckSymbolExists)
9 include(CheckCXXSymbolExists)
10 include(CheckFunctionExists)
11 include(CheckStructHasMember)
12 include(CheckCCompilerFlag)
13 include(CMakePushCheckState)
15 include(CheckCompilerVersion)
16 include(CheckProblematicConfigurations)
17 include(HandleLLVMStdlib)
19 if( UNIX AND NOT (APPLE OR BEOS OR HAIKU) )
20 # Used by check_symbol_exists:
21 list(APPEND CMAKE_REQUIRED_LIBRARIES "m")
23 # x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.
24 if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND
25 CMAKE_SIZEOF_VOID_P EQUAL 8 )
26 list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt")
29 # Do checks with _XOPEN_SOURCE and large-file API on AIX, because we will build
31 if (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")
36 # Do checks with _FILE_OFFSET_BITS=64 on Solaris, because we will build
38 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
39 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
43 check_include_file(dlfcn.h HAVE_DLFCN_H)
44 check_include_file(errno.h HAVE_ERRNO_H)
45 check_include_file(fcntl.h HAVE_FCNTL_H)
46 check_include_file(link.h HAVE_LINK_H)
47 check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
48 if( NOT PURE_WINDOWS )
49 check_include_file(pthread.h HAVE_PTHREAD_H)
51 check_include_file(signal.h HAVE_SIGNAL_H)
52 check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
53 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
54 check_include_file(sys/param.h HAVE_SYS_PARAM_H)
55 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
56 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
57 check_include_file(sys/time.h HAVE_SYS_TIME_H)
58 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
59 check_include_file(sysexits.h HAVE_SYSEXITS_H)
60 check_include_file(termios.h HAVE_TERMIOS_H)
61 check_include_file(unistd.h HAVE_UNISTD_H)
62 check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
63 check_include_file(fenv.h HAVE_FENV_H)
64 check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
65 check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
67 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
68 check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
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)
78 if(${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)
88 if( NOT PURE_WINDOWS )
89 check_library_exists(pthread pthread_create "" 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)
94 # this could be Android
95 check_library_exists(c pthread_create "" 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)
101 check_library_exists(dl dlopen "" HAVE_LIBDL)
102 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
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})
119 if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON)
120 find_package(ZLIB REQUIRED)
121 elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
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")
136 set(LLVM_ENABLE_ZLIB "${HAVE_ZLIB}")
138 set(LLVM_ENABLE_ZLIB 0)
143 if(LLVM_ENABLE_ZSTD STREQUAL FORCE_ON)
144 find_package(zstd REQUIRED)
146 message(FATAL_ERROR "Failed to configure zstd, but LLVM_ENABLE_ZSTD is FORCE_ON")
148 elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
149 find_package(zstd QUIET)
152 set(LLVM_ENABLE_ZSTD ${zstd_FOUND})
154 if(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)
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")
173 set(LLVM_ENABLE_LIBXML2 "${HAVE_LIBXML2}")
177 if(LLVM_ENABLE_CURL STREQUAL FORCE_ON)
178 find_package(CURL REQUIRED)
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")
193 set(LLVM_ENABLE_CURL "${HAVE_CURL}")
196 if(LLVM_ENABLE_HTTPLIB)
197 if(LLVM_ENABLE_HTTPLIB STREQUAL FORCE_ON)
198 find_package(httplib REQUIRED)
200 find_package(httplib)
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")
213 set(LLVM_ENABLE_HTTPLIB "${HAVE_HTTPLIB}")
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.
218 if(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 if(LLVM_ENABLE_LIBEDIT STREQUAL FORCE_ON)
224 find_package(LibEdit REQUIRED)
226 find_package(LibEdit)
228 set(HAVE_LIBEDIT "${LibEdit_FOUND}")
232 if(LLVM_ENABLE_TERMINFO)
233 if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
234 find_package(Terminfo REQUIRED)
236 find_package(Terminfo)
238 set(LLVM_ENABLE_TERMINFO "${Terminfo_FOUND}")
242 set(LLVM_ENABLE_TERMINFO 0)
246 set(LLVM_ENABLE_TERMINFO 0)
249 check_library_exists(xar xar_open "" LLVM_HAVE_LIBXAR)
251 message(STATUS "The xar file format has been deprecated: LLVM_HAVE_LIBXAR might be removed in the future.")
252 # The xar file format has been deprecated since macOS 12.0.
253 if (CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 12)
254 set(LLVM_HAVE_LIBXAR 0)
261 check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
262 find_package(Backtrace)
263 set(HAVE_BACKTRACE ${Backtrace_FOUND})
264 set(BACKTRACE_HEADER ${Backtrace_HEADER})
266 # Prevent check_symbol_exists from using API that is not supported for a given
268 check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW")
269 if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW)
270 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new")
273 # Determine whether we can register EH tables.
274 check_symbol_exists(__register_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_REGISTER_FRAME)
275 check_symbol_exists(__deregister_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_DEREGISTER_FRAME)
276 check_symbol_exists(__unw_add_dynamic_fde "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_UNW_ADD_DYNAMIC_FDE)
278 check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE)
279 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
280 check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
281 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
282 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
283 check_symbol_exists(isatty unistd.h HAVE_ISATTY)
284 check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
285 check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
286 # AddressSanitizer conflicts with lib/Support/Unix/Signals.inc
287 # Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it
288 # (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind
289 # past the signal handler after an assertion failure (rdar://29866587).
290 if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )
291 check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
293 check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
294 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
295 check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)
296 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
297 HAVE_MALLOC_ZONE_STATISTICS)
298 check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
299 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
300 check_symbol_exists(pread unistd.h HAVE_PREAD)
301 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
302 check_symbol_exists(strerror string.h HAVE_STRERROR)
303 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
304 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
305 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
307 check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
309 check_function_exists(_alloca HAVE__ALLOCA)
310 check_function_exists(__alloca HAVE___ALLOCA)
311 check_function_exists(__chkstk HAVE___CHKSTK)
312 check_function_exists(__chkstk_ms HAVE___CHKSTK_MS)
313 check_function_exists(___chkstk HAVE____CHKSTK)
314 check_function_exists(___chkstk_ms HAVE____CHKSTK_MS)
316 check_function_exists(__ashldi3 HAVE___ASHLDI3)
317 check_function_exists(__ashrdi3 HAVE___ASHRDI3)
318 check_function_exists(__divdi3 HAVE___DIVDI3)
319 check_function_exists(__fixdfdi HAVE___FIXDFDI)
320 check_function_exists(__fixsfdi HAVE___FIXSFDI)
321 check_function_exists(__floatdidf HAVE___FLOATDIDF)
322 check_function_exists(__lshrdi3 HAVE___LSHRDI3)
323 check_function_exists(__moddi3 HAVE___MODDI3)
324 check_function_exists(__udivdi3 HAVE___UDIVDI3)
325 check_function_exists(__umoddi3 HAVE___UMODDI3)
327 check_function_exists(__main HAVE___MAIN)
328 check_function_exists(__cmpdi2 HAVE___CMPDI2)
331 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec
332 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
333 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
334 # The st_mtim.tv_nsec member of a `stat` structure is not reliable on some AIX
336 set(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 0)
338 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec
339 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
342 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
343 if( LLVM_USING_GLIBC )
344 add_compile_definitions(_GNU_SOURCE)
345 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
346 # enable 64bit off_t on 32bit systems using glibc
347 if (CMAKE_SIZEOF_VOID_P EQUAL 4)
348 add_compile_definitions(_FILE_OFFSET_BITS=64)
349 list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
353 # This check requires _GNU_SOURCE.
354 if (NOT PURE_WINDOWS)
355 if (LLVM_PTHREAD_LIB)
356 list(APPEND CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})
358 check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP)
359 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
360 if (LLVM_PTHREAD_LIB)
361 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})
365 # This check requires _GNU_SOURCE.
368 list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
370 check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
371 check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR)
373 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
377 # available programs checks
378 function(llvm_find_program name)
379 string(TOUPPER ${name} NAME)
380 string(REGEX REPLACE "\\." "_" NAME ${NAME})
382 find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
383 mark_as_advanced(LLVM_PATH_${NAME})
384 if(LLVM_PATH_${NAME})
385 set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
386 mark_as_advanced(HAVE_${NAME})
387 else(LLVM_PATH_${NAME})
388 set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
389 endif(LLVM_PATH_${NAME})
392 if (LLVM_ENABLE_DOXYGEN)
393 llvm_find_program(dot)
397 set(FFI_REQUIRE_INCLUDE On)
398 if(LLVM_ENABLE_FFI STREQUAL FORCE_ON)
399 find_package(FFI REQUIRED)
403 set(LLVM_ENABLE_FFI "${FFI_FOUND}")
405 unset(HAVE_FFI_FFI_H CACHE)
406 unset(HAVE_FFI_H CACHE)
407 unset(HAVE_FFI_CALL CACHE)
410 check_symbol_exists(proc_pid_rusage "libproc.h" HAVE_PROC_PID_RUSAGE)
412 # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
415 if( LLVM_ENABLE_PIC )
419 check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG)
420 if(SUPPORTS_NO_PIE_FLAG)
421 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
425 check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG)
426 check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments"
427 SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
429 set(USE_NO_MAYBE_UNINITIALIZED 0)
430 set(USE_NO_UNINITIALIZED 0)
432 # Disable gcc's potentially uninitialized use analysis as it presents lots of
434 if (CMAKE_COMPILER_IS_GNUCXX)
435 check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
436 if (HAS_MAYBE_UNINITIALIZED)
437 set(USE_NO_MAYBE_UNINITIALIZED 1)
439 # Only recent versions of gcc make the distinction between -Wuninitialized
440 # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
441 # turn off all uninitialized use warnings.
442 check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
443 set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
447 if(LLVM_INCLUDE_TESTS)
448 include(GetErrcMessages)
449 get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
452 # By default, we target the host, but this can be overridden at CMake
454 include(GetHostTriple)
455 get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
457 set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
458 "Host on which LLVM binaries will run")
460 # Determine the native architecture.
461 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
462 if( LLVM_NATIVE_ARCH STREQUAL "host" )
463 string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
466 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
467 set(LLVM_NATIVE_ARCH X86)
468 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
469 set(LLVM_NATIVE_ARCH X86)
470 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
471 set(LLVM_NATIVE_ARCH X86)
472 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
473 set(LLVM_NATIVE_ARCH X86)
474 elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
475 set(LLVM_NATIVE_ARCH Sparc)
476 elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
477 set(LLVM_NATIVE_ARCH PowerPC)
478 elseif (LLVM_NATIVE_ARCH MATCHES "ppc64le")
479 set(LLVM_NATIVE_ARCH PowerPC)
480 elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
481 set(LLVM_NATIVE_ARCH AArch64)
482 elseif (LLVM_NATIVE_ARCH MATCHES "arm64")
483 set(LLVM_NATIVE_ARCH AArch64)
484 elseif (LLVM_NATIVE_ARCH MATCHES "arm")
485 set(LLVM_NATIVE_ARCH ARM)
486 elseif (LLVM_NATIVE_ARCH MATCHES "avr")
487 set(LLVM_NATIVE_ARCH AVR)
488 elseif (LLVM_NATIVE_ARCH MATCHES "mips")
489 set(LLVM_NATIVE_ARCH Mips)
490 elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
491 set(LLVM_NATIVE_ARCH XCore)
492 elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
493 set(LLVM_NATIVE_ARCH MSP430)
494 elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
495 set(LLVM_NATIVE_ARCH Hexagon)
496 elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
497 set(LLVM_NATIVE_ARCH SystemZ)
498 elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
499 set(LLVM_NATIVE_ARCH WebAssembly)
500 elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
501 set(LLVM_NATIVE_ARCH WebAssembly)
502 elseif (LLVM_NATIVE_ARCH MATCHES "riscv32")
503 set(LLVM_NATIVE_ARCH RISCV)
504 elseif (LLVM_NATIVE_ARCH MATCHES "riscv64")
505 set(LLVM_NATIVE_ARCH RISCV)
506 elseif (LLVM_NATIVE_ARCH STREQUAL "m68k")
507 set(LLVM_NATIVE_ARCH M68k)
508 elseif (LLVM_NATIVE_ARCH MATCHES "loongarch")
509 set(LLVM_NATIVE_ARCH LoongArch)
511 message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
514 # If build targets includes "host" or "Native", then replace with native architecture.
515 foreach (NATIVE_KEYWORD host Native)
516 list(FIND LLVM_TARGETS_TO_BUILD ${NATIVE_KEYWORD} idx)
518 list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
519 list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
520 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
524 if (NOT ${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD)
526 "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
528 message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
529 set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
530 set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
531 set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
532 set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
534 # We don't have an ASM parser for all architectures yet.
535 if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
536 set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
539 # We don't have an disassembler for all architectures yet.
540 if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
541 set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
547 set(stricmp "_stricmp")
548 set(strdup "_strdup")
550 # Allow setting clang-cl's /winsysroot flag.
551 set(LLVM_WINSYSROOT "" CACHE STRING
552 "If set, argument to clang-cl's /winsysroot")
555 set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
556 "Path to the DIA SDK")
558 set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
559 "Path to the DIA SDK")
562 # See if the DIA SDK is available and usable.
563 # Due to a bug in MSVC 2013's installation software, it is possible
564 # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
565 # install directory. If this happens, the installation is corrupt
566 # and there's nothing we can do. It happens with enough frequency
567 # though that we should handle it. We do so by simply checking that
568 # the DIA SDK folder exists. Should this happen you will need to
569 # uninstall VS 2012 and then re-install VS 2013.
570 if (IS_DIRECTORY "${MSVC_DIA_SDK_DIR}")
576 option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available."
579 if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK)
580 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.")
583 set(LLVM_ENABLE_DIA_SDK 0)
586 if( LLVM_ENABLE_THREADS )
587 # Check if threading primitives aren't supported on this platform
588 if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
589 set(LLVM_ENABLE_THREADS 0)
593 if( LLVM_ENABLE_THREADS )
594 message(STATUS "Threads enabled.")
595 else( LLVM_ENABLE_THREADS )
596 message(STATUS "Threads disabled.")
599 if (LLVM_ENABLE_DOXYGEN)
600 message(STATUS "Doxygen enabled.")
601 find_package(Doxygen REQUIRED)
604 # If we find doxygen and we want to enable doxygen by default create a
605 # global aggregate doxygen target for generating llvm and any/all
606 # subprojects doxygen documentation.
608 add_custom_target(doxygen ALL)
611 option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
612 if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
613 set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.")
614 set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
618 message(STATUS "Doxygen disabled.")
621 find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker")
622 set(LLVM_BINUTILS_INCDIR "" CACHE PATH
623 "PATH to binutils/include containing plugin-api.h for gold plugin.")
625 if(CMAKE_GENERATOR MATCHES "Ninja")
626 execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
627 OUTPUT_VARIABLE NINJA_VERSION
628 OUTPUT_STRIP_TRAILING_WHITESPACE)
629 set(NINJA_VERSION ${NINJA_VERSION} CACHE STRING "Ninja version number" FORCE)
630 message(STATUS "Ninja version: ${NINJA_VERSION}")
633 if(CMAKE_GENERATOR MATCHES "Ninja" AND
634 NOT "${NINJA_VERSION}" VERSION_LESS "1.9.0" AND
635 CMAKE_HOST_APPLE AND CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER "15.6.0")
636 set(LLVM_TOUCH_STATIC_LIBRARIES ON)
639 if(CMAKE_HOST_APPLE AND APPLE)
640 if(NOT LD64_EXECUTABLE)
642 find_program(CMAKE_XCRUN NAMES xcrun)
645 execute_process(COMMAND ${CMAKE_XCRUN} -find ld
646 OUTPUT_VARIABLE LD64_EXECUTABLE
647 OUTPUT_STRIP_TRAILING_WHITESPACE)
649 find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker")
654 set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable")
655 message(STATUS "Found ld64 - ${LD64_EXECUTABLE}")
659 # Keep the version requirements in sync with bindings/ocaml/README.txt.
660 set(LLVM_BINDINGS "")
663 if(WIN32 OR NOT LLVM_ENABLE_BINDINGS)
664 message(STATUS "OCaml bindings disabled.")
667 if( NOT OCAML_FOUND )
668 message(STATUS "OCaml bindings disabled.")
670 if( OCAML_VERSION VERSION_LESS "4.00.0" )
671 message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.")
673 find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL)
674 if( HAVE_OCAML_CTYPES )
675 message(STATUS "OCaml bindings enabled.")
676 set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
678 set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING
679 "Install directory for LLVM OCaml packages")
681 message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
687 string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")
689 function(find_python_module module)
690 string(REPLACE "." "_" module_name ${module})
691 string(TOUPPER ${module_name} module_upper)
692 set(FOUND_VAR PY_${module_upper}_FOUND)
693 if (DEFINED ${FOUND_VAR})
697 execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import ${module}"
698 RESULT_VARIABLE status
702 set(${FOUND_VAR} OFF CACHE BOOL "Failed to find python module '${module}'")
703 message(STATUS "Could NOT find Python module ${module}")
705 set(${FOUND_VAR} ON CACHE BOOL "Found python module '${module}'")
706 message(STATUS "Found Python module ${module}")
712 # Some systems still don't have pygments.lexers.c_cpp which was introduced in
713 # version 2.0 in 2014...
714 pygments.lexers.c_cpp
717 foreach(module ${PYTHON_MODULES})
718 find_python_module(${module})
721 if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND)
722 set (LLVM_HAVE_OPT_VIEWER_MODULES 1)
724 set (LLVM_HAVE_OPT_VIEWER_MODULES 0)
727 function(llvm_get_host_prefixes_and_suffixes)
728 # Not all platform files will set these variables (relying on them being
729 # implicitly empty if they're unset), so unset the variables before including
730 # the platform file, to prevent any values from the target system leaking.
731 unset(CMAKE_STATIC_LIBRARY_PREFIX)
732 unset(CMAKE_STATIC_LIBRARY_SUFFIX)
733 unset(CMAKE_SHARED_LIBRARY_PREFIX)
734 unset(CMAKE_SHARED_LIBRARY_SUFFIX)
735 unset(CMAKE_IMPORT_LIBRARY_PREFIX)
736 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
737 unset(CMAKE_EXECUTABLE_SUFFIX)
738 unset(CMAKE_LINK_LIBRARY_SUFFIX)
739 include(Platform/${CMAKE_HOST_SYSTEM_NAME} OPTIONAL RESULT_VARIABLE _includedFile)
741 set(LLVM_HOST_STATIC_LIBRARY_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX} PARENT_SCOPE)
742 set(LLVM_HOST_STATIC_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX} PARENT_SCOPE)
743 set(LLVM_HOST_SHARED_LIBRARY_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX} PARENT_SCOPE)
744 set(LLVM_HOST_SHARED_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX} PARENT_SCOPE)
745 set(LLVM_HOST_IMPORT_LIBRARY_PREFIX ${CMAKE_IMPORT_LIBRARY_PREFIX} PARENT_SCOPE)
746 set(LLVM_HOST_IMPORT_LIBRARY_SUFFIX ${CMAKE_IMPORT_LIBRARY_SUFFIX} PARENT_SCOPE)
747 set(LLVM_HOST_EXECUTABLE_SUFFIX ${CMAKE_EXECUTABLE_SUFFIX} PARENT_SCOPE)
748 set(LLVM_HOST_LINK_LIBRARY_SUFFIX ${CMAKE_LINK_LIBRARY_SUFFIX} PARENT_SCOPE)
752 llvm_get_host_prefixes_and_suffixes()