1# See docs/CMake.html for instructions about how to build LLVM with CMake.
2
3cmake_minimum_required(VERSION 3.13.4)
4
5# CMP0114: ExternalProject step targets fully adopt their steps.
6# New in CMake 3.19: https://cmake.org/cmake/help/latest/policy/CMP0114.html
7if(POLICY CMP0114)
8  cmake_policy(SET CMP0114 OLD)
9endif()
10# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()`
11# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html
12if(POLICY CMP0116)
13  cmake_policy(SET CMP0116 OLD)
14endif()
15
16set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
17
18if(NOT DEFINED LLVM_VERSION_MAJOR)
19  set(LLVM_VERSION_MAJOR 15)
20endif()
21if(NOT DEFINED LLVM_VERSION_MINOR)
22  set(LLVM_VERSION_MINOR 0)
23endif()
24if(NOT DEFINED LLVM_VERSION_PATCH)
25  set(LLVM_VERSION_PATCH 7)
26endif()
27if(NOT DEFINED LLVM_VERSION_SUFFIX)
28  set(LLVM_VERSION_SUFFIX)
29endif()
30
31if (NOT PACKAGE_VERSION)
32  set(PACKAGE_VERSION
33    "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
34endif()
35
36if(NOT DEFINED LLVM_SHLIB_SYMBOL_VERSION)
37  # "Symbol version prefix for libLLVM.so"
38  set(LLVM_SHLIB_SYMBOL_VERSION "LLVM_${LLVM_VERSION_MAJOR}")
39endif()
40
41if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (MSVC_TOOLSET_VERSION LESS 142) AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))
42  message(WARNING "Visual Studio generators use the x86 host compiler by "
43                  "default, even for 64-bit targets. This can result in linker "
44                  "instability and out of memory errors. To use the 64-bit "
45                  "host compiler, pass -Thost=x64 on the CMake command line.")
46endif()
47
48if (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_OSX_ARCHITECTURES)
49  # Some CMake features like object libraries get confused if you don't
50  # explicitly specify an architecture setting with the Xcode generator.
51  set(CMAKE_OSX_ARCHITECTURES "x86_64")
52endif()
53
54project(LLVM
55  VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
56  LANGUAGES C CXX ASM)
57
58# Must go after project(..)
59include(GNUInstallDirs)
60
61set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
62set(CMAKE_CXX_STANDARD_REQUIRED YES)
63if (CYGWIN)
64  # Cygwin is a bit stricter and lack things like 'strdup', 'stricmp', etc in
65  # c++xx mode.
66  set(CMAKE_CXX_EXTENSIONS YES)
67else()
68  set(CMAKE_CXX_EXTENSIONS NO)
69endif()
70
71if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
72  message(FATAL_ERROR "
73No build type selected. You need to pass -DCMAKE_BUILD_TYPE=<type> in order to configure LLVM.
74Available options are:
75  * -DCMAKE_BUILD_TYPE=Release - For an optimized build with no assertions or debug info.
76  * -DCMAKE_BUILD_TYPE=Debug - For an unoptimized build with assertions and debug info.
77  * -DCMAKE_BUILD_TYPE=RelWithDebInfo - For an optimized build with no assertions but with debug info.
78  * -DCMAKE_BUILD_TYPE=MinSizeRel - For a build optimized for size instead of speed.
79Learn more about these options in our documentation at https://llvm.org/docs/CMake.html#cmake-build-type
80")
81endif()
82
83# Side-by-side subprojects layout: automatically set the
84# LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS
85# This allows an easy way of setting up a build directory for llvm and another
86# one for llvm+clang+... using the same sources.
87set(LLVM_ALL_PROJECTS "bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;libcxx;libcxxabi;libunwind;lld;lldb;mlir;openmp;polly;pstl")
88# The flang project is not yet part of "all" projects (see C++ requirements)
89set(LLVM_EXTRA_PROJECTS "flang")
90# List of all known projects in the mono repo
91set(LLVM_KNOWN_PROJECTS "${LLVM_ALL_PROJECTS};${LLVM_EXTRA_PROJECTS}")
92set(LLVM_ENABLE_PROJECTS "" CACHE STRING
93    "Semicolon-separated list of projects to build (${LLVM_KNOWN_PROJECTS}), or \"all\".")
94foreach(proj ${LLVM_ENABLE_PROJECTS})
95  if (NOT proj STREQUAL "all" AND NOT proj STREQUAL "llvm" AND NOT "${proj}" IN_LIST LLVM_KNOWN_PROJECTS)
96     MESSAGE(FATAL_ERROR "${proj} isn't a known project: ${LLVM_KNOWN_PROJECTS}")
97  endif()
98endforeach()
99foreach(proj "libcxx" "libcxxabi" "libunwind")
100  if (${proj} IN_LIST LLVM_ENABLE_PROJECTS)
101    message(WARNING "Using LLVM_ENABLE_PROJECTS=${proj} is deprecated now, please use -DLLVM_ENABLE_RUNTIMES=${proj} or "
102                    "see the instructions at https://libcxx.llvm.org/BuildingLibcxx.html for building the runtimes.")
103  endif()
104endforeach()
105
106if( LLVM_ENABLE_PROJECTS STREQUAL "all" )
107  set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS})
108endif()
109
110if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
111  if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
112    message(STATUS "Enabling MLIR as a dependency to flang")
113    list(APPEND LLVM_ENABLE_PROJECTS "mlir")
114  endif()
115
116  if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)
117    message(FATAL_ERROR "Clang is not enabled, but is required for the Flang driver")
118  endif()
119endif()
120
121# LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
122# `LLVM_ENABLE_PROJECTS` CMake cache variable.  This exists for
123# several reasons:
124#
125# * As an indicator that the `LLVM_ENABLE_PROJECTS` list is now the single
126# source of truth for which projects to build. This means we will ignore user
127# supplied `LLVM_TOOL_<project>_BUILD` CMake cache variables and overwrite
128# them.
129#
130# * The case where the user previously had `LLVM_ENABLE_PROJECTS` set to a
131# non-empty list but now the user wishes to disable building all other projects
132# by setting `LLVM_ENABLE_PROJECTS` to an empty string. In that case we still
133# need to set the `LLVM_TOOL_${upper_proj}_BUILD` variables so that we disable
134# building all the projects that were previously enabled.
135set(LLVM_ENABLE_PROJECTS_USED OFF CACHE BOOL "")
136mark_as_advanced(LLVM_ENABLE_PROJECTS_USED)
137
138if (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "")
139  set(LLVM_ENABLE_PROJECTS_USED ON CACHE BOOL "" FORCE)
140  foreach(proj ${LLVM_KNOWN_PROJECTS} ${LLVM_EXTERNAL_PROJECTS})
141    string(TOUPPER "${proj}" upper_proj)
142    string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})
143    if ("${proj}" IN_LIST LLVM_ENABLE_PROJECTS)
144      message(STATUS "${proj} project is enabled")
145      set(SHOULD_ENABLE_PROJECT TRUE)
146      set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
147      if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")
148        message(FATAL_ERROR "LLVM_ENABLE_PROJECTS requests ${proj} but directory not found: ${PROJ_DIR}")
149      endif()
150      if( LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" )
151        set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "" FORCE)
152      else()
153        set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "")
154      endif()
155    elseif ("${proj}" IN_LIST LLVM_EXTERNAL_PROJECTS)
156      message(STATUS "${proj} project is enabled")
157      set(SHOULD_ENABLE_PROJECT TRUE)
158    else()
159      message(STATUS "${proj} project is disabled")
160      set(SHOULD_ENABLE_PROJECT FALSE)
161    endif()
162    # Force `LLVM_TOOL_${upper_proj}_BUILD` variables to have values that
163    # corresponds with `LLVM_ENABLE_PROJECTS`. This prevents the user setting
164    # `LLVM_TOOL_${upper_proj}_BUILD` variables externally. At some point
165    # we should deprecate allowing users to set these variables by turning them
166    # into normal CMake variables rather than cache variables.
167    set(LLVM_TOOL_${upper_proj}_BUILD
168      ${SHOULD_ENABLE_PROJECT}
169      CACHE
170      BOOL "Whether to build ${upper_proj} as part of LLVM" FORCE
171    )
172  endforeach()
173endif()
174unset(SHOULD_ENABLE_PROJECT)
175
176# Build llvm with ccache if the package is present
177set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
178if(LLVM_CCACHE_BUILD)
179  find_program(CCACHE_PROGRAM ccache)
180  if(CCACHE_PROGRAM)
181    set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
182    set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
183    set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
184        CACHE STRING "Parameters to pass through to ccache")
185
186    if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
187      set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
188      if (LLVM_CCACHE_MAXSIZE)
189        set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
190      endif()
191      if (LLVM_CCACHE_DIR)
192        set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")
193      endif()
194      set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
195    else()
196      if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
197         NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
198        message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
199      endif()
200      # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
201      # with cmd.exe and some MSVC tools other than cl.exe
202      set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
203      set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
204    endif()
205  else()
206    message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")
207  endif()
208endif()
209
210set(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS "" CACHE STRING
211  "Optional arguments for the native tool used in CMake --build invocations for external projects.")
212mark_as_advanced(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS)
213
214option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF)
215
216# Some features of the LLVM build may be disallowed when dependency debugging is
217# enabled. In particular you cannot use ccache because we want to force compile
218# operations to always happen.
219if(LLVM_DEPENDENCY_DEBUGGING)
220  if(NOT CMAKE_HOST_APPLE)
221    message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.")
222  endif()
223  if(LLVM_CCACHE_BUILD)
224    message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.")
225  endif()
226endif()
227
228option(LLVM_ENABLE_DAGISEL_COV "Debug: Prints tablegen patterns that were used for selecting" OFF)
229option(LLVM_ENABLE_GISEL_COV "Enable collection of GlobalISel rule coverage" OFF)
230if(LLVM_ENABLE_GISEL_COV)
231  set(LLVM_GISEL_COV_PREFIX "${CMAKE_BINARY_DIR}/gisel-coverage-" CACHE STRING "Provide a filename prefix to collect the GlobalISel rule coverage")
232endif()
233
234set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
235
236# Add path for custom modules
237list(INSERT CMAKE_MODULE_PATH 0
238  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
239  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
240  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
241  )
242
243# Generate a CompilationDatabase (compile_commands.json file) for our build,
244# for use by clang_complete, YouCompleteMe, etc.
245set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
246
247option(LLVM_INSTALL_BINUTILS_SYMLINKS
248  "Install symlinks from the binutils tool names to the corresponding LLVM tools." OFF)
249
250option(LLVM_INSTALL_CCTOOLS_SYMLINKS
251  "Install symlinks from the cctools tool names to the corresponding LLVM tools." OFF)
252
253option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
254
255option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
256
257# Unfortunatly Clang is too eager to search directories for module maps, which can cause the
258# installed version of the maps to be found when building LLVM from source. Therefore we turn off
259# the installation by default. See llvm.org/PR31905.
260option(LLVM_INSTALL_MODULEMAPS "Install the modulemap files in the 'install' target." OFF)
261
262option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
263if ( LLVM_USE_FOLDERS )
264  set_property(GLOBAL PROPERTY USE_FOLDERS ON)
265endif()
266
267include(VersionFromVCS)
268
269option(LLVM_APPEND_VC_REV
270  "Embed the version control system revision in LLVM" ON)
271
272option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OFF)
273
274set(PACKAGE_NAME LLVM)
275set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
276set(PACKAGE_BUGREPORT "https://github.com/llvm/llvm-project/issues/")
277
278set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
279  "Default URL where bug reports are to be submitted.")
280
281# Configure CPack.
282set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
283set(CPACK_PACKAGE_VENDOR "LLVM")
284set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
285set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
286set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
287set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
288set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
289set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
290if(WIN32 AND NOT UNIX)
291  set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
292  set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
293  set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
294  set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
295  set(CPACK_NSIS_MODIFY_PATH "ON")
296  set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
297  if( CMAKE_CL_64 )
298    set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
299  endif()
300endif()
301include(CPack)
302
303# Sanity check our source directory to make sure that we are not trying to
304# generate an in-source build (unless on MSVC_IDE, where it is ok), and to make
305# sure that we don't have any stray generated files lying around in the tree
306# (which would end up getting picked up by header search, instead of the correct
307# versions).
308if( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE )
309  message(FATAL_ERROR "In-source builds are not allowed.
310Please create a directory and run cmake from there, passing the path
311to this source directory as the last argument.
312This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
313Please delete them.")
314endif()
315
316string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
317
318if (CMAKE_BUILD_TYPE AND
319    NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
320  message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
321endif()
322
323set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
324
325# LLVM_INSTALL_PACKAGE_DIR needs to be declared prior to adding the tools
326# subdirectory in order to have the value available for llvm-config.
327include(GNUInstallPackageDir)
328set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
329  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
330
331set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
332    "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
333mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)
334
335set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING
336    "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)")
337mark_as_advanced(LLVM_UTILS_INSTALL_DIR)
338
339set(LLVM_EXAMPLES_INSTALL_DIR "examples" CACHE STRING
340    "Path for examples subdirectory (enabled by LLVM_BUILD_EXAMPLES=ON) (defaults to 'examples')")
341mark_as_advanced(LLVM_EXAMPLES_INSTALL_DIR)
342
343# They are used as destination of target generators.
344set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
345set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
346if(WIN32 OR CYGWIN)
347  # DLL platform -- put DLLs into bin.
348  set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
349else()
350  set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
351endif()
352
353# Each of them corresponds to llvm-config's.
354set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
355set(LLVM_LIBRARY_DIR      ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
356set(LLVM_MAIN_SRC_DIR     ${CMAKE_CURRENT_SOURCE_DIR}  ) # --src-root
357set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
358set(LLVM_BINARY_DIR       ${CMAKE_CURRENT_BINARY_DIR}  ) # --prefix
359
360set(LLVM_THIRD_PARTY_DIR  ${CMAKE_CURRENT_SOURCE_DIR}/../third-party)
361
362# Note: LLVM_CMAKE_DIR does not include generated files
363set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)
364set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
365set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
366
367# List of all targets to be built by default:
368set(LLVM_ALL_TARGETS
369  AArch64
370  AMDGPU
371  ARM
372  AVR
373  BPF
374  Hexagon
375  Lanai
376  Mips
377  MSP430
378  NVPTX
379  PowerPC
380  RISCV
381  Sparc
382  SystemZ
383  VE
384  WebAssembly
385  X86
386  XCore
387  )
388
389# List of targets with JIT support:
390set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
391
392set(LLVM_TARGETS_TO_BUILD "all"
393    CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
394
395set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
396    CACHE STRING "Semicolon-separated list of experimental targets to build.")
397
398option(BUILD_SHARED_LIBS
399  "Build all libraries as shared libraries instead of static" OFF)
400
401option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
402if(LLVM_ENABLE_BACKTRACES)
403  set(ENABLE_BACKTRACES 1)
404endif()
405
406option(LLVM_ENABLE_UNWIND_TABLES "Emit unwind tables for the libraries" ON)
407
408option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
409if(LLVM_ENABLE_CRASH_OVERRIDES)
410  set(ENABLE_CRASH_OVERRIDES 1)
411endif()
412
413option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF)
414
415set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)
416if (MINGW)
417  # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix
418  # as native path style, regardless of what this is set to.
419  set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT ON)
420endif()
421option(LLVM_WINDOWS_PREFER_FORWARD_SLASH "Prefer path names with forward slashes on Windows." ${WINDOWS_PREFER_FORWARD_SLASH_DEFAULT})
422
423option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
424set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
425set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
426
427set(LLVM_TARGET_ARCH "host"
428  CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
429
430option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
431
432set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")
433
434option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)
435
436option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON)
437
438# On z/OS, threads cannot be used because TLS is not supported.
439if (CMAKE_SYSTEM_NAME MATCHES "OS390")
440  option(LLVM_ENABLE_THREADS "Use threads if available." OFF)
441else()
442  option(LLVM_ENABLE_THREADS "Use threads if available." ON)
443endif()
444
445set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
446
447set(LLVM_ENABLE_ZSTD "ON" CACHE STRING "Use zstd for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
448
449set(LLVM_USE_STATIC_ZSTD FALSE CACHE BOOL "Use static version of zstd. Can be TRUE, FALSE")
450
451set(LLVM_ENABLE_CURL "OFF" CACHE STRING "Use libcurl for the HTTP client if available. Can be ON, OFF, or FORCE_ON")
452
453set(LLVM_ENABLE_HTTPLIB "OFF" CACHE STRING "Use cpp-httplib HTTP server library if available. Can be ON, OFF, or FORCE_ON")
454
455set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")
456
457option(LLVM_ENABLE_Z3_SOLVER
458  "Enable Support for the Z3 constraint solver in LLVM."
459  ${LLVM_ENABLE_Z3_SOLVER_DEFAULT}
460)
461
462if (LLVM_ENABLE_Z3_SOLVER)
463  find_package(Z3 4.7.1)
464
465  if (LLVM_Z3_INSTALL_DIR)
466    if (NOT Z3_FOUND)
467      message(FATAL_ERROR "Z3 >= 4.7.1 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.")
468    endif()
469  endif()
470
471  if (NOT Z3_FOUND)
472    message(FATAL_ERROR "LLVM_ENABLE_Z3_SOLVER cannot be enabled when Z3 is not available.")
473  endif()
474
475  set(LLVM_WITH_Z3 1)
476endif()
477
478set(LLVM_ENABLE_Z3_SOLVER_DEFAULT "${Z3_FOUND}")
479
480
481if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
482  set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
483endif()
484
485set(LLVM_TARGETS_TO_BUILD
486   ${LLVM_TARGETS_TO_BUILD}
487   ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
488list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
489
490option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
491option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
492if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
493  option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)
494else()
495  option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)
496endif()
497option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
498option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
499option(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF)
500option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
501option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
502option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
503
504option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
505option(LLVM_UNREACHABLE_OPTIMIZE "Optimize llvm_unreachable() as undefined behavior (default), guaranteed trap when OFF" ON)
506
507if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
508  option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
509else()
510  option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
511endif()
512
513option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
514
515# While adding scalable vector support to LLVM, we temporarily want to
516# allow an implicit conversion of TypeSize to uint64_t, and to allow
517# code to get the fixed number of elements from a possibly scalable vector.
518# This CMake flag enables a more strict mode where it asserts that the type
519# is not a scalable vector type.
520#
521# Enabling this flag makes it easier to find cases where the compiler makes
522# assumptions on the size being 'fixed size', when building tests for
523# SVE/SVE2 or other scalable vector architectures.
524option(LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS
525       "Enable assertions that type is not scalable in implicit conversion from TypeSize to uint64_t and calls to getNumElements" OFF)
526
527set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
528  "Enable abi-breaking checks.  Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
529
530option(LLVM_FORCE_USE_OLD_TOOLCHAIN
531       "Set to ON to force using an old, unsupported host toolchain." OFF)
532
533set(LLVM_LOCAL_RPATH "" CACHE FILEPATH
534  "If set, an absolute path added as rpath on binaries that do not already contain an executable-relative rpath.")
535
536option(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN
537       "Set to ON to only warn when using a toolchain which is about to be deprecated, instead of emitting an error." OFF)
538
539option(LLVM_USE_INTEL_JITEVENTS
540  "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
541  OFF)
542
543if( LLVM_USE_INTEL_JITEVENTS )
544  # Verify we are on a supported platform
545  if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
546    message(FATAL_ERROR
547      "Intel JIT API support is available on Linux and Windows only.")
548  endif()
549endif( LLVM_USE_INTEL_JITEVENTS )
550
551option(LLVM_USE_OPROFILE
552  "Use opagent JIT interface to inform OProfile about JIT code" OFF)
553
554option(LLVM_EXTERNALIZE_DEBUGINFO
555  "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
556
557set(LLVM_CODESIGNING_IDENTITY "" CACHE STRING
558  "Sign executables and dylibs with the given identity or skip if empty (Darwin Only)")
559
560# If enabled, verify we are on a platform that supports oprofile.
561if( LLVM_USE_OPROFILE )
562  if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
563    message(FATAL_ERROR "OProfile support is available on Linux only.")
564  endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
565endif( LLVM_USE_OPROFILE )
566
567option(LLVM_USE_PERF
568  "Use perf JIT interface to inform perf about JIT code" OFF)
569
570# If enabled, verify we are on a platform that supports perf.
571if( LLVM_USE_PERF )
572  if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
573    message(FATAL_ERROR "perf support is available on Linux only.")
574  endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
575endif( LLVM_USE_PERF )
576
577set(LLVM_USE_SANITIZER "" CACHE STRING
578  "Define the sanitizer used to build binaries and tests.")
579option(LLVM_OPTIMIZE_SANITIZED_BUILDS "Pass -O1 on debug sanitizer builds" ON)
580set(LLVM_UBSAN_FLAGS
581    "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"
582    CACHE STRING
583    "Compile flags set to enable UBSan. Only used if LLVM_USE_SANITIZER contains 'Undefined'.")
584set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH
585  "Path to fuzzing library for linking with fuzz targets")
586
587option(LLVM_USE_SPLIT_DWARF
588  "Use -gsplit-dwarf when compiling llvm and --gdb-index when linking." OFF)
589
590# Define an option controlling whether we should build for 32-bit on 64-bit
591# platforms, where supported.
592if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX"))
593  # TODO: support other platforms and toolchains.
594  option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
595endif()
596
597# Define the default arguments to use with 'lit', and an option for the user to
598# override.
599set(LIT_ARGS_DEFAULT "-sv")
600if (MSVC_IDE OR XCODE)
601  set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
602endif()
603set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
604
605# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
606if( WIN32 AND NOT CYGWIN )
607  set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
608endif()
609
610set(LLVM_INTEGRATED_CRT_ALLOC "" CACHE PATH "Replace the Windows CRT allocator with any of {rpmalloc|mimalloc|snmalloc}. Only works with /MT enabled.")
611if(LLVM_INTEGRATED_CRT_ALLOC)
612  if(NOT WIN32)
613    message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows.")
614  endif()
615  if(LLVM_USE_SANITIZER)
616    message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used along with LLVM_USE_SANITIZER!")
617  endif()
618  if(CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
619    message(FATAL_ERROR "The Debug target isn't supported along with LLVM_INTEGRATED_CRT_ALLOC!")
620  endif()
621endif()
622
623# Define options to control the inclusion and default build behavior for
624# components which may not strictly be necessary (tools, examples, and tests).
625#
626# This is primarily to support building smaller or faster project files.
627option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
628option(LLVM_BUILD_TOOLS
629  "Build the LLVM tools. If OFF, just generate build targets." ON)
630
631option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
632option(LLVM_BUILD_UTILS
633  "Build LLVM utility binaries. If OFF, just generate build targets." ON)
634
635option(LLVM_INCLUDE_RUNTIMES "Generate build targets for the LLVM runtimes." ON)
636option(LLVM_BUILD_RUNTIMES
637  "Build the LLVM runtimes. If OFF, just generate build targets." ON)
638
639option(LLVM_BUILD_RUNTIME
640  "Build the LLVM runtime libraries." ON)
641option(LLVM_BUILD_EXAMPLES
642  "Build the LLVM example programs. If OFF, just generate build targets." OFF)
643option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
644
645if(LLVM_BUILD_EXAMPLES)
646  add_definitions(-DBUILD_EXAMPLES)
647endif(LLVM_BUILD_EXAMPLES)
648
649option(LLVM_BUILD_TESTS
650  "Build LLVM unit tests. If OFF, just generate build targets." OFF)
651option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
652option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." OFF)
653
654option(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default
655targets. If OFF, benchmarks still could be built using Benchmarks target." OFF)
656option(LLVM_INCLUDE_BENCHMARKS "Generate benchmark targets. If OFF, benchmarks can't be built." ON)
657
658option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
659option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
660option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
661option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
662option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
663option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
664
665set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html"
666    CACHE STRING "Doxygen-generated HTML documentation install directory")
667set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/ocaml-html"
668    CACHE STRING "OCamldoc-generated HTML documentation install directory")
669
670option (LLVM_BUILD_EXTERNAL_COMPILER_RT
671  "Build compiler-rt as an external project." OFF)
672
673option (LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO
674  "Show target and host info when tools are invoked with --version." ON)
675
676# You can configure which libraries from LLVM you want to include in the
677# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
678# list of LLVM components. All component names handled by llvm-config are valid.
679if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
680  set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
681    "Semicolon-separated list of components to include in libLLVM, or \"all\".")
682endif()
683
684if(MSVC)
685  option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" ON)
686  # Set this variable to OFF here so it can't be set with a command-line
687  # argument.
688  set (LLVM_LINK_LLVM_DYLIB OFF)
689  if (BUILD_SHARED_LIBS)
690    message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.")
691  endif()
692else()
693  option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
694  option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)
695  set(LLVM_BUILD_LLVM_DYLIB_default OFF)
696  if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
697    set(LLVM_BUILD_LLVM_DYLIB_default ON)
698  endif()
699  option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
700endif()
701
702if (LLVM_LINK_LLVM_DYLIB AND BUILD_SHARED_LIBS)
703  message(FATAL_ERROR "Cannot enable BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB.  We recommend disabling BUILD_SHARED_LIBS.")
704endif()
705
706option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
707if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES)))
708  set(LLVM_USE_HOST_TOOLS ON)
709endif()
710
711option(LLVM_OMIT_DAGISEL_COMMENTS "Do not add comments to DAG ISel" ON)
712if (CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE MATCHES "^(RELWITHDEBINFO|DEBUG)$")
713  set(LLVM_OMIT_DAGISEL_COMMENTS OFF)
714endif()
715
716if (MSVC_IDE)
717  option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
718endif()
719
720if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE OR
721    LLVM_ENABLE_IR_PGO)
722  if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
723    # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine
724    # for spining disks. Anything higher may only help on slower mediums.
725    set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
726  endif()
727  if(NOT LLVM_PROFILE_FILE_PATTERN)
728    if(NOT LLVM_PROFILE_DATA_DIR)
729      file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles" LLVM_PROFILE_DATA_DIR)
730    endif()
731    file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
732  endif()
733  if(NOT LLVM_CSPROFILE_FILE_PATTERN)
734    if(NOT LLVM_CSPROFILE_DATA_DIR)
735      file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/csprofiles" LLVM_CSPROFILE_DATA_DIR)
736    endif()
737    file(TO_NATIVE_PATH "${LLVM_CSPROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_CSPROFILE_FILE_PATTERN)
738  endif()
739endif()
740
741if (LLVM_BUILD_STATIC)
742  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
743  # Remove shared library suffixes from use in find_library
744  foreach (shared_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_IMPORT_LIBRARY_SUFFIX})
745    list(FIND CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix} shared_lib_suffix_idx)
746    if(NOT ${shared_lib_suffix_idx} EQUAL -1)
747      list(REMOVE_AT CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix_idx})
748    endif()
749  endforeach()
750endif()
751
752# Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
753if(CMAKE_HOST_APPLE AND APPLE)
754  include(UseLibtool)
755endif()
756
757# Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
758set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")
759mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
760
761# Per target dir not yet supported on Arm 32 bit due to arm vs armhf handling
762if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
763  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)
764else()
765  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF)
766endif()
767set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default} CACHE BOOL
768  "Enable per-target runtimes directory")
769
770set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
771  "Profiling data file to use when compiling in order to improve runtime performance.")
772
773# All options referred to from HandleLLVMOptions have to be specified
774# BEFORE this include, otherwise options will not be correctly set on
775# first cmake run
776include(config-ix)
777
778# By default, we target the host, but this can be overridden at CMake
779# invocation time. Except on 64-bit AIX, where the system toolchain
780# expect 32-bit objects by default.
781if("${LLVM_HOST_TRIPLE}" MATCHES "^powerpc64-ibm-aix")
782  string(REGEX REPLACE "^powerpc64" "powerpc" LLVM_DEFAULT_TARGET_TRIPLE_default "${LLVM_HOST_TRIPLE}")
783else()
784  set(LLVM_DEFAULT_TARGET_TRIPLE_default "${LLVM_HOST_TRIPLE}")
785endif()
786
787set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE_default}" CACHE STRING
788  "Default target for which LLVM will generate code." )
789if (TARGET_TRIPLE)
790  message(WARNING "TARGET_TRIPLE is deprecated and will be removed in a future release. "
791                  "Please use LLVM_DEFAULT_TARGET_TRIPLE instead.")
792  set(LLVM_TARGET_TRIPLE "${TARGET_TRIPLE}")
793else()
794  set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
795endif()
796message(STATUS "LLVM host triple: ${LLVM_HOST_TRIPLE}")
797message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")
798
799if(WIN32 OR CYGWIN)
800  if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
801    set(LLVM_ENABLE_PLUGINS_default ON)
802  else()
803    set(LLVM_ENABLE_PLUGINS_default OFF)
804  endif()
805else()
806  set(LLVM_ENABLE_PLUGINS_default ${LLVM_ENABLE_PIC})
807endif()
808option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})
809
810set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL
811  "Enable the new pass manager by default.")
812if(NOT LLVM_ENABLE_NEW_PASS_MANAGER)
813  message(FATAL_ERROR "Enabling the legacy pass manager on the cmake level is"
814                      " no longer supported.")
815endif()
816
817include(HandleLLVMOptions)
818
819find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
820    COMPONENTS Interpreter)
821
822######
823
824# Configure all of the various header file fragments LLVM uses which depend on
825# configuration variables.
826set(LLVM_ENUM_TARGETS "")
827set(LLVM_ENUM_ASM_PRINTERS "")
828set(LLVM_ENUM_ASM_PARSERS "")
829set(LLVM_ENUM_DISASSEMBLERS "")
830set(LLVM_ENUM_TARGETMCAS "")
831foreach(t ${LLVM_TARGETS_TO_BUILD})
832  set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
833
834  list(FIND LLVM_ALL_TARGETS ${t} idx)
835  list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
836  # At this point, LLVMBUILDTOOL already checked all the targets passed in
837  # LLVM_TARGETS_TO_BUILD and LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, so
838  # this test just makes sure that any experimental targets were passed via
839  # LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, not LLVM_TARGETS_TO_BUILD.
840  if( idx LESS 0 AND idy LESS 0 )
841    message(FATAL_ERROR "The target `${t}' is experimental and must be passed "
842      "via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.")
843  else()
844    set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
845  endif()
846
847  file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
848  if( asmp_file )
849    set(LLVM_ENUM_ASM_PRINTERS
850      "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
851  endif()
852  if( EXISTS ${td}/AsmParser/CMakeLists.txt )
853    set(LLVM_ENUM_ASM_PARSERS
854      "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
855  endif()
856  if( EXISTS ${td}/Disassembler/CMakeLists.txt )
857    set(LLVM_ENUM_DISASSEMBLERS
858      "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
859  endif()
860    if( EXISTS ${td}/MCA/CMakeLists.txt )
861    set(LLVM_ENUM_TARGETMCAS
862      "${LLVM_ENUM_TARGETMCAS}LLVM_TARGETMCA(${t})\n")
863  endif()
864endforeach(t)
865
866# Provide an LLVM_ namespaced alias for use in #cmakedefine.
867set(LLVM_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
868
869# Produce the target definition files, which provide a way for clients to easily
870# include various classes of targets.
871configure_file(
872  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
873  ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
874  )
875configure_file(
876  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
877  ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
878  )
879configure_file(
880  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
881  ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
882  )
883configure_file(
884  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
885  ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
886  )
887configure_file(
888  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetMCAs.def.in
889  ${LLVM_INCLUDE_DIR}/llvm/Config/TargetMCAs.def
890  )
891
892# They are not referenced. See set_output_directory().
893set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
894set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
895set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
896
897if(LLVM_INCLUDE_TESTS)
898  include(GetErrcMessages)
899  get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
900endif()
901
902# For up-to-date instructions for installing the Tensorflow dependency, refer to
903# the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh
904# In this case, the latest C API library is available for download from
905# https://www.tensorflow.org/install/lang_c.
906# We will expose the conditional compilation variable,
907# LLVM_HAVE_TF_API, through llvm-config.h, so that a user of the LLVM library may
908# also leverage the dependency.
909set(TENSORFLOW_C_LIB_PATH "" CACHE PATH "Path to TensorFlow C library install")
910if (TENSORFLOW_C_LIB_PATH)
911  find_library(tensorflow_c_api tensorflow PATHS ${TENSORFLOW_C_LIB_PATH}/lib NO_DEFAULT_PATH REQUIRED)
912  # Currently, the protobuf headers are distributed with the pip package that corresponds to the version
913  # of the C API library.
914  find_library(tensorflow_fx tensorflow_framework PATHS ${TENSORFLOW_C_LIB_PATH}/lib NO_DEFAULT_PATH REQUIRED)
915  set(LLVM_HAVE_TF_API "ON" CACHE BOOL "Full Tensorflow API available")
916  include_directories(${TENSORFLOW_C_LIB_PATH}/include)
917  if (NOT TF_PROTO_HEADERS)
918    message(STATUS "TF_PROTO_HEADERS not defined. Looking for tensorflow pip package.")
919    execute_process(COMMAND
920      ${Python3_EXECUTABLE} "-m" "pip" "show" "tensorflow"
921      OUTPUT_VARIABLE TF_PIP_OUT)
922    if ("${TF_PIP_OUT}" STREQUAL "")
923      message(FATAL ERROR "Tensorflow pip package is also required for 'development' mode (protobuf headers)")
924    endif()
925    string(REGEX MATCH "Location: ([^\n]*\n)" TF_PIP_LOC "${TF_PIP_OUT}")
926    string(REPLACE "Location: " "" TF_PIP ${TF_PIP_LOC})
927    string(STRIP ${TF_PIP} TF_PIP)
928    set(TF_PROTO_HEADERS "${TF_PIP}/tensorflow/include")
929  endif()
930  message(STATUS "Using Tensorflow headers under: ${TF_PROTO_HEADERS}")
931  include_directories(${TF_PROTO_HEADERS})
932  add_definitions("-DGOOGLE_PROTOBUF_NO_RTTI")
933  add_definitions("-D_GLIBCXX_USE_CXX11_ABI=0")
934endif()
935
936# For up-to-date instructions for installing the Tensorflow dependency, refer to
937# the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh
938# Specifically, assuming python3 is installed:
939# python3 -m pip install --upgrade pip && python3 -m pip install --user tf_nightly==2.3.0.dev20200528
940# Then set TENSORFLOW_AOT_PATH to the package install - usually it's ~/.local/lib/python3.7/site-packages/tensorflow
941#
942set(TENSORFLOW_AOT_PATH "" CACHE PATH "Path to TensorFlow pip install dir")
943
944if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
945  set(LLVM_HAVE_TF_AOT "ON" CACHE BOOL "Tensorflow AOT available")
946  set(TENSORFLOW_AOT_COMPILER
947    "${TENSORFLOW_AOT_PATH}/../../../../bin/saved_model_cli"
948    CACHE PATH "Path to the Tensorflow AOT compiler")
949  include_directories(${TENSORFLOW_AOT_PATH}/include)
950  add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
951    ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
952  install(TARGETS tf_xla_runtime EXPORT LLVMExports
953    ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
954  set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
955  # Once we add more modules, we should handle this more automatically.
956  if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL)
957    set(LLVM_INLINER_MODEL_PATH "none")
958  elseif(NOT DEFINED LLVM_INLINER_MODEL_PATH
959      OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL ""
960      OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL "autogenerate")
961    set(LLVM_INLINER_MODEL_PATH "autogenerate")
962    set(LLVM_INLINER_MODEL_AUTOGENERATED 1)
963  endif()
964  if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_REGALLOCEVICTMODEL)
965    set(LLVM_RAEVICT_MODEL_PATH "none")
966  elseif(NOT DEFINED LLVM_RAEVICT_MODEL_PATH
967      OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL ""
968      OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL "autogenerate")
969    set(LLVM_RAEVICT_MODEL_PATH "autogenerate")
970    set(LLVM_RAEVICT_MODEL_AUTOGENERATED 1)
971  endif()
972
973endif()
974
975# Configure the three LLVM configuration header files.
976configure_file(
977  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
978  ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
979configure_file(
980  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
981  ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
982configure_file(
983  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake
984  ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)
985
986# Add target for generating source rpm package.
987set(LLVM_SRPM_USER_BINARY_SPECFILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm.spec.in
988    CACHE FILEPATH ".spec file to use for srpm generation")
989set(LLVM_SRPM_BINARY_SPECFILE ${CMAKE_CURRENT_BINARY_DIR}/llvm.spec)
990set(LLVM_SRPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/srpm")
991
992get_source_info(${CMAKE_CURRENT_SOURCE_DIR} revision repository)
993string(LENGTH "${revision}" revision_length)
994set(LLVM_RPM_SPEC_REVISION "${revision}")
995
996configure_file(
997  ${LLVM_SRPM_USER_BINARY_SPECFILE}
998  ${LLVM_SRPM_BINARY_SPECFILE} @ONLY)
999
1000add_custom_target(srpm
1001  COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES
1002  COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE})
1003set_target_properties(srpm PROPERTIES FOLDER "Misc")
1004
1005if(APPLE AND DARWIN_LTO_LIBRARY)
1006  set(CMAKE_EXE_LINKER_FLAGS
1007    "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
1008  set(CMAKE_SHARED_LINKER_FLAGS
1009    "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
1010  set(CMAKE_MODULE_LINKER_FLAGS
1011    "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
1012endif()
1013
1014# Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to
1015# break things. In this case we need to enable the large-file API as well.
1016if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
1017          add_definitions("-D_XOPEN_SOURCE=700")
1018          add_definitions("-D_LARGE_FILE_API")
1019
1020  # CMake versions less than 3.16 set default linker flags to include -brtl, as
1021  # well as setting -G when building libraries, so clear them out. Note we only
1022  # try to clear the form that CMake will set as part of its initial
1023  # configuration, it is still possible the user may force it as part of a
1024  # compound option.
1025  if(CMAKE_VERSION VERSION_LESS 3.16)
1026    string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS}")
1027    string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_SHARED_LINKER_FLAGS  "${CMAKE_SHARED_LINKER_FLAGS}")
1028    string(REGEX REPLACE "(^|[ \t]+)-Wl,-brtl([ \t]+|$)" " " CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
1029    string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
1030      "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
1031    string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS
1032      "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}")
1033    string(REGEX REPLACE "(^|[ \t]+)(-Wl,)?-G([ \t]+|$)" " " CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS
1034      "${CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS}")
1035    string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
1036      "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
1037    string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS
1038      "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}")
1039    string(REGEX REPLACE "(^|[ \t]+)-Wl,-G," " -Wl," CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS
1040      "${CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS}")
1041  endif()
1042
1043  # Modules should be built with -shared -Wl,-G, so we can use runtime linking
1044  # with plugins.
1045  string(APPEND CMAKE_MODULE_LINKER_FLAGS " -shared -Wl,-G")
1046
1047  # Also set the correct flags for building shared libraries.
1048  string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared")
1049endif()
1050
1051# Build with _XOPEN_SOURCE on z/OS.
1052if (CMAKE_SYSTEM_NAME MATCHES "OS390")
1053  add_definitions("-D_XOPEN_SOURCE=600")
1054  add_definitions("-D_OPEN_SYS") # Needed for process information.
1055  add_definitions("-D_OPEN_SYS_FILE_EXT") # Needed for EBCDIC I/O.
1056endif()
1057
1058# Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9.
1059if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
1060          add_definitions("-D_FILE_OFFSET_BITS=64")
1061endif()
1062
1063set(CMAKE_INCLUDE_CURRENT_DIR ON)
1064
1065include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
1066
1067# when crosscompiling import the executable targets from a file
1068if(LLVM_USE_HOST_TOOLS)
1069  include(CrossCompile)
1070  llvm_create_cross_target(LLVM NATIVE "" Release)
1071endif(LLVM_USE_HOST_TOOLS)
1072if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
1073# Dummy use to avoid CMake Warning: Manually-specified variables were not used
1074# (this is a variable that CrossCompile sets on recursive invocations)
1075endif()
1076
1077if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
1078   # special hack for Solaris to handle crazy system sys/regset.h
1079   include_directories("${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/Solaris")
1080endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
1081
1082# Make sure we don't get -rdynamic in every binary. For those that need it,
1083# use export_executable_symbols(target).
1084set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
1085
1086set(LLVM_EXTRACT_SYMBOLS_FLAGS ""
1087  CACHE STRING "Additional options to pass to llvm/utils/extract_symbols.py.
1088  These cannot override the options set by cmake, but can add extra options
1089  such as --tools.")
1090
1091include(AddLLVM)
1092include(TableGen)
1093
1094include(LLVMDistributionSupport)
1095
1096if( MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
1097  # People report that -O3 is unreliable on MinGW. The traditional
1098  # build also uses -O2 for that reason:
1099  llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
1100endif()
1101
1102if(LLVM_INCLUDE_TESTS)
1103  umbrella_lit_testsuite_begin(check-all)
1104endif()
1105
1106# Put this before tblgen. Else we have a circular dependence.
1107add_subdirectory(lib/Demangle)
1108add_subdirectory(lib/Support)
1109add_subdirectory(lib/TableGen)
1110
1111add_subdirectory(utils/TableGen)
1112
1113add_subdirectory(include/llvm)
1114
1115add_subdirectory(lib)
1116
1117if( LLVM_INCLUDE_UTILS )
1118  add_subdirectory(utils/FileCheck)
1119  add_subdirectory(utils/PerfectShuffle)
1120  add_subdirectory(utils/count)
1121  add_subdirectory(utils/not)
1122  add_subdirectory(utils/UnicodeData)
1123  add_subdirectory(utils/yaml-bench)
1124else()
1125  if ( LLVM_INCLUDE_TESTS )
1126    message(FATAL_ERROR "Including tests when not building utils will not work.
1127    Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLUDE_TESTS to Off.")
1128  endif()
1129endif()
1130
1131# Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
1132if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
1133  add_subdirectory(utils/LLVMVisualizers)
1134endif()
1135
1136foreach( binding ${LLVM_BINDINGS_LIST} )
1137  if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
1138    add_subdirectory(bindings/${binding})
1139  endif()
1140endforeach()
1141
1142add_subdirectory(projects)
1143
1144if( LLVM_INCLUDE_TOOLS )
1145  add_subdirectory(tools)
1146endif()
1147
1148if( LLVM_INCLUDE_RUNTIMES )
1149  add_subdirectory(runtimes)
1150endif()
1151
1152if( LLVM_INCLUDE_EXAMPLES )
1153  add_subdirectory(examples)
1154endif()
1155
1156if( LLVM_INCLUDE_TESTS )
1157  if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
1158    include(LLVMExternalProjectUtils)
1159    llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
1160      USE_TOOLCHAIN
1161      EXCLUDE_FROM_ALL
1162      NO_INSTALL
1163      ALWAYS_CLEAN)
1164  endif()
1165  add_subdirectory(utils/lit)
1166  add_subdirectory(test)
1167  add_subdirectory(unittests)
1168  if( LLVM_INCLUDE_UTILS )
1169    add_subdirectory(utils/unittest)
1170  endif()
1171
1172  if (WIN32)
1173    # This utility is used to prevent crashing tests from calling Dr. Watson on
1174    # Windows.
1175    add_subdirectory(utils/KillTheDoctor)
1176  endif()
1177
1178  umbrella_lit_testsuite_end(check-all)
1179  get_property(LLVM_ALL_LIT_DEPENDS GLOBAL PROPERTY LLVM_ALL_LIT_DEPENDS)
1180  get_property(LLVM_ALL_ADDITIONAL_TEST_DEPENDS
1181      GLOBAL PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS)
1182  add_custom_target(test-depends
1183      DEPENDS ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS})
1184  set_target_properties(test-depends PROPERTIES FOLDER "Tests")
1185endif()
1186
1187if (LLVM_INCLUDE_DOCS)
1188  add_subdirectory(docs)
1189endif()
1190
1191add_subdirectory(cmake/modules)
1192
1193# Do this last so that all lit targets have already been created.
1194if (LLVM_INCLUDE_UTILS)
1195  add_subdirectory(utils/llvm-lit)
1196endif()
1197
1198if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
1199  install(DIRECTORY include/llvm include/llvm-c
1200    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1201    COMPONENT llvm-headers
1202    FILES_MATCHING
1203    PATTERN "*.def"
1204    PATTERN "*.h"
1205    PATTERN "*.td"
1206    PATTERN "*.inc"
1207    PATTERN "LICENSE.TXT"
1208    )
1209
1210  install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c
1211    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1212    COMPONENT llvm-headers
1213    FILES_MATCHING
1214    PATTERN "*.def"
1215    PATTERN "*.h"
1216    PATTERN "*.gen"
1217    PATTERN "*.inc"
1218    # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
1219    PATTERN "CMakeFiles" EXCLUDE
1220    PATTERN "config.h" EXCLUDE
1221    )
1222
1223  if (LLVM_INSTALL_MODULEMAPS)
1224    install(DIRECTORY include/llvm include/llvm-c
1225            DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1226            COMPONENT llvm-headers
1227            FILES_MATCHING
1228            PATTERN "module.modulemap"
1229            )
1230    install(FILES include/llvm/module.install.modulemap
1231            DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm"
1232            COMPONENT llvm-headers
1233            RENAME "module.extern.modulemap"
1234            )
1235  endif(LLVM_INSTALL_MODULEMAPS)
1236
1237  # Installing the headers needs to depend on generating any public
1238  # tablegen'd headers.
1239  add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen)
1240  set_target_properties(llvm-headers PROPERTIES FOLDER "Misc")
1241
1242  if (NOT LLVM_ENABLE_IDE)
1243    add_llvm_install_targets(install-llvm-headers
1244                             DEPENDS llvm-headers
1245                             COMPONENT llvm-headers)
1246  endif()
1247
1248  # Custom target to install all libraries.
1249  add_custom_target(llvm-libraries)
1250  set_target_properties(llvm-libraries PROPERTIES FOLDER "Misc")
1251
1252  if (NOT LLVM_ENABLE_IDE)
1253    add_llvm_install_targets(install-llvm-libraries
1254                             DEPENDS llvm-libraries
1255                             COMPONENT llvm-libraries)
1256  endif()
1257
1258  get_property(LLVM_LIBS GLOBAL PROPERTY LLVM_LIBS)
1259  if(LLVM_LIBS)
1260    list(REMOVE_DUPLICATES LLVM_LIBS)
1261    foreach(lib ${LLVM_LIBS})
1262      add_dependencies(llvm-libraries ${lib})
1263      if (NOT LLVM_ENABLE_IDE)
1264        add_dependencies(install-llvm-libraries install-${lib})
1265        add_dependencies(install-llvm-libraries-stripped install-${lib}-stripped)
1266      endif()
1267    endforeach()
1268  endif()
1269endif()
1270
1271# This must be at the end of the LLVM root CMakeLists file because it must run
1272# after all targets are created.
1273llvm_distribution_add_targets()
1274process_llvm_pass_plugins(GEN_CONFIG)
1275include(CoverageReport)
1276
1277# This allows us to deploy the Universal CRT DLLs by passing -DCMAKE_INSTALL_UCRT_LIBRARIES=ON to CMake
1278if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_INSTALL_UCRT_LIBRARIES)
1279  include(InstallRequiredSystemLibraries)
1280endif()
1281
1282if (LLVM_INCLUDE_BENCHMARKS)
1283  # Override benchmark defaults so that when the library itself is updated these
1284  # modifications are not lost.
1285  set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing" FORCE)
1286  set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Disable benchmark exceptions" FORCE)
1287  set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install benchmark" FORCE)
1288  set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE BOOL "Don't download dependencies" FORCE)
1289  set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE)
1290  set(BENCHMARK_ENABLE_WERROR ${LLVM_ENABLE_WERROR} CACHE BOOL
1291    "Handle -Werror for Google Benchmark based on LLVM_ENABLE_WERROR" FORCE)
1292  # Since LLVM requires C++11 it is safe to assume that std::regex is available.
1293  set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
1294  add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark
1295    ${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark)
1296  add_subdirectory(benchmarks)
1297endif()
1298
1299if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
1300  add_subdirectory(utils/llvm-locstats)
1301endif()
1302