brintos

brintos / llvm-project-archived public Read only

0
0
Text · 29.2 KiB · ed2bfa6 Raw
840 lines · plain
1include(CheckIncludeFile)2include(CheckLibraryExists)3include(CheckSymbolExists)4include(CheckCXXSymbolExists)5include(CheckFunctionExists)6include(CheckStructHasMember)7include(CheckCCompilerFlag)8include(CheckCSourceCompiles)9include(CMakePushCheckState)10 11include(CheckCompilerVersion)12include(CheckProblematicConfigurations)13include(HandleLLVMStdlib)14 15if (ANDROID OR CYGWIN OR CMAKE_SYSTEM_NAME MATCHES "AIX|DragonFly|FreeBSD|Haiku|Linux|NetBSD|OpenBSD|SunOS")16  set(HAVE_MACH_MACH_H 0)17  set(HAVE_MALLOC_MALLOC_H 0)18  set(HAVE_PTHREAD_H 1)19  set(HAVE_SYS_MMAN_H 1)20  set(HAVE_SYSEXITS_H 1)21  set(HAVE_UNISTD_H 1)22  set(HAVE_SYS_IOCTL_H 1)23elseif (APPLE)24  set(HAVE_MACH_MACH_H 1)25  set(HAVE_MALLOC_MALLOC_H 1)26  set(HAVE_PTHREAD_H 1)27  set(HAVE_SYS_MMAN_H 1)28  set(HAVE_SYSEXITS_H 1)29  set(HAVE_UNISTD_H 1)30  set(HAVE_SYS_IOCTL_H 1)31elseif (WIN32)32  set(HAVE_MACH_MACH_H 0)33  set(HAVE_MALLOC_MALLOC_H 0)34  set(HAVE_PTHREAD_H 0)35  set(HAVE_SYS_MMAN_H 0)36  set(HAVE_SYSEXITS_H 0)37  set(HAVE_UNISTD_H 0)38  set(HAVE_SYS_IOCTL_H 0)39elseif (ZOS)40  # Confirmed in41  # https://github.com/llvm/llvm-project/pull/104706#issuecomment-229710961342  set(HAVE_MACH_MACH_H 0)43  set(HAVE_MALLOC_MALLOC_H 0)44  set(HAVE_PTHREAD_H 1)45  set(HAVE_SYS_MMAN_H 1)46  set(HAVE_SYSEXITS_H 0)47  set(HAVE_UNISTD_H 1)48  set(HAVE_SYS_IOCTL_H 1)49else()50  # Other platforms that we don't promise support for.51  check_include_file(mach/mach.h HAVE_MACH_MACH_H)52  check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)53  check_include_file(pthread.h HAVE_PTHREAD_H)54  check_include_file(sys/mman.h HAVE_SYS_MMAN_H)55  check_include_file(sysexits.h HAVE_SYSEXITS_H)56  check_include_file(unistd.h HAVE_UNISTD_H)57  check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)58endif()59 60if( UNIX AND NOT (APPLE OR BEOS OR HAIKU) )61  # Used by check_symbol_exists:62  list(APPEND CMAKE_REQUIRED_LIBRARIES "m")63endif()64# x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.65if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND66    CMAKE_SIZEOF_VOID_P EQUAL 8 )67  list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt")68endif()69 70# Do checks with _XOPEN_SOURCE and large-file API on AIX, because we will build71# with those too.72if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")73          list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_XOPEN_SOURCE=700")74          list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_LARGE_FILE_API")75endif()76 77# Do checks with _FILE_OFFSET_BITS=64 on Solaris, because we will build78# with those too.79if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")80          list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")81endif()82 83# Newer POSIX functions aren't available without the appropriate defines.84# Usually those are set by the use of -std=gnuXX, but one can also use the85# newer functions with -std=c(++)XX, i.e. without the GNU language extensions.86# Keep this at the top to make sure we don't add _GNU_SOURCE dependent checks87# before adding it.88check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)89if(LLVM_USING_GLIBC OR CYGWIN)90  add_compile_definitions(_GNU_SOURCE)91  list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")92endif()93 94# enable 64bit off_t on 32bit systems using glibc95if(LLVM_USING_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4)96  add_compile_definitions(_FILE_OFFSET_BITS=64)97  list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")98endif()99 100# include checks101check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)102check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)103check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)104check_c_source_compiles("105        #if __has_attribute(used)106        #define LLVM_ATTRIBUTE_USED __attribute__((__used__))107        #else108        #define LLVM_ATTRIBUTE_USED109        #endif110        LLVM_ATTRIBUTE_USED void *foo() {111          return __builtin_thread_pointer();112        }113        int main(void) { return 0; }"114        HAVE_BUILTIN_THREAD_POINTER)115 116check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)117if(APPLE)118  check_c_source_compiles("119     static const char *__crashreporter_info__ = 0;120     asm(\".desc ___crashreporter_info__, 0x10\");121     int main(void) { return 0; }"122    HAVE_CRASHREPORTER_INFO)123endif()124 125if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")126  check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H)127  if(NOT HAVE_LINUX_MAGIC_H)128    # older kernels use split files129    check_include_file(linux/nfs_fs.h HAVE_LINUX_NFS_FS_H)130    check_include_file(linux/smb.h HAVE_LINUX_SMB_H)131  endif()132endif()133 134# library checks135if(NOT WIN32)136  check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)137  if (HAVE_LIBPTHREAD)138    check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)139    check_library_exists(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)140  else()141    # this could be Android142    check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)143    if (PTHREAD_IN_LIBC)144      check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)145      check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)146    endif()147  endif()148  check_library_exists(dl dlopen "" HAVE_LIBDL)149  check_library_exists(rt shm_open "" HAVE_LIBRT)150endif()151 152# Check for libpfm.153include(FindLibpfm)154 155if(HAVE_LIBPTHREAD)156  # We want to find pthreads library and at the moment we do want to157  # have it reported as '-l<lib>' instead of '-pthread'.158  # TODO: switch to -pthread once the rest of the build system can deal with it.159  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)160  set(THREADS_HAVE_PTHREAD_ARG Off)161  find_package(Threads REQUIRED)162  set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})163endif()164 165if(LLVM_ENABLE_ZLIB)166  if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON)167    find_package(ZLIB REQUIRED)168  elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")169    find_package(ZLIB)170  endif()171  if(ZLIB_FOUND)172    # Check if zlib we found is usable; for example, we may have found a 32-bit173    # library on a 64-bit system which would result in a link-time failure.174    cmake_push_check_state()175    list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})176    list(APPEND CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY})177    check_symbol_exists(compress2 zlib.h HAVE_ZLIB)178    cmake_pop_check_state()179    if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON AND NOT HAVE_ZLIB)180      message(FATAL_ERROR "Failed to configure zlib")181    endif()182  endif()183  set(LLVM_ENABLE_ZLIB "${HAVE_ZLIB}")184else()185  set(LLVM_ENABLE_ZLIB 0)186endif()187 188set(zstd_FOUND 0)189if(LLVM_ENABLE_ZSTD)190  if(LLVM_ENABLE_ZSTD STREQUAL FORCE_ON)191    find_package(zstd REQUIRED)192    if(NOT zstd_FOUND)193      message(FATAL_ERROR "Failed to configure zstd, but LLVM_ENABLE_ZSTD is FORCE_ON")194    endif()195  elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")196    find_package(zstd QUIET)197  endif()198 199  # If LLVM_USE_STATIC_ZSTD is specified, make sure we enable zstd only if static200  # libraries are found.201  if(LLVM_USE_STATIC_ZSTD AND NOT TARGET zstd::libzstd_static)202    # Fail if LLVM_ENABLE_ZSTD is FORCE_ON.203    if(LLVM_ENABLE_ZSTD STREQUAL FORCE_ON)204        message(FATAL_ERROR "Failed to find static zstd libraries, but LLVM_USE_STATIC_ZSTD=ON and LLVM_ENABLE_ZSTD=FORCE_ON.")205    endif()206    set(LLVM_ENABLE_ZSTD OFF)207  else()208    set(LLVM_ENABLE_ZSTD ${zstd_FOUND})209  endif()210endif()211 212if(LLVM_ENABLE_LIBXML2)213  if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON)214    find_package(LibXml2 REQUIRED)215  elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")216    find_package(LibXml2)217  endif()218  if(LibXml2_FOUND)219    # Check if libxml2 we found is usable; for example, we may have found a 32-bit220    # library on a 64-bit system which would result in a link-time failure.221    cmake_push_check_state()222    list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIRS})223    list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBXML2_LIBRARIES})224    list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LIBXML2_DEFINITIONS})225    check_symbol_exists(xmlReadMemory libxml/xmlreader.h HAVE_LIBXML2)226    cmake_pop_check_state()227    if(LLVM_ENABLE_LIBXML2 STREQUAL FORCE_ON AND NOT HAVE_LIBXML2)228      message(FATAL_ERROR "Failed to configure libxml2")229    endif()230  endif()231  set(LLVM_ENABLE_LIBXML2 "${HAVE_LIBXML2}")232endif()233 234if(LLVM_ENABLE_CURL)235  if(LLVM_ENABLE_CURL STREQUAL FORCE_ON)236    find_package(CURL REQUIRED)237  else()238    find_package(CURL)239  endif()240  if(CURL_FOUND)241    # Check if curl we found is usable; for example, we may have found a 32-bit242    # library on a 64-bit system which would result in a link-time failure.243    cmake_push_check_state()244    list(APPEND CMAKE_REQUIRED_LIBRARIES CURL::libcurl)245    check_symbol_exists(curl_easy_init curl/curl.h HAVE_CURL)246    cmake_pop_check_state()247    if(LLVM_ENABLE_CURL STREQUAL FORCE_ON AND NOT HAVE_CURL)248      message(FATAL_ERROR "Failed to configure curl")249    endif()250  endif()251  set(LLVM_ENABLE_CURL "${HAVE_CURL}")252endif()253 254if(LLVM_ENABLE_HTTPLIB)255  if(LLVM_ENABLE_HTTPLIB STREQUAL FORCE_ON)256    find_package(httplib REQUIRED)257  else()258    find_package(httplib)259  endif()260  if(HTTPLIB_FOUND)261    # Check if the "httplib" we found is usable; for example there may be another262    # library with the same name.263    cmake_push_check_state()264    list(APPEND CMAKE_REQUIRED_LIBRARIES ${HTTPLIB_LIBRARY})265    check_cxx_symbol_exists(CPPHTTPLIB_HTTPLIB_H ${HTTPLIB_HEADER_PATH} HAVE_HTTPLIB)266    cmake_pop_check_state()267    if(LLVM_ENABLE_HTTPLIB STREQUAL FORCE_ON AND NOT HAVE_HTTPLIB)268      message(FATAL_ERROR "Failed to configure cpp-httplib")269    endif()270  endif()271  set(LLVM_ENABLE_HTTPLIB "${HAVE_HTTPLIB}")272endif()273 274# Don't look for these libraries if we're using MSan, since uninstrumented third275# party code may call MSan interceptors like strlen, leading to false positives.276if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")277  # Don't look for these libraries on Windows.278  if (NOT WIN32)279    # Skip libedit if using ASan as it contains memory leaks.280    if (LLVM_ENABLE_LIBEDIT AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")281      if(LLVM_ENABLE_LIBEDIT STREQUAL FORCE_ON)282        find_package(LibEdit REQUIRED)283      else()284        find_package(LibEdit)285      endif()286      set(HAVE_LIBEDIT "${LibEdit_FOUND}")287    else()288      set(HAVE_LIBEDIT 0)289    endif()290  else()291    set(HAVE_LIBEDIT 0)292  endif()293else()294  set(HAVE_LIBEDIT 0)295endif()296 297if(LLVM_HAS_LOGF128)298  include(CheckCXXSymbolExists)299  check_cxx_symbol_exists(logf128 math.h HAS_LOGF128)300 301  if(LLVM_HAS_LOGF128 STREQUAL FORCE_ON AND NOT HAS_LOGF128)302    message(FATAL_ERROR "Failed to configure logf128")303  endif()304 305  set(LLVM_HAS_LOGF128 "${HAS_LOGF128}")306endif()307 308if (LLVM_ENABLE_ICU STREQUAL FORCE_ON AND LLVM_ENABLE_ICONV STREQUAL FORCE_ON)309  message(FATAL_ERROR "LLVM_ENABLE_ICU and LLVM_ENABLE_ICONV should not both be FORCE_ON")310endif()311 312# Check for ICU. Only allow an optional, dynamic link for ICU so we don't impact LLVM's licensing.313if(LLVM_ENABLE_ICU AND NOT(LLVM_ENABLE_ICONV STREQUAL FORCE_ON))314  set(LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})315  set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")316  if (LLVM_ENABLE_ICU STREQUAL FORCE_ON)317    find_package(ICU REQUIRED COMPONENTS uc i18n)318    if (NOT ICU_FOUND)319      message(FATAL_ERROR "Failed to configure ICU, but LLVM_ENABLE_ICU is FORCE_ON")320    endif()321  else()322    find_package(ICU COMPONENTS uc i18n)323  endif()324  set(HAVE_ICU ${ICU_FOUND})325  set(CMAKE_FIND_LIBRARY_SUFFIXES ${LIBRARY_SUFFIXES})326endif()327 328# Check only for builtin iconv to avoid licensing issues.329if(LLVM_ENABLE_ICONV AND NOT HAVE_ICU)330  if (LLVM_ENABLE_ICONV STREQUAL FORCE_ON)331    find_package(Iconv REQUIRED)332    if (NOT Iconv_FOUND OR NOT Iconv_IS_BUILT_IN)333      message(FATAL_ERROR "Failed to configure iconv, but LLVM_ENABLE_ICONV is FORCE_ON")334    endif()335  else()336    find_package(Iconv)337  endif()338  if(Iconv_FOUND AND Iconv_IS_BUILT_IN)339    set(HAVE_ICONV 1)340  endif()341endif()342 343# function checks344check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)345find_package(Backtrace)346set(HAVE_BACKTRACE ${Backtrace_FOUND})347set(BACKTRACE_HEADER ${Backtrace_HEADER})348 349# Prevent check_symbol_exists from using API that is not supported for a given350# deployment target.351check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW")352if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW)353  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new")354endif()355 356# Determine whether we can register EH tables.357check_symbol_exists(__register_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_REGISTER_FRAME)358check_symbol_exists(__deregister_frame "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_DEREGISTER_FRAME)359check_symbol_exists(__unw_add_dynamic_fde "${CMAKE_CURRENT_LIST_DIR}/unwind.h" HAVE_UNW_ADD_DYNAMIC_FDE)360 361check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE)362check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)363check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)364check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)365check_symbol_exists(isatty unistd.h HAVE_ISATTY)366check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)367check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)368check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL)369# AddressSanitizer conflicts with lib/Support/Unix/Signals.inc370# Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it371# (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind372# past the signal handler after an assertion failure (rdar://29866587).373if( NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )374  check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)375endif()376check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)377check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)378check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2)379check_symbol_exists(malloc_zone_statistics malloc/malloc.h380                    HAVE_MALLOC_ZONE_STATISTICS)381check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)382check_symbol_exists(pread unistd.h HAVE_PREAD)383check_symbol_exists(sbrk unistd.h HAVE_SBRK)384check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)385check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)386check_symbol_exists(setenv stdlib.h HAVE_SETENV)387if(WIN32)388  check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)389 390  check_function_exists(_alloca HAVE__ALLOCA)391  check_function_exists(__alloca HAVE___ALLOCA)392  check_function_exists(__chkstk HAVE___CHKSTK)393  check_function_exists(__chkstk_ms HAVE___CHKSTK_MS)394  check_function_exists(___chkstk HAVE____CHKSTK)395  check_function_exists(___chkstk_ms HAVE____CHKSTK_MS)396 397  check_function_exists(__ashldi3 HAVE___ASHLDI3)398  check_function_exists(__ashrdi3 HAVE___ASHRDI3)399  check_function_exists(__divdi3 HAVE___DIVDI3)400  check_function_exists(__fixdfdi HAVE___FIXDFDI)401  check_function_exists(__fixsfdi HAVE___FIXSFDI)402  check_function_exists(__floatdidf HAVE___FLOATDIDF)403  check_function_exists(__lshrdi3 HAVE___LSHRDI3)404  check_function_exists(__moddi3 HAVE___MODDI3)405  check_function_exists(__udivdi3 HAVE___UDIVDI3)406  check_function_exists(__umoddi3 HAVE___UMODDI3)407 408  check_function_exists(__main HAVE___MAIN)409  check_function_exists(__cmpdi2 HAVE___CMPDI2)410endif()411 412CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec413    "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)414if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")415# The st_mtim.tv_nsec member of a `stat` structure is not reliable on some AIX416# environments.417  set(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 0)418else()419  CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec420      "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)421endif()422 423if (NOT WIN32)424  if (LLVM_PTHREAD_LIB)425    list(APPEND CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})426  endif()427  check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP)428  check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)429  check_symbol_exists(pthread_get_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_GET_NAME_NP)430  check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)431  if (LLVM_PTHREAD_LIB)432    list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})433  endif()434 435  if( HAVE_LIBDL )436    list(APPEND CMAKE_REQUIRED_LIBRARIES dl)437  endif()438  # Add the _XOPEN_SOURCE macro on z/OS, as certain test(s) use dlopen439  if (ZOS)440    list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_XOPEN_SOURCE=600")441  endif()442  check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)443  if (ZOS)444    list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS "-D_XOPEN_SOURCE=600")445  endif()446  if( HAVE_LIBDL )447    list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)448  endif()449endif()450 451# available programs checks452function(llvm_find_program name)453  string(TOUPPER ${name} NAME)454  string(REGEX REPLACE "\\." "_" NAME ${NAME})455 456  find_program(LLVM_PATH_${NAME} NAMES ${ARGV})457  mark_as_advanced(LLVM_PATH_${NAME})458  if(LLVM_PATH_${NAME})459    set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")460    mark_as_advanced(HAVE_${NAME})461  else(LLVM_PATH_${NAME})462    set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")463  endif(LLVM_PATH_${NAME})464endfunction()465 466if (LLVM_ENABLE_DOXYGEN)467  llvm_find_program(dot)468endif ()469 470if(LLVM_ENABLE_FFI)471  set(FFI_REQUIRE_INCLUDE On)472  if(LLVM_ENABLE_FFI STREQUAL FORCE_ON)473    find_package(FFI REQUIRED)474  else()475    find_package(FFI)476  endif()477  set(LLVM_ENABLE_FFI "${FFI_FOUND}")478else()479  unset(HAVE_FFI_FFI_H CACHE)480  unset(HAVE_FFI_H CACHE)481  unset(HAVE_FFI_CALL CACHE)482endif()483 484check_symbol_exists(proc_pid_rusage "libproc.h" HAVE_PROC_PID_RUSAGE)485 486# Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.487include(CheckAtomic)488 489if( LLVM_ENABLE_PIC )490  set(ENABLE_PIC 1)491else()492  set(ENABLE_PIC 0)493  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")494endif()495 496set(SUPPORTS_VARIADIC_MACROS_FLAG 0)497if (LLVM_COMPILER_IS_GCC_COMPATIBLE)498  set(SUPPORTS_VARIADIC_MACROS_FLAG 1)499endif()500if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")501  set(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG 1)502else()503  set(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG 0)504endif()505 506set(USE_NO_MAYBE_UNINITIALIZED 0)507set(USE_NO_UNINITIALIZED 0)508 509# Disable gcc's potentially uninitialized use analysis as it presents lots of510# false positives.511if (CMAKE_COMPILER_IS_GNUCXX)512  # Disable all -Wuninitialized warning for old GCC versions.513  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0)514    set(USE_NO_UNINITIALIZED 1)515  else()516    set(USE_NO_MAYBE_UNINITIALIZED 1)517  endif()518endif()519 520if(LLVM_INCLUDE_TESTS)521  include(GetErrcMessages)522  get_errc_messages(LLVM_LIT_ERRC_MESSAGES)523endif()524 525# By default, we target the host, but this can be overridden at CMake526# invocation time.527include(GetHostTriple)528get_host_triple(LLVM_INFERRED_HOST_TRIPLE)529 530set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING531    "Host on which LLVM binaries will run")532message(STATUS "LLVM host triple: ${LLVM_HOST_TRIPLE}")533 534# Determine the native architecture.535string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)536if( LLVM_NATIVE_ARCH STREQUAL "host" )537  string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})538endif ()539 540if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")541  set(LLVM_NATIVE_ARCH X86)542elseif (LLVM_NATIVE_ARCH STREQUAL "x86")543  set(LLVM_NATIVE_ARCH X86)544elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")545  set(LLVM_NATIVE_ARCH X86)546elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")547  set(LLVM_NATIVE_ARCH X86)548elseif (LLVM_NATIVE_ARCH MATCHES "sparc")549  set(LLVM_NATIVE_ARCH Sparc)550elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")551  set(LLVM_NATIVE_ARCH PowerPC)552elseif (LLVM_NATIVE_ARCH MATCHES "ppc64le")553  set(LLVM_NATIVE_ARCH PowerPC)554elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")555  set(LLVM_NATIVE_ARCH AArch64)556elseif (LLVM_NATIVE_ARCH MATCHES "arm64")557  set(LLVM_NATIVE_ARCH AArch64)558elseif (LLVM_NATIVE_ARCH MATCHES "arm")559  set(LLVM_NATIVE_ARCH ARM)560elseif (LLVM_NATIVE_ARCH MATCHES "avr")561  set(LLVM_NATIVE_ARCH AVR)562elseif (LLVM_NATIVE_ARCH MATCHES "mips")563  set(LLVM_NATIVE_ARCH Mips)564elseif (LLVM_NATIVE_ARCH MATCHES "xcore")565  set(LLVM_NATIVE_ARCH XCore)566elseif (LLVM_NATIVE_ARCH MATCHES "msp430")567  set(LLVM_NATIVE_ARCH MSP430)568elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")569  set(LLVM_NATIVE_ARCH Hexagon)570elseif (LLVM_NATIVE_ARCH MATCHES "s390x")571  set(LLVM_NATIVE_ARCH SystemZ)572elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")573  set(LLVM_NATIVE_ARCH WebAssembly)574elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")575  set(LLVM_NATIVE_ARCH WebAssembly)576elseif (LLVM_NATIVE_ARCH MATCHES "riscv32")577  set(LLVM_NATIVE_ARCH RISCV)578elseif (LLVM_NATIVE_ARCH MATCHES "riscv64")579  set(LLVM_NATIVE_ARCH RISCV)580elseif (LLVM_NATIVE_ARCH STREQUAL "m68k")581  set(LLVM_NATIVE_ARCH M68k)582elseif (LLVM_NATIVE_ARCH MATCHES "loongarch")583  set(LLVM_NATIVE_ARCH LoongArch)584else ()585  message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")586endif ()587 588# If build targets includes "host" or "Native", then replace with native architecture.589foreach (NATIVE_KEYWORD host Native)590  list(FIND LLVM_TARGETS_TO_BUILD ${NATIVE_KEYWORD} idx)591  if( NOT idx LESS 0 )592    list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})593    list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})594    list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)595  endif()596endforeach()597 598if (NOT ${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD)599  message(STATUS600    "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")601else ()602  message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")603  set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)604  set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)605  set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)606  set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)607 608  # We don't have an ASM parser for all architectures yet.609  if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)610    set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)611  endif ()612 613  # We don't have an disassembler for all architectures yet.614  if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)615    set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)616  endif ()617endif ()618 619if( MSVC )620  set(SHLIBEXT ".lib")621  set(stricmp "_stricmp")622  set(strdup "_strdup")623 624  # Allow setting clang-cl's /winsysroot flag.625  set(LLVM_WINSYSROOT "" CACHE STRING626    "If set, argument to clang-cl's /winsysroot")627 628  if (LLVM_WINSYSROOT)629    set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH630        "Path to the DIA SDK")631  else()632    set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH633        "Path to the DIA SDK")634  endif()635 636  # See if the DIA SDK is available and usable.637  # Due to a bug in MSVC 2013's installation software, it is possible638  # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012639  # install directory.  If this happens, the installation is corrupt640  # and there's nothing we can do.  It happens with enough frequency641  # though that we should handle it.  We do so by simply checking that642  # the DIA SDK folder exists.  Should this happen you will need to643  # uninstall VS 2012 and then re-install VS 2013.644  if (IS_DIRECTORY "${MSVC_DIA_SDK_DIR}")645    set(HAVE_DIA_SDK 1)646  else()647    set(HAVE_DIA_SDK 0)648  endif()649 650  option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available."651                             ${HAVE_DIA_SDK})652 653  if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK)654    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.")655  endif()656else()657  set(LLVM_ENABLE_DIA_SDK 0)658endif( MSVC )659 660if( LLVM_ENABLE_THREADS )661  # Check if threading primitives aren't supported on this platform662  if( NOT HAVE_PTHREAD_H AND NOT WIN32 )663    set(LLVM_ENABLE_THREADS 0)664  endif()665endif()666 667if( LLVM_ENABLE_THREADS )668  message(STATUS "Threads enabled.")669else( LLVM_ENABLE_THREADS )670  message(STATUS "Threads disabled.")671endif()672 673if (LLVM_ENABLE_DOXYGEN)674  message(STATUS "Doxygen enabled.")675  find_package(Doxygen REQUIRED)676 677  if (DOXYGEN_FOUND)678    # If we find doxygen and we want to enable doxygen by default create a679    # global aggregate doxygen target for generating llvm and any/all680    # subprojects doxygen documentation.681    if (LLVM_BUILD_DOCS)682      add_custom_target(doxygen ALL)683    endif()684 685    option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)686    if (LLVM_DOXYGEN_EXTERNAL_SEARCH)687      set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.")688      set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")689    endif()690  endif()691else()692  message(STATUS "Doxygen disabled.")693endif()694 695find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker")696set(LLVM_BINUTILS_INCDIR "" CACHE PATH697    "PATH to binutils/include containing plugin-api.h for gold plugin.")698 699if(CMAKE_GENERATOR MATCHES "Ninja")700  execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version701    OUTPUT_VARIABLE NINJA_VERSION702    OUTPUT_STRIP_TRAILING_WHITESPACE)703  set(NINJA_VERSION ${NINJA_VERSION} CACHE STRING "Ninja version number" FORCE)704  message(STATUS "Ninja version: ${NINJA_VERSION}")705endif()706 707if(CMAKE_GENERATOR MATCHES "Ninja" AND708    NOT "${NINJA_VERSION}" VERSION_LESS "1.9.0" AND709    CMAKE_HOST_APPLE AND CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER "15.6.0")710  set(LLVM_TOUCH_STATIC_LIBRARIES ON)711endif()712 713if(CMAKE_HOST_APPLE AND APPLE)714  if(NOT LD64_EXECUTABLE)715    if(NOT CMAKE_XCRUN)716      find_program(CMAKE_XCRUN NAMES xcrun)717    endif()718 719    # First, check if there's ld-classic, which is ld64 in newer SDKs.720    if(CMAKE_XCRUN)721      execute_process(COMMAND ${CMAKE_XCRUN} -find ld-classic722        OUTPUT_VARIABLE LD64_EXECUTABLE723        OUTPUT_STRIP_TRAILING_WHITESPACE)724    else()725      find_program(LD64_EXECUTABLE NAMES ld-classic DOC "The ld64 linker")726    endif()727 728    # Otherwise look for ld directly.729    if(NOT LD64_EXECUTABLE)730        if(CMAKE_XCRUN)731          execute_process(COMMAND ${CMAKE_XCRUN} -find ld732            OUTPUT_VARIABLE LD64_EXECUTABLE733            OUTPUT_STRIP_TRAILING_WHITESPACE)734        else()735          find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker")736        endif()737    endif()738  endif()739 740  if(LD64_EXECUTABLE)741    set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable")742    message(STATUS "Found ld64 - ${LD64_EXECUTABLE}")743  endif()744endif()745 746# Keep the version requirements in sync with bindings/ocaml/README.txt.747set(LLVM_BINDINGS "")748include(FindOCaml)749include(AddOCaml)750if(WIN32 OR NOT LLVM_ENABLE_BINDINGS)751  message(STATUS "OCaml bindings disabled.")752else()753  find_package(OCaml)754  if( NOT OCAML_FOUND )755    message(STATUS "OCaml bindings disabled.")756  else()757    if( OCAML_VERSION VERSION_LESS "4.00.0" )758      message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.")759    else()760      find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL)761      if( HAVE_OCAML_CTYPES )762        message(STATUS "OCaml bindings enabled.")763        set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")764 765        set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING766            "Install directory for LLVM OCaml packages")767      else()768        message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")769      endif()770    endif()771  endif()772endif()773 774string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")775 776function(find_python_module module)777  string(REPLACE "." "_" module_name ${module})778  string(TOUPPER ${module_name} module_upper)779  set(FOUND_VAR PY_${module_upper}_FOUND)780  if (DEFINED ${FOUND_VAR})781    return()782  endif()783 784  execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import ${module}"785    RESULT_VARIABLE status786    ERROR_QUIET)787 788  if(status)789    set(${FOUND_VAR} OFF CACHE BOOL "Failed to find python module '${module}'")790    message(STATUS "Could NOT find Python module ${module}")791  else()792  set(${FOUND_VAR} ON CACHE BOOL "Found python module '${module}'")793    message(STATUS "Found Python module ${module}")794  endif()795endfunction()796 797set (PYTHON_MODULES798  pygments799  # Some systems still don't have pygments.lexers.c_cpp which was introduced in800  # version 2.0 in 2014...801  pygments.lexers.c_cpp802  yaml803  )804foreach(module ${PYTHON_MODULES})805  find_python_module(${module})806endforeach()807 808if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND)809  set (LLVM_HAVE_OPT_VIEWER_MODULES 1)810else()811  set (LLVM_HAVE_OPT_VIEWER_MODULES 0)812endif()813 814function(llvm_get_host_prefixes_and_suffixes)815  # Not all platform files will set these variables (relying on them being816  # implicitly empty if they're unset), so unset the variables before including817  # the platform file, to prevent any values from the target system leaking.818  unset(CMAKE_STATIC_LIBRARY_PREFIX)819  unset(CMAKE_STATIC_LIBRARY_SUFFIX)820  unset(CMAKE_SHARED_LIBRARY_PREFIX)821  unset(CMAKE_SHARED_LIBRARY_SUFFIX)822  unset(CMAKE_IMPORT_LIBRARY_PREFIX)823  unset(CMAKE_IMPORT_LIBRARY_SUFFIX)824  unset(CMAKE_EXECUTABLE_SUFFIX)825  unset(CMAKE_LINK_LIBRARY_SUFFIX)826  include(Platform/${CMAKE_HOST_SYSTEM_NAME} OPTIONAL RESULT_VARIABLE _includedFile)827  if (_includedFile)828    set(LLVM_HOST_STATIC_LIBRARY_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX} PARENT_SCOPE)829    set(LLVM_HOST_STATIC_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX} PARENT_SCOPE)830    set(LLVM_HOST_SHARED_LIBRARY_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX} PARENT_SCOPE)831    set(LLVM_HOST_SHARED_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX} PARENT_SCOPE)832    set(LLVM_HOST_IMPORT_LIBRARY_PREFIX ${CMAKE_IMPORT_LIBRARY_PREFIX} PARENT_SCOPE)833    set(LLVM_HOST_IMPORT_LIBRARY_SUFFIX ${CMAKE_IMPORT_LIBRARY_SUFFIX} PARENT_SCOPE)834    set(LLVM_HOST_EXECUTABLE_SUFFIX ${CMAKE_EXECUTABLE_SUFFIX} PARENT_SCOPE)835    set(LLVM_HOST_LINK_LIBRARY_SUFFIX ${CMAKE_LINK_LIBRARY_SUFFIX} PARENT_SCOPE)836  endif()837endfunction()838 839llvm_get_host_prefixes_and_suffixes()840