109467b48Spatrick# See docs/CMake.html for instructions about how to build LLVM with CMake. 209467b48Spatrick 373471bf0Spatrickcmake_minimum_required(VERSION 3.13.4) 4*d415bd75Srobertif ("${CMAKE_VERSION}" VERSION_LESS "3.20.0") 5*d415bd75Srobert message(WARNING 6*d415bd75Srobert "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the " 7*d415bd75Srobert "minimum version of CMake required to build LLVM will become 3.20.0, and " 8*d415bd75Srobert "using an older CMake will become an error. Please upgrade your CMake to " 9*d415bd75Srobert "at least 3.20.0 now to avoid issues in the future!") 10097a140dSpatrickendif() 11097a140dSpatrick 12*d415bd75Srobertset(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) 13*d415bd75Srobertinclude(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake 14*d415bd75Srobert NO_POLICY_SCOPE) 15*d415bd75Srobert 1609467b48Spatrickset(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) 1709467b48Spatrick 1809467b48Spatrickif(NOT DEFINED LLVM_VERSION_MAJOR) 19*d415bd75Srobert set(LLVM_VERSION_MAJOR 16) 2009467b48Spatrickendif() 2109467b48Spatrickif(NOT DEFINED LLVM_VERSION_MINOR) 2273471bf0Spatrick set(LLVM_VERSION_MINOR 0) 2309467b48Spatrickendif() 2409467b48Spatrickif(NOT DEFINED LLVM_VERSION_PATCH) 25*d415bd75Srobert set(LLVM_VERSION_PATCH 6) 2609467b48Spatrickendif() 2709467b48Spatrickif(NOT DEFINED LLVM_VERSION_SUFFIX) 2873471bf0Spatrick set(LLVM_VERSION_SUFFIX) 2909467b48Spatrickendif() 3009467b48Spatrick 3109467b48Spatrickif (NOT PACKAGE_VERSION) 3209467b48Spatrick set(PACKAGE_VERSION 3309467b48Spatrick "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}") 3409467b48Spatrickendif() 3509467b48Spatrick 36*d415bd75Srobertif(NOT DEFINED LLVM_SHLIB_SYMBOL_VERSION) 37*d415bd75Srobert # "Symbol version prefix for libLLVM.so" 38*d415bd75Srobert set(LLVM_SHLIB_SYMBOL_VERSION "LLVM_${LLVM_VERSION_MAJOR}") 39*d415bd75Srobertendif() 40*d415bd75Srobert 41*d415bd75Srobertif ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (MSVC_TOOLSET_VERSION LESS 142) AND (CMAKE_GENERATOR_TOOLSET STREQUAL "")) 4209467b48Spatrick message(WARNING "Visual Studio generators use the x86 host compiler by " 4309467b48Spatrick "default, even for 64-bit targets. This can result in linker " 4409467b48Spatrick "instability and out of memory errors. To use the 64-bit " 4509467b48Spatrick "host compiler, pass -Thost=x64 on the CMake command line.") 4609467b48Spatrickendif() 4709467b48Spatrick 4809467b48Spatrickif (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_OSX_ARCHITECTURES) 4909467b48Spatrick # Some CMake features like object libraries get confused if you don't 5009467b48Spatrick # explicitly specify an architecture setting with the Xcode generator. 5109467b48Spatrick set(CMAKE_OSX_ARCHITECTURES "x86_64") 5209467b48Spatrickendif() 5309467b48Spatrick 5409467b48Spatrickproject(LLVM 5509467b48Spatrick VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH} 5609467b48Spatrick LANGUAGES C CXX ASM) 5709467b48Spatrick 58*d415bd75Srobertif (NOT DEFINED CMAKE_INSTALL_LIBDIR AND DEFINED LLVM_LIBDIR_SUFFIX) 59*d415bd75Srobert # Must go before `include(GNUInstallDirs)`. 60*d415bd75Srobert set(CMAKE_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}") 61*d415bd75Srobertendif() 62*d415bd75Srobert 63*d415bd75Srobert# Must go after `DEFINED LLVM_LIBDIR_SUFFIX` check. 64*d415bd75Srobertset(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) 65*d415bd75Srobert 66*d415bd75Srobert# Must go after `project(..)`. 67*d415bd75Srobertinclude(GNUInstallDirs) 68*d415bd75Srobert 69*d415bd75Srobert# This C++ standard is required to build LLVM. 70*d415bd75Srobertset(LLVM_REQUIRED_CXX_STANDARD 17) 71*d415bd75Srobert 72*d415bd75Srobert# If we find that the cache contains CMAKE_CXX_STANDARD it means that it's a old CMakeCache.txt 73*d415bd75Srobert# and we can just inform the user and then reset it. 74*d415bd75Srobertif($CACHE{CMAKE_CXX_STANDARD} AND $CACHE{CMAKE_CXX_STANDARD} LESS ${LLVM_REQUIRED_CXX_STANDARD}) 75*d415bd75Srobert message(WARNING "Resetting cache value for CMAKE_CXX_STANDARD to ${LLVM_REQUIRED_CXX_STANDARD}") 76*d415bd75Srobert unset(CMAKE_CXX_STANDARD CACHE) 77*d415bd75Srobertendif() 78*d415bd75Srobert 79*d415bd75Srobert# if CMAKE_CXX_STANDARD is still set after the cache unset above it means that the user requested it 80*d415bd75Srobert# and we allow it to be set to something newer than the required standard but otherwise we fail. 81*d415bd75Srobertif(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS ${LLVM_REQUIRED_CXX_STANDARD}) 82*d415bd75Srobert message(FATAL_ERROR "Requested CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} which is less than the required ${LLVM_REQUIRED_CXX_STANDARD}.") 83*d415bd75Srobertendif() 84*d415bd75Srobert 85*d415bd75Srobertset(CMAKE_CXX_STANDARD ${LLVM_REQUIRED_CXX_STANDARD} CACHE STRING "C++ standard to conform to") 8609467b48Spatrickset(CMAKE_CXX_STANDARD_REQUIRED YES) 87*d415bd75Srobert 8873471bf0Spatrickif (CYGWIN) 8973471bf0Spatrick # Cygwin is a bit stricter and lack things like 'strdup', 'stricmp', etc in 9073471bf0Spatrick # c++xx mode. 9173471bf0Spatrick set(CMAKE_CXX_EXTENSIONS YES) 9273471bf0Spatrickelse() 9309467b48Spatrick set(CMAKE_CXX_EXTENSIONS NO) 9473471bf0Spatrickendif() 9509467b48Spatrick 9609467b48Spatrickif (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 97*d415bd75Srobert message(FATAL_ERROR " 98*d415bd75SrobertNo build type selected. You need to pass -DCMAKE_BUILD_TYPE=<type> in order to configure LLVM. 99*d415bd75SrobertAvailable options are: 100*d415bd75Srobert * -DCMAKE_BUILD_TYPE=Release - For an optimized build with no assertions or debug info. 101*d415bd75Srobert * -DCMAKE_BUILD_TYPE=Debug - For an unoptimized build with assertions and debug info. 102*d415bd75Srobert * -DCMAKE_BUILD_TYPE=RelWithDebInfo - For an optimized build with no assertions but with debug info. 103*d415bd75Srobert * -DCMAKE_BUILD_TYPE=MinSizeRel - For a build optimized for size instead of speed. 104*d415bd75SrobertLearn more about these options in our documentation at https://llvm.org/docs/CMake.html#cmake-build-type 105*d415bd75Srobert") 106*d415bd75Srobertendif() 107*d415bd75Srobert 108*d415bd75Srobert# Set default build type for cmake's try_compile module. 109*d415bd75Srobert# CMake 3.17 or newer sets CMAKE_DEFAULT_BUILD_TYPE to one of the 110*d415bd75Srobert# items from CMAKE_CONFIGURATION_TYPES. Logic below can be further 111*d415bd75Srobert# simplified once LLVM's minimum CMake version is updated to 3.17. 112*d415bd75Srobertif(CMAKE_DEFAULT_BUILD_TYPE) 113*d415bd75Srobert set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_DEFAULT_BUILD_TYPE}) 114*d415bd75Srobertelse() 115*d415bd75Srobert if(CMAKE_CONFIGURATION_TYPES) 116*d415bd75Srobert list(GET CMAKE_CONFIGURATION_TYPES 0 CMAKE_TRY_COMPILE_CONFIGURATION) 117*d415bd75Srobert elseif(CMAKE_BUILD_TYPE) 118*d415bd75Srobert set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE}) 119*d415bd75Srobert endif() 12009467b48Spatrickendif() 12109467b48Spatrick 12209467b48Spatrick# Side-by-side subprojects layout: automatically set the 12309467b48Spatrick# LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS 12409467b48Spatrick# This allows an easy way of setting up a build directory for llvm and another 12509467b48Spatrick# one for llvm+clang+... using the same sources. 126*d415bd75Srobertset(LLVM_ALL_PROJECTS "bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;lld;lldb;mlir;openmp;polly;pstl") 127097a140dSpatrick# The flang project is not yet part of "all" projects (see C++ requirements) 128097a140dSpatrickset(LLVM_EXTRA_PROJECTS "flang") 129097a140dSpatrick# List of all known projects in the mono repo 130097a140dSpatrickset(LLVM_KNOWN_PROJECTS "${LLVM_ALL_PROJECTS};${LLVM_EXTRA_PROJECTS}") 13109467b48Spatrickset(LLVM_ENABLE_PROJECTS "" CACHE STRING 132097a140dSpatrick "Semicolon-separated list of projects to build (${LLVM_KNOWN_PROJECTS}), or \"all\".") 133*d415bd75Srobert# Make sure expansion happens first to not handle "all" in rest of the checks. 13409467b48Spatrickif( LLVM_ENABLE_PROJECTS STREQUAL "all" ) 13509467b48Spatrick set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS}) 13609467b48Spatrickendif() 137*d415bd75Srobertforeach(proj ${LLVM_ENABLE_PROJECTS}) 138*d415bd75Srobert if (NOT proj STREQUAL "llvm" AND NOT "${proj}" IN_LIST LLVM_KNOWN_PROJECTS) 139*d415bd75Srobert 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?") 140*d415bd75Srobert endif() 141*d415bd75Srobertendforeach() 14273471bf0Spatrick 14373471bf0Spatrickif ("flang" IN_LIST LLVM_ENABLE_PROJECTS) 14473471bf0Spatrick if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS) 145097a140dSpatrick message(STATUS "Enabling MLIR as a dependency to flang") 146097a140dSpatrick list(APPEND LLVM_ENABLE_PROJECTS "mlir") 147097a140dSpatrick endif() 14809467b48Spatrick 149*d415bd75Srobert if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS) 150*d415bd75Srobert message(FATAL_ERROR "Clang is not enabled, but is required for the Flang driver") 15173471bf0Spatrick endif() 15273471bf0Spatrickendif() 15373471bf0Spatrick 154*d415bd75Srobert# Select the runtimes to build 155*d415bd75Srobert# 156*d415bd75Srobert# As we migrate runtimes to using the bootstrapping build, the set of default runtimes 157*d415bd75Srobert# should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above. 158*d415bd75Srobertset(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind") 159*d415bd75Srobertset(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc") 160*d415bd75Srobertset(LLVM_ENABLE_RUNTIMES "" CACHE STRING 161*d415bd75Srobert "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.") 162*d415bd75Srobertif(LLVM_ENABLE_RUNTIMES STREQUAL "all") 163*d415bd75Srobert set(LLVM_ENABLE_RUNTIMES ${LLVM_DEFAULT_RUNTIMES}) 164*d415bd75Srobertendif() 165*d415bd75Srobertforeach(proj IN LISTS LLVM_ENABLE_RUNTIMES) 166*d415bd75Srobert if (NOT "${proj}" IN_LIST LLVM_SUPPORTED_RUNTIMES) 167*d415bd75Srobert message(FATAL_ERROR "Runtime \"${proj}\" is not a supported runtime. Supported runtimes are: ${LLVM_SUPPORTED_RUNTIMES}") 168*d415bd75Srobert endif() 169*d415bd75Srobertendforeach() 170*d415bd75Srobert 17109467b48Spatrick# LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the 17209467b48Spatrick# `LLVM_ENABLE_PROJECTS` CMake cache variable. This exists for 17309467b48Spatrick# several reasons: 17409467b48Spatrick# 17509467b48Spatrick# * As an indicator that the `LLVM_ENABLE_PROJECTS` list is now the single 17609467b48Spatrick# source of truth for which projects to build. This means we will ignore user 17709467b48Spatrick# supplied `LLVM_TOOL_<project>_BUILD` CMake cache variables and overwrite 17809467b48Spatrick# them. 17909467b48Spatrick# 18009467b48Spatrick# * The case where the user previously had `LLVM_ENABLE_PROJECTS` set to a 18109467b48Spatrick# non-empty list but now the user wishes to disable building all other projects 18209467b48Spatrick# by setting `LLVM_ENABLE_PROJECTS` to an empty string. In that case we still 18309467b48Spatrick# need to set the `LLVM_TOOL_${upper_proj}_BUILD` variables so that we disable 18409467b48Spatrick# building all the projects that were previously enabled. 18509467b48Spatrickset(LLVM_ENABLE_PROJECTS_USED OFF CACHE BOOL "") 18609467b48Spatrickmark_as_advanced(LLVM_ENABLE_PROJECTS_USED) 18709467b48Spatrick 18809467b48Spatrickif (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "") 18909467b48Spatrick set(LLVM_ENABLE_PROJECTS_USED ON CACHE BOOL "" FORCE) 190097a140dSpatrick foreach(proj ${LLVM_KNOWN_PROJECTS} ${LLVM_EXTERNAL_PROJECTS}) 19109467b48Spatrick string(TOUPPER "${proj}" upper_proj) 19209467b48Spatrick string(REGEX REPLACE "-" "_" upper_proj ${upper_proj}) 19309467b48Spatrick if ("${proj}" IN_LIST LLVM_ENABLE_PROJECTS) 19409467b48Spatrick message(STATUS "${proj} project is enabled") 19509467b48Spatrick set(SHOULD_ENABLE_PROJECT TRUE) 19609467b48Spatrick set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}") 19709467b48Spatrick if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}") 19809467b48Spatrick message(FATAL_ERROR "LLVM_ENABLE_PROJECTS requests ${proj} but directory not found: ${PROJ_DIR}") 19909467b48Spatrick endif() 20009467b48Spatrick if( LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" ) 20109467b48Spatrick set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "" FORCE) 20209467b48Spatrick else() 20309467b48Spatrick set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "") 20409467b48Spatrick endif() 20509467b48Spatrick elseif ("${proj}" IN_LIST LLVM_EXTERNAL_PROJECTS) 20609467b48Spatrick message(STATUS "${proj} project is enabled") 20709467b48Spatrick set(SHOULD_ENABLE_PROJECT TRUE) 20809467b48Spatrick else() 20909467b48Spatrick message(STATUS "${proj} project is disabled") 21009467b48Spatrick set(SHOULD_ENABLE_PROJECT FALSE) 21109467b48Spatrick endif() 21209467b48Spatrick # Force `LLVM_TOOL_${upper_proj}_BUILD` variables to have values that 21309467b48Spatrick # corresponds with `LLVM_ENABLE_PROJECTS`. This prevents the user setting 21409467b48Spatrick # `LLVM_TOOL_${upper_proj}_BUILD` variables externally. At some point 21509467b48Spatrick # we should deprecate allowing users to set these variables by turning them 21609467b48Spatrick # into normal CMake variables rather than cache variables. 21709467b48Spatrick set(LLVM_TOOL_${upper_proj}_BUILD 21809467b48Spatrick ${SHOULD_ENABLE_PROJECT} 21909467b48Spatrick CACHE 22009467b48Spatrick BOOL "Whether to build ${upper_proj} as part of LLVM" FORCE 22109467b48Spatrick ) 22209467b48Spatrick endforeach() 22309467b48Spatrickendif() 22409467b48Spatrickunset(SHOULD_ENABLE_PROJECT) 22509467b48Spatrick 22609467b48Spatrick# Build llvm with ccache if the package is present 22709467b48Spatrickset(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build") 22809467b48Spatrickif(LLVM_CCACHE_BUILD) 22909467b48Spatrick find_program(CCACHE_PROGRAM ccache) 23009467b48Spatrick if(CCACHE_PROGRAM) 23109467b48Spatrick set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache") 23209467b48Spatrick set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data") 23309467b48Spatrick set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes" 23409467b48Spatrick CACHE STRING "Parameters to pass through to ccache") 23509467b48Spatrick 236*d415bd75Srobert if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") 23709467b48Spatrick set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}") 23809467b48Spatrick if (LLVM_CCACHE_MAXSIZE) 23909467b48Spatrick set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}") 24009467b48Spatrick endif() 24109467b48Spatrick if (LLVM_CCACHE_DIR) 24209467b48Spatrick set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}") 24309467b48Spatrick endif() 24409467b48Spatrick set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM}) 24509467b48Spatrick else() 246*d415bd75Srobert if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR 247*d415bd75Srobert NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes") 248*d415bd75Srobert message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.") 249*d415bd75Srobert endif() 250*d415bd75Srobert # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues 251*d415bd75Srobert # with cmd.exe and some MSVC tools other than cl.exe 252*d415bd75Srobert set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) 253*d415bd75Srobert set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) 254*d415bd75Srobert endif() 255*d415bd75Srobert else() 25609467b48Spatrick message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF") 25709467b48Spatrick endif() 25809467b48Spatrickendif() 25909467b48Spatrick 260*d415bd75Srobertset(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS "" CACHE STRING 261*d415bd75Srobert "Optional arguments for the native tool used in CMake --build invocations for external projects.") 262*d415bd75Srobertmark_as_advanced(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS) 263*d415bd75Srobert 26409467b48Spatrickoption(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF) 26509467b48Spatrick 26609467b48Spatrick# Some features of the LLVM build may be disallowed when dependency debugging is 26709467b48Spatrick# enabled. In particular you cannot use ccache because we want to force compile 26809467b48Spatrick# operations to always happen. 26909467b48Spatrickif(LLVM_DEPENDENCY_DEBUGGING) 27009467b48Spatrick if(NOT CMAKE_HOST_APPLE) 27109467b48Spatrick message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.") 27209467b48Spatrick endif() 27309467b48Spatrick if(LLVM_CCACHE_BUILD) 27409467b48Spatrick message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.") 27509467b48Spatrick endif() 27609467b48Spatrickendif() 27709467b48Spatrick 27809467b48Spatrickoption(LLVM_ENABLE_DAGISEL_COV "Debug: Prints tablegen patterns that were used for selecting" OFF) 27909467b48Spatrickoption(LLVM_ENABLE_GISEL_COV "Enable collection of GlobalISel rule coverage" OFF) 28009467b48Spatrickif(LLVM_ENABLE_GISEL_COV) 28109467b48Spatrick set(LLVM_GISEL_COV_PREFIX "${CMAKE_BINARY_DIR}/gisel-coverage-" CACHE STRING "Provide a filename prefix to collect the GlobalISel rule coverage") 28209467b48Spatrickendif() 28309467b48Spatrick 28409467b48Spatrick# Add path for custom modules 285*d415bd75Srobertlist(INSERT CMAKE_MODULE_PATH 0 28609467b48Spatrick "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 28709467b48Spatrick "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" 288*d415bd75Srobert "${LLVM_COMMON_CMAKE_UTILS}/Modules" 28909467b48Spatrick ) 29009467b48Spatrick 29109467b48Spatrick# Generate a CompilationDatabase (compile_commands.json file) for our build, 29209467b48Spatrick# for use by clang_complete, YouCompleteMe, etc. 29309467b48Spatrickset(CMAKE_EXPORT_COMPILE_COMMANDS 1) 29409467b48Spatrick 29509467b48Spatrickoption(LLVM_INSTALL_BINUTILS_SYMLINKS 29609467b48Spatrick "Install symlinks from the binutils tool names to the corresponding LLVM tools." OFF) 29709467b48Spatrick 29809467b48Spatrickoption(LLVM_INSTALL_CCTOOLS_SYMLINKS 29909467b48Spatrick "Install symlinks from the cctools tool names to the corresponding LLVM tools." OFF) 30009467b48Spatrick 301*d415bd75Srobert# By default we use symlinks on Unix platforms and copy binaries on Windows 302*d415bd75Srobert# If you have the correct setup on Windows you can use this option to enable 303*d415bd75Srobert# symlinks and save a lot of diskspace. 304*d415bd75Srobertoption(LLVM_USE_SYMLINKS "Use symlinks instead of copying binaries" ${CMAKE_HOST_UNIX}) 305*d415bd75Srobert 30609467b48Spatrickoption(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF) 30709467b48Spatrick 30809467b48Spatrickoption(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF) 30909467b48Spatrick 31009467b48Spatrick# Unfortunatly Clang is too eager to search directories for module maps, which can cause the 31109467b48Spatrick# installed version of the maps to be found when building LLVM from source. Therefore we turn off 31209467b48Spatrick# the installation by default. See llvm.org/PR31905. 31309467b48Spatrickoption(LLVM_INSTALL_MODULEMAPS "Install the modulemap files in the 'install' target." OFF) 31409467b48Spatrick 31509467b48Spatrickoption(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON) 31609467b48Spatrickif ( LLVM_USE_FOLDERS ) 31709467b48Spatrick set_property(GLOBAL PROPERTY USE_FOLDERS ON) 31809467b48Spatrickendif() 31909467b48Spatrick 32009467b48Spatrickinclude(VersionFromVCS) 32109467b48Spatrick 32209467b48Spatrickoption(LLVM_APPEND_VC_REV 32309467b48Spatrick "Embed the version control system revision in LLVM" ON) 32409467b48Spatrick 325*d415bd75Srobertoption(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OFF) 326*d415bd75Srobert 32709467b48Spatrickset(PACKAGE_NAME LLVM) 32809467b48Spatrickset(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") 329*d415bd75Srobertset(PACKAGE_BUGREPORT "https://github.com/llvm/llvm-project/issues/") 33009467b48Spatrick 33109467b48Spatrickset(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING 33209467b48Spatrick "Default URL where bug reports are to be submitted.") 33309467b48Spatrick 33409467b48Spatrick# Configure CPack. 335*d415bd75Srobertif(NOT DEFINED CPACK_PACKAGE_INSTALL_DIRECTORY) 33609467b48Spatrick set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM") 337*d415bd75Srobertendif() 338*d415bd75Srobertif(NOT DEFINED CPACK_PACKAGE_VENDOR) 33909467b48Spatrick set(CPACK_PACKAGE_VENDOR "LLVM") 340*d415bd75Srobertendif() 34109467b48Spatrickset(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) 34209467b48Spatrickset(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR}) 34309467b48Spatrickset(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH}) 34409467b48Spatrickset(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}) 34509467b48Spatrickset(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT") 34609467b48Spatrickif(WIN32 AND NOT UNIX) 347*d415bd75Srobert set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32") 348*d415bd75Srobert if(NOT DEFINED CPACK_PACKAGE_INSTALL_REGISTRY_KEY) 34909467b48Spatrick set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM") 350*d415bd75Srobert endif() 35109467b48Spatrick set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp") 35209467b48Spatrick set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico") 35309467b48Spatrick set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico") 35409467b48Spatrick set(CPACK_NSIS_MODIFY_PATH "ON") 35509467b48Spatrick set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON") 35609467b48Spatrick if( CMAKE_CL_64 ) 357*d415bd75Srobert if(NOT DEFINED CPACK_NSIS_INSTALL_ROOT) 35809467b48Spatrick set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") 35909467b48Spatrick endif() 36009467b48Spatrick endif() 361*d415bd75Srobertendif() 36209467b48Spatrickinclude(CPack) 36309467b48Spatrick 36409467b48Spatrick# Sanity check our source directory to make sure that we are not trying to 36509467b48Spatrick# generate an in-source build (unless on MSVC_IDE, where it is ok), and to make 36609467b48Spatrick# sure that we don't have any stray generated files lying around in the tree 36709467b48Spatrick# (which would end up getting picked up by header search, instead of the correct 36809467b48Spatrick# versions). 36909467b48Spatrickif( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE ) 37009467b48Spatrick message(FATAL_ERROR "In-source builds are not allowed. 37109467b48SpatrickPlease create a directory and run cmake from there, passing the path 37209467b48Spatrickto this source directory as the last argument. 37309467b48SpatrickThis process created the file `CMakeCache.txt' and the directory `CMakeFiles'. 37409467b48SpatrickPlease delete them.") 37509467b48Spatrickendif() 37609467b48Spatrick 37709467b48Spatrickstring(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) 37809467b48Spatrick 37909467b48Spatrickif (CMAKE_BUILD_TYPE AND 38009467b48Spatrick NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$") 38109467b48Spatrick message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") 38209467b48Spatrickendif() 38309467b48Spatrick 384*d415bd75Srobert# LLVM_INSTALL_PACKAGE_DIR needs to be declared prior to adding the tools 385*d415bd75Srobert# subdirectory in order to have the value available for llvm-config. 386*d415bd75Srobertinclude(GNUInstallPackageDir) 387*d415bd75Srobertset(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING 388*d415bd75Srobert "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')") 38909467b48Spatrick 390*d415bd75Srobertset(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING 391*d415bd75Srobert "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") 39209467b48Spatrickmark_as_advanced(LLVM_TOOLS_INSTALL_DIR) 39309467b48Spatrick 39409467b48Spatrickset(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING 39509467b48Spatrick "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") 39609467b48Spatrickmark_as_advanced(LLVM_UTILS_INSTALL_DIR) 39709467b48Spatrick 398*d415bd75Srobertset(LLVM_EXAMPLES_INSTALL_DIR "examples" CACHE STRING 399*d415bd75Srobert "Path for examples subdirectory (enabled by LLVM_BUILD_EXAMPLES=ON) (defaults to 'examples')") 400*d415bd75Srobertmark_as_advanced(LLVM_EXAMPLES_INSTALL_DIR) 401*d415bd75Srobert 40209467b48Spatrick# They are used as destination of target generators. 40309467b48Spatrickset(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) 40409467b48Spatrickset(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) 40509467b48Spatrickif(WIN32 OR CYGWIN) 40609467b48Spatrick # DLL platform -- put DLLs into bin. 40709467b48Spatrick set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) 40809467b48Spatrickelse() 40909467b48Spatrick set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) 41009467b48Spatrickendif() 41109467b48Spatrick 41209467b48Spatrick# Each of them corresponds to llvm-config's. 41309467b48Spatrickset(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir 41409467b48Spatrickset(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir 41509467b48Spatrickset(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root 41609467b48Spatrickset(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir 41709467b48Spatrickset(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix 41809467b48Spatrick 419*d415bd75Srobert 420*d415bd75Srobert# Note: LLVM_CMAKE_DIR does not include generated files 421*d415bd75Srobertset(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules) 42209467b48Spatrickset(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples) 42309467b48Spatrickset(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) 42409467b48Spatrick 42509467b48Spatrick# List of all targets to be built by default: 42609467b48Spatrickset(LLVM_ALL_TARGETS 42709467b48Spatrick AArch64 42809467b48Spatrick AMDGPU 42909467b48Spatrick ARM 430097a140dSpatrick AVR 43109467b48Spatrick BPF 43209467b48Spatrick Hexagon 43309467b48Spatrick Lanai 434*d415bd75Srobert LoongArch 43509467b48Spatrick Mips 43609467b48Spatrick MSP430 43709467b48Spatrick NVPTX 43809467b48Spatrick PowerPC 43909467b48Spatrick RISCV 44009467b48Spatrick Sparc 44109467b48Spatrick SystemZ 442*d415bd75Srobert VE 44309467b48Spatrick WebAssembly 44409467b48Spatrick X86 44509467b48Spatrick XCore 44609467b48Spatrick ) 44709467b48Spatrick 44809467b48Spatrick# List of targets with JIT support: 44909467b48Spatrickset(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ) 45009467b48Spatrick 45109467b48Spatrickset(LLVM_TARGETS_TO_BUILD "all" 45209467b48Spatrick CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") 45309467b48Spatrick 45409467b48Spatrickset(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD "" 45509467b48Spatrick CACHE STRING "Semicolon-separated list of experimental targets to build.") 45609467b48Spatrick 45709467b48Spatrickoption(BUILD_SHARED_LIBS 45809467b48Spatrick "Build all libraries as shared libraries instead of static" OFF) 45909467b48Spatrick 46009467b48Spatrickoption(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON) 46109467b48Spatrickif(LLVM_ENABLE_BACKTRACES) 46209467b48Spatrick set(ENABLE_BACKTRACES 1) 46309467b48Spatrickendif() 46409467b48Spatrick 46509467b48Spatrickoption(LLVM_ENABLE_UNWIND_TABLES "Emit unwind tables for the libraries" ON) 46609467b48Spatrick 46709467b48Spatrickoption(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON) 46809467b48Spatrickif(LLVM_ENABLE_CRASH_OVERRIDES) 46909467b48Spatrick set(ENABLE_CRASH_OVERRIDES 1) 47009467b48Spatrickendif() 47109467b48Spatrick 47209467b48Spatrickoption(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF) 47309467b48Spatrick 474*d415bd75Srobertset(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF) 475*d415bd75Srobertif (MINGW) 476*d415bd75Srobert # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix 477*d415bd75Srobert # as native path style, regardless of what this is set to. 478*d415bd75Srobert set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT ON) 479*d415bd75Srobertendif() 480*d415bd75Srobertoption(LLVM_WINDOWS_PREFER_FORWARD_SLASH "Prefer path names with forward slashes on Windows." ${WINDOWS_PREFER_FORWARD_SLASH_DEFAULT}) 481*d415bd75Srobert 48209467b48Spatrickoption(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF) 48309467b48Spatrickset(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so") 48409467b48Spatrickset(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h") 48509467b48Spatrick 48609467b48Spatrickset(LLVM_TARGET_ARCH "host" 48709467b48Spatrick CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.") 48809467b48Spatrick 48909467b48Spatrickoption(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON) 49009467b48Spatrick 49109467b48Spatrickset(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON") 49209467b48Spatrick 49309467b48Spatrickoption(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON) 49409467b48Spatrick 49509467b48Spatrickoption(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON) 49609467b48Spatrick 49773471bf0Spatrick# On z/OS, threads cannot be used because TLS is not supported. 49873471bf0Spatrickif (CMAKE_SYSTEM_NAME MATCHES "OS390") 49973471bf0Spatrick option(LLVM_ENABLE_THREADS "Use threads if available." OFF) 50073471bf0Spatrickelse() 50109467b48Spatrick option(LLVM_ENABLE_THREADS "Use threads if available." ON) 50273471bf0Spatrickendif() 50309467b48Spatrick 504097a140dSpatrickset(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON") 50509467b48Spatrick 506*d415bd75Srobertset(LLVM_ENABLE_ZSTD "ON" CACHE STRING "Use zstd for compression/decompression if available. Can be ON, OFF, or FORCE_ON") 507*d415bd75Srobert 508*d415bd75Srobertset(LLVM_USE_STATIC_ZSTD FALSE CACHE BOOL "Use static version of zstd. Can be TRUE, FALSE") 509*d415bd75Srobert 510*d415bd75Srobertset(LLVM_ENABLE_CURL "OFF" CACHE STRING "Use libcurl for the HTTP client if available. Can be ON, OFF, or FORCE_ON") 511*d415bd75Srobert 512*d415bd75Srobertset(LLVM_ENABLE_HTTPLIB "OFF" CACHE STRING "Use cpp-httplib HTTP server library if available. Can be ON, OFF, or FORCE_ON") 513*d415bd75Srobert 51409467b48Spatrickset(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.") 51509467b48Spatrick 516097a140dSpatrickoption(LLVM_ENABLE_Z3_SOLVER 517097a140dSpatrick "Enable Support for the Z3 constraint solver in LLVM." 518097a140dSpatrick ${LLVM_ENABLE_Z3_SOLVER_DEFAULT} 519097a140dSpatrick) 520097a140dSpatrick 521097a140dSpatrickif (LLVM_ENABLE_Z3_SOLVER) 52209467b48Spatrick find_package(Z3 4.7.1) 52309467b48Spatrick 52409467b48Spatrick if (LLVM_Z3_INSTALL_DIR) 52509467b48Spatrick if (NOT Z3_FOUND) 52609467b48Spatrick message(FATAL_ERROR "Z3 >= 4.7.1 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.") 52709467b48Spatrick endif() 52809467b48Spatrick endif() 52909467b48Spatrick 53009467b48Spatrick if (NOT Z3_FOUND) 53109467b48Spatrick message(FATAL_ERROR "LLVM_ENABLE_Z3_SOLVER cannot be enabled when Z3 is not available.") 53209467b48Spatrick endif() 53309467b48Spatrick 53409467b48Spatrick set(LLVM_WITH_Z3 1) 53509467b48Spatrickendif() 53609467b48Spatrick 537097a140dSpatrickset(LLVM_ENABLE_Z3_SOLVER_DEFAULT "${Z3_FOUND}") 538097a140dSpatrick 539097a140dSpatrick 54009467b48Spatrickif( LLVM_TARGETS_TO_BUILD STREQUAL "all" ) 54109467b48Spatrick set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} ) 54209467b48Spatrickendif() 54309467b48Spatrick 54409467b48Spatrickset(LLVM_TARGETS_TO_BUILD 54509467b48Spatrick ${LLVM_TARGETS_TO_BUILD} 54609467b48Spatrick ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}) 54709467b48Spatricklist(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) 54809467b48Spatrick 54909467b48Spatrickoption(LLVM_ENABLE_PIC "Build Position-Independent Code" ON) 55009467b48Spatrickoption(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF) 55109467b48Spatrickif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 55209467b48Spatrick option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON) 55309467b48Spatrickelse() 55409467b48Spatrick option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF) 55509467b48Spatrickendif() 556097a140dSpatrickoption(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON) 55709467b48Spatrickoption(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF) 55809467b48Spatrickoption(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF) 55909467b48Spatrickoption(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF) 56009467b48Spatrickoption(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) 56109467b48Spatrickoption(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) 56209467b48Spatrick 56309467b48Spatrickoption(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF) 564*d415bd75Srobertoption(LLVM_UNREACHABLE_OPTIMIZE "Optimize llvm_unreachable() as undefined behavior (default), guaranteed trap when OFF" ON) 56509467b48Spatrick 56609467b48Spatrickif( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) 56709467b48Spatrick option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF) 56809467b48Spatrickelse() 56909467b48Spatrick option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON) 57009467b48Spatrickendif() 57109467b48Spatrick 57209467b48Spatrickoption(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF) 57309467b48Spatrick 574097a140dSpatrick# While adding scalable vector support to LLVM, we temporarily want to 575097a140dSpatrick# allow an implicit conversion of TypeSize to uint64_t, and to allow 576097a140dSpatrick# code to get the fixed number of elements from a possibly scalable vector. 577097a140dSpatrick# This CMake flag enables a more strict mode where it asserts that the type 578097a140dSpatrick# is not a scalable vector type. 579097a140dSpatrick# 580097a140dSpatrick# Enabling this flag makes it easier to find cases where the compiler makes 581097a140dSpatrick# assumptions on the size being 'fixed size', when building tests for 582097a140dSpatrick# SVE/SVE2 or other scalable vector architectures. 583097a140dSpatrickoption(LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS 584097a140dSpatrick "Enable assertions that type is not scalable in implicit conversion from TypeSize to uint64_t and calls to getNumElements" OFF) 585097a140dSpatrick 58609467b48Spatrickset(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING 58709467b48Spatrick "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.") 58809467b48Spatrick 58909467b48Spatrickoption(LLVM_FORCE_USE_OLD_TOOLCHAIN 59009467b48Spatrick "Set to ON to force using an old, unsupported host toolchain." OFF) 59109467b48Spatrick 592097a140dSpatrickset(LLVM_LOCAL_RPATH "" CACHE FILEPATH 593097a140dSpatrick "If set, an absolute path added as rpath on binaries that do not already contain an executable-relative rpath.") 594097a140dSpatrick 59509467b48Spatrickoption(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN 59609467b48Spatrick "Set to ON to only warn when using a toolchain which is about to be deprecated, instead of emitting an error." OFF) 59709467b48Spatrick 59809467b48Spatrickoption(LLVM_USE_INTEL_JITEVENTS 59909467b48Spatrick "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code" 60009467b48Spatrick OFF) 60109467b48Spatrick 60209467b48Spatrickif( LLVM_USE_INTEL_JITEVENTS ) 60309467b48Spatrick # Verify we are on a supported platform 60409467b48Spatrick if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) 60509467b48Spatrick message(FATAL_ERROR 60609467b48Spatrick "Intel JIT API support is available on Linux and Windows only.") 60709467b48Spatrick endif() 60809467b48Spatrickendif( LLVM_USE_INTEL_JITEVENTS ) 60909467b48Spatrick 61009467b48Spatrickoption(LLVM_USE_OPROFILE 61109467b48Spatrick "Use opagent JIT interface to inform OProfile about JIT code" OFF) 61209467b48Spatrick 61309467b48Spatrickoption(LLVM_EXTERNALIZE_DEBUGINFO 61409467b48Spatrick "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF) 61509467b48Spatrick 61609467b48Spatrickset(LLVM_CODESIGNING_IDENTITY "" CACHE STRING 61709467b48Spatrick "Sign executables and dylibs with the given identity or skip if empty (Darwin Only)") 61809467b48Spatrick 61909467b48Spatrick# If enabled, verify we are on a platform that supports oprofile. 62009467b48Spatrickif( LLVM_USE_OPROFILE ) 62109467b48Spatrick if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) 62209467b48Spatrick message(FATAL_ERROR "OProfile support is available on Linux only.") 62309467b48Spatrick endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) 62409467b48Spatrickendif( LLVM_USE_OPROFILE ) 62509467b48Spatrick 62609467b48Spatrickoption(LLVM_USE_PERF 62709467b48Spatrick "Use perf JIT interface to inform perf about JIT code" OFF) 62809467b48Spatrick 62909467b48Spatrick# If enabled, verify we are on a platform that supports perf. 63009467b48Spatrickif( LLVM_USE_PERF ) 63109467b48Spatrick if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) 63209467b48Spatrick message(FATAL_ERROR "perf support is available on Linux only.") 63309467b48Spatrick endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) 63409467b48Spatrickendif( LLVM_USE_PERF ) 63509467b48Spatrick 63609467b48Spatrickset(LLVM_USE_SANITIZER "" CACHE STRING 63709467b48Spatrick "Define the sanitizer used to build binaries and tests.") 63809467b48Spatrickoption(LLVM_OPTIMIZE_SANITIZED_BUILDS "Pass -O1 on debug sanitizer builds" ON) 63973471bf0Spatrickset(LLVM_UBSAN_FLAGS 64073471bf0Spatrick "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all" 64173471bf0Spatrick CACHE STRING 64273471bf0Spatrick "Compile flags set to enable UBSan. Only used if LLVM_USE_SANITIZER contains 'Undefined'.") 64309467b48Spatrickset(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH 64409467b48Spatrick "Path to fuzzing library for linking with fuzz targets") 64509467b48Spatrick 64609467b48Spatrickoption(LLVM_USE_SPLIT_DWARF 647*d415bd75Srobert "Use -gsplit-dwarf when compiling llvm and --gdb-index when linking." OFF) 64809467b48Spatrick 64909467b48Spatrick# Define an option controlling whether we should build for 32-bit on 64-bit 65009467b48Spatrick# platforms, where supported. 651097a140dSpatrickif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")) 65209467b48Spatrick # TODO: support other platforms and toolchains. 65309467b48Spatrick option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF) 65409467b48Spatrickendif() 65509467b48Spatrick 65609467b48Spatrick# Define the default arguments to use with 'lit', and an option for the user to 65709467b48Spatrick# override. 65809467b48Spatrickset(LIT_ARGS_DEFAULT "-sv") 65909467b48Spatrickif (MSVC_IDE OR XCODE) 66009467b48Spatrick set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") 66109467b48Spatrickendif() 66209467b48Spatrickset(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") 66309467b48Spatrick 66409467b48Spatrick# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. 66509467b48Spatrickif( WIN32 AND NOT CYGWIN ) 66609467b48Spatrick set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") 66709467b48Spatrickendif() 668*d415bd75Srobertset(LLVM_NATIVE_TOOL_DIR "" CACHE PATH "Path to a directory containing prebuilt matching native tools (such as llvm-tblgen)") 66909467b48Spatrick 67073471bf0Spatrickset(LLVM_INTEGRATED_CRT_ALLOC "" CACHE PATH "Replace the Windows CRT allocator with any of {rpmalloc|mimalloc|snmalloc}. Only works with /MT enabled.") 67173471bf0Spatrickif(LLVM_INTEGRATED_CRT_ALLOC) 67273471bf0Spatrick if(NOT WIN32) 67373471bf0Spatrick message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows.") 67473471bf0Spatrick endif() 67573471bf0Spatrick if(LLVM_USE_SANITIZER) 67673471bf0Spatrick message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used along with LLVM_USE_SANITIZER!") 67773471bf0Spatrick endif() 67873471bf0Spatrick if(CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") 67973471bf0Spatrick message(FATAL_ERROR "The Debug target isn't supported along with LLVM_INTEGRATED_CRT_ALLOC!") 68073471bf0Spatrick endif() 68173471bf0Spatrickendif() 68273471bf0Spatrick 68309467b48Spatrick# Define options to control the inclusion and default build behavior for 68409467b48Spatrick# components which may not strictly be necessary (tools, examples, and tests). 68509467b48Spatrick# 68609467b48Spatrick# This is primarily to support building smaller or faster project files. 68709467b48Spatrickoption(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON) 68809467b48Spatrickoption(LLVM_BUILD_TOOLS 68909467b48Spatrick "Build the LLVM tools. If OFF, just generate build targets." ON) 69009467b48Spatrick 69109467b48Spatrickoption(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON) 69209467b48Spatrickoption(LLVM_BUILD_UTILS 69309467b48Spatrick "Build LLVM utility binaries. If OFF, just generate build targets." ON) 69409467b48Spatrick 69509467b48Spatrickoption(LLVM_INCLUDE_RUNTIMES "Generate build targets for the LLVM runtimes." ON) 69609467b48Spatrickoption(LLVM_BUILD_RUNTIMES 69709467b48Spatrick "Build the LLVM runtimes. If OFF, just generate build targets." ON) 69809467b48Spatrick 69909467b48Spatrickoption(LLVM_BUILD_RUNTIME 70009467b48Spatrick "Build the LLVM runtime libraries." ON) 70109467b48Spatrickoption(LLVM_BUILD_EXAMPLES 70209467b48Spatrick "Build the LLVM example programs. If OFF, just generate build targets." OFF) 70309467b48Spatrickoption(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON) 70409467b48Spatrick 70509467b48Spatrickif(LLVM_BUILD_EXAMPLES) 706*d415bd75Srobert add_compile_definitions(BUILD_EXAMPLES) 70709467b48Spatrickendif(LLVM_BUILD_EXAMPLES) 70809467b48Spatrick 70909467b48Spatrickoption(LLVM_BUILD_TESTS 71009467b48Spatrick "Build LLVM unit tests. If OFF, just generate build targets." OFF) 71109467b48Spatrickoption(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON) 71209467b48Spatrick 71309467b48Spatrickoption(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default 71409467b48Spatricktargets. If OFF, benchmarks still could be built using Benchmarks target." OFF) 71509467b48Spatrickoption(LLVM_INCLUDE_BENCHMARKS "Generate benchmark targets. If OFF, benchmarks can't be built." ON) 71609467b48Spatrick 71709467b48Spatrickoption (LLVM_BUILD_DOCS "Build the llvm documentation." OFF) 71809467b48Spatrickoption (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON) 71909467b48Spatrickoption (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF) 72009467b48Spatrickoption (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) 72109467b48Spatrickoption (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) 72209467b48Spatrickoption (LLVM_ENABLE_BINDINGS "Build bindings." ON) 72309467b48Spatrick 724*d415bd75Srobertset(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html" 72509467b48Spatrick CACHE STRING "Doxygen-generated HTML documentation install directory") 726*d415bd75Srobertset(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/ocaml-html" 72709467b48Spatrick CACHE STRING "OCamldoc-generated HTML documentation install directory") 72809467b48Spatrick 72909467b48Spatrickoption (LLVM_BUILD_EXTERNAL_COMPILER_RT 73009467b48Spatrick "Build compiler-rt as an external project." OFF) 73109467b48Spatrick 73209467b48Spatrickoption (LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO 73309467b48Spatrick "Show target and host info when tools are invoked with --version." ON) 73409467b48Spatrick 73509467b48Spatrick# You can configure which libraries from LLVM you want to include in the 73609467b48Spatrick# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited 73709467b48Spatrick# list of LLVM components. All component names handled by llvm-config are valid. 73809467b48Spatrickif(NOT DEFINED LLVM_DYLIB_COMPONENTS) 73909467b48Spatrick set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING 74009467b48Spatrick "Semicolon-separated list of components to include in libLLVM, or \"all\".") 74109467b48Spatrickendif() 74209467b48Spatrick 74309467b48Spatrickif(MSVC) 74409467b48Spatrick option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" ON) 74509467b48Spatrick # Set this variable to OFF here so it can't be set with a command-line 74609467b48Spatrick # argument. 74709467b48Spatrick set (LLVM_LINK_LLVM_DYLIB OFF) 74809467b48Spatrick if (BUILD_SHARED_LIBS) 74909467b48Spatrick message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.") 75009467b48Spatrick endif() 75109467b48Spatrickelse() 75209467b48Spatrick option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF) 75309467b48Spatrick option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF) 75409467b48Spatrick set(LLVM_BUILD_LLVM_DYLIB_default OFF) 75509467b48Spatrick if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB) 75609467b48Spatrick set(LLVM_BUILD_LLVM_DYLIB_default ON) 75709467b48Spatrick endif() 75809467b48Spatrick option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}) 75909467b48Spatrickendif() 76009467b48Spatrick 76109467b48Spatrickif (LLVM_LINK_LLVM_DYLIB AND BUILD_SHARED_LIBS) 76209467b48Spatrick message(FATAL_ERROR "Cannot enable BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB. We recommend disabling BUILD_SHARED_LIBS.") 76309467b48Spatrickendif() 76409467b48Spatrick 76509467b48Spatrickoption(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF) 76609467b48Spatrickif(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES))) 76709467b48Spatrick set(LLVM_USE_HOST_TOOLS ON) 76809467b48Spatrickendif() 76909467b48Spatrick 770*d415bd75Srobertoption(LLVM_OMIT_DAGISEL_COMMENTS "Do not add comments to DAG ISel" ON) 771*d415bd75Srobertif (CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE MATCHES "^(RELWITHDEBINFO|DEBUG)$") 772*d415bd75Srobert set(LLVM_OMIT_DAGISEL_COMMENTS OFF) 773*d415bd75Srobertendif() 774*d415bd75Srobert 77509467b48Spatrickif (MSVC_IDE) 77609467b48Spatrick option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE) 77709467b48Spatrickendif() 77809467b48Spatrick 77909467b48Spatrickif (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE OR 78009467b48Spatrick LLVM_ENABLE_IR_PGO) 78109467b48Spatrick if(NOT LLVM_PROFILE_MERGE_POOL_SIZE) 78209467b48Spatrick # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine 78309467b48Spatrick # for spining disks. Anything higher may only help on slower mediums. 78409467b48Spatrick set(LLVM_PROFILE_MERGE_POOL_SIZE "4") 78509467b48Spatrick endif() 78609467b48Spatrick if(NOT LLVM_PROFILE_FILE_PATTERN) 78709467b48Spatrick if(NOT LLVM_PROFILE_DATA_DIR) 78809467b48Spatrick file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles" LLVM_PROFILE_DATA_DIR) 78909467b48Spatrick endif() 79009467b48Spatrick file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN) 79109467b48Spatrick endif() 79209467b48Spatrick if(NOT LLVM_CSPROFILE_FILE_PATTERN) 79309467b48Spatrick if(NOT LLVM_CSPROFILE_DATA_DIR) 79409467b48Spatrick file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/csprofiles" LLVM_CSPROFILE_DATA_DIR) 79509467b48Spatrick endif() 79609467b48Spatrick file(TO_NATIVE_PATH "${LLVM_CSPROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_CSPROFILE_FILE_PATTERN) 79709467b48Spatrick endif() 79809467b48Spatrickendif() 79909467b48Spatrick 80009467b48Spatrickif (LLVM_BUILD_STATIC) 80109467b48Spatrick set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") 80273471bf0Spatrick # Remove shared library suffixes from use in find_library 80373471bf0Spatrick foreach (shared_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_IMPORT_LIBRARY_SUFFIX}) 80473471bf0Spatrick list(FIND CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix} shared_lib_suffix_idx) 80573471bf0Spatrick if(NOT ${shared_lib_suffix_idx} EQUAL -1) 80673471bf0Spatrick list(REMOVE_AT CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix_idx}) 80773471bf0Spatrick endif() 80873471bf0Spatrick endforeach() 80909467b48Spatrickendif() 81009467b48Spatrick 81109467b48Spatrick# Use libtool instead of ar if you are both on an Apple host, and targeting Apple. 81209467b48Spatrickif(CMAKE_HOST_APPLE AND APPLE) 81309467b48Spatrick include(UseLibtool) 81409467b48Spatrickendif() 81509467b48Spatrick 81609467b48Spatrick# Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV. 81709467b48Spatrickset(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.") 81809467b48Spatrickmark_as_advanced(LLVM_TARGET_TRIPLE_ENV) 81909467b48Spatrick 820*d415bd75Srobert# Per target dir not yet supported on Arm 32 bit due to arm vs armhf handling 821*d415bd75Srobertif(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") 822*d415bd75Srobert set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON) 823*d415bd75Srobertelse() 824*d415bd75Srobert set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF) 825*d415bd75Srobertendif() 826*d415bd75Srobertset(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default} CACHE BOOL 82709467b48Spatrick "Enable per-target runtimes directory") 82809467b48Spatrick 82909467b48Spatrickset(LLVM_PROFDATA_FILE "" CACHE FILEPATH 83009467b48Spatrick "Profiling data file to use when compiling in order to improve runtime performance.") 83109467b48Spatrick 832*d415bd75Srobertif(LLVM_INCLUDE_TESTS) 833*d415bd75Srobert # Lit test suite requires at least python 3.6 834*d415bd75Srobert set(LLVM_MINIMUM_PYTHON_VERSION 3.6) 835*d415bd75Srobertelse() 836*d415bd75Srobert # FIXME: it is unknown if this is the actual minimum bound 837*d415bd75Srobert set(LLVM_MINIMUM_PYTHON_VERSION 3.0) 838*d415bd75Srobertendif() 839*d415bd75Srobert 840*d415bd75Srobert# Find python before including config-ix, since it needs to be able to search 841*d415bd75Srobert# for python modules. 842*d415bd75Srobertfind_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED 843*d415bd75Srobert COMPONENTS Interpreter) 844*d415bd75Srobert 84509467b48Spatrick# All options referred to from HandleLLVMOptions have to be specified 84609467b48Spatrick# BEFORE this include, otherwise options will not be correctly set on 84709467b48Spatrick# first cmake run 84809467b48Spatrickinclude(config-ix) 84909467b48Spatrick 85009467b48Spatrick# By default, we target the host, but this can be overridden at CMake 851*d415bd75Srobert# invocation time. Except on 64-bit AIX, where the system toolchain 852*d415bd75Srobert# expect 32-bit objects by default. 853*d415bd75Srobertif("${LLVM_HOST_TRIPLE}" MATCHES "^powerpc64-ibm-aix") 854*d415bd75Srobert string(REGEX REPLACE "^powerpc64" "powerpc" LLVM_DEFAULT_TARGET_TRIPLE_default "${LLVM_HOST_TRIPLE}") 855*d415bd75Srobertelse() 856*d415bd75Srobert # Only set default triple when native target is enabled. 857*d415bd75Srobert if (LLVM_NATIVE_TARGET) 858*d415bd75Srobert set(LLVM_DEFAULT_TARGET_TRIPLE_default "${LLVM_HOST_TRIPLE}") 859*d415bd75Srobert endif() 860*d415bd75Srobertendif() 861*d415bd75Srobert 862*d415bd75Srobertinclude(SetTargetTriple) 863*d415bd75Srobertset_llvm_target_triple() 86409467b48Spatrick 86509467b48Spatrickif(WIN32 OR CYGWIN) 86609467b48Spatrick if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB) 86709467b48Spatrick set(LLVM_ENABLE_PLUGINS_default ON) 86809467b48Spatrick else() 86909467b48Spatrick set(LLVM_ENABLE_PLUGINS_default OFF) 87009467b48Spatrick endif() 87109467b48Spatrickelse() 87209467b48Spatrick set(LLVM_ENABLE_PLUGINS_default ${LLVM_ENABLE_PIC}) 87309467b48Spatrickendif() 87409467b48Spatrickoption(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default}) 87509467b48Spatrick 87673471bf0Spatrickset(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL 87773471bf0Spatrick "Enable the new pass manager by default.") 87873471bf0Spatrickif(NOT LLVM_ENABLE_NEW_PASS_MANAGER) 879*d415bd75Srobert message(FATAL_ERROR "Enabling the legacy pass manager on the cmake level is" 880*d415bd75Srobert " no longer supported.") 88173471bf0Spatrickendif() 88273471bf0Spatrick 88309467b48Spatrickinclude(HandleLLVMOptions) 88409467b48Spatrick 88509467b48Spatrick###### 88609467b48Spatrick 88709467b48Spatrick# Configure all of the various header file fragments LLVM uses which depend on 88809467b48Spatrick# configuration variables. 88909467b48Spatrickset(LLVM_ENUM_TARGETS "") 89009467b48Spatrickset(LLVM_ENUM_ASM_PRINTERS "") 89109467b48Spatrickset(LLVM_ENUM_ASM_PARSERS "") 89209467b48Spatrickset(LLVM_ENUM_DISASSEMBLERS "") 893*d415bd75Srobertset(LLVM_ENUM_TARGETMCAS "") 894*d415bd75Srobertset(LLVM_ENUM_EXEGESIS "") 89509467b48Spatrickforeach(t ${LLVM_TARGETS_TO_BUILD}) 89609467b48Spatrick set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} ) 89709467b48Spatrick 89809467b48Spatrick list(FIND LLVM_ALL_TARGETS ${t} idx) 89909467b48Spatrick list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy) 90009467b48Spatrick # At this point, LLVMBUILDTOOL already checked all the targets passed in 90109467b48Spatrick # LLVM_TARGETS_TO_BUILD and LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, so 90209467b48Spatrick # this test just makes sure that any experimental targets were passed via 90309467b48Spatrick # LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, not LLVM_TARGETS_TO_BUILD. 90409467b48Spatrick if( idx LESS 0 AND idy LESS 0 ) 90509467b48Spatrick message(FATAL_ERROR "The target `${t}' is experimental and must be passed " 90609467b48Spatrick "via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.") 90709467b48Spatrick else() 90809467b48Spatrick set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n") 90909467b48Spatrick endif() 91009467b48Spatrick 91109467b48Spatrick file(GLOB asmp_file "${td}/*AsmPrinter.cpp") 91209467b48Spatrick if( asmp_file ) 91309467b48Spatrick set(LLVM_ENUM_ASM_PRINTERS 91409467b48Spatrick "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n") 91509467b48Spatrick endif() 91609467b48Spatrick if( EXISTS ${td}/AsmParser/CMakeLists.txt ) 91709467b48Spatrick set(LLVM_ENUM_ASM_PARSERS 91809467b48Spatrick "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n") 91909467b48Spatrick endif() 92009467b48Spatrick if( EXISTS ${td}/Disassembler/CMakeLists.txt ) 92109467b48Spatrick set(LLVM_ENUM_DISASSEMBLERS 92209467b48Spatrick "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n") 92309467b48Spatrick endif() 924*d415bd75Srobert if( EXISTS ${td}/MCA/CMakeLists.txt ) 925*d415bd75Srobert set(LLVM_ENUM_TARGETMCAS 926*d415bd75Srobert "${LLVM_ENUM_TARGETMCAS}LLVM_TARGETMCA(${t})\n") 927*d415bd75Srobert endif() 928*d415bd75Srobert if( EXISTS ${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib/${t}/CMakeLists.txt ) 929*d415bd75Srobert set(LLVM_ENUM_EXEGESIS 930*d415bd75Srobert "${LLVM_ENUM_EXEGESIS}LLVM_EXEGESIS(${t})\n") 931*d415bd75Srobert endif() 93209467b48Spatrickendforeach(t) 93309467b48Spatrick 934*d415bd75Srobert# Provide an LLVM_ namespaced alias for use in #cmakedefine. 935*d415bd75Srobertset(LLVM_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) 936*d415bd75Srobert 93709467b48Spatrick# Produce the target definition files, which provide a way for clients to easily 93809467b48Spatrick# include various classes of targets. 93909467b48Spatrickconfigure_file( 94009467b48Spatrick ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in 94109467b48Spatrick ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def 94209467b48Spatrick ) 94309467b48Spatrickconfigure_file( 94409467b48Spatrick ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in 94509467b48Spatrick ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def 94609467b48Spatrick ) 94709467b48Spatrickconfigure_file( 94809467b48Spatrick ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in 94909467b48Spatrick ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def 95009467b48Spatrick ) 95109467b48Spatrickconfigure_file( 95209467b48Spatrick ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in 95309467b48Spatrick ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def 95409467b48Spatrick ) 955*d415bd75Srobertconfigure_file( 956*d415bd75Srobert ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetMCAs.def.in 957*d415bd75Srobert ${LLVM_INCLUDE_DIR}/llvm/Config/TargetMCAs.def 958*d415bd75Srobert ) 959*d415bd75Srobertconfigure_file( 960*d415bd75Srobert ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetExegesis.def.in 961*d415bd75Srobert ${LLVM_INCLUDE_DIR}/llvm/Config/TargetExegesis.def 962*d415bd75Srobert ) 96309467b48Spatrick 964097a140dSpatrick# They are not referenced. See set_output_directory(). 965*d415bd75Srobertset( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} ) 966*d415bd75Srobertset( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_LIBRARY_DIR} ) 967*d415bd75Srobertset( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_LIBRARY_DIR} ) 968097a140dSpatrick 96973471bf0Spatrickif(LLVM_INCLUDE_TESTS) 97073471bf0Spatrick include(GetErrcMessages) 97173471bf0Spatrick get_errc_messages(LLVM_LIT_ERRC_MESSAGES) 97273471bf0Spatrickendif() 97373471bf0Spatrick 974*d415bd75Srobert# For up-to-date instructions for installing the TFLite dependency, refer to 975*d415bd75Srobert# the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh 976*d415bd75Srobertset(LLVM_HAVE_TFLITE "" CACHE BOOL "Use tflite") 977*d415bd75Srobertif (LLVM_HAVE_TFLITE) 978*d415bd75Srobert find_package(tensorflow-lite REQUIRED) 97973471bf0Spatrickendif() 98073471bf0Spatrick 98173471bf0Spatrick# For up-to-date instructions for installing the Tensorflow dependency, refer to 982*d415bd75Srobert# the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh 98373471bf0Spatrick# Specifically, assuming python3 is installed: 98473471bf0Spatrick# python3 -m pip install --upgrade pip && python3 -m pip install --user tf_nightly==2.3.0.dev20200528 98573471bf0Spatrick# Then set TENSORFLOW_AOT_PATH to the package install - usually it's ~/.local/lib/python3.7/site-packages/tensorflow 98673471bf0Spatrick# 98773471bf0Spatrickset(TENSORFLOW_AOT_PATH "" CACHE PATH "Path to TensorFlow pip install dir") 98873471bf0Spatrick 98973471bf0Spatrickif (NOT TENSORFLOW_AOT_PATH STREQUAL "") 99073471bf0Spatrick set(LLVM_HAVE_TF_AOT "ON" CACHE BOOL "Tensorflow AOT available") 99173471bf0Spatrick set(TENSORFLOW_AOT_COMPILER 99273471bf0Spatrick "${TENSORFLOW_AOT_PATH}/../../../../bin/saved_model_cli" 99373471bf0Spatrick CACHE PATH "Path to the Tensorflow AOT compiler") 99473471bf0Spatrick include_directories(${TENSORFLOW_AOT_PATH}/include) 99573471bf0Spatrick add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src 99673471bf0Spatrick ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) 99773471bf0Spatrick install(TARGETS tf_xla_runtime EXPORT LLVMExports 99873471bf0Spatrick ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) 99973471bf0Spatrick set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) 1000*d415bd75Srobert # Once we add more modules, we should handle this more automatically. 1001*d415bd75Srobert if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) 1002*d415bd75Srobert set(LLVM_INLINER_MODEL_PATH "none") 1003*d415bd75Srobert elseif(NOT DEFINED LLVM_INLINER_MODEL_PATH 1004*d415bd75Srobert OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL "" 1005*d415bd75Srobert OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL "autogenerate") 1006*d415bd75Srobert set(LLVM_INLINER_MODEL_PATH "autogenerate") 1007*d415bd75Srobert set(LLVM_INLINER_MODEL_AUTOGENERATED 1) 1008*d415bd75Srobert endif() 1009*d415bd75Srobert if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_REGALLOCEVICTMODEL) 1010*d415bd75Srobert set(LLVM_RAEVICT_MODEL_PATH "none") 1011*d415bd75Srobert elseif(NOT DEFINED LLVM_RAEVICT_MODEL_PATH 1012*d415bd75Srobert OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL "" 1013*d415bd75Srobert OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL "autogenerate") 1014*d415bd75Srobert set(LLVM_RAEVICT_MODEL_PATH "autogenerate") 1015*d415bd75Srobert set(LLVM_RAEVICT_MODEL_AUTOGENERATED 1) 1016*d415bd75Srobert endif() 1017*d415bd75Srobert 1018097a140dSpatrickendif() 1019097a140dSpatrick 102009467b48Spatrick# Configure the three LLVM configuration header files. 102109467b48Spatrickconfigure_file( 102209467b48Spatrick ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake 102309467b48Spatrick ${LLVM_INCLUDE_DIR}/llvm/Config/config.h) 102409467b48Spatrickconfigure_file( 102509467b48Spatrick ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake 102609467b48Spatrick ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h) 102709467b48Spatrickconfigure_file( 102809467b48Spatrick ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake 102909467b48Spatrick ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h) 103009467b48Spatrick 103109467b48Spatrick# Add target for generating source rpm package. 103209467b48Spatrickset(LLVM_SRPM_USER_BINARY_SPECFILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm.spec.in 103309467b48Spatrick CACHE FILEPATH ".spec file to use for srpm generation") 103409467b48Spatrickset(LLVM_SRPM_BINARY_SPECFILE ${CMAKE_CURRENT_BINARY_DIR}/llvm.spec) 103509467b48Spatrickset(LLVM_SRPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/srpm") 103609467b48Spatrick 103709467b48Spatrickget_source_info(${CMAKE_CURRENT_SOURCE_DIR} revision repository) 103809467b48Spatrickstring(LENGTH "${revision}" revision_length) 103909467b48Spatrickset(LLVM_RPM_SPEC_REVISION "${revision}") 104009467b48Spatrick 104109467b48Spatrickconfigure_file( 104209467b48Spatrick ${LLVM_SRPM_USER_BINARY_SPECFILE} 104309467b48Spatrick ${LLVM_SRPM_BINARY_SPECFILE} @ONLY) 104409467b48Spatrick 104509467b48Spatrickadd_custom_target(srpm 104609467b48Spatrick COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES 104709467b48Spatrick COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE}) 104809467b48Spatrickset_target_properties(srpm PROPERTIES FOLDER "Misc") 104909467b48Spatrick 105009467b48Spatrickif(APPLE AND DARWIN_LTO_LIBRARY) 105109467b48Spatrick set(CMAKE_EXE_LINKER_FLAGS 105209467b48Spatrick "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") 105309467b48Spatrick set(CMAKE_SHARED_LINKER_FLAGS 105409467b48Spatrick "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") 105509467b48Spatrick set(CMAKE_MODULE_LINKER_FLAGS 105609467b48Spatrick "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") 105709467b48Spatrickendif() 105809467b48Spatrick 105909467b48Spatrick# Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to 106009467b48Spatrick# break things. In this case we need to enable the large-file API as well. 106109467b48Spatrickif (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") 1062*d415bd75Srobert add_compile_definitions(_XOPEN_SOURCE=700) 1063*d415bd75Srobert add_compile_definitions(_LARGE_FILE_API) 1064097a140dSpatrick 1065097a140dSpatrick # CMake versions less than 3.16 set default linker flags to include -brtl, as 1066097a140dSpatrick # well as setting -G when building libraries, so clear them out. Note we only 1067097a140dSpatrick # try to clear the form that CMake will set as part of its initial 1068097a140dSpatrick # configuration, it is still possible the user may force it as part of a 1069097a140dSpatrick # compound option. 1070097a140dSpatrick if(CMAKE_VERSION VERSION_LESS 3.16) 1071097a140dSpatrick string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") 1072097a140dSpatrick string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") 1073097a140dSpatrick string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}") 1074097a140dSpatrick string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS 1075097a140dSpatrick "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}") 1076097a140dSpatrick string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS 1077097a140dSpatrick "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}") 1078097a140dSpatrick string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS 1079097a140dSpatrick "${CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS}") 108073471bf0Spatrick string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS 108173471bf0Spatrick "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}") 108273471bf0Spatrick string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS 108373471bf0Spatrick "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}") 108473471bf0Spatrick string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS 108573471bf0Spatrick "${CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS}") 1086097a140dSpatrick endif() 1087097a140dSpatrick 108873471bf0Spatrick # Modules should be built with -shared -Wl,-G, so we can use runtime linking 108973471bf0Spatrick # with plugins. 109073471bf0Spatrick string(APPEND CMAKE_MODULE_LINKER_FLAGS " -shared -Wl,-G") 1091097a140dSpatrick 1092097a140dSpatrick # Also set the correct flags for building shared libraries. 1093097a140dSpatrick string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared") 109409467b48Spatrickendif() 109509467b48Spatrick 109673471bf0Spatrick# Build with _XOPEN_SOURCE on z/OS. 109773471bf0Spatrickif (CMAKE_SYSTEM_NAME MATCHES "OS390") 1098*d415bd75Srobert add_compile_definitions(_XOPEN_SOURCE=600) 1099*d415bd75Srobert add_compile_definitions(_OPEN_SYS) # Needed for process information. 1100*d415bd75Srobert add_compile_definitions(_OPEN_SYS_FILE_EXT) # Needed for EBCDIC I/O. 110173471bf0Spatrickendif() 110273471bf0Spatrick 110309467b48Spatrick# Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9. 110409467b48Spatrickif (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") 1105*d415bd75Srobert add_compile_definitions(_FILE_OFFSET_BITS=64) 110609467b48Spatrickendif() 110709467b48Spatrick 110809467b48Spatrickset(CMAKE_INCLUDE_CURRENT_DIR ON) 110909467b48Spatrick 111009467b48Spatrickinclude_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}) 111109467b48Spatrick 111209467b48Spatrick# when crosscompiling import the executable targets from a file 111309467b48Spatrickif(LLVM_USE_HOST_TOOLS) 111409467b48Spatrick include(CrossCompile) 111509467b48Spatrick llvm_create_cross_target(LLVM NATIVE "" Release) 111609467b48Spatrickendif(LLVM_USE_HOST_TOOLS) 111709467b48Spatrickif(LLVM_TARGET_IS_CROSSCOMPILE_HOST) 111809467b48Spatrick# Dummy use to avoid CMake Warning: Manually-specified variables were not used 111909467b48Spatrick# (this is a variable that CrossCompile sets on recursive invocations) 112009467b48Spatrickendif() 112109467b48Spatrick 112209467b48Spatrickif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) 112309467b48Spatrick # special hack for Solaris to handle crazy system sys/regset.h 112409467b48Spatrick include_directories("${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/Solaris") 112509467b48Spatrickendif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) 112609467b48Spatrick 112709467b48Spatrick# Make sure we don't get -rdynamic in every binary. For those that need it, 112809467b48Spatrick# use export_executable_symbols(target). 112909467b48Spatrickset(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") 113009467b48Spatrick 1131*d415bd75Srobertset(LLVM_EXTRACT_SYMBOLS_FLAGS "" 1132*d415bd75Srobert CACHE STRING "Additional options to pass to llvm/utils/extract_symbols.py. 1133*d415bd75Srobert These cannot override the options set by cmake, but can add extra options 1134*d415bd75Srobert such as --tools.") 1135*d415bd75Srobert 113609467b48Spatrickinclude(AddLLVM) 113709467b48Spatrickinclude(TableGen) 113809467b48Spatrick 113973471bf0Spatrickinclude(LLVMDistributionSupport) 114073471bf0Spatrick 114109467b48Spatrickif( MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) 114209467b48Spatrick # People report that -O3 is unreliable on MinGW. The traditional 114309467b48Spatrick # build also uses -O2 for that reason: 114409467b48Spatrick llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2") 114509467b48Spatrickendif() 114609467b48Spatrick 1147*d415bd75Srobertif(LLVM_INCLUDE_TESTS) 1148*d415bd75Srobert umbrella_lit_testsuite_begin(check-all) 1149*d415bd75Srobertendif() 1150*d415bd75Srobert 115109467b48Spatrick# Put this before tblgen. Else we have a circular dependence. 115209467b48Spatrickadd_subdirectory(lib/Demangle) 115309467b48Spatrickadd_subdirectory(lib/Support) 115409467b48Spatrickadd_subdirectory(lib/TableGen) 115509467b48Spatrick 115609467b48Spatrickadd_subdirectory(utils/TableGen) 115709467b48Spatrick 115809467b48Spatrickadd_subdirectory(include/llvm) 115909467b48Spatrick 116009467b48Spatrickadd_subdirectory(lib) 116109467b48Spatrick 116209467b48Spatrickif( LLVM_INCLUDE_UTILS ) 116309467b48Spatrick add_subdirectory(utils/FileCheck) 116409467b48Spatrick add_subdirectory(utils/PerfectShuffle) 116509467b48Spatrick add_subdirectory(utils/count) 116609467b48Spatrick add_subdirectory(utils/not) 1167*d415bd75Srobert add_subdirectory(utils/UnicodeData) 116809467b48Spatrick add_subdirectory(utils/yaml-bench) 1169*d415bd75Srobert add_subdirectory(utils/split-file) 1170*d415bd75Srobert if( LLVM_INCLUDE_TESTS ) 1171*d415bd75Srobert add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest) 1172*d415bd75Srobert endif() 117309467b48Spatrickelse() 117409467b48Spatrick if ( LLVM_INCLUDE_TESTS ) 117509467b48Spatrick message(FATAL_ERROR "Including tests when not building utils will not work. 117609467b48Spatrick Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLUDE_TESTS to Off.") 117709467b48Spatrick endif() 117809467b48Spatrickendif() 117909467b48Spatrick 118009467b48Spatrick# Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util 118109467b48Spatrickif (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION) 118209467b48Spatrick add_subdirectory(utils/LLVMVisualizers) 118309467b48Spatrickendif() 118409467b48Spatrick 118509467b48Spatrickforeach( binding ${LLVM_BINDINGS_LIST} ) 118609467b48Spatrick if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" ) 118709467b48Spatrick add_subdirectory(bindings/${binding}) 118809467b48Spatrick endif() 118909467b48Spatrickendforeach() 119009467b48Spatrick 119109467b48Spatrickadd_subdirectory(projects) 119209467b48Spatrick 119309467b48Spatrickif( LLVM_INCLUDE_TOOLS ) 119409467b48Spatrick add_subdirectory(tools) 119509467b48Spatrickendif() 119609467b48Spatrick 119709467b48Spatrickif( LLVM_INCLUDE_RUNTIMES ) 119809467b48Spatrick add_subdirectory(runtimes) 119909467b48Spatrickendif() 120009467b48Spatrick 120109467b48Spatrickif( LLVM_INCLUDE_EXAMPLES ) 120209467b48Spatrick add_subdirectory(examples) 120309467b48Spatrickendif() 120409467b48Spatrick 120509467b48Spatrickif( LLVM_INCLUDE_TESTS ) 120609467b48Spatrick if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang) 120709467b48Spatrick include(LLVMExternalProjectUtils) 120809467b48Spatrick llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite 120909467b48Spatrick USE_TOOLCHAIN 121009467b48Spatrick EXCLUDE_FROM_ALL 121109467b48Spatrick NO_INSTALL 121209467b48Spatrick ALWAYS_CLEAN) 121309467b48Spatrick endif() 121409467b48Spatrick add_subdirectory(utils/lit) 121509467b48Spatrick add_subdirectory(test) 121609467b48Spatrick add_subdirectory(unittests) 121709467b48Spatrick 121809467b48Spatrick if (WIN32) 121909467b48Spatrick # This utility is used to prevent crashing tests from calling Dr. Watson on 122009467b48Spatrick # Windows. 122109467b48Spatrick add_subdirectory(utils/KillTheDoctor) 122209467b48Spatrick endif() 122309467b48Spatrick 1224*d415bd75Srobert umbrella_lit_testsuite_end(check-all) 1225*d415bd75Srobert get_property(LLVM_ALL_LIT_DEPENDS GLOBAL PROPERTY LLVM_ALL_LIT_DEPENDS) 1226*d415bd75Srobert get_property(LLVM_ALL_ADDITIONAL_TEST_DEPENDS 1227*d415bd75Srobert GLOBAL PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS) 122809467b48Spatrick add_custom_target(test-depends 1229*d415bd75Srobert DEPENDS ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS}) 123009467b48Spatrick set_target_properties(test-depends PROPERTIES FOLDER "Tests") 123109467b48Spatrickendif() 123209467b48Spatrick 123309467b48Spatrickif (LLVM_INCLUDE_DOCS) 123409467b48Spatrick add_subdirectory(docs) 123509467b48Spatrickendif() 123609467b48Spatrick 123709467b48Spatrickadd_subdirectory(cmake/modules) 123809467b48Spatrick 123909467b48Spatrick# Do this last so that all lit targets have already been created. 124009467b48Spatrickif (LLVM_INCLUDE_UTILS) 124109467b48Spatrick add_subdirectory(utils/llvm-lit) 124209467b48Spatrickendif() 124309467b48Spatrick 124409467b48Spatrickif (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) 124509467b48Spatrick install(DIRECTORY include/llvm include/llvm-c 1246*d415bd75Srobert DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 124709467b48Spatrick COMPONENT llvm-headers 124809467b48Spatrick FILES_MATCHING 124909467b48Spatrick PATTERN "*.def" 125009467b48Spatrick PATTERN "*.h" 125109467b48Spatrick PATTERN "*.td" 125209467b48Spatrick PATTERN "*.inc" 125309467b48Spatrick PATTERN "LICENSE.TXT" 125409467b48Spatrick ) 125509467b48Spatrick 125609467b48Spatrick install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c 1257*d415bd75Srobert DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 125809467b48Spatrick COMPONENT llvm-headers 125909467b48Spatrick FILES_MATCHING 126009467b48Spatrick PATTERN "*.def" 126109467b48Spatrick PATTERN "*.h" 126209467b48Spatrick PATTERN "*.gen" 126309467b48Spatrick PATTERN "*.inc" 126409467b48Spatrick # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def" 126509467b48Spatrick PATTERN "CMakeFiles" EXCLUDE 126609467b48Spatrick PATTERN "config.h" EXCLUDE 126709467b48Spatrick ) 126809467b48Spatrick 126909467b48Spatrick if (LLVM_INSTALL_MODULEMAPS) 127009467b48Spatrick install(DIRECTORY include/llvm include/llvm-c 1271*d415bd75Srobert DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 127209467b48Spatrick COMPONENT llvm-headers 127309467b48Spatrick FILES_MATCHING 127409467b48Spatrick PATTERN "module.modulemap" 127509467b48Spatrick ) 127609467b48Spatrick install(FILES include/llvm/module.install.modulemap 1277*d415bd75Srobert DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm" 127809467b48Spatrick COMPONENT llvm-headers 127909467b48Spatrick RENAME "module.extern.modulemap" 128009467b48Spatrick ) 128109467b48Spatrick endif(LLVM_INSTALL_MODULEMAPS) 128209467b48Spatrick 128309467b48Spatrick # Installing the headers needs to depend on generating any public 128409467b48Spatrick # tablegen'd headers. 1285097a140dSpatrick add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen) 128609467b48Spatrick set_target_properties(llvm-headers PROPERTIES FOLDER "Misc") 128709467b48Spatrick 128809467b48Spatrick if (NOT LLVM_ENABLE_IDE) 128909467b48Spatrick add_llvm_install_targets(install-llvm-headers 129009467b48Spatrick DEPENDS llvm-headers 129109467b48Spatrick COMPONENT llvm-headers) 129209467b48Spatrick endif() 129309467b48Spatrick 129409467b48Spatrick # Custom target to install all libraries. 129509467b48Spatrick add_custom_target(llvm-libraries) 129609467b48Spatrick set_target_properties(llvm-libraries PROPERTIES FOLDER "Misc") 129709467b48Spatrick 129809467b48Spatrick if (NOT LLVM_ENABLE_IDE) 129909467b48Spatrick add_llvm_install_targets(install-llvm-libraries 130009467b48Spatrick DEPENDS llvm-libraries 130109467b48Spatrick COMPONENT llvm-libraries) 130209467b48Spatrick endif() 130309467b48Spatrick 130409467b48Spatrick get_property(LLVM_LIBS GLOBAL PROPERTY LLVM_LIBS) 130509467b48Spatrick if(LLVM_LIBS) 130609467b48Spatrick list(REMOVE_DUPLICATES LLVM_LIBS) 130709467b48Spatrick foreach(lib ${LLVM_LIBS}) 130809467b48Spatrick add_dependencies(llvm-libraries ${lib}) 130909467b48Spatrick if (NOT LLVM_ENABLE_IDE) 131009467b48Spatrick add_dependencies(install-llvm-libraries install-${lib}) 1311097a140dSpatrick add_dependencies(install-llvm-libraries-stripped install-${lib}-stripped) 131209467b48Spatrick endif() 131309467b48Spatrick endforeach() 131409467b48Spatrick endif() 131509467b48Spatrickendif() 131609467b48Spatrick 131709467b48Spatrick# This must be at the end of the LLVM root CMakeLists file because it must run 131809467b48Spatrick# after all targets are created. 131909467b48Spatrickllvm_distribution_add_targets() 13207299aa8dSpatrickprocess_llvm_pass_plugins(GEN_CONFIG) 1321*d415bd75Srobertinclude(CoverageReport) 132209467b48Spatrick 132309467b48Spatrick# This allows us to deploy the Universal CRT DLLs by passing -DCMAKE_INSTALL_UCRT_LIBRARIES=ON to CMake 132409467b48Spatrickif (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_INSTALL_UCRT_LIBRARIES) 132509467b48Spatrick include(InstallRequiredSystemLibraries) 132609467b48Spatrickendif() 132709467b48Spatrick 132809467b48Spatrickif (LLVM_INCLUDE_BENCHMARKS) 132909467b48Spatrick # Override benchmark defaults so that when the library itself is updated these 133009467b48Spatrick # modifications are not lost. 133109467b48Spatrick set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing" FORCE) 133209467b48Spatrick set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Disable benchmark exceptions" FORCE) 133309467b48Spatrick set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install benchmark" FORCE) 133409467b48Spatrick set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE BOOL "Don't download dependencies" FORCE) 133509467b48Spatrick set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE) 1336*d415bd75Srobert set(BENCHMARK_ENABLE_WERROR ${LLVM_ENABLE_WERROR} CACHE BOOL 1337*d415bd75Srobert "Handle -Werror for Google Benchmark based on LLVM_ENABLE_WERROR" FORCE) 133809467b48Spatrick # Since LLVM requires C++11 it is safe to assume that std::regex is available. 133909467b48Spatrick set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE) 1340*d415bd75Srobert add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark 1341*d415bd75Srobert ${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark) 134209467b48Spatrick add_subdirectory(benchmarks) 134309467b48Spatrickendif() 134409467b48Spatrick 134509467b48Spatrickif (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS) 134609467b48Spatrick add_subdirectory(utils/llvm-locstats) 134709467b48Spatrickendif() 1348