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