brintos

brintos / llvm-project-archived public Read only

0
0
Text · 62.7 KiB · 908580f Raw
1552 lines · plain
1# See docs/CMake.html for instructions about how to build LLVM with CMake.2cmake_minimum_required(VERSION 3.20.0)3 4include(CMakeDependentOption)5 6set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)7include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake8  NO_POLICY_SCOPE)9 10# Builds with custom install names and installation rpath setups may not work11# in the build tree. Allow these cases to use CMake's default build tree12# behavior by setting `LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE` to do this.13option(LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE "If set, use CMake's default build tree install name directory logic (Darwin only)" OFF)14mark_as_advanced(LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE)15if(NOT LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE)16  set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)17endif()18 19include(${LLVM_COMMON_CMAKE_UTILS}/Modules/LLVMVersion.cmake)20 21set_directory_properties(PROPERTIES LLVM_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")22 23if (NOT PACKAGE_VERSION)24  set(PACKAGE_VERSION25    "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")26endif()27 28if(NOT DEFINED LLVM_SHLIB_SYMBOL_VERSION)29  # "Symbol version prefix for libLLVM.so and libclang-cpp.so"30  set(LLVM_SHLIB_SYMBOL_VERSION "LLVM_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")31endif()32 33if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (MSVC_TOOLSET_VERSION LESS 142) AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))34  message(WARNING "Visual Studio generators use the x86 host compiler by "35                  "default, even for 64-bit targets. This can result in linker "36                  "instability and out of memory errors. To use the 64-bit "37                  "host compiler, pass -Thost=x64 on the CMake command line.")38endif()39 40if (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_OSX_ARCHITECTURES)41  # Some CMake features like object libraries get confused if you don't42  # explicitly specify an architecture setting with the Xcode generator.43  set(CMAKE_OSX_ARCHITECTURES "x86_64")44endif()45 46project(LLVM47  VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}48  LANGUAGES C CXX ASM)49 50if (NOT DEFINED CMAKE_INSTALL_LIBDIR AND DEFINED LLVM_LIBDIR_SUFFIX)51  # Must go before `include(GNUInstallDirs)`.52  set(CMAKE_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")53endif()54 55# Must go after `DEFINED LLVM_LIBDIR_SUFFIX` check.56set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )57 58# Must go after `project(..)`.59include(GNUInstallDirs)60 61# This C++ standard is required to build LLVM.62set(LLVM_REQUIRED_CXX_STANDARD 17)63 64# If we find that the cache contains CMAKE_CXX_STANDARD it means that it's a old CMakeCache.txt65# and we can just inform the user and then reset it.66if($CACHE{CMAKE_CXX_STANDARD} AND $CACHE{CMAKE_CXX_STANDARD} LESS ${LLVM_REQUIRED_CXX_STANDARD})67  message(WARNING "Resetting cache value for CMAKE_CXX_STANDARD to ${LLVM_REQUIRED_CXX_STANDARD}")68  unset(CMAKE_CXX_STANDARD CACHE)69endif()70 71# if CMAKE_CXX_STANDARD is still set after the cache unset above it means that the user requested it72# and we allow it to be set to something newer than the required standard but otherwise we fail.73if(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS ${LLVM_REQUIRED_CXX_STANDARD})74  message(FATAL_ERROR "Requested CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} which is less than the required ${LLVM_REQUIRED_CXX_STANDARD}.")75endif()76 77set(CMAKE_CXX_STANDARD ${LLVM_REQUIRED_CXX_STANDARD} CACHE STRING "C++ standard to conform to")78set(CMAKE_CXX_STANDARD_REQUIRED YES)79set(CMAKE_CXX_EXTENSIONS NO)80 81if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)82  message(FATAL_ERROR "83No build type selected. You need to pass -DCMAKE_BUILD_TYPE=<type> in order to configure LLVM.84Available options are:85  * -DCMAKE_BUILD_TYPE=Release - For an optimized build with no assertions or debug info.86  * -DCMAKE_BUILD_TYPE=Debug - For an unoptimized build with assertions and debug info.87  * -DCMAKE_BUILD_TYPE=RelWithDebInfo - For an optimized build with no assertions but with debug info.88  * -DCMAKE_BUILD_TYPE=MinSizeRel - For a build optimized for size instead of speed.89Learn more about these options in our documentation at https://llvm.org/docs/CMake.html#cmake-build-type90")91endif()92 93# Set default build type for cmake's try_compile module.94# CMake 3.17 or newer sets CMAKE_DEFAULT_BUILD_TYPE to one of the95# items from CMAKE_CONFIGURATION_TYPES. Logic below can be further96# simplified once LLVM's minimum CMake version is updated to 3.17.97if(CMAKE_DEFAULT_BUILD_TYPE)98  set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_DEFAULT_BUILD_TYPE})99else()100  if(CMAKE_CONFIGURATION_TYPES)101    list(GET CMAKE_CONFIGURATION_TYPES 0 CMAKE_TRY_COMPILE_CONFIGURATION)102  elseif(CMAKE_BUILD_TYPE)103    set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})104  endif()105endif()106 107# Side-by-side subprojects layout: automatically set the108# LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS109# This allows an easy way of setting up a build directory for llvm and another110# one for llvm+clang+... using the same sources.111# These projects will be included when "all" is included in LLVM_ENABLE_PROJECTS.112set(LLVM_ALL_PROJECTS "bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libclc;lld;lldb;mlir;openmp;polly")113if ("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")114  # Disallow 'openmp' as a LLVM PROJECT on AIX as the supported way is to use115  # LLVM_ENABLE_RUNTIMES.116  list(REMOVE_ITEM LLVM_ALL_PROJECTS openmp)117endif()118 119# The "libc" project, which is not part of "all" projects, could be included in120# LLVM_ENABLE_PROJECTS.  It is preferred to include "libc" in121# LLVM_ENABLE_RUNTIMES instead of LLVM_ENABLE_PROJECTS.122#123# The flang project is not yet part of "all" projects (see C++ requirements).124set(LLVM_EXTRA_PROJECTS "flang" "libc")125# List of all known projects in the mono repo126set(LLVM_KNOWN_PROJECTS "${LLVM_ALL_PROJECTS};${LLVM_EXTRA_PROJECTS}")127set(LLVM_ENABLE_PROJECTS "" CACHE STRING128    "Semicolon-separated list of projects to build (${LLVM_KNOWN_PROJECTS}), or \"all\".")129# Make sure expansion happens first to not handle "all" in rest of the checks.130if( LLVM_ENABLE_PROJECTS STREQUAL "all" )131  set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS})132endif()133 134# The pstl project was removed. Ignore it to pacify certain buildbots.135list(FIND LLVM_ENABLE_PROJECTS "pstl" FOUND_INDEX)136if(NOT "${FOUND_INDEX}" STREQUAL "-1")137  message(WARNING "The pstl project has been removed and will not be built")138  list(REMOVE_ITEM LLVM_ENABLE_PROJECTS "pstl")139endif()140 141foreach(proj ${LLVM_ENABLE_PROJECTS})142  if (NOT proj STREQUAL "llvm" AND NOT "${proj}" IN_LIST LLVM_KNOWN_PROJECTS)143     MESSAGE(FATAL_ERROR "${proj} isn't a known project: ${LLVM_KNOWN_PROJECTS}. Did you mean to enable it as a runtime in LLVM_ENABLE_RUNTIMES?")144  endif()145endforeach()146 147# Select the runtimes to build148#149# As we migrate runtimes to using the bootstrapping build, the set of default runtimes150# should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.151set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")152set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;libcxx;compiler-rt;openmp;llvm-libgcc;offload;flang-rt;libclc;libsycl;orc-rt")153set(LLVM_ENABLE_RUNTIMES "" CACHE STRING154  "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")155if(LLVM_ENABLE_RUNTIMES STREQUAL "all")156  set(LLVM_ENABLE_RUNTIMES ${LLVM_DEFAULT_RUNTIMES})157endif()158foreach(proj IN LISTS LLVM_ENABLE_RUNTIMES)159  if (NOT "${proj}" IN_LIST LLVM_SUPPORTED_RUNTIMES)160    message(FATAL_ERROR "Runtime \"${proj}\" is not a supported runtime. Supported runtimes are: ${LLVM_SUPPORTED_RUNTIMES}")161  endif()162endforeach()163 164if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)165  if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)166    message(STATUS "Enabling MLIR as a dependency to flang")167    list(APPEND LLVM_ENABLE_PROJECTS "mlir")168  endif()169 170  if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)171    message(STATUS "Enabling clang as a dependency to flang")172    list(APPEND LLVM_ENABLE_PROJECTS "clang")173  endif()174 175  option(FLANG_ENABLE_FLANG_RT "Implicitly add LLVM_ENABLE_RUNTIMES=flang-rt when compiling Flang" ON)176  if (FLANG_ENABLE_FLANG_RT AND NOT "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)177    message(STATUS "Enabling Flang-RT as a dependency of Flang")178    list(APPEND LLVM_ENABLE_RUNTIMES "flang-rt")179  endif ()180endif()181 182if ("lldb" IN_LIST LLVM_ENABLE_PROJECTS)183  if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)184    message(STATUS "Enabling clang as a dependency of lldb")185    list(APPEND LLVM_ENABLE_PROJECTS "clang")186  endif()187endif ()188 189if ("libc" IN_LIST LLVM_ENABLE_PROJECTS)190  message(WARNING "Using LLVM_ENABLE_PROJECTS=libc is deprecated now, and will "191    "become a fatal error in a future release. Please use "192    "-DLLVM_ENABLE_RUNTIMES=libc or see the instructions at "193    "https://libc.llvm.org/ for building the runtimes.")194endif()195 196if ("compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS)197  message(WARNING "Using LLVM_ENABLE_PROJECTS=compiler-rt is deprecated now, and will "198    "become a fatal error in a future release.  Please use "199    "-DLLVM_ENABLE_RUNTIMES=compiler-rt or see the instructions at "200    "https://compiler-rt.llvm.org/ for building the runtimes.")201endif()202 203if ("offload" IN_LIST LLVM_ENABLE_PROJECTS)204  message(WARNING "Using LLVM_ENABLE_PROJECTS=offload is deprecated now, and will "205    "become a fatal error in a future release.  Please use "206    "-DLLVM_ENABLE_RUNTIMES=offload or see the instructions at "207    "https://openmp.llvm.org/ for building the runtimes.")208endif()209 210if ("openmp" IN_LIST LLVM_ENABLE_PROJECTS)211  message(WARNING "Using LLVM_ENABLE_PROJECTS=openmp is deprecated now, and will "212    "become a fatal error in a future release.  Please use "213    "-DLLVM_ENABLE_RUNTIMES=openmp or see the instructions at "214    "https://openmp.llvm.org/ for building the runtimes.")215endif()216 217if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)218  if (NOT "flang" IN_LIST LLVM_ENABLE_PROJECTS)219    message(FATAL_ERROR "Flang is not enabled, but is required for the Flang-RT runtime")220  endif ()221endif ()222 223if ("libclc" IN_LIST LLVM_ENABLE_PROJECTS)224  message(WARNING "Using LLVM_ENABLE_PROJECTS=libclc is deprecated now, and will "225    "become a fatal error in a future release.  Please use "226    "-DLLVM_ENABLE_RUNTIMES=libclc or see the instructions at "227    "https://libclc.llvm.org/ for building the runtimes.")228endif()229 230# Set a shorthand option to enable the GPU build of the 'libc' project.231option(LIBC_GPU_BUILD "Enable the 'libc' project targeting the GPU" OFF)232if(LIBC_GPU_BUILD)233  if(LLVM_RUNTIME_TARGETS)234    list(APPEND LLVM_RUNTIME_TARGETS "nvptx64-nvidia-cuda" "amdgcn-amd-amdhsa")235  else()236    set(LLVM_RUNTIME_TARGETS "default;nvptx64-nvidia-cuda;amdgcn-amd-amdhsa")237  endif()238  list(APPEND RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES "libc")239  list(APPEND RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES "libc")240endif()241 242foreach(_name ${LLVM_RUNTIME_TARGETS})243  if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)244    if("${_name}" STREQUAL "amdgcn-amd-amdhsa" OR "${_name}" STREQUAL "nvptx64-nvidia-cuda")245      set(LLVM_LIBC_GPU_BUILD ON)246    endif()247  endif()248endforeach()249if("${LIBC_TARGET_TRIPLE}" STREQUAL "amdgcn-amd-amdhsa" OR250   "${LIBC_TARGET_TRIPLE}" STREQUAL "nvptx64-nvidia-cuda")251  set(LLVM_LIBC_GPU_BUILD ON)252endif()253 254# LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the255# `LLVM_ENABLE_PROJECTS` CMake cache variable.  This exists for256# several reasons:257#258# * As an indicator that the `LLVM_ENABLE_PROJECTS` list is now the single259# source of truth for which projects to build. This means we will ignore user260# supplied `LLVM_TOOL_<project>_BUILD` CMake cache variables and overwrite261# them.262#263# * The case where the user previously had `LLVM_ENABLE_PROJECTS` set to a264# non-empty list but now the user wishes to disable building all other projects265# by setting `LLVM_ENABLE_PROJECTS` to an empty string. In that case we still266# need to set the `LLVM_TOOL_${upper_proj}_BUILD` variables so that we disable267# building all the projects that were previously enabled.268set(LLVM_ENABLE_PROJECTS_USED OFF CACHE BOOL "")269mark_as_advanced(LLVM_ENABLE_PROJECTS_USED)270 271if (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "")272  set(LLVM_ENABLE_PROJECTS_USED ON CACHE BOOL "" FORCE)273  foreach(proj ${LLVM_KNOWN_PROJECTS} ${LLVM_EXTERNAL_PROJECTS})274    string(TOUPPER "${proj}" upper_proj)275    string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})276    if ("${proj}" IN_LIST LLVM_ENABLE_PROJECTS)277      message(STATUS "${proj} project is enabled")278      set(SHOULD_ENABLE_PROJECT TRUE)279      set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")280      if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")281        message(FATAL_ERROR "LLVM_ENABLE_PROJECTS requests ${proj} but directory not found: ${PROJ_DIR}")282      endif()283      if( LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" )284        set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "" FORCE)285      else()286        set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "")287      endif()288    elseif ("${proj}" IN_LIST LLVM_EXTERNAL_PROJECTS)289      message(STATUS "${proj} project is enabled")290      set(SHOULD_ENABLE_PROJECT TRUE)291    else()292      message(STATUS "${proj} project is disabled")293      set(SHOULD_ENABLE_PROJECT FALSE)294    endif()295    # Force `LLVM_TOOL_${upper_proj}_BUILD` variables to have values that296    # corresponds with `LLVM_ENABLE_PROJECTS`. This prevents the user setting297    # `LLVM_TOOL_${upper_proj}_BUILD` variables externally. At some point298    # we should deprecate allowing users to set these variables by turning them299    # into normal CMake variables rather than cache variables.300    set(LLVM_TOOL_${upper_proj}_BUILD301      ${SHOULD_ENABLE_PROJECT}302      CACHE303      BOOL "Whether to build ${upper_proj} as part of LLVM" FORCE304    )305  endforeach()306endif()307unset(SHOULD_ENABLE_PROJECT)308 309# Build llvm with ccache if the package is present310set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")311if(LLVM_CCACHE_BUILD)312  find_program(CCACHE_PROGRAM ccache)313  if(CCACHE_PROGRAM)314    set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")315    set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")316    set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros"317        CACHE STRING "Parameters to pass through to ccache")318 319    if(NOT CMAKE_HOST_WIN32)320      set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")321      if (LLVM_CCACHE_MAXSIZE)322        set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")323      endif()324      if (LLVM_CCACHE_DIR)325        set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")326      endif()327      set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})328    else()329      # Until a way to reliably configure ccache on Windows is found,330      # disable precompiled headers for Windows + ccache builds331      if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)332        message(WARNING "Using ccache with precompiled headers on Windows is currently not supported.333          CMAKE_DISABLE_PRECOMPILE_HEADERS will be set to ON.")334        set(CMAKE_DISABLE_PRECOMPILE_HEADERS "ON")335      endif()336      if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR337         NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros")338        message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")339      endif()340      # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues341      # with cmd.exe and some MSVC tools other than cl.exe342      set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})343      set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})344    endif()345  else()346    message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")347  endif()348endif()349 350set(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS "" CACHE STRING351  "Optional arguments for the native tool used in CMake --build invocations for external projects.")352mark_as_advanced(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS)353 354option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF)355 356# Some features of the LLVM build may be disallowed when dependency debugging is357# enabled. In particular you cannot use ccache because we want to force compile358# operations to always happen.359if(LLVM_DEPENDENCY_DEBUGGING)360  if(NOT CMAKE_HOST_APPLE)361    message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.")362  endif()363  if(LLVM_CCACHE_BUILD)364    message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.")365  endif()366endif()367 368option(LLVM_ENABLE_DAGISEL_COV "Debug: Prints tablegen patterns that were used for selecting" OFF)369option(LLVM_ENABLE_GISEL_COV "Enable collection of GlobalISel rule coverage" OFF)370if(LLVM_ENABLE_GISEL_COV)371  set(LLVM_GISEL_COV_PREFIX "${CMAKE_BINARY_DIR}/gisel-coverage-" CACHE STRING "Provide a filename prefix to collect the GlobalISel rule coverage")372endif()373 374# Add path for custom modules375list(INSERT CMAKE_MODULE_PATH 0376  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"377  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"378  "${LLVM_COMMON_CMAKE_UTILS}/Modules"379  )380 381# Generate a CompilationDatabase (compile_commands.json file) for our build,382# for use by clang_complete, YouCompleteMe, etc.383set(CMAKE_EXPORT_COMPILE_COMMANDS 1)384 385option(LLVM_INSTALL_BINUTILS_SYMLINKS386  "Install symlinks from the binutils tool names to the corresponding LLVM tools." OFF)387 388option(LLVM_INSTALL_CCTOOLS_SYMLINKS389  "Install symlinks from the cctools tool names to the corresponding LLVM tools." OFF)390 391# By default we use symlinks on Unix platforms and copy binaries on Windows392# If you have the correct setup on Windows you can use this option to enable393# symlinks and save a lot of diskspace.394option(LLVM_USE_SYMLINKS "Use symlinks instead of copying binaries" ${CMAKE_HOST_UNIX})395 396option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)397 398option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)399 400# Unfortunatly Clang is too eager to search directories for module maps, which can cause the401# installed version of the maps to be found when building LLVM from source. Therefore we turn off402# the installation by default. See llvm.org/PR31905.403option(LLVM_INSTALL_MODULEMAPS "Install the modulemap files in the 'install' target." OFF)404 405option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)406if ( LLVM_USE_FOLDERS )407  set_property(GLOBAL PROPERTY USE_FOLDERS ON)408endif()409 410include(VersionFromVCS)411 412option(LLVM_APPEND_VC_REV413  "Embed the version control system revision in LLVM" ON)414 415set(LLVM_FORCE_VC_REVISION416  "" CACHE STRING "Force custom VC revision for LLVM_APPEND_VC_REV")417 418set(LLVM_FORCE_VC_REPOSITORY419  "" CACHE STRING "Force custom VC repository for LLVM_APPEND_VC_REV")420 421option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OFF)422 423set(PACKAGE_NAME LLVM)424set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")425set(PACKAGE_BUGREPORT "https://github.com/llvm/llvm-project/issues/")426 427set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING428  "Default URL where bug reports are to be submitted.")429set(LLDB_BUG_REPORT_URL "${BUG_REPORT_URL}" CACHE STRING430  "Default URL where lldb bug reports are to be submitted.")431 432# Configure CPack.433if(NOT DEFINED CPACK_PACKAGE_INSTALL_DIRECTORY)434  set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")435endif()436if(NOT DEFINED CPACK_PACKAGE_VENDOR)437  set(CPACK_PACKAGE_VENDOR "LLVM")438endif()439set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})440set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})441set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})442set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})443set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")444if(WIN32 AND NOT UNIX)445  set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")446  if(NOT DEFINED CPACK_PACKAGE_INSTALL_REGISTRY_KEY)447    set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")448  endif()449  set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")450  set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")451  set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")452  set(CPACK_NSIS_MODIFY_PATH "ON")453  set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")454  if( CMAKE_CL_64 )455    if(NOT DEFINED CPACK_NSIS_INSTALL_ROOT)456      set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")457    endif()458  endif()459endif()460include(CPack)461 462# Sanity check our source directory to make sure that we are not trying to463# generate an in-source build (unless on MSVC_IDE, where it is ok), and to make464# sure that we don't have any stray generated files lying around in the tree465# (which would end up getting picked up by header search, instead of the correct466# versions).467if( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE )468  message(FATAL_ERROR "In-source builds are not allowed.469Please create a directory and run cmake from there, passing the path470to this source directory as the last argument.471This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.472Please delete them.")473endif()474 475string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)476 477option(LLVM_ADDITIONAL_BUILD_TYPES "Additional build types that are allowed to be passed into CMAKE_BUILD_TYPE" "")478 479set(ALLOWED_BUILD_TYPES DEBUG RELEASE RELWITHDEBINFO MINSIZEREL ${LLVM_ADDITIONAL_BUILD_TYPES})480string (REPLACE ";" "|" ALLOWED_BUILD_TYPES_STRING "${ALLOWED_BUILD_TYPES}")481string (TOUPPER "${ALLOWED_BUILD_TYPES_STRING}" uppercase_ALLOWED_BUILD_TYPES)482 483if (CMAKE_BUILD_TYPE AND484    NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(${uppercase_ALLOWED_BUILD_TYPES})$")485  message(FATAL_ERROR "Unknown value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")486endif()487 488# LLVM_INSTALL_PACKAGE_DIR needs to be declared prior to adding the tools489# subdirectory in order to have the value available for llvm-config.490include(GNUInstallPackageDir)491set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING492  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")493 494set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING495    "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")496mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)497 498set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING499    "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)")500mark_as_advanced(LLVM_UTILS_INSTALL_DIR)501 502set(LLVM_EXAMPLES_INSTALL_DIR "examples" CACHE STRING503    "Path for examples subdirectory (enabled by LLVM_BUILD_EXAMPLES=ON) (defaults to 'examples')")504mark_as_advanced(LLVM_EXAMPLES_INSTALL_DIR)505 506# They are used as destination of target generators.507set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)508set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})509if(WIN32 OR CYGWIN)510  # DLL platform -- put DLLs into bin.511  set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})512else()513  set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})514endif()515 516# Each of them corresponds to llvm-config's.517set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir518set(LLVM_LIBRARY_DIR      ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir519set(LLVM_MAIN_SRC_DIR     ${CMAKE_CURRENT_SOURCE_DIR}  ) # --src-root520set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir521set(LLVM_BINARY_DIR       ${CMAKE_CURRENT_BINARY_DIR}  ) # --prefix522 523 524# Note: LLVM_CMAKE_DIR does not include generated files525set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)526set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)527set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)528 529# List of all targets to be built by default:530set(LLVM_ALL_TARGETS531  AArch64532  AMDGPU533  ARM534  AVR535  BPF536  Hexagon537  Lanai538  LoongArch539  Mips540  MSP430541  NVPTX542  PowerPC543  RISCV544  Sparc545  SPIRV546  SystemZ547  VE548  WebAssembly549  X86550  XCore551  )552 553set(LLVM_ALL_EXPERIMENTAL_TARGETS554  ARC555  CSKY556  DirectX557  M68k558  Xtensa559)560 561# List of targets with JIT support:562set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)563 564set(LLVM_TARGETS_TO_BUILD "all"565    CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")566 567set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""568    CACHE STRING "Semicolon-separated list of experimental targets to build, or \"all\".")569 570option(BUILD_SHARED_LIBS571  "Build all libraries as shared libraries instead of static" OFF)572 573option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)574if(LLVM_ENABLE_BACKTRACES)575  set(ENABLE_BACKTRACES 1)576endif()577 578option(LLVM_ENABLE_UNWIND_TABLES "Emit unwind tables for the libraries" ON)579 580option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)581if(LLVM_ENABLE_CRASH_OVERRIDES)582  set(ENABLE_CRASH_OVERRIDES 1)583endif()584 585option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF)586 587set(LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING "DISABLED" CACHE STRING588  "Enhance Debugify's line number coverage tracking; enabling this is ABI-breaking. Can be DISABLED, COVERAGE, or COVERAGE_AND_ORIGIN.")589set_property(CACHE LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING PROPERTY STRINGS DISABLED COVERAGE COVERAGE_AND_ORIGIN)590 591set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)592if (MINGW)593  # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix594  # as native path style, regardless of what this is set to.595  set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT ON)596endif()597option(LLVM_WINDOWS_PREFER_FORWARD_SLASH "Prefer path names with forward slashes on Windows." ${WINDOWS_PREFER_FORWARD_SLASH_DEFAULT})598 599option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)600set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")601set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")602 603set(LLVM_TARGET_ARCH "host"604  CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")605 606set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")607 608option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)609 610option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON)611 612# On z/OS, threads cannot be used because TLS is not supported.613if (CMAKE_SYSTEM_NAME MATCHES "OS390")614  option(LLVM_ENABLE_THREADS "Use threads if available." OFF)615else()616  option(LLVM_ENABLE_THREADS "Use threads if available." ON)617endif()618 619set(LLVM_ENABLE_ICU "OFF" CACHE STRING "Use ICU for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")620 621set(LLVM_ENABLE_ICONV "OFF" CACHE STRING "Use iconv for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")622 623set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")624 625set(LLVM_ENABLE_ZSTD "ON" CACHE STRING "Use zstd for compression/decompression if available. Can be ON, OFF, or FORCE_ON")626 627set(LLVM_USE_STATIC_ZSTD FALSE CACHE BOOL "Use static version of zstd. Can be TRUE, FALSE")628 629set(LLVM_ENABLE_CURL "OFF" CACHE STRING "Use libcurl for the HTTP client if available. Can be ON, OFF, or FORCE_ON")630 631set(LLVM_HAS_LOGF128 "OFF" CACHE STRING "Use logf128 to constant fold fp128 logarithm calls. Can be ON, OFF, or FORCE_ON")632 633set(LLVM_ENABLE_HTTPLIB "OFF" CACHE STRING "Use cpp-httplib HTTP server library if available. Can be ON, OFF, or FORCE_ON")634 635set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")636 637option(LLVM_ENABLE_Z3_SOLVER638  "Enable Support for the Z3 constraint solver in LLVM."639  ${LLVM_ENABLE_Z3_SOLVER_DEFAULT}640)641 642if (LLVM_ENABLE_Z3_SOLVER)643  find_package(Z3 4.8.9)644 645  if (LLVM_Z3_INSTALL_DIR)646    if (NOT Z3_FOUND)647      message(FATAL_ERROR "Z3 >= 4.8.9 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.")648    endif()649  endif()650 651  if (NOT Z3_FOUND)652    message(FATAL_ERROR "LLVM_ENABLE_Z3_SOLVER cannot be enabled when Z3 is not available.")653  endif()654 655  set(LLVM_WITH_Z3 1)656endif()657 658set(LLVM_ENABLE_Z3_SOLVER_DEFAULT "${Z3_FOUND}")659 660 661if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )662  set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )663endif()664 665if(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD STREQUAL "all")666  set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${LLVM_ALL_EXPERIMENTAL_TARGETS})667endif()668 669if("flang" IN_LIST LLVM_ENABLE_PROJECTS AND670   "AArch64" IN_LIST LLVM_TARGETS_TO_BUILD AND671   NOT ("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES OR "compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS))672  message(STATUS "Enabling compiler-rt as a dependency of Flang")673  list(APPEND LLVM_ENABLE_RUNTIMES "compiler-rt")674endif()675 676set(LLVM_TARGETS_TO_BUILD677   ${LLVM_TARGETS_TO_BUILD}678   ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})679list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)680 681if (NOT CMAKE_SYSTEM_NAME MATCHES "OS390")682  option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)683endif()684option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)685if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")686  option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)687else()688  option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)689endif()690option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)691option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)692option(LLVM_ENABLE_LLVM_LIBC "Set to on to link all LLVM executables against LLVM libc, assuming it is accessible by the host compiler." OFF)693option(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF)694option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)695option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)696option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)697 698option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)699option(LLVM_UNREACHABLE_OPTIMIZE "Optimize llvm_unreachable() as undefined behavior (default), guaranteed trap when OFF" ON)700 701if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )702  option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)703else()704  option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)705endif()706 707option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)708 709set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING710  "Enable abi-breaking checks.  Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")711 712option(LLVM_FORCE_USE_OLD_TOOLCHAIN713       "Set to ON to force using an old, unsupported host toolchain." OFF)714 715set(LLVM_LOCAL_RPATH "" CACHE FILEPATH716  "If set, an absolute path added as rpath on binaries that do not already contain an executable-relative rpath.")717 718option(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN719       "Set to ON to only warn when using a toolchain which is about to be deprecated, instead of emitting an error." OFF)720 721option(LLVM_USE_INTEL_JITEVENTS722  "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"723  OFF)724 725if( LLVM_USE_INTEL_JITEVENTS )726  # Verify we are on a supported platform727  if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )728    message(FATAL_ERROR729      "Intel JIT API support is available on Linux and Windows only.")730  endif()731endif( LLVM_USE_INTEL_JITEVENTS )732 733option(LLVM_USE_OPROFILE734  "Use opagent JIT interface to inform OProfile about JIT code" OFF)735 736option(LLVM_EXTERNALIZE_DEBUGINFO737  "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)738 739option(LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES740  "Preserve exported symbols in executables" ON)741 742set(LLVM_CODESIGNING_IDENTITY "" CACHE STRING743  "Sign executables and dylibs with the given identity or skip if empty (Darwin Only)")744 745# If enabled, verify we are on a platform that supports oprofile.746if( LLVM_USE_OPROFILE )747  if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )748    message(FATAL_ERROR "OProfile support is available on Linux only.")749  endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )750endif( LLVM_USE_OPROFILE )751 752option(LLVM_USE_PERF753  "Use perf JIT interface to inform perf about JIT code" OFF)754 755# If enabled, verify we are on a platform that supports perf.756if( LLVM_USE_PERF )757  if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )758    message(FATAL_ERROR "perf support is available on Linux only.")759  endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )760endif( LLVM_USE_PERF )761 762set(LLVM_USE_SANITIZER "" CACHE STRING763  "Define the sanitizer used to build binaries and tests.")764option(LLVM_OPTIMIZE_SANITIZED_BUILDS "Pass -O1 on debug sanitizer builds" ON)765set(LLVM_UBSAN_FLAGS766    "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"767    CACHE STRING768    "Compile flags set to enable UBSan. Only used if LLVM_USE_SANITIZER contains 'Undefined'.")769set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH770  "Path to fuzzing library for linking with fuzz targets")771 772option(LLVM_USE_SPLIT_DWARF773  "Use -gsplit-dwarf when compiling llvm and --gdb-index when linking." OFF)774 775# Define an option controlling whether we should build for 32-bit on 64-bit776# platforms, where supported.777if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT (WIN32 OR "${CMAKE_SYSTEM_NAME}" MATCHES "AIX"))778  # TODO: support other platforms and toolchains.779  option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)780endif()781 782# Define the default arguments to use with 'lit', and an option for the user to783# override.784set(LIT_ARGS_DEFAULT "-sv")785if (MSVC_IDE OR XCODE)786  set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")787endif()788if(LLVM_INDIVIDUAL_TEST_COVERAGE)789   set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --per-test-coverage")790endif()791set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")792 793# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.794if( WIN32 AND NOT CYGWIN )795  set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")796endif()797set(LLVM_NATIVE_TOOL_DIR "" CACHE PATH "Path to a directory containing prebuilt matching native tools (such as llvm-tblgen)")798 799set(LLVM_ENABLE_RPMALLOC "" CACHE BOOL "Replace the CRT allocator with rpmalloc.")800if(LLVM_ENABLE_RPMALLOC)801  if(NOT (CMAKE_SYSTEM_NAME MATCHES "Windows|Linux"))802    message(FATAL_ERROR "LLVM_ENABLE_RPMALLOC is only supported on Windows and Linux.")803  endif()804  if(LLVM_USE_SANITIZER)805    message(FATAL_ERROR "LLVM_ENABLE_RPMALLOC cannot be used along with LLVM_USE_SANITIZER!")806  endif()807  if(WIN32)808    if(CMAKE_CONFIGURATION_TYPES)809      foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES})810        string(TOUPPER "${BUILD_MODE}" uppercase_BUILD_MODE)811        if(uppercase_BUILD_MODE STREQUAL "DEBUG")812          message(WARNING "The Debug target isn't supported along with LLVM_ENABLE_RPMALLOC!")813        endif()814      endforeach()815    else()816      if(CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")817        message(FATAL_ERROR "The Debug target isn't supported along with LLVM_ENABLE_RPMALLOC!")818      endif()819    endif()820  endif()821 822  # Override the C runtime allocator with the in-tree rpmalloc823  set(LLVM_INTEGRATED_CRT_ALLOC "${CMAKE_CURRENT_SOURCE_DIR}/lib/Support")824  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")825endif()826 827set(LLVM_INTEGRATED_CRT_ALLOC "${LLVM_INTEGRATED_CRT_ALLOC}" CACHE PATH "Replace the Windows CRT allocator with any of {rpmalloc|mimalloc|snmalloc}. Only works with CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded.")828if(LLVM_INTEGRATED_CRT_ALLOC)829  if(NOT WIN32)830    message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows.")831  endif()832  if(LLVM_USE_SANITIZER)833    message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used along with LLVM_USE_SANITIZER!")834  endif()835  if(CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")836    message(FATAL_ERROR "The Debug target isn't supported along with LLVM_INTEGRATED_CRT_ALLOC!")837  endif()838endif()839 840# Define options to control the inclusion and default build behavior for841# components which may not strictly be necessary (tools, examples, and tests).842#843# This is primarily to support building smaller or faster project files.844option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)845option(LLVM_BUILD_TOOLS846  "Build the LLVM tools. If OFF, just generate build targets." ON)847 848option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)849option(LLVM_BUILD_UTILS850  "Build LLVM utility binaries. If OFF, just generate build targets." ON)851 852option(LLVM_INCLUDE_RUNTIMES "Generate build targets for the LLVM runtimes." ON)853option(LLVM_BUILD_RUNTIMES854  "Build the LLVM runtimes. If OFF, just generate build targets." ON)855 856option(LLVM_BUILD_RUNTIME857  "Build the LLVM runtime libraries." ON)858option(LLVM_BUILD_EXAMPLES859  "Build the LLVM example programs. If OFF, just generate build targets." OFF)860option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)861 862option(LLVM_BUILD_TESTS863  "Build LLVM unit tests. If OFF, just generate build targets." OFF)864option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)865 866option(LLVM_INSTALL_GTEST867  "Install the llvm gtest library.  This should be on if you want to do868   stand-alone builds of the other projects and run their unit tests." OFF)869 870option(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default871targets. If OFF, benchmarks still could be built using Benchmarks target." OFF)872option(LLVM_INCLUDE_BENCHMARKS "Generate benchmark targets. If OFF, benchmarks can't be built." ON)873 874option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)875option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)876option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)877option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)878option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)879option (LLVM_ENABLE_BINDINGS "Build bindings." ON)880option (LLVM_ENABLE_TELEMETRY "Enable the telemetry library. If set to OFF, library cannot be enabled after build (eg., at runtime)" ON)881 882set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html"883    CACHE STRING "Doxygen-generated HTML documentation install directory")884set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/ocaml-html"885    CACHE STRING "OCamldoc-generated HTML documentation install directory")886 887option (LLVM_BUILD_EXTERNAL_COMPILER_RT888  "Build compiler-rt as an external project." OFF)889 890option (LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO891  "Show target and host info when tools are invoked with --version." ON)892 893option(LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG894  "Show the optional build config flags when tools are invoked with --version." ON)895 896# You can configure which libraries from LLVM you want to include in the897# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited898# list of LLVM components. All component names handled by llvm-config are valid.899if(NOT DEFINED LLVM_DYLIB_COMPONENTS)900  set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING901    "Semicolon-separated list of components to include in libLLVM, or \"all\".")902endif()903 904if(MSVC)905  option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" ON)906  if (BUILD_SHARED_LIBS)907    message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.")908  endif()909else()910  option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)911endif()912 913# Used to test building the llvm shared library with explicit symbol visibility on914# Windows and Linux. For ELF platforms default symbols visibility is set to hidden.915set(LLVM_BUILD_LLVM_DYLIB_VIS FALSE CACHE BOOL "")916mark_as_advanced(LLVM_BUILD_LLVM_DYLIB_VIS)917 918set(CAN_BUILD_LLVM_DYLIB OFF)919if(NOT MSVC OR LLVM_BUILD_LLVM_DYLIB_VIS)920  set(CAN_BUILD_LLVM_DYLIB ON)921endif()922 923cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF924                       "CAN_BUILD_LLVM_DYLIB" OFF)925 926set(LLVM_BUILD_LLVM_DYLIB_default OFF)927if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)928  set(LLVM_BUILD_LLVM_DYLIB_default ON)929endif()930cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}931                       "CAN_BUILD_LLVM_DYLIB" OFF)932 933cmake_dependent_option(LLVM_DYLIB_EXPORT_INLINES "Force inline members of classes to be DLL exported when934                       building with clang-cl so the libllvm DLL is compatible with MSVC"935                       OFF936                       "MSVC;LLVM_BUILD_LLVM_DYLIB_VIS" OFF)937 938if(LLVM_BUILD_LLVM_DYLIB_VIS)939  set(LLVM_BUILD_LLVM_DYLIB ON)940endif()941 942if (LLVM_LINK_LLVM_DYLIB AND BUILD_SHARED_LIBS)943  message(FATAL_ERROR "Cannot enable BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB.  We recommend disabling BUILD_SHARED_LIBS.")944endif()945 946option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)947if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS948  OR CMAKE_CONFIGURATION_TYPES OR LLVM_USE_SANITIZER)))949  set(LLVM_USE_HOST_TOOLS ON)950endif()951 952option(LLVM_OMIT_DAGISEL_COMMENTS "Do not add comments to DAG ISel" ON)953if (CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE MATCHES "^(RELWITHDEBINFO|DEBUG)$")954  set(LLVM_OMIT_DAGISEL_COMMENTS OFF)955endif()956 957if (MSVC_IDE)958  option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)959endif()960 961if(NOT LLVM_INDIVIDUAL_TEST_COVERAGE)962  if(LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE OR LLVM_ENABLE_IR_PGO)963    if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)964      # A pool size of 1-2 is probably sufficient on an SSD. 3-4 should be fine965      # for spinning disks. Anything higher may only help on slower mediums.966      set(LLVM_PROFILE_MERGE_POOL_SIZE "4")967    endif()968    if(NOT LLVM_PROFILE_FILE_PATTERN)969      if(NOT LLVM_PROFILE_DATA_DIR)970        file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles" LLVM_PROFILE_DATA_DIR)971      endif()972      file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)973    endif()974    if(NOT LLVM_CSPROFILE_FILE_PATTERN)975      if(NOT LLVM_CSPROFILE_DATA_DIR)976        file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/csprofiles" LLVM_CSPROFILE_DATA_DIR)977      endif()978      file(TO_NATIVE_PATH "${LLVM_CSPROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_CSPROFILE_FILE_PATTERN)979    endif()980  endif()981endif()982 983if (LLVM_BUILD_STATIC)984  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")985  # Remove shared library suffixes from use in find_library986  foreach (shared_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_IMPORT_LIBRARY_SUFFIX})987    list(FIND CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix} shared_lib_suffix_idx)988    if(NOT ${shared_lib_suffix_idx} EQUAL -1)989      list(REMOVE_AT CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix_idx})990    endif()991  endforeach()992endif()993 994# Use libtool instead of ar if you are both on an Apple host, and targeting Apple.995if(CMAKE_HOST_APPLE AND APPLE)996  include(UseLibtool)997endif()998 999# Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.1000set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")1001mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)1002 1003if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux|OS390|AIX")1004  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)1005else()1006  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF)1007endif()1008set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default} CACHE BOOL1009  "Enable per-target runtimes directory")1010 1011set(LLVM_PROFDATA_FILE "" CACHE FILEPATH1012  "Profiling data file to use when compiling in order to improve runtime performance.")1013 1014set(LLVM_SPROFDATA_FILE "" CACHE FILEPATH1015  "Sampling profiling data file to use when compiling in order to improve runtime performance.")1016 1017if(LLVM_INCLUDE_TESTS)1018  # All LLVM Python files should be compatible down to this minimum version.1019  set(LLVM_MINIMUM_PYTHON_VERSION 3.8)1020else()1021  # FIXME: it is unknown if this is the actual minimum bound1022  set(LLVM_MINIMUM_PYTHON_VERSION 3.0)1023endif()1024 1025# Find python before including config-ix, since it needs to be able to search1026# for python modules.1027find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED1028    COMPONENTS Interpreter)1029 1030# All options referred to from HandleLLVMOptions have to be specified1031# BEFORE this include, otherwise options will not be correctly set on1032# first cmake run1033include(config-ix)1034 1035# By default, we target the host, but this can be overridden at CMake1036# invocation time. Except on 64-bit AIX, where the system toolchain1037# expect 32-bit objects by default.1038if("${LLVM_HOST_TRIPLE}" MATCHES "^powerpc64-ibm-aix")1039  string(REGEX REPLACE "^powerpc64" "powerpc" LLVM_DEFAULT_TARGET_TRIPLE_DEFAULT "${LLVM_HOST_TRIPLE}")1040else()1041  # Only set default triple when native target is enabled.1042  if (LLVM_NATIVE_TARGET)1043    set(LLVM_DEFAULT_TARGET_TRIPLE_DEFAULT "${LLVM_HOST_TRIPLE}")1044  endif()1045endif()1046 1047set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE_DEFAULT}" CACHE STRING1048    "Default target for which LLVM will generate code." )1049message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")1050 1051set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")1052 1053if(WIN32 OR CYGWIN)1054  if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)1055    set(LLVM_ENABLE_PLUGINS_default ON)1056  else()1057    set(LLVM_ENABLE_PLUGINS_default OFF)1058  endif()1059else()1060  set(LLVM_ENABLE_PLUGINS_default ${LLVM_ENABLE_PIC})1061endif()1062option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})1063 1064set(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS OFF)1065if (LLVM_BUILD_LLVM_DYLIB OR LLVM_BUILD_SHARED_LIBS OR LLVM_ENABLE_PLUGINS)1066  # Export annotations for LLVM must be enabled if building as a shared lib or1067  # enabling plugins.1068  set(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS ON)1069endif()1070 1071# Because LLVM-C is built into the LLVM library, for now export its symbols1072# whenever LLVM symbols are exported.1073set(LLVM_ENABLE_LLVM_C_EXPORT_ANNOTATIONS ${LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS})1074 1075set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL1076  "Enable the new pass manager by default.")1077if(NOT LLVM_ENABLE_NEW_PASS_MANAGER)1078  message(FATAL_ERROR "Enabling the legacy pass manager on the cmake level is"1079                      " no longer supported.")1080endif()1081 1082include(HandleLLVMOptions)1083 1084######1085 1086# Configure all of the various header file fragments LLVM uses which depend on1087# configuration variables.1088set(LLVM_ENUM_TARGETS "")1089set(LLVM_ENUM_ASM_PRINTERS "")1090set(LLVM_ENUM_ASM_PARSERS "")1091set(LLVM_ENUM_DISASSEMBLERS "")1092set(LLVM_ENUM_TARGETMCAS "")1093set(LLVM_ENUM_EXEGESIS "")1094foreach(t ${LLVM_TARGETS_TO_BUILD})1095  set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )1096 1097  # Make sure that any experimental targets were passed via1098  # LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, not LLVM_TARGETS_TO_BUILD.1099  # We allow experimental targets that are not in LLVM_ALL_EXPERIMENTAL_TARGETS,1100  # as long as they are passed via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.1101  if ( NOT "${t}" IN_LIST LLVM_ALL_TARGETS AND NOT "${t}" IN_LIST LLVM_EXPERIMENTAL_TARGETS_TO_BUILD )1102    if( "${t}" IN_LIST LLVM_ALL_EXPERIMENTAL_TARGETS )1103      message(FATAL_ERROR "The target `${t}' is experimental and must be passed "1104        "via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.")1105    else()1106      message(FATAL_ERROR "The target `${t}' is not a core tier target. It may be "1107        "experimental, if so it must be passed via "1108        "LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.\n"1109        "Core tier targets: ${LLVM_ALL_TARGETS}\n"1110        "Known experimental targets: ${LLVM_ALL_EXPERIMENTAL_TARGETS}")1111    endif()1112  else()1113    set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")1114    string(TOUPPER ${t} T_UPPER)1115    set(LLVM_HAS_${T_UPPER}_TARGET 1)1116  endif()1117 1118  file(GLOB asmp_file "${td}/*AsmPrinter.cpp")1119  if( asmp_file )1120    set(LLVM_ENUM_ASM_PRINTERS1121      "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")1122  endif()1123  if( EXISTS ${td}/AsmParser/CMakeLists.txt )1124    set(LLVM_ENUM_ASM_PARSERS1125      "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")1126  endif()1127  if( EXISTS ${td}/Disassembler/CMakeLists.txt )1128    set(LLVM_ENUM_DISASSEMBLERS1129      "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")1130  endif()1131  if( EXISTS ${td}/MCA/CMakeLists.txt )1132    set(LLVM_ENUM_TARGETMCAS1133      "${LLVM_ENUM_TARGETMCAS}LLVM_TARGETMCA(${t})\n")1134  endif()1135  if( EXISTS ${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib/${t}/CMakeLists.txt )1136    set(LLVM_ENUM_EXEGESIS1137      "${LLVM_ENUM_EXEGESIS}LLVM_EXEGESIS(${t})\n")1138  endif()1139endforeach(t)1140 1141# Provide an LLVM_ namespaced alias for use in #cmakedefine.1142set(LLVM_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})1143 1144# Produce the target definition files, which provide a way for clients to easily1145# include various classes of targets.1146configure_file(1147  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in1148  ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def1149  )1150configure_file(1151  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in1152  ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def1153  )1154configure_file(1155  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in1156  ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def1157  )1158configure_file(1159  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in1160  ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def1161  )1162configure_file(1163  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetMCAs.def.in1164  ${LLVM_INCLUDE_DIR}/llvm/Config/TargetMCAs.def1165  )1166configure_file(1167  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetExegesis.def.in1168  ${LLVM_INCLUDE_DIR}/llvm/Config/TargetExegesis.def1169  )1170 1171# They are not referenced. See set_output_directory().1172set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )1173set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_LIBRARY_DIR} )1174set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_LIBRARY_DIR} )1175 1176# For up-to-date instructions for installing the TFLite dependency, refer to1177# the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh1178set(LLVM_HAVE_TFLITE "" CACHE BOOL "Use tflite")1179if (LLVM_HAVE_TFLITE)1180  find_package(tensorflow-lite REQUIRED)1181endif()1182 1183set(LLVM_ENABLE_PROFCHECK OFF CACHE BOOL "Enable profile checking in test tools")1184 1185# For up-to-date instructions for installing the Tensorflow dependency, refer to1186# the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh1187# Specifically, assuming python3 is installed:1188# python3 -m pip install --upgrade pip && python3 -m pip install --user tf_nightly==2.3.0.dev202005281189# Then set TENSORFLOW_AOT_PATH to the package install - usually it's ~/.local/lib/python3.7/site-packages/tensorflow1190#1191set(TENSORFLOW_AOT_PATH "" CACHE PATH "Path to TensorFlow pip install dir")1192 1193if (NOT TENSORFLOW_AOT_PATH STREQUAL "")1194  set(LLVM_HAVE_TF_AOT "ON" CACHE BOOL "Tensorflow AOT available")1195  set(TENSORFLOW_AOT_COMPILER1196    "${TENSORFLOW_AOT_PATH}/../../../../bin/saved_model_cli"1197    CACHE PATH "Path to the Tensorflow AOT compiler")1198  include_directories(${TENSORFLOW_AOT_PATH}/include)1199  add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src1200    ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)1201  install(TARGETS tf_xla_runtime EXPORT LLVMExports1202    ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)1203  install(TARGETS tf_xla_runtime EXPORT LLVMDevelopmentExports1204    ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)1205  set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)1206  # Once we add more modules, we should handle this more automatically.1207  if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL)1208    set(LLVM_INLINER_MODEL_PATH "none")1209  elseif(NOT DEFINED LLVM_INLINER_MODEL_PATH1210      OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL ""1211      OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL "autogenerate")1212    set(LLVM_INLINER_MODEL_PATH "autogenerate")1213    set(LLVM_INLINER_MODEL_AUTOGENERATED 1)1214  endif()1215  if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_REGALLOCEVICTMODEL)1216    set(LLVM_RAEVICT_MODEL_PATH "none")1217  elseif(NOT DEFINED LLVM_RAEVICT_MODEL_PATH1218      OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL ""1219      OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL "autogenerate")1220    set(LLVM_RAEVICT_MODEL_PATH "autogenerate")1221    set(LLVM_RAEVICT_MODEL_AUTOGENERATED 1)1222  endif()1223 1224endif()1225 1226# Configure the LLVM configuration header files.1227configure_file(1228  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake1229  ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)1230configure_file(1231  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake1232  ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)1233configure_file(1234  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.h.cmake1235  ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.h)1236configure_file(1237  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake1238  ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)1239 1240if(APPLE AND DARWIN_LTO_LIBRARY)1241  set(CMAKE_EXE_LINKER_FLAGS1242    "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")1243  set(CMAKE_SHARED_LINKER_FLAGS1244    "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")1245  set(CMAKE_MODULE_LINKER_FLAGS1246    "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")1247endif()1248 1249# Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to1250# break things. In this case we need to enable the large-file API as well.1251if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")1252          add_compile_definitions(_XOPEN_SOURCE=700)1253          add_compile_definitions(_LARGE_FILE_API)1254          add_compile_options(-pthread)1255 1256  # Modules should be built with -shared -Wl,-G, so we can use runtime linking1257  # with plugins.1258  string(APPEND CMAKE_MODULE_LINKER_FLAGS " -shared -Wl,-G")1259 1260  # Also set the correct flags for building shared libraries.1261  string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared")1262endif()1263 1264# Build with _XOPEN_SOURCE on z/OS.1265if (CMAKE_SYSTEM_NAME MATCHES "OS390")1266  add_compile_definitions(_XOPEN_SOURCE=600)1267  add_compile_definitions(_XPLATFORM_SOURCE) # Needed e.g. for O_CLOEXEC.1268  add_compile_definitions(_OPEN_SYS) # Needed for process information.1269  add_compile_definitions(_OPEN_SYS_FILE_EXT) # Needed for EBCDIC I/O.1270  add_compile_definitions(_EXT) # Needed for file data.1271  # Need to build LLVM as ASCII application.1272  # This can't be a global setting because other projects may1273  # need to be built in EBCDIC mode.1274  append("-fzos-le-char-mode=ascii" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)1275  append("-m64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)1276endif()1277 1278# Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9.1279if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")1280          add_compile_definitions(_FILE_OFFSET_BITS=64)1281endif()1282 1283set(CMAKE_INCLUDE_CURRENT_DIR ON)1284 1285include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})1286 1287# when crosscompiling import the executable targets from a file1288if(LLVM_USE_HOST_TOOLS)1289  include(CrossCompile)1290  llvm_create_cross_target(LLVM NATIVE "" Release)1291endif(LLVM_USE_HOST_TOOLS)1292if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)1293# Dummy use to avoid CMake Warning: Manually-specified variables were not used1294# (this is a variable that CrossCompile sets on recursive invocations)1295endif()1296 1297# Special hack for z/OS for missing POSIX functions1298if (CMAKE_SYSTEM_NAME MATCHES "OS390")1299  include_directories(SYSTEM "${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/SystemZ/zos_wrappers" )1300endif()1301 1302if( "${CMAKE_SYSTEM_NAME}" MATCHES SunOS )1303   # special hack for Solaris to handle crazy system sys/regset.h1304   include_directories("${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/Solaris")1305endif( "${CMAKE_SYSTEM_NAME}" MATCHES SunOS )1306 1307# Make sure we don't get -rdynamic in every binary. For those that need it,1308# use EXPORT_SYMBOLS argument.1309set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")1310 1311include(AddLLVM)1312include(TableGen)1313 1314include(LLVMDistributionSupport)1315 1316if( MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )1317  # People report that -O3 is unreliable on MinGW. The traditional1318  # build also uses -O2 for that reason:1319  llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")1320endif()1321 1322if(LLVM_INCLUDE_TESTS)1323  umbrella_lit_testsuite_begin(check-all)1324endif()1325 1326# Put this before tblgen. Else we have a circular dependence.1327add_subdirectory(lib/Demangle)1328add_subdirectory(lib/Support)1329add_subdirectory(lib/TableGen)1330 1331add_subdirectory(utils/TableGen)1332 1333add_subdirectory(include)1334 1335add_subdirectory(lib)1336 1337if( LLVM_INCLUDE_UTILS )1338  add_subdirectory(utils/FileCheck)1339  add_subdirectory(utils/PerfectShuffle)1340  add_subdirectory(utils/count)1341  add_subdirectory(utils/not)1342  add_subdirectory(utils/UnicodeData)1343  add_subdirectory(utils/yaml-bench)1344  add_subdirectory(utils/split-file)1345  add_subdirectory(utils/mlgo-utils)1346  add_subdirectory(utils/llvm-test-mustache-spec)1347  if( LLVM_INCLUDE_TESTS )1348    add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest)1349  endif()1350else()1351  if ( LLVM_INCLUDE_TESTS )1352    message(FATAL_ERROR "Including tests when not building utils will not work.1353    Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLUDE_TESTS to Off.")1354  endif()1355endif()1356 1357# Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util1358if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)1359  add_subdirectory(utils/LLVMVisualizers)1360endif()1361 1362foreach( binding ${LLVM_BINDINGS_LIST} )1363  if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )1364    add_subdirectory(bindings/${binding})1365  endif()1366endforeach()1367 1368add_subdirectory(projects)1369 1370if( LLVM_INCLUDE_TOOLS )1371  add_subdirectory(tools)1372endif()1373 1374# We need to setup KillTheDoctor before setting up the runtimes build because1375# the runtimes build needs to add a KillTheDoctor dep for compiler-rt on1376# Windows.1377if (LLVM_INCLUDE_TESTS)1378  if (WIN32)1379    # This utility is used to prevent crashing tests from calling Dr. Watson on1380    # Windows.1381    add_subdirectory(utils/KillTheDoctor)1382  endif()1383endif()1384 1385if( LLVM_INCLUDE_RUNTIMES )1386  add_subdirectory(runtimes)1387endif()1388 1389if( LLVM_INCLUDE_EXAMPLES )1390  add_subdirectory(examples)1391endif()1392 1393if( LLVM_INCLUDE_TESTS )1394  set(LLVM_GTEST_RUN_UNDER1395    "" CACHE STRING1396    "Define the wrapper program that LLVM unit tests should be run under.")1397  if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)1398    include(LLVMExternalProjectUtils)1399    llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite1400      USE_TOOLCHAIN1401      EXCLUDE_FROM_ALL1402      NO_INSTALL1403      ALWAYS_CLEAN)1404  endif()1405  add_subdirectory(utils/lit)1406  add_subdirectory(test)1407  add_subdirectory(unittests)1408 1409  umbrella_lit_testsuite_end(check-all)1410  get_property(LLVM_ALL_LIT_DEPENDS GLOBAL PROPERTY LLVM_ALL_LIT_DEPENDS)1411  get_property(LLVM_ALL_ADDITIONAL_TEST_DEPENDS1412      GLOBAL PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS)1413  add_custom_target(test-depends)1414  if(LLVM_ALL_LIT_DEPENDS OR LLVM_ALL_ADDITIONAL_TEST_DEPENDS)1415    add_dependencies(test-depends ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS})1416  endif()1417  set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests")1418  add_dependencies(check-all test-depends)1419endif()1420 1421if (LLVM_INCLUDE_DOCS)1422  add_subdirectory(docs)1423endif()1424 1425add_subdirectory(cmake/modules)1426 1427# Do this last so that all lit targets have already been created.1428if (LLVM_INCLUDE_UTILS)1429  add_subdirectory(utils/llvm-lit)1430endif()1431 1432if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)1433  install(DIRECTORY include/llvm include/llvm-c1434    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"1435    COMPONENT llvm-headers1436    FILES_MATCHING1437    PATTERN "*.def"1438    PATTERN "*.h"1439    PATTERN "*.td"1440    PATTERN "*.inc"1441    PATTERN "LICENSE.TXT"1442    )1443 1444  install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c1445    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"1446    COMPONENT llvm-headers1447    FILES_MATCHING1448    PATTERN "*.def"1449    PATTERN "*.h"1450    PATTERN "*.gen"1451    PATTERN "*.inc"1452    # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"1453    PATTERN "CMakeFiles" EXCLUDE1454    PATTERN "config.h" EXCLUDE1455    )1456 1457  if (LLVM_INSTALL_MODULEMAPS)1458    install(DIRECTORY include1459            DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"1460            COMPONENT llvm-headers1461            FILES_MATCHING1462            PATTERN "module.modulemap"1463            )1464    install(FILES include/module.install.modulemap1465            DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"1466            COMPONENT llvm-headers1467            RENAME "module.extern.modulemap"1468            )1469  endif(LLVM_INSTALL_MODULEMAPS)1470 1471  # Installing the headers needs to depend on generating any public1472  # tablegen'd headers.1473  add_custom_target(llvm-headers)1474  add_dependencies(llvm-headers intrinsics_gen omp_gen target_parser_gen)1475  set_target_properties(llvm-headers PROPERTIES FOLDER "LLVM/Resources")1476 1477  if (NOT LLVM_ENABLE_IDE)1478    add_llvm_install_targets(install-llvm-headers1479                             DEPENDS llvm-headers1480                             COMPONENT llvm-headers)1481  endif()1482 1483  # Custom target to install all libraries.1484  add_custom_target(llvm-libraries)1485  set_target_properties(llvm-libraries PROPERTIES FOLDER "LLVM/Resources")1486 1487  if (NOT LLVM_ENABLE_IDE)1488    add_llvm_install_targets(install-llvm-libraries1489                             DEPENDS llvm-libraries1490                             COMPONENT llvm-libraries)1491  endif()1492 1493  get_property(LLVM_LIBS GLOBAL PROPERTY LLVM_LIBS)1494  if(LLVM_LIBS)1495    list(REMOVE_DUPLICATES LLVM_LIBS)1496    foreach(lib ${LLVM_LIBS})1497      add_dependencies(llvm-libraries ${lib})1498      if (NOT LLVM_ENABLE_IDE)1499        add_dependencies(install-llvm-libraries install-${lib})1500        add_dependencies(install-llvm-libraries-stripped install-${lib}-stripped)1501      endif()1502    endforeach()1503  endif()1504endif()1505 1506# This must be at the end of the LLVM root CMakeLists file because it must run1507# after all targets are created.1508llvm_distribution_add_targets()1509process_llvm_pass_plugins(GEN_CONFIG)1510include(CoverageReport)1511 1512# This allows us to deploy the Universal CRT DLLs by passing -DCMAKE_INSTALL_UCRT_LIBRARIES=ON to CMake1513if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_INSTALL_UCRT_LIBRARIES)1514  include(InstallRequiredSystemLibraries)1515endif()1516 1517if (LLVM_INCLUDE_BENCHMARKS)1518  # Override benchmark defaults so that when the library itself is updated these1519  # modifications are not lost.1520  set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing" FORCE)1521  set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Disable benchmark exceptions" FORCE)1522  set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install benchmark" FORCE)1523  set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE BOOL "Don't download dependencies" FORCE)1524  set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE)1525  set(BENCHMARK_ENABLE_WERROR ${LLVM_ENABLE_WERROR} CACHE BOOL1526    "Handle -Werror for Google Benchmark based on LLVM_ENABLE_WERROR" FORCE)1527  # Since LLVM requires C++11 it is safe to assume that std::regex is available.1528  set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)1529  add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark1530    ${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark)1531  set_target_properties(benchmark PROPERTIES FOLDER "Third-Party/Google Benchmark")1532  set_target_properties(benchmark_main PROPERTIES FOLDER "Third-Party/Google Benchmark")1533  add_subdirectory(benchmarks)1534endif()1535 1536if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)1537  add_subdirectory(utils/llvm-locstats)1538endif()1539 1540if (XCODE)1541  # For additional targets that you would like to add schemes, specify e.g:1542  #1543  #   -DLLVM_XCODE_EXTRA_TARGET_SCHEMES="TargetParserTests;SupportTests"1544  #1545  # at CMake configure time.1546  set(LLVM_XCODE_EXTRA_TARGET_SCHEMES "" CACHE STRING "Specifies an extra list of targets to turn into schemes")1547 1548  foreach(target ${LLVM_XCODE_EXTRA_TARGET_SCHEMES})1549    set_target_properties(${target} PROPERTIES XCODE_GENERATE_SCHEME ON)1550  endforeach()1551endif()1552