1 # See docs/CMake.html for instructions about how to build LLVM with CMake.
3 cmake_minimum_required(VERSION 3.20.0)
5 include(CMakeDependentOption)
7 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
8 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
11 # Builds with custom install names and installation rpath setups may not work
12 # in the build tree. Allow these cases to use CMake's default build tree
13 # behavior by setting `LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE` to do this.
14 option(LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE "If set, use CMake's default build tree install name directory logic (Darwin only)" OFF)
15 mark_as_advanced(LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE)
16 if(NOT LLVM_NO_INSTALL_NAME_DIR_FOR_BUILD_TREE)
17 set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
20 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/LLVMVersion.cmake)
22 set_directory_properties(PROPERTIES LLVM_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")
24 if (NOT PACKAGE_VERSION)
26 "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
29 if(NOT DEFINED LLVM_SHLIB_SYMBOL_VERSION)
30 # "Symbol version prefix for libLLVM.so and libclang-cpp.so"
31 set(LLVM_SHLIB_SYMBOL_VERSION "LLVM_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
34 if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (MSVC_TOOLSET_VERSION LESS 142) AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))
35 message(WARNING "Visual Studio generators use the x86 host compiler by "
36 "default, even for 64-bit targets. This can result in linker "
37 "instability and out of memory errors. To use the 64-bit "
38 "host compiler, pass -Thost=x64 on the CMake command line.")
41 if (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_OSX_ARCHITECTURES)
42 # Some CMake features like object libraries get confused if you don't
43 # explicitly specify an architecture setting with the Xcode generator.
44 set(CMAKE_OSX_ARCHITECTURES "x86_64")
48 VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
51 if (NOT DEFINED CMAKE_INSTALL_LIBDIR AND DEFINED LLVM_LIBDIR_SUFFIX)
52 # Must go before `include(GNUInstallDirs)`.
53 set(CMAKE_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
56 # Must go after `DEFINED LLVM_LIBDIR_SUFFIX` check.
57 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
59 # Must go after `project(..)`.
60 include(GNUInstallDirs)
62 # This C++ standard is required to build LLVM.
63 set(LLVM_REQUIRED_CXX_STANDARD 17)
65 # If we find that the cache contains CMAKE_CXX_STANDARD it means that it's a old CMakeCache.txt
66 # and we can just inform the user and then reset it.
67 if($CACHE{CMAKE_CXX_STANDARD} AND $CACHE{CMAKE_CXX_STANDARD} LESS ${LLVM_REQUIRED_CXX_STANDARD})
68 message(WARNING "Resetting cache value for CMAKE_CXX_STANDARD to ${LLVM_REQUIRED_CXX_STANDARD}")
69 unset(CMAKE_CXX_STANDARD CACHE)
72 # if CMAKE_CXX_STANDARD is still set after the cache unset above it means that the user requested it
73 # and we allow it to be set to something newer than the required standard but otherwise we fail.
74 if(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS ${LLVM_REQUIRED_CXX_STANDARD})
75 message(FATAL_ERROR "Requested CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} which is less than the required ${LLVM_REQUIRED_CXX_STANDARD}.")
78 set(CMAKE_CXX_STANDARD ${LLVM_REQUIRED_CXX_STANDARD} CACHE STRING "C++ standard to conform to")
79 set(CMAKE_CXX_STANDARD_REQUIRED YES)
82 # Cygwin is a bit stricter and lack things like 'strdup', 'stricmp', etc in
84 set(CMAKE_CXX_EXTENSIONS YES)
86 set(CMAKE_CXX_EXTENSIONS NO)
89 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
91 No build type selected. You need to pass -DCMAKE_BUILD_TYPE=<type> in order to configure LLVM.
92 Available options are:
93 * -DCMAKE_BUILD_TYPE=Release - For an optimized build with no assertions or debug info.
94 * -DCMAKE_BUILD_TYPE=Debug - For an unoptimized build with assertions and debug info.
95 * -DCMAKE_BUILD_TYPE=RelWithDebInfo - For an optimized build with no assertions but with debug info.
96 * -DCMAKE_BUILD_TYPE=MinSizeRel - For a build optimized for size instead of speed.
97 Learn more about these options in our documentation at https://llvm.org/docs/CMake.html#cmake-build-type
101 # Set default build type for cmake's try_compile module.
102 # CMake 3.17 or newer sets CMAKE_DEFAULT_BUILD_TYPE to one of the
103 # items from CMAKE_CONFIGURATION_TYPES. Logic below can be further
104 # simplified once LLVM's minimum CMake version is updated to 3.17.
105 if(CMAKE_DEFAULT_BUILD_TYPE)
106 set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_DEFAULT_BUILD_TYPE})
108 if(CMAKE_CONFIGURATION_TYPES)
109 list(GET CMAKE_CONFIGURATION_TYPES 0 CMAKE_TRY_COMPILE_CONFIGURATION)
110 elseif(CMAKE_BUILD_TYPE)
111 set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
115 # Side-by-side subprojects layout: automatically set the
116 # LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS
117 # This allows an easy way of setting up a build directory for llvm and another
118 # one for llvm+clang+... using the same sources.
119 set(LLVM_ALL_PROJECTS "bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;lld;lldb;mlir;openmp;polly;pstl")
120 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
121 # Disallow 'openmp' as a LLVM PROJECT on AIX as the supported way is to use
122 # LLVM_ENABLE_RUNTIMES.
123 list(REMOVE_ITEM LLVM_ALL_PROJECTS openmp)
126 # The flang project is not yet part of "all" projects (see C++ requirements)
127 set(LLVM_EXTRA_PROJECTS "flang")
128 # List of all known projects in the mono repo
129 set(LLVM_KNOWN_PROJECTS "${LLVM_ALL_PROJECTS};${LLVM_EXTRA_PROJECTS}")
130 set(LLVM_ENABLE_PROJECTS "" CACHE STRING
131 "Semicolon-separated list of projects to build (${LLVM_KNOWN_PROJECTS}), or \"all\".")
132 # Make sure expansion happens first to not handle "all" in rest of the checks.
133 if( LLVM_ENABLE_PROJECTS STREQUAL "all" )
134 set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS})
136 foreach(proj ${LLVM_ENABLE_PROJECTS})
137 if (NOT proj STREQUAL "llvm" AND NOT "${proj}" IN_LIST LLVM_KNOWN_PROJECTS)
138 MESSAGE(FATAL_ERROR "${proj} isn't a known project: ${LLVM_KNOWN_PROJECTS}. Did you mean to enable it as a runtime in LLVM_ENABLE_RUNTIMES?")
142 if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
143 if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
144 message(STATUS "Enabling MLIR as a dependency to flang")
145 list(APPEND LLVM_ENABLE_PROJECTS "mlir")
148 if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)
149 message(FATAL_ERROR "Clang is not enabled, but is required for the Flang driver")
153 if ("libc" IN_LIST LLVM_ENABLE_PROJECTS)
154 message(WARNING "Using LLVM_ENABLE_PROJECTS=libc is deprecated now, and will "
155 "become a fatal error in the LLVM 21 release. Please use "
156 "-DLLVM_ENABLE_RUNTIMES=libc or see the instructions at "
157 "https://libc.llvm.org/ for building the runtimes.")
160 # Select the runtimes to build
162 # As we migrate runtimes to using the bootstrapping build, the set of default runtimes
163 # should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
164 set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
165 set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload")
166 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
167 "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
168 if(LLVM_ENABLE_RUNTIMES STREQUAL "all")
169 set(LLVM_ENABLE_RUNTIMES ${LLVM_DEFAULT_RUNTIMES})
171 foreach(proj IN LISTS LLVM_ENABLE_RUNTIMES)
172 if (NOT "${proj}" IN_LIST LLVM_SUPPORTED_RUNTIMES)
173 message(FATAL_ERROR "Runtime \"${proj}\" is not a supported runtime. Supported runtimes are: ${LLVM_SUPPORTED_RUNTIMES}")
177 # Set a shorthand option to enable the GPU build of the 'libc' project.
178 option(LIBC_GPU_BUILD "Enable the 'libc' project targeting the GPU" OFF)
180 if(LLVM_RUNTIME_TARGETS)
181 list(APPEND LLVM_RUNTIME_TARGETS "nvptx64-nvidia-cuda" "amdgcn-amd-amdhsa")
183 set(LLVM_RUNTIME_TARGETS "default;nvptx64-nvidia-cuda;amdgcn-amd-amdhsa")
185 list(APPEND RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES "libc")
186 list(APPEND RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES "libc")
189 foreach(_name ${LLVM_RUNTIME_TARGETS})
190 if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
191 if("${_name}" STREQUAL "amdgcn-amd-amdhsa" OR "${_name}" STREQUAL "nvptx64-nvidia-cuda")
192 set(LLVM_LIBC_GPU_BUILD ON)
196 if("${LIBC_TARGET_TRIPLE}" STREQUAL "amdgcn-amd-amdhsa" OR
197 "${LIBC_TARGET_TRIPLE}" STREQUAL "nvptx64-nvidia-cuda")
198 set(LLVM_LIBC_GPU_BUILD ON)
200 if (NOT "libc" IN_LIST LLVM_ENABLE_PROJECTS AND LLVM_LIBC_GPU_BUILD)
201 message(STATUS "Enabling libc project to build libc testing tools")
202 list(APPEND LLVM_ENABLE_PROJECTS "libc")
205 # LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
206 # `LLVM_ENABLE_PROJECTS` CMake cache variable. This exists for
209 # * As an indicator that the `LLVM_ENABLE_PROJECTS` list is now the single
210 # source of truth for which projects to build. This means we will ignore user
211 # supplied `LLVM_TOOL_<project>_BUILD` CMake cache variables and overwrite
214 # * The case where the user previously had `LLVM_ENABLE_PROJECTS` set to a
215 # non-empty list but now the user wishes to disable building all other projects
216 # by setting `LLVM_ENABLE_PROJECTS` to an empty string. In that case we still
217 # need to set the `LLVM_TOOL_${upper_proj}_BUILD` variables so that we disable
218 # building all the projects that were previously enabled.
219 set(LLVM_ENABLE_PROJECTS_USED OFF CACHE BOOL "")
220 mark_as_advanced(LLVM_ENABLE_PROJECTS_USED)
222 if (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "")
223 set(LLVM_ENABLE_PROJECTS_USED ON CACHE BOOL "" FORCE)
224 foreach(proj ${LLVM_KNOWN_PROJECTS} ${LLVM_EXTERNAL_PROJECTS})
225 string(TOUPPER "${proj}" upper_proj)
226 string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})
227 if ("${proj}" IN_LIST LLVM_ENABLE_PROJECTS)
228 message(STATUS "${proj} project is enabled")
229 set(SHOULD_ENABLE_PROJECT TRUE)
230 set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
231 if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")
232 message(FATAL_ERROR "LLVM_ENABLE_PROJECTS requests ${proj} but directory not found: ${PROJ_DIR}")
234 if( LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" )
235 set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "" FORCE)
237 set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "")
239 elseif ("${proj}" IN_LIST LLVM_EXTERNAL_PROJECTS)
240 message(STATUS "${proj} project is enabled")
241 set(SHOULD_ENABLE_PROJECT TRUE)
243 message(STATUS "${proj} project is disabled")
244 set(SHOULD_ENABLE_PROJECT FALSE)
246 # Force `LLVM_TOOL_${upper_proj}_BUILD` variables to have values that
247 # corresponds with `LLVM_ENABLE_PROJECTS`. This prevents the user setting
248 # `LLVM_TOOL_${upper_proj}_BUILD` variables externally. At some point
249 # we should deprecate allowing users to set these variables by turning them
250 # into normal CMake variables rather than cache variables.
251 set(LLVM_TOOL_${upper_proj}_BUILD
252 ${SHOULD_ENABLE_PROJECT}
254 BOOL "Whether to build ${upper_proj} as part of LLVM" FORCE
258 unset(SHOULD_ENABLE_PROJECT)
260 # Build llvm with ccache if the package is present
261 set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
262 if(LLVM_CCACHE_BUILD)
263 find_program(CCACHE_PROGRAM ccache)
265 set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
266 set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
267 set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
268 CACHE STRING "Parameters to pass through to ccache")
270 if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
271 set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
272 if (LLVM_CCACHE_MAXSIZE)
273 set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
276 set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")
278 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
280 if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
281 NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
282 message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
284 # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
285 # with cmd.exe and some MSVC tools other than cl.exe
286 set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
287 set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
290 message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")
294 set(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS "" CACHE STRING
295 "Optional arguments for the native tool used in CMake --build invocations for external projects.")
296 mark_as_advanced(LLVM_EXTERNAL_PROJECT_BUILD_TOOL_ARGS)
298 option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF)
300 # Some features of the LLVM build may be disallowed when dependency debugging is
301 # enabled. In particular you cannot use ccache because we want to force compile
302 # operations to always happen.
303 if(LLVM_DEPENDENCY_DEBUGGING)
304 if(NOT CMAKE_HOST_APPLE)
305 message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.")
307 if(LLVM_CCACHE_BUILD)
308 message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.")
312 option(LLVM_ENABLE_DAGISEL_COV "Debug: Prints tablegen patterns that were used for selecting" OFF)
313 option(LLVM_ENABLE_GISEL_COV "Enable collection of GlobalISel rule coverage" OFF)
314 if(LLVM_ENABLE_GISEL_COV)
315 set(LLVM_GISEL_COV_PREFIX "${CMAKE_BINARY_DIR}/gisel-coverage-" CACHE STRING "Provide a filename prefix to collect the GlobalISel rule coverage")
318 # Add path for custom modules
319 list(INSERT CMAKE_MODULE_PATH 0
320 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
321 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
322 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
325 # Generate a CompilationDatabase (compile_commands.json file) for our build,
326 # for use by clang_complete, YouCompleteMe, etc.
327 set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
329 option(LLVM_INSTALL_BINUTILS_SYMLINKS
330 "Install symlinks from the binutils tool names to the corresponding LLVM tools." OFF)
332 option(LLVM_INSTALL_CCTOOLS_SYMLINKS
333 "Install symlinks from the cctools tool names to the corresponding LLVM tools." OFF)
335 # By default we use symlinks on Unix platforms and copy binaries on Windows
336 # If you have the correct setup on Windows you can use this option to enable
337 # symlinks and save a lot of diskspace.
338 option(LLVM_USE_SYMLINKS "Use symlinks instead of copying binaries" ${CMAKE_HOST_UNIX})
340 option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
342 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
344 # Unfortunatly Clang is too eager to search directories for module maps, which can cause the
345 # installed version of the maps to be found when building LLVM from source. Therefore we turn off
346 # the installation by default. See llvm.org/PR31905.
347 option(LLVM_INSTALL_MODULEMAPS "Install the modulemap files in the 'install' target." OFF)
349 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
350 if ( LLVM_USE_FOLDERS )
351 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
354 include(VersionFromVCS)
356 option(LLVM_APPEND_VC_REV
357 "Embed the version control system revision in LLVM" ON)
359 set(LLVM_FORCE_VC_REVISION
360 "" CACHE STRING "Force custom VC revision for LLVM_APPEND_VC_REV")
362 set(LLVM_FORCE_VC_REPOSITORY
363 "" CACHE STRING "Force custom VC repository for LLVM_APPEND_VC_REV")
365 option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OFF)
367 set(PACKAGE_NAME LLVM)
368 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
369 set(PACKAGE_BUGREPORT "https://github.com/llvm/llvm-project/issues/")
371 set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
372 "Default URL where bug reports are to be submitted.")
373 set(LLDB_BUG_REPORT_URL "${BUG_REPORT_URL}" CACHE STRING
374 "Default URL where lldb bug reports are to be submitted.")
377 if(NOT DEFINED CPACK_PACKAGE_INSTALL_DIRECTORY)
378 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
380 if(NOT DEFINED CPACK_PACKAGE_VENDOR)
381 set(CPACK_PACKAGE_VENDOR "LLVM")
383 set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
384 set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
385 set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
386 set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
387 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
388 if(WIN32 AND NOT UNIX)
389 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
390 if(NOT DEFINED CPACK_PACKAGE_INSTALL_REGISTRY_KEY)
391 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
393 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
394 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
395 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
396 set(CPACK_NSIS_MODIFY_PATH "ON")
397 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
399 if(NOT DEFINED CPACK_NSIS_INSTALL_ROOT)
400 set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
406 # Sanity check our source directory to make sure that we are not trying to
407 # generate an in-source build (unless on MSVC_IDE, where it is ok), and to make
408 # sure that we don't have any stray generated files lying around in the tree
409 # (which would end up getting picked up by header search, instead of the correct
411 if( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE )
412 message(FATAL_ERROR "In-source builds are not allowed.
413 Please create a directory and run cmake from there, passing the path
414 to this source directory as the last argument.
415 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
416 Please delete them.")
419 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
421 option(LLVM_ADDITIONAL_BUILD_TYPES "Additional build types that are allowed to be passed into CMAKE_BUILD_TYPE" "")
423 set(ALLOWED_BUILD_TYPES DEBUG RELEASE RELWITHDEBINFO MINSIZEREL ${LLVM_ADDITIONAL_BUILD_TYPES})
424 string (REPLACE ";" "|" ALLOWED_BUILD_TYPES_STRING "${ALLOWED_BUILD_TYPES}")
425 string (TOUPPER "${ALLOWED_BUILD_TYPES_STRING}" uppercase_ALLOWED_BUILD_TYPES)
427 if (CMAKE_BUILD_TYPE AND
428 NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(${uppercase_ALLOWED_BUILD_TYPES})$")
429 message(FATAL_ERROR "Unknown value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
432 # LLVM_INSTALL_PACKAGE_DIR needs to be declared prior to adding the tools
433 # subdirectory in order to have the value available for llvm-config.
434 include(GNUInstallPackageDir)
435 set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
436 "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
438 set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
439 "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
440 mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)
442 set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING
443 "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)")
444 mark_as_advanced(LLVM_UTILS_INSTALL_DIR)
446 set(LLVM_EXAMPLES_INSTALL_DIR "examples" CACHE STRING
447 "Path for examples subdirectory (enabled by LLVM_BUILD_EXAMPLES=ON) (defaults to 'examples')")
448 mark_as_advanced(LLVM_EXAMPLES_INSTALL_DIR)
450 # They are used as destination of target generators.
451 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
452 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
454 # DLL platform -- put DLLs into bin.
455 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
457 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
460 # Each of them corresponds to llvm-config's.
461 set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
462 set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
463 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
464 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
465 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
468 # Note: LLVM_CMAKE_DIR does not include generated files
469 set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)
470 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
471 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
473 # List of all targets to be built by default:
496 set(LLVM_ALL_EXPERIMENTAL_TARGETS
505 # List of targets with JIT support:
506 set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
508 set(LLVM_TARGETS_TO_BUILD "all"
509 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
511 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
512 CACHE STRING "Semicolon-separated list of experimental targets to build, or \"all\".")
514 option(BUILD_SHARED_LIBS
515 "Build all libraries as shared libraries instead of static" OFF)
517 option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
518 if(LLVM_ENABLE_BACKTRACES)
519 set(ENABLE_BACKTRACES 1)
522 option(LLVM_ENABLE_UNWIND_TABLES "Emit unwind tables for the libraries" ON)
524 option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
525 if(LLVM_ENABLE_CRASH_OVERRIDES)
526 set(ENABLE_CRASH_OVERRIDES 1)
529 option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF)
531 set(LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING "DISABLED" CACHE STRING
532 "Enhance Debugify's line number coverage tracking; enabling this is ABI-breaking. Can be DISABLED, or COVERAGE.")
533 set_property(CACHE LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING PROPERTY STRINGS DISABLED COVERAGE)
535 set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)
537 # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix
538 # as native path style, regardless of what this is set to.
539 set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT ON)
541 option(LLVM_WINDOWS_PREFER_FORWARD_SLASH "Prefer path names with forward slashes on Windows." ${WINDOWS_PREFER_FORWARD_SLASH_DEFAULT})
543 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
544 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
545 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
547 set(LLVM_TARGET_ARCH "host"
548 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
550 set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")
552 option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)
554 option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON)
556 # On z/OS, threads cannot be used because TLS is not supported.
557 if (CMAKE_SYSTEM_NAME MATCHES "OS390")
558 option(LLVM_ENABLE_THREADS "Use threads if available." OFF)
560 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
563 set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
565 set(LLVM_ENABLE_ZSTD "ON" CACHE STRING "Use zstd for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
567 set(LLVM_USE_STATIC_ZSTD FALSE CACHE BOOL "Use static version of zstd. Can be TRUE, FALSE")
569 set(LLVM_ENABLE_CURL "OFF" CACHE STRING "Use libcurl for the HTTP client if available. Can be ON, OFF, or FORCE_ON")
571 set(LLVM_HAS_LOGF128 "OFF" CACHE STRING "Use logf128 to constant fold fp128 logarithm calls. Can be ON, OFF, or FORCE_ON")
573 set(LLVM_ENABLE_HTTPLIB "OFF" CACHE STRING "Use cpp-httplib HTTP server library if available. Can be ON, OFF, or FORCE_ON")
575 set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")
577 option(LLVM_ENABLE_Z3_SOLVER
578 "Enable Support for the Z3 constraint solver in LLVM."
579 ${LLVM_ENABLE_Z3_SOLVER_DEFAULT}
582 if (LLVM_ENABLE_Z3_SOLVER)
583 find_package(Z3 4.8.9)
585 if (LLVM_Z3_INSTALL_DIR)
587 message(FATAL_ERROR "Z3 >= 4.8.9 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.")
592 message(FATAL_ERROR "LLVM_ENABLE_Z3_SOLVER cannot be enabled when Z3 is not available.")
598 set(LLVM_ENABLE_Z3_SOLVER_DEFAULT "${Z3_FOUND}")
601 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
602 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
605 if(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD STREQUAL "all")
606 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${LLVM_ALL_EXPERIMENTAL_TARGETS})
609 set(LLVM_TARGETS_TO_BUILD
610 ${LLVM_TARGETS_TO_BUILD}
611 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
612 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
614 if (NOT CMAKE_SYSTEM_NAME MATCHES "OS390")
615 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
617 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
618 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
619 option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)
621 option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)
623 option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
624 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
625 option(LLVM_ENABLE_LLVM_LIBC "Set to on to link all LLVM executables against LLVM libc, assuming it is accessible by the host compiler." OFF)
626 option(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF)
627 option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
628 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
629 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
631 option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
632 option(LLVM_UNREACHABLE_OPTIMIZE "Optimize llvm_unreachable() as undefined behavior (default), guaranteed trap when OFF" ON)
634 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
635 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
637 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
640 option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
642 # While adding scalable vector support to LLVM, we temporarily want to
643 # allow an implicit conversion of TypeSize to uint64_t, and to allow
644 # code to get the fixed number of elements from a possibly scalable vector.
645 # This CMake flag enables a more strict mode where it asserts that the type
646 # is not a scalable vector type.
648 # Enabling this flag makes it easier to find cases where the compiler makes
649 # assumptions on the size being 'fixed size', when building tests for
650 # SVE/SVE2 or other scalable vector architectures.
651 option(LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS
652 "Enable assertions that type is not scalable in implicit conversion from TypeSize to uint64_t and calls to getNumElements" OFF)
654 set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
655 "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
657 option(LLVM_FORCE_USE_OLD_TOOLCHAIN
658 "Set to ON to force using an old, unsupported host toolchain." OFF)
660 set(LLVM_LOCAL_RPATH "" CACHE FILEPATH
661 "If set, an absolute path added as rpath on binaries that do not already contain an executable-relative rpath.")
663 option(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN
664 "Set to ON to only warn when using a toolchain which is about to be deprecated, instead of emitting an error." OFF)
666 option(LLVM_USE_INTEL_JITEVENTS
667 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
670 if( LLVM_USE_INTEL_JITEVENTS )
671 # Verify we are on a supported platform
672 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
674 "Intel JIT API support is available on Linux and Windows only.")
676 endif( LLVM_USE_INTEL_JITEVENTS )
678 option(LLVM_USE_OPROFILE
679 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
681 option(LLVM_EXTERNALIZE_DEBUGINFO
682 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
684 option(LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES
685 "Preserve exported symbols in executables" ON)
687 set(LLVM_CODESIGNING_IDENTITY "" CACHE STRING
688 "Sign executables and dylibs with the given identity or skip if empty (Darwin Only)")
690 # If enabled, verify we are on a platform that supports oprofile.
691 if( LLVM_USE_OPROFILE )
692 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
693 message(FATAL_ERROR "OProfile support is available on Linux only.")
694 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
695 endif( LLVM_USE_OPROFILE )
698 "Use perf JIT interface to inform perf about JIT code" OFF)
700 # If enabled, verify we are on a platform that supports perf.
702 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
703 message(FATAL_ERROR "perf support is available on Linux only.")
704 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
705 endif( LLVM_USE_PERF )
707 set(LLVM_USE_SANITIZER "" CACHE STRING
708 "Define the sanitizer used to build binaries and tests.")
709 option(LLVM_OPTIMIZE_SANITIZED_BUILDS "Pass -O1 on debug sanitizer builds" ON)
711 "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all"
713 "Compile flags set to enable UBSan. Only used if LLVM_USE_SANITIZER contains 'Undefined'.")
714 set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH
715 "Path to fuzzing library for linking with fuzz targets")
717 option(LLVM_USE_SPLIT_DWARF
718 "Use -gsplit-dwarf when compiling llvm and --gdb-index when linking." OFF)
720 # Define an option controlling whether we should build for 32-bit on 64-bit
721 # platforms, where supported.
722 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX"))
723 # TODO: support other platforms and toolchains.
724 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
727 # Define the default arguments to use with 'lit', and an option for the user to
729 set(LIT_ARGS_DEFAULT "-sv")
730 if (MSVC_IDE OR XCODE)
731 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
733 if(LLVM_INDIVIDUAL_TEST_COVERAGE)
734 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --per-test-coverage")
736 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
738 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
739 if( WIN32 AND NOT CYGWIN )
740 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
742 set(LLVM_NATIVE_TOOL_DIR "" CACHE PATH "Path to a directory containing prebuilt matching native tools (such as llvm-tblgen)")
744 set(LLVM_ENABLE_RPMALLOC "" CACHE BOOL "Replace the CRT allocator with rpmalloc.")
745 if(LLVM_ENABLE_RPMALLOC)
746 if(NOT (CMAKE_SYSTEM_NAME MATCHES "Windows|Linux"))
747 message(FATAL_ERROR "LLVM_ENABLE_RPMALLOC is only supported on Windows and Linux.")
749 if(LLVM_USE_SANITIZER)
750 message(FATAL_ERROR "LLVM_ENABLE_RPMALLOC cannot be used along with LLVM_USE_SANITIZER!")
753 if(CMAKE_CONFIGURATION_TYPES)
754 foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES})
755 string(TOUPPER "${BUILD_MODE}" uppercase_BUILD_MODE)
756 if(uppercase_BUILD_MODE STREQUAL "DEBUG")
757 message(WARNING "The Debug target isn't supported along with LLVM_ENABLE_RPMALLOC!")
761 if(CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
762 message(FATAL_ERROR "The Debug target isn't supported along with LLVM_ENABLE_RPMALLOC!")
767 # Override the C runtime allocator with the in-tree rpmalloc
768 set(LLVM_INTEGRATED_CRT_ALLOC "${CMAKE_CURRENT_SOURCE_DIR}/lib/Support")
769 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
772 set(LLVM_INTEGRATED_CRT_ALLOC "${LLVM_INTEGRATED_CRT_ALLOC}" CACHE PATH "Replace the Windows CRT allocator with any of {rpmalloc|mimalloc|snmalloc}. Only works with CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded.")
773 if(LLVM_INTEGRATED_CRT_ALLOC)
775 message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows.")
777 if(LLVM_USE_SANITIZER)
778 message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used along with LLVM_USE_SANITIZER!")
780 if(CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
781 message(FATAL_ERROR "The Debug target isn't supported along with LLVM_INTEGRATED_CRT_ALLOC!")
785 # Define options to control the inclusion and default build behavior for
786 # components which may not strictly be necessary (tools, examples, and tests).
788 # This is primarily to support building smaller or faster project files.
789 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
790 option(LLVM_BUILD_TOOLS
791 "Build the LLVM tools. If OFF, just generate build targets." ON)
793 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
794 option(LLVM_BUILD_UTILS
795 "Build LLVM utility binaries. If OFF, just generate build targets." ON)
797 option(LLVM_INCLUDE_RUNTIMES "Generate build targets for the LLVM runtimes." ON)
798 option(LLVM_BUILD_RUNTIMES
799 "Build the LLVM runtimes. If OFF, just generate build targets." ON)
801 option(LLVM_BUILD_RUNTIME
802 "Build the LLVM runtime libraries." ON)
803 option(LLVM_BUILD_EXAMPLES
804 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
805 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
807 option(LLVM_BUILD_TESTS
808 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
809 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
811 option(LLVM_INSTALL_GTEST
812 "Install the llvm gtest library. This should be on if you want to do
813 stand-alone builds of the other projects and run their unit tests." OFF)
815 option(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default
816 targets. If OFF, benchmarks still could be built using Benchmarks target." OFF)
817 option(LLVM_INCLUDE_BENCHMARKS "Generate benchmark targets. If OFF, benchmarks can't be built." ON)
819 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
820 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
821 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
822 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
823 option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
824 option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
826 set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html"
827 CACHE STRING "Doxygen-generated HTML documentation install directory")
828 set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/ocaml-html"
829 CACHE STRING "OCamldoc-generated HTML documentation install directory")
831 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
832 "Build compiler-rt as an external project." OFF)
834 option (LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO
835 "Show target and host info when tools are invoked with --version." ON)
837 option(LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG
838 "Show the optional build config flags when tools are invoked with --version." ON)
840 # You can configure which libraries from LLVM you want to include in the
841 # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
842 # list of LLVM components. All component names handled by llvm-config are valid.
843 if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
844 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
845 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
849 option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" ON)
850 if (BUILD_SHARED_LIBS)
851 message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.")
854 option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)
857 # Used to test building the llvm shared library with explicit symbol visibility on
858 # Windows and Linux. For ELF platforms default symbols visibility is set to hidden.
859 set(LLVM_BUILD_LLVM_DYLIB_VIS FALSE CACHE BOOL "")
860 mark_as_advanced(LLVM_BUILD_LLVM_DYLIB_VIS)
862 set(CAN_BUILD_LLVM_DYLIB OFF)
863 if(NOT MSVC OR LLVM_BUILD_LLVM_DYLIB_VIS)
864 set(CAN_BUILD_LLVM_DYLIB ON)
867 cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF
868 "CAN_BUILD_LLVM_DYLIB" OFF)
870 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
871 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
872 set(LLVM_BUILD_LLVM_DYLIB_default ON)
874 cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}
875 "CAN_BUILD_LLVM_DYLIB" OFF)
877 cmake_dependent_option(LLVM_DYLIB_EXPORT_INLINES "Force inline members of classes to be DLL exported when
878 building with clang-cl so the libllvm DLL is compatible with MSVC"
880 "MSVC;LLVM_BUILD_LLVM_DYLIB_VIS" OFF)
882 if(LLVM_BUILD_LLVM_DYLIB_VIS)
883 set(LLVM_BUILD_LLVM_DYLIB ON)
886 if (LLVM_LINK_LLVM_DYLIB AND BUILD_SHARED_LIBS)
887 message(FATAL_ERROR "Cannot enable BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB. We recommend disabling BUILD_SHARED_LIBS.")
890 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
891 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES)))
892 set(LLVM_USE_HOST_TOOLS ON)
895 option(LLVM_OMIT_DAGISEL_COMMENTS "Do not add comments to DAG ISel" ON)
896 if (CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE MATCHES "^(RELWITHDEBINFO|DEBUG)$")
897 set(LLVM_OMIT_DAGISEL_COMMENTS OFF)
901 option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
904 if(NOT LLVM_INDIVIDUAL_TEST_COVERAGE)
905 if(LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE OR LLVM_ENABLE_IR_PGO)
906 if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
907 # A pool size of 1-2 is probably sufficient on an SSD. 3-4 should be fine
908 # for spinning disks. Anything higher may only help on slower mediums.
909 set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
911 if(NOT LLVM_PROFILE_FILE_PATTERN)
912 if(NOT LLVM_PROFILE_DATA_DIR)
913 file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles" LLVM_PROFILE_DATA_DIR)
915 file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
917 if(NOT LLVM_CSPROFILE_FILE_PATTERN)
918 if(NOT LLVM_CSPROFILE_DATA_DIR)
919 file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/csprofiles" LLVM_CSPROFILE_DATA_DIR)
921 file(TO_NATIVE_PATH "${LLVM_CSPROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_CSPROFILE_FILE_PATTERN)
926 if (LLVM_BUILD_STATIC)
927 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
928 # Remove shared library suffixes from use in find_library
929 foreach (shared_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_IMPORT_LIBRARY_SUFFIX})
930 list(FIND CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix} shared_lib_suffix_idx)
931 if(NOT ${shared_lib_suffix_idx} EQUAL -1)
932 list(REMOVE_AT CMAKE_FIND_LIBRARY_SUFFIXES ${shared_lib_suffix_idx})
937 # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
938 if(CMAKE_HOST_APPLE AND APPLE)
942 # Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
943 set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")
944 mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
946 if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux|OS390")
947 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)
949 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF)
951 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default} CACHE BOOL
952 "Enable per-target runtimes directory")
954 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
955 "Profiling data file to use when compiling in order to improve runtime performance.")
957 if(LLVM_INCLUDE_TESTS)
958 # All LLVM Python files should be compatible down to this minimum version.
959 set(LLVM_MINIMUM_PYTHON_VERSION 3.8)
961 # FIXME: it is unknown if this is the actual minimum bound
962 set(LLVM_MINIMUM_PYTHON_VERSION 3.0)
965 # Find python before including config-ix, since it needs to be able to search
966 # for python modules.
967 find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
968 COMPONENTS Interpreter)
970 # All options referred to from HandleLLVMOptions have to be specified
971 # BEFORE this include, otherwise options will not be correctly set on
975 # By default, we target the host, but this can be overridden at CMake
976 # invocation time. Except on 64-bit AIX, where the system toolchain
977 # expect 32-bit objects by default.
978 if("${LLVM_HOST_TRIPLE}" MATCHES "^powerpc64-ibm-aix")
979 string(REGEX REPLACE "^powerpc64" "powerpc" LLVM_DEFAULT_TARGET_TRIPLE_DEFAULT "${LLVM_HOST_TRIPLE}")
981 # Only set default triple when native target is enabled.
982 if (LLVM_NATIVE_TARGET)
983 set(LLVM_DEFAULT_TARGET_TRIPLE_DEFAULT "${LLVM_HOST_TRIPLE}")
987 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE_DEFAULT}" CACHE STRING
988 "Default target for which LLVM will generate code." )
989 message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")
991 set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
994 if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
995 set(LLVM_ENABLE_PLUGINS_default ON)
997 set(LLVM_ENABLE_PLUGINS_default OFF)
1000 set(LLVM_ENABLE_PLUGINS_default ${LLVM_ENABLE_PIC})
1002 option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})
1004 set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL
1005 "Enable the new pass manager by default.")
1006 if(NOT LLVM_ENABLE_NEW_PASS_MANAGER)
1007 message(FATAL_ERROR "Enabling the legacy pass manager on the cmake level is"
1008 " no longer supported.")
1011 include(HandleLLVMOptions)
1015 # Configure all of the various header file fragments LLVM uses which depend on
1016 # configuration variables.
1017 set(LLVM_ENUM_TARGETS "")
1018 set(LLVM_ENUM_ASM_PRINTERS "")
1019 set(LLVM_ENUM_ASM_PARSERS "")
1020 set(LLVM_ENUM_DISASSEMBLERS "")
1021 set(LLVM_ENUM_TARGETMCAS "")
1022 set(LLVM_ENUM_EXEGESIS "")
1023 foreach(t ${LLVM_TARGETS_TO_BUILD})
1024 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
1026 # Make sure that any experimental targets were passed via
1027 # LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, not LLVM_TARGETS_TO_BUILD.
1028 # We allow experimental targets that are not in LLVM_ALL_EXPERIMENTAL_TARGETS,
1029 # as long as they are passed via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.
1030 if ( NOT "${t}" IN_LIST LLVM_ALL_TARGETS AND NOT "${t}" IN_LIST LLVM_EXPERIMENTAL_TARGETS_TO_BUILD )
1031 if( "${t}" IN_LIST LLVM_ALL_EXPERIMENTAL_TARGETS )
1032 message(FATAL_ERROR "The target `${t}' is experimental and must be passed "
1033 "via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.")
1035 message(FATAL_ERROR "The target `${t}' is not a core tier target. It may be "
1036 "experimental, if so it must be passed via "
1037 "LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.\n"
1038 "Core tier targets: ${LLVM_ALL_TARGETS}\n"
1039 "Known experimental targets: ${LLVM_ALL_EXPERIMENTAL_TARGETS}")
1042 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
1043 string(TOUPPER ${t} T_UPPER)
1044 set(LLVM_HAS_${T_UPPER}_TARGET 1)
1047 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
1049 set(LLVM_ENUM_ASM_PRINTERS
1050 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
1052 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
1053 set(LLVM_ENUM_ASM_PARSERS
1054 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
1056 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
1057 set(LLVM_ENUM_DISASSEMBLERS
1058 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
1060 if( EXISTS ${td}/MCA/CMakeLists.txt )
1061 set(LLVM_ENUM_TARGETMCAS
1062 "${LLVM_ENUM_TARGETMCAS}LLVM_TARGETMCA(${t})\n")
1064 if( EXISTS ${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib/${t}/CMakeLists.txt )
1065 set(LLVM_ENUM_EXEGESIS
1066 "${LLVM_ENUM_EXEGESIS}LLVM_EXEGESIS(${t})\n")
1070 # Provide an LLVM_ namespaced alias for use in #cmakedefine.
1071 set(LLVM_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
1073 # Produce the target definition files, which provide a way for clients to easily
1074 # include various classes of targets.
1076 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
1077 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
1080 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
1081 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
1084 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
1085 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
1088 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
1089 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
1092 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetMCAs.def.in
1093 ${LLVM_INCLUDE_DIR}/llvm/Config/TargetMCAs.def
1096 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetExegesis.def.in
1097 ${LLVM_INCLUDE_DIR}/llvm/Config/TargetExegesis.def
1100 # They are not referenced. See set_output_directory().
1101 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
1102 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_LIBRARY_DIR} )
1103 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_LIBRARY_DIR} )
1105 # For up-to-date instructions for installing the TFLite dependency, refer to
1106 # the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh
1107 set(LLVM_HAVE_TFLITE "" CACHE BOOL "Use tflite")
1108 if (LLVM_HAVE_TFLITE)
1109 find_package(tensorflow-lite REQUIRED)
1112 # For up-to-date instructions for installing the Tensorflow dependency, refer to
1113 # the bot setup script: https://github.com/google/ml-compiler-opt/blob/main/buildbot/buildbot_init.sh
1114 # Specifically, assuming python3 is installed:
1115 # python3 -m pip install --upgrade pip && python3 -m pip install --user tf_nightly==2.3.0.dev20200528
1116 # Then set TENSORFLOW_AOT_PATH to the package install - usually it's ~/.local/lib/python3.7/site-packages/tensorflow
1118 set(TENSORFLOW_AOT_PATH "" CACHE PATH "Path to TensorFlow pip install dir")
1120 if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
1121 set(LLVM_HAVE_TF_AOT "ON" CACHE BOOL "Tensorflow AOT available")
1122 set(TENSORFLOW_AOT_COMPILER
1123 "${TENSORFLOW_AOT_PATH}/../../../../bin/saved_model_cli"
1124 CACHE PATH "Path to the Tensorflow AOT compiler")
1125 include_directories(${TENSORFLOW_AOT_PATH}/include)
1126 add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
1127 ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
1128 install(TARGETS tf_xla_runtime EXPORT LLVMExports
1129 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
1130 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
1131 # Once we add more modules, we should handle this more automatically.
1132 if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL)
1133 set(LLVM_INLINER_MODEL_PATH "none")
1134 elseif(NOT DEFINED LLVM_INLINER_MODEL_PATH
1135 OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL ""
1136 OR "${LLVM_INLINER_MODEL_PATH}" STREQUAL "autogenerate")
1137 set(LLVM_INLINER_MODEL_PATH "autogenerate")
1138 set(LLVM_INLINER_MODEL_AUTOGENERATED 1)
1140 if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_REGALLOCEVICTMODEL)
1141 set(LLVM_RAEVICT_MODEL_PATH "none")
1142 elseif(NOT DEFINED LLVM_RAEVICT_MODEL_PATH
1143 OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL ""
1144 OR "${LLVM_RAEVICT_MODEL_PATH}" STREQUAL "autogenerate")
1145 set(LLVM_RAEVICT_MODEL_PATH "autogenerate")
1146 set(LLVM_RAEVICT_MODEL_AUTOGENERATED 1)
1151 # Configure the three LLVM configuration header files.
1153 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
1154 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
1156 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
1157 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
1159 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake
1160 ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)
1162 if(APPLE AND DARWIN_LTO_LIBRARY)
1163 set(CMAKE_EXE_LINKER_FLAGS
1164 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
1165 set(CMAKE_SHARED_LINKER_FLAGS
1166 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
1167 set(CMAKE_MODULE_LINKER_FLAGS
1168 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
1171 # Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to
1172 # break things. In this case we need to enable the large-file API as well.
1173 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
1174 add_compile_definitions(_XOPEN_SOURCE=700)
1175 add_compile_definitions(_LARGE_FILE_API)
1177 # Modules should be built with -shared -Wl,-G, so we can use runtime linking
1179 string(APPEND CMAKE_MODULE_LINKER_FLAGS " -shared -Wl,-G")
1181 # Also set the correct flags for building shared libraries.
1182 string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared")
1185 # Build with _XOPEN_SOURCE on z/OS.
1186 if (CMAKE_SYSTEM_NAME MATCHES "OS390")
1187 add_compile_definitions(_XOPEN_SOURCE=600)
1188 add_compile_definitions(_OPEN_SYS) # Needed for process information.
1189 add_compile_definitions(_OPEN_SYS_FILE_EXT) # Needed for EBCDIC I/O.
1190 add_compile_definitions(_EXT) # Needed for file data.
1191 add_compile_definitions(_UNIX03_THREADS) # Multithreading support.
1192 # Need to build LLVM as ASCII application.
1193 # This can't be a global setting because other projects may
1194 # need to be built in EBCDIC mode.
1195 append("-fzos-le-char-mode=ascii" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
1196 append("-m64" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
1199 # Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9.
1200 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
1201 add_compile_definitions(_FILE_OFFSET_BITS=64)
1204 set(CMAKE_INCLUDE_CURRENT_DIR ON)
1206 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
1208 # when crosscompiling import the executable targets from a file
1209 if(LLVM_USE_HOST_TOOLS)
1210 include(CrossCompile)
1211 llvm_create_cross_target(LLVM NATIVE "" Release)
1212 endif(LLVM_USE_HOST_TOOLS)
1213 if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
1214 # Dummy use to avoid CMake Warning: Manually-specified variables were not used
1215 # (this is a variable that CrossCompile sets on recursive invocations)
1218 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
1219 # special hack for Solaris to handle crazy system sys/regset.h
1220 include_directories("${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/Solaris")
1221 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
1223 # Make sure we don't get -rdynamic in every binary. For those that need it,
1224 # use EXPORT_SYMBOLS argument.
1225 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
1230 include(LLVMDistributionSupport)
1232 if( MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
1233 # People report that -O3 is unreliable on MinGW. The traditional
1234 # build also uses -O2 for that reason:
1235 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
1238 if(LLVM_INCLUDE_TESTS)
1239 umbrella_lit_testsuite_begin(check-all)
1242 # Put this before tblgen. Else we have a circular dependence.
1243 add_subdirectory(lib/Demangle)
1244 add_subdirectory(lib/Support)
1245 add_subdirectory(lib/TableGen)
1247 add_subdirectory(utils/TableGen)
1249 add_subdirectory(include)
1251 add_subdirectory(lib)
1253 if( LLVM_INCLUDE_UTILS )
1254 add_subdirectory(utils/FileCheck)
1255 add_subdirectory(utils/PerfectShuffle)
1256 add_subdirectory(utils/count)
1257 add_subdirectory(utils/not)
1258 add_subdirectory(utils/UnicodeData)
1259 add_subdirectory(utils/yaml-bench)
1260 add_subdirectory(utils/split-file)
1261 add_subdirectory(utils/mlgo-utils)
1262 if( LLVM_INCLUDE_TESTS )
1263 set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
1264 add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest)
1265 set(LLVM_SUBPROJECT_TITLE)
1268 if ( LLVM_INCLUDE_TESTS )
1269 message(FATAL_ERROR "Including tests when not building utils will not work.
1270 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLUDE_TESTS to Off.")
1274 # Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
1275 if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
1276 add_subdirectory(utils/LLVMVisualizers)
1279 foreach( binding ${LLVM_BINDINGS_LIST} )
1280 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
1281 add_subdirectory(bindings/${binding})
1285 add_subdirectory(projects)
1287 if( LLVM_INCLUDE_TOOLS )
1288 add_subdirectory(tools)
1291 if( LLVM_INCLUDE_RUNTIMES )
1292 add_subdirectory(runtimes)
1295 if( LLVM_INCLUDE_EXAMPLES )
1296 add_subdirectory(examples)
1299 if( LLVM_INCLUDE_TESTS )
1300 set(LLVM_GTEST_RUN_UNDER
1302 "Define the wrapper program that LLVM unit tests should be run under.")
1303 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
1304 include(LLVMExternalProjectUtils)
1305 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
1311 add_subdirectory(utils/lit)
1312 add_subdirectory(test)
1313 add_subdirectory(unittests)
1316 # This utility is used to prevent crashing tests from calling Dr. Watson on
1318 add_subdirectory(utils/KillTheDoctor)
1321 umbrella_lit_testsuite_end(check-all)
1322 get_property(LLVM_ALL_LIT_DEPENDS GLOBAL PROPERTY LLVM_ALL_LIT_DEPENDS)
1323 get_property(LLVM_ALL_ADDITIONAL_TEST_DEPENDS
1324 GLOBAL PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS)
1325 add_custom_target(test-depends)
1326 if(LLVM_ALL_LIT_DEPENDS OR LLVM_ALL_ADDITIONAL_TEST_DEPENDS)
1327 add_dependencies(test-depends ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS})
1329 set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests")
1330 add_dependencies(check-all test-depends)
1333 if (LLVM_INCLUDE_DOCS)
1334 add_subdirectory(docs)
1337 add_subdirectory(cmake/modules)
1339 # Do this last so that all lit targets have already been created.
1340 if (LLVM_INCLUDE_UTILS)
1341 add_subdirectory(utils/llvm-lit)
1344 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
1345 install(DIRECTORY include/llvm include/llvm-c
1346 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1347 COMPONENT llvm-headers
1353 PATTERN "LICENSE.TXT"
1356 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c
1357 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1358 COMPONENT llvm-headers
1364 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
1365 PATTERN "CMakeFiles" EXCLUDE
1366 PATTERN "config.h" EXCLUDE
1369 if (LLVM_INSTALL_MODULEMAPS)
1370 install(DIRECTORY include
1371 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1372 COMPONENT llvm-headers
1374 PATTERN "module.modulemap"
1376 install(FILES include/module.install.modulemap
1377 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1378 COMPONENT llvm-headers
1379 RENAME "module.extern.modulemap"
1381 endif(LLVM_INSTALL_MODULEMAPS)
1383 # Installing the headers needs to depend on generating any public
1384 # tablegen'd headers.
1385 add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen)
1386 set_target_properties(llvm-headers PROPERTIES FOLDER "LLVM/Resources")
1388 if (NOT LLVM_ENABLE_IDE)
1389 add_llvm_install_targets(install-llvm-headers
1390 DEPENDS llvm-headers
1391 COMPONENT llvm-headers)
1394 # Custom target to install all libraries.
1395 add_custom_target(llvm-libraries)
1396 set_target_properties(llvm-libraries PROPERTIES FOLDER "LLVM/Resources")
1398 if (NOT LLVM_ENABLE_IDE)
1399 add_llvm_install_targets(install-llvm-libraries
1400 DEPENDS llvm-libraries
1401 COMPONENT llvm-libraries)
1404 get_property(LLVM_LIBS GLOBAL PROPERTY LLVM_LIBS)
1406 list(REMOVE_DUPLICATES LLVM_LIBS)
1407 foreach(lib ${LLVM_LIBS})
1408 add_dependencies(llvm-libraries ${lib})
1409 if (NOT LLVM_ENABLE_IDE)
1410 add_dependencies(install-llvm-libraries install-${lib})
1411 add_dependencies(install-llvm-libraries-stripped install-${lib}-stripped)
1417 # This must be at the end of the LLVM root CMakeLists file because it must run
1418 # after all targets are created.
1419 llvm_distribution_add_targets()
1420 process_llvm_pass_plugins(GEN_CONFIG)
1421 include(CoverageReport)
1423 # This allows us to deploy the Universal CRT DLLs by passing -DCMAKE_INSTALL_UCRT_LIBRARIES=ON to CMake
1424 if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_INSTALL_UCRT_LIBRARIES)
1425 include(InstallRequiredSystemLibraries)
1428 if (LLVM_INCLUDE_BENCHMARKS)
1429 # Override benchmark defaults so that when the library itself is updated these
1430 # modifications are not lost.
1431 set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing" FORCE)
1432 set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Disable benchmark exceptions" FORCE)
1433 set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install benchmark" FORCE)
1434 set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE BOOL "Don't download dependencies" FORCE)
1435 set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE)
1436 set(BENCHMARK_ENABLE_WERROR ${LLVM_ENABLE_WERROR} CACHE BOOL
1437 "Handle -Werror for Google Benchmark based on LLVM_ENABLE_WERROR" FORCE)
1438 # Since LLVM requires C++11 it is safe to assume that std::regex is available.
1439 set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
1440 add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark
1441 ${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark)
1442 set_target_properties(benchmark PROPERTIES FOLDER "Third-Party/Google Benchmark")
1443 set_target_properties(benchmark_main PROPERTIES FOLDER "Third-Party/Google Benchmark")
1444 add_subdirectory(benchmarks)
1447 if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
1448 add_subdirectory(utils/llvm-locstats)
1452 # For additional targets that you would like to add schemes, specify e.g:
1454 # -DLLVM_XCODE_EXTRA_TARGET_SCHEMES="TargetParserTests;SupportTests"
1456 # at CMake configure time.
1457 set(LLVM_XCODE_EXTRA_TARGET_SCHEMES "" CACHE STRING "Specifies an extra list of targets to turn into schemes")
1459 foreach(target ${LLVM_XCODE_EXTRA_TARGET_SCHEMES})
1460 set_target_properties(${target} PROPERTIES XCODE_GENERATE_SCHEME ON)