OSDN Git Service

[cmake] Treat polly as "in tree" if LLVM_EXTERNAL_POLLY_SOURCE_DIR is provided
[android-x86/external-llvm.git] / CMakeLists.txt
1 # See docs/CMake.html for instructions about how to build LLVM with CMake.
2
3 cmake_minimum_required(VERSION 3.4.3)
4
5 if(POLICY CMP0022)
6   cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
7 endif()
8
9 if (POLICY CMP0051)
10   # CMake 3.1 and higher include generator expressions of the form
11   # $<TARGETLIB:obj> in the SOURCES property.  These need to be
12   # stripped everywhere that access the SOURCES property, so we just
13   # defer to the OLD behavior of not including generator expressions
14   # in the output for now.
15   cmake_policy(SET CMP0051 OLD)
16 endif()
17
18 if(POLICY CMP0057)
19   cmake_policy(SET CMP0057 NEW)
20 endif()
21
22 if(NOT DEFINED LLVM_VERSION_MAJOR)
23   set(LLVM_VERSION_MAJOR 4)
24 endif()
25 if(NOT DEFINED LLVM_VERSION_MINOR)
26   set(LLVM_VERSION_MINOR 0)
27 endif()
28 if(NOT DEFINED LLVM_VERSION_PATCH)
29   set(LLVM_VERSION_PATCH 0)
30 endif()
31 if(NOT DEFINED LLVM_VERSION_SUFFIX)
32   set(LLVM_VERSION_SUFFIX svn)
33 endif()
34
35 if (POLICY CMP0048)
36   cmake_policy(SET CMP0048 NEW)
37   set(cmake_3_0_PROJ_VERSION
38     VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
39   set(cmake_3_0_LANGUAGES LANGUAGES)
40 endif()
41
42 if (NOT PACKAGE_VERSION)
43   set(PACKAGE_VERSION
44     "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
45 endif()
46
47 project(LLVM
48   ${cmake_3_0_PROJ_VERSION}
49   ${cmake_3_0_LANGUAGES}
50   C CXX ASM)
51
52 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
53   message(STATUS "No build type selected, default to Debug")
54   set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (default Debug)")
55 endif()
56
57 # This should only apply if you are both on an Apple host, and targeting Apple.
58 if(CMAKE_HOST_APPLE AND APPLE)
59   if(NOT CMAKE_XCRUN)
60     find_program(CMAKE_XCRUN NAMES xcrun)
61   endif()
62   if(CMAKE_XCRUN)
63     execute_process(COMMAND ${CMAKE_XCRUN} -find libtool
64       OUTPUT_VARIABLE CMAKE_LIBTOOL
65       OUTPUT_STRIP_TRAILING_WHITESPACE)
66   endif()
67
68   if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL)
69     find_program(CMAKE_LIBTOOL NAMES libtool)
70   endif()
71
72   get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
73   if(CMAKE_LIBTOOL)
74     set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
75     message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
76     foreach(lang ${languages})
77       set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
78         "${CMAKE_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
79     endforeach()
80   endif()
81
82   # If DYLD_LIBRARY_PATH is set we need to set it on archiver commands
83   if(DYLD_LIBRARY_PATH)
84     set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
85     foreach(lang ${languages})
86       foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY})
87         list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW
88              "${dyld_envar} ${cmd}")
89       endforeach()
90       set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
91         ${CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW})
92     endforeach()
93   endif()
94 endif()
95
96 # The following only works with the Ninja generator in CMake >= 3.0.
97 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
98   "Define the maximum number of concurrent compilation jobs.")
99 if(LLVM_PARALLEL_COMPILE_JOBS)
100   if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
101     message(WARNING "Job pooling is only available with Ninja generators.")
102   else()
103     set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
104     set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
105   endif()
106 endif()
107
108 # Build llvm with ccache if the package is present
109 set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
110 if(LLVM_CCACHE_BUILD)
111   find_program(CCACHE_PROGRAM ccache)
112   if(CCACHE_PROGRAM)
113       set(LLVM_CCACHE_SIZE "" CACHE STRING "Size of ccache")
114       set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
115       set(CCACHE_PROGRAM "CCACHE_CPP2=yes CCACHE_HASHDIR=yes ${CCACHE_PROGRAM}")
116       if (LLVM_CCACHE_SIZE)
117         set(CCACHE_PROGRAM "CCACHE_SIZE=${LLVM_CCACHE_SIZE} ${CCACHE_PROGRAM}")
118       endif()
119       if (LLVM_CCACHE_DIR)
120         set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")
121       endif()
122       set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
123   else()
124     message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")
125   endif()
126 endif()
127
128 option(LLVM_BUILD_GLOBAL_ISEL "Experimental: Build GlobalISel" OFF)
129 if(LLVM_BUILD_GLOBAL_ISEL)
130   add_definitions(-DLLVM_BUILD_GLOBAL_ISEL)
131 endif()
132
133 set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
134   "Define the maximum number of concurrent link jobs.")
135 if(LLVM_PARALLEL_LINK_JOBS)
136   if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
137     message(WARNING "Job pooling is only available with Ninja generators.")
138   else()
139     set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
140     set(CMAKE_JOB_POOL_LINK link_job_pool)
141   endif()
142 endif()
143
144 # Add path for custom modules
145 set(CMAKE_MODULE_PATH
146   ${CMAKE_MODULE_PATH}
147   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
148   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
149   )
150
151 # Generate a CompilationDatabase (compile_commands.json file) for our build,
152 # for use by clang_complete, YouCompleteMe, etc.
153 set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
154
155 option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
156
157 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
158
159 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
160 if ( LLVM_USE_FOLDERS )
161   set_property(GLOBAL PROPERTY USE_FOLDERS ON)
162 endif()
163
164 include(VersionFromVCS)
165
166 option(LLVM_APPEND_VC_REV
167   "Append the version control system revision id to LLVM version" OFF)
168
169 if( LLVM_APPEND_VC_REV )
170   add_version_info_from_vcs(PACKAGE_VERSION)
171 endif()
172
173 set(PACKAGE_NAME LLVM)
174 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
175 set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
176
177 set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
178   "Default URL where bug reports are to be submitted.")
179
180 # Configure CPack.
181 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
182 set(CPACK_PACKAGE_VENDOR "LLVM")
183 set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
184 set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
185 set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
186 set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
187 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
188 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
189 if(WIN32 AND NOT UNIX)
190   set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
191   set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
192   set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
193   set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
194   set(CPACK_NSIS_MODIFY_PATH "ON")
195   set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
196   set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
197     "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
198   set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
199     "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
200   if( CMAKE_CL_64 )
201     set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
202   endif()
203 endif()
204 include(CPack)
205
206 # Sanity check our source directory to make sure that we are not trying to
207 # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
208 # sure that we don't have any stray generated files lying around in the tree
209 # (which would end up getting picked up by header search, instead of the correct
210 # versions).
211 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
212   message(FATAL_ERROR "In-source builds are not allowed.
213 CMake would overwrite the makefiles distributed with LLVM.
214 Please create a directory and run cmake from there, passing the path
215 to this source directory as the last argument.
216 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
217 Please delete them.")
218 endif()
219 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
220   file(GLOB_RECURSE
221     tablegenned_files_on_include_dir
222     "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
223   file(GLOB_RECURSE
224     tablegenned_files_on_lib_dir
225     "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
226   if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
227     message(FATAL_ERROR "Apparently there is a previous in-source build,
228 probably as the result of running `configure' and `make' on
229 ${CMAKE_CURRENT_SOURCE_DIR}.
230 This may cause problems. The suspicious files are:
231 ${tablegenned_files_on_lib_dir}
232 ${tablegenned_files_on_include_dir}
233 Please clean the source directory.")
234   endif()
235 endif()
236
237 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
238
239 if (CMAKE_BUILD_TYPE AND
240     NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
241   message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
242 endif()
243
244 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
245
246 set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')")
247 mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)
248
249 # They are used as destination of target generators.
250 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
251 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
252 if(WIN32 OR CYGWIN)
253   # DLL platform -- put DLLs into bin.
254   set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
255 else()
256   set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
257 endif()
258
259 # Each of them corresponds to llvm-config's.
260 set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
261 set(LLVM_LIBRARY_DIR      ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
262 set(LLVM_MAIN_SRC_DIR     ${CMAKE_CURRENT_SOURCE_DIR}  ) # --src-root
263 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
264 set(LLVM_BINARY_DIR       ${CMAKE_CURRENT_BINARY_DIR}  ) # --prefix
265
266 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
267 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
268
269 set(LLVM_ALL_TARGETS
270   AArch64
271   AMDGPU
272   ARM
273   BPF
274   Hexagon
275   Lanai
276   Mips
277   MSP430
278   NVPTX
279   PowerPC
280   Sparc
281   SystemZ
282   X86
283   XCore
284   )
285
286 # List of targets with JIT support:
287 set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
288
289 set(LLVM_TARGETS_TO_BUILD "all"
290     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
291
292 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
293   CACHE STRING "Semicolon-separated list of experimental targets to build.")
294
295 option(BUILD_SHARED_LIBS
296   "Build all libraries as shared libraries instead of static" OFF)
297
298 option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
299 if(LLVM_ENABLE_BACKTRACES)
300   set(ENABLE_BACKTRACES 1)
301 endif()
302
303 option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
304 if(LLVM_ENABLE_CRASH_OVERRIDES)
305   set(ENABLE_CRASH_OVERRIDES 1)
306 endif()
307
308 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
309 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
310 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
311
312 set(LLVM_TARGET_ARCH "host"
313   CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
314
315 option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
316
317 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
318
319 option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
320
321 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
322   set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
323 endif()
324
325 set(LLVM_TARGETS_TO_BUILD
326    ${LLVM_TARGETS_TO_BUILD}
327    ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
328 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
329
330 include(AddLLVMDefinitions)
331
332 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
333 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
334 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
335 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
336   option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)
337   option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." OFF)
338 else()
339   option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)
340   option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
341 endif()
342 option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
343 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
344 option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
345 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
346 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
347
348 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
349   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
350 else()
351   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
352 endif()
353
354 option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
355
356 set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
357   "Enable abi-breaking checks.  Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
358
359 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
360        "Set to ON to force using an old, unsupported host toolchain." OFF)
361
362 option(LLVM_USE_INTEL_JITEVENTS
363   "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
364   OFF)
365
366 if( LLVM_USE_INTEL_JITEVENTS )
367   # Verify we are on a supported platform
368   if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
369     message(FATAL_ERROR
370       "Intel JIT API support is available on Linux and Windows only.")
371   endif()
372 endif( LLVM_USE_INTEL_JITEVENTS )
373
374 option(LLVM_USE_OPROFILE
375   "Use opagent JIT interface to inform OProfile about JIT code" OFF)
376
377 option(LLVM_EXTERNALIZE_DEBUGINFO
378   "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
379
380 # If enabled, verify we are on a platform that supports oprofile.
381 if( LLVM_USE_OPROFILE )
382   if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
383     message(FATAL_ERROR "OProfile support is available on Linux only.")
384   endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
385 endif( LLVM_USE_OPROFILE )
386
387 set(LLVM_USE_SANITIZER "" CACHE STRING
388   "Define the sanitizer used to build binaries and tests.")
389
390 option(LLVM_USE_SPLIT_DWARF
391   "Use -gsplit-dwarf when compiling llvm." OFF)
392
393 option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ON)
394 option(LLVM_POLLY_BUILD "Build LLVM with Polly" ON)
395
396 if (EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
397   set(POLLY_IN_TREE TRUE)
398 elseif(LLVM_EXTERNAL_POLLY_SOURCE_DIR)
399   set(POLLY_IN_TREE TRUE)
400 else()
401   set(POLLY_IN_TREE FALSE)
402 endif()
403
404 if (LLVM_POLLY_BUILD AND POLLY_IN_TREE)
405   set(WITH_POLLY ON)
406 else()
407   set(WITH_POLLY OFF)
408 endif()
409
410 if (LLVM_POLLY_LINK_INTO_TOOLS AND WITH_POLLY)
411   set(LINK_POLLY_INTO_TOOLS ON)
412 else()
413   set(LINK_POLLY_INTO_TOOLS OFF)
414 endif()
415
416 # Define an option controlling whether we should build for 32-bit on 64-bit
417 # platforms, where supported.
418 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
419   # TODO: support other platforms and toolchains.
420   option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
421 endif()
422
423 # Define the default arguments to use with 'lit', and an option for the user to
424 # override.
425 set(LIT_ARGS_DEFAULT "-sv")
426 if (MSVC_IDE OR XCODE)
427   set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
428 endif()
429 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
430
431 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
432 if( WIN32 AND NOT CYGWIN )
433   set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
434 endif()
435
436 # Define options to control the inclusion and default build behavior for
437 # components which may not strictly be necessary (tools, examples, and tests).
438 #
439 # This is primarily to support building smaller or faster project files.
440 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
441 option(LLVM_BUILD_TOOLS
442   "Build the LLVM tools. If OFF, just generate build targets." ON)
443
444 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
445 option(LLVM_BUILD_UTILS
446   "Build LLVM utility binaries. If OFF, just generate build targets." ON)
447
448 option(LLVM_BUILD_RUNTIME
449   "Build the LLVM runtime libraries." ON)
450 option(LLVM_BUILD_EXAMPLES
451   "Build the LLVM example programs. If OFF, just generate build targets." OFF)
452 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
453
454 option(LLVM_BUILD_TESTS
455   "Build LLVM unit tests. If OFF, just generate build targets." OFF)
456 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
457 option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
458
459 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
460 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
461 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
462 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
463 option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
464
465 set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html"
466     CACHE STRING "Doxygen-generated HTML documentation install directory")
467 set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html"
468     CACHE STRING "OCamldoc-generated HTML documentation install directory")
469
470 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
471   "Build compiler-rt as an external project." OFF)
472
473 # You can configure which libraries from LLVM you want to include in the
474 # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
475 # list of LLVM components. All component names handled by llvm-config are valid.
476 if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
477   set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
478     "Semicolon-separated list of components to include in libLLVM, or \"all\".")
479 endif()
480 option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
481 option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
482 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
483 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
484   set(LLVM_BUILD_LLVM_DYLIB_default ON)
485 endif()
486 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
487
488 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
489 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
490   set(LLVM_USE_HOST_TOOLS ON)
491 endif()
492
493 if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900))
494   option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
495 else()
496   set(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION FALSE CACHE INTERNAL "For Visual Studio 2013, manually copy natvis files to Documents\\Visual Studio 2013\\Visualizers" FORCE)
497 endif()
498
499 if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE)
500   if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
501     # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine
502     # for spining disks. Anything higher may only help on slower mediums.
503     set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
504   endif()
505   if(NOT LLVM_PROFILE_FILE_PATTERN)
506     if(NOT LLVM_PROFILE_DATA_DIR)
507       file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
508     else()
509       file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
510     endif()
511   endif()
512 endif()
513
514 # All options referred to from HandleLLVMOptions have to be specified
515 # BEFORE this include, otherwise options will not be correctly set on
516 # first cmake run
517 include(config-ix)
518
519 string(REPLACE "Native" ${LLVM_NATIVE_ARCH}
520   LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}")
521 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
522
523 # By default, we target the host, but this can be overridden at CMake
524 # invocation time.
525 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
526   "Default target for which LLVM will generate code." )
527 set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
528 message(STATUS "LLVM host triple: ${LLVM_HOST_TRIPLE}")
529 message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")
530
531 include(HandleLLVMOptions)
532
533 # Verify that we can find a Python 2 interpreter.  Python 3 is unsupported.
534 # FIXME: We should support systems with only Python 3, but that requires work
535 # on LLDB.
536 set(Python_ADDITIONAL_VERSIONS 2.7)
537 include(FindPythonInterp)
538 if( NOT PYTHONINTERP_FOUND )
539   message(FATAL_ERROR
540 "Unable to find Python interpreter, required for builds and testing.
541
542 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
543 endif()
544
545 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
546   message(FATAL_ERROR "Python 2.7 or newer is required")
547 endif()
548
549 ######
550 # LLVMBuild Integration
551 #
552 # We use llvm-build to generate all the data required by the CMake based
553 # build system in one swoop:
554 #
555 #  - We generate a file (a CMake fragment) in the object root which contains
556 #    all the definitions that are required by CMake.
557 #
558 #  - We generate the library table used by llvm-config.
559 #
560 #  - We generate the dependencies for the CMake fragment, so that we will
561 #    automatically reconfigure outselves.
562
563 set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
564 set(LLVMCONFIGLIBRARYDEPENDENCIESINC
565   "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
566 set(LLVMBUILDCMAKEFRAG
567   "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
568
569 # Create the list of optional components that are enabled
570 if (LLVM_USE_INTEL_JITEVENTS)
571   set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
572 endif (LLVM_USE_INTEL_JITEVENTS)
573 if (LLVM_USE_OPROFILE)
574   set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
575 endif (LLVM_USE_OPROFILE)
576
577 message(STATUS "Constructing LLVMBuild project information")
578 execute_process(
579   COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
580             --native-target "${LLVM_NATIVE_ARCH}"
581             --enable-targets "${LLVM_TARGETS_TO_BUILD}"
582             --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
583             --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
584             --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
585             OUTPUT_VARIABLE LLVMBUILDOUTPUT
586             ERROR_VARIABLE LLVMBUILDERRORS
587             OUTPUT_STRIP_TRAILING_WHITESPACE
588             ERROR_STRIP_TRAILING_WHITESPACE
589   RESULT_VARIABLE LLVMBUILDRESULT)
590
591 # On Win32, CMake doesn't properly handle piping the default output/error
592 # streams into the GUI console. So, we explicitly catch and report them.
593 if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
594   message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
595 endif()
596 if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
597   message(FATAL_ERROR
598     "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
599 endif()
600
601 # Include the generated CMake fragment. This will define properties from the
602 # LLVMBuild files in a format which is easy to consume from CMake, and will add
603 # the dependencies so that CMake will reconfigure properly when the LLVMBuild
604 # files change.
605 include(${LLVMBUILDCMAKEFRAG})
606
607 ######
608
609 # Configure all of the various header file fragments LLVM uses which depend on
610 # configuration variables.
611 set(LLVM_ENUM_TARGETS "")
612 set(LLVM_ENUM_ASM_PRINTERS "")
613 set(LLVM_ENUM_ASM_PARSERS "")
614 set(LLVM_ENUM_DISASSEMBLERS "")
615 foreach(t ${LLVM_TARGETS_TO_BUILD})
616   set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
617
618   list(FIND LLVM_ALL_TARGETS ${t} idx)
619   list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
620   if( idx LESS 0 AND idy LESS 0 )
621     message(FATAL_ERROR "The target `${t}' does not exist.
622     It should be one of\n${LLVM_ALL_TARGETS}")
623   else()
624     set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
625   endif()
626
627   file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
628   if( asmp_file )
629     set(LLVM_ENUM_ASM_PRINTERS
630       "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
631   endif()
632   if( EXISTS ${td}/AsmParser/CMakeLists.txt )
633     set(LLVM_ENUM_ASM_PARSERS
634       "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
635   endif()
636   if( EXISTS ${td}/Disassembler/CMakeLists.txt )
637     set(LLVM_ENUM_DISASSEMBLERS
638       "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
639   endif()
640 endforeach(t)
641
642 # Produce the target definition files, which provide a way for clients to easily
643 # include various classes of targets.
644 configure_file(
645   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
646   ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
647   )
648 configure_file(
649   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
650   ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
651   )
652 configure_file(
653   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
654   ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
655   )
656 configure_file(
657   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
658   ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
659   )
660
661 # Configure the three LLVM configuration header files.
662 configure_file(
663   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
664   ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
665 configure_file(
666   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
667   ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
668 configure_file(
669   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
670   ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
671
672 # They are not referenced. See set_output_directory().
673 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
674 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
675 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
676
677 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
678 if (APPLE)
679   set(CMAKE_INSTALL_NAME_DIR "@rpath")
680   set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
681 else(UNIX)
682   if(NOT DEFINED CMAKE_INSTALL_RPATH)
683     set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
684     if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
685       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
686       set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
687     endif()
688   endif(NOT DEFINED CMAKE_INSTALL_RPATH)
689 endif()
690
691 if(APPLE AND DARWIN_LTO_LIBRARY)
692   set(CMAKE_EXE_LINKER_FLAGS
693     "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
694   set(CMAKE_SHARED_LINKER_FLAGS
695     "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
696   set(CMAKE_MODULE_LINKER_FLAGS
697     "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
698 endif()
699
700 # Work around a broken bfd ld behavior. When linking a binary with a
701 # foo.so library, it will try to find any library that foo.so uses and
702 # check its symbols. This is wasteful (the check was done when foo.so
703 # was created) and can fail since it is not the dynamic linker and
704 # doesn't know how to handle search paths correctly.
705 if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS|AIX")
706   set(CMAKE_EXE_LINKER_FLAGS
707       "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
708 endif()
709
710 set(CMAKE_INCLUDE_CURRENT_DIR ON)
711
712 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
713
714 # when crosscompiling import the executable targets from a file
715 if(LLVM_USE_HOST_TOOLS)
716   include(CrossCompile)
717 endif(LLVM_USE_HOST_TOOLS)
718 if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
719 # Dummy use to avoid CMake Wraning: Manually-specified variables were not used
720 # (this is a variable that CrossCompile sets on recursive invocations)
721 endif()
722
723 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
724   # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
725   # with libxml2, iconv.h, etc., we must add /usr/local paths.
726   include_directories("/usr/local/include")
727   link_directories("/usr/local/lib")
728 endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
729
730 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
731    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
732 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
733
734 # Make sure we don't get -rdynamic in every binary. For those that need it,
735 # use export_executable_symbols(target).
736 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
737
738 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
739   "Profiling data file to use when compiling in order to improve runtime performance.")
740
741 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
742   if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
743     add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
744   else()
745     message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
746   endif()
747 endif()
748
749 include(AddLLVM)
750 include(TableGen)
751
752 if( MINGW )
753   # People report that -O3 is unreliable on MinGW. The traditional
754   # build also uses -O2 for that reason:
755   llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
756 endif()
757
758 # Put this before tblgen. Else we have a circular dependence.
759 add_subdirectory(lib/Demangle)
760 add_subdirectory(lib/Support)
761 add_subdirectory(lib/TableGen)
762
763 add_subdirectory(utils/TableGen)
764
765 # Force target to be built as soon as possible. Clang modules builds depend
766 # header-wise on it as they ship all headers from the umbrella folders. Building
767 # an entire module might include header, which depends on intrinsics_gen. This
768 # should be right after LLVMSupport and LLVMTableGen otherwise we introduce a
769 # circular dependence.
770 if (LLVM_ENABLE_MODULES)
771   list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
772 endif(LLVM_ENABLE_MODULES)
773
774 add_subdirectory(include/llvm)
775
776 add_subdirectory(lib)
777
778 if( LLVM_INCLUDE_UTILS )
779   add_subdirectory(utils/FileCheck)
780   add_subdirectory(utils/PerfectShuffle)
781   add_subdirectory(utils/count)
782   add_subdirectory(utils/not)
783   add_subdirectory(utils/llvm-lit)
784   add_subdirectory(utils/yaml-bench)
785   add_subdirectory(utils/unittest)
786 else()
787   if ( LLVM_INCLUDE_TESTS )
788     message(FATAL_ERROR "Including tests when not building utils will not work.
789     Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
790   endif()
791 endif()
792
793 # Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
794 if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
795   add_subdirectory(utils/LLVMVisualizers)
796 endif()
797
798 foreach( binding ${LLVM_BINDINGS_LIST} )
799   if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
800     add_subdirectory(bindings/${binding})
801   endif()
802 endforeach()
803
804 add_subdirectory(projects)
805
806 if( LLVM_INCLUDE_TOOLS )
807   add_subdirectory(tools)
808 endif()
809
810 add_subdirectory(runtimes)
811
812 if( LLVM_INCLUDE_EXAMPLES )
813   add_subdirectory(examples)
814 endif()
815
816 if( LLVM_INCLUDE_TESTS )
817   if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
818     include(LLVMExternalProjectUtils)
819     llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
820       USE_TOOLCHAIN
821       EXCLUDE_FROM_ALL
822       NO_INSTALL
823       ALWAYS_CLEAN)
824   endif()
825   add_subdirectory(test)
826   add_subdirectory(unittests)
827   if (MSVC)
828     # This utility is used to prevent crashing tests from calling Dr. Watson on
829     # Windows.
830     add_subdirectory(utils/KillTheDoctor)
831   endif()
832
833   # Add a global check rule now that all subdirectories have been traversed
834   # and we know the total set of lit testsuites.
835   get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
836   get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
837   get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
838   get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
839   get_property(LLVM_ADDITIONAL_TEST_TARGETS
840                GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_TARGETS)
841   get_property(LLVM_ADDITIONAL_TEST_DEPENDS
842                GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS)
843   add_lit_target(check-all
844     "Running all regression tests"
845     ${LLVM_LIT_TESTSUITES}
846     PARAMS ${LLVM_LIT_PARAMS}
847     DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_TARGETS}
848     ARGS ${LLVM_LIT_EXTRA_ARGS}
849     )
850   if(TARGET check-runtimes)
851     add_dependencies(check-all check-runtimes)
852   endif()
853   add_custom_target(test-depends
854                     DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_DEPENDS})
855   set_target_properties(test-depends PROPERTIES FOLDER "Tests")
856 endif()
857
858 if (LLVM_INCLUDE_DOCS)
859   add_subdirectory(docs)
860 endif()
861
862 add_subdirectory(cmake/modules)
863
864 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
865   install(DIRECTORY include/llvm include/llvm-c
866     DESTINATION include
867     COMPONENT llvm-headers
868     FILES_MATCHING
869     PATTERN "*.def"
870     PATTERN "*.h"
871     PATTERN "*.td"
872     PATTERN "*.inc"
873     PATTERN "LICENSE.TXT"
874     PATTERN ".svn" EXCLUDE
875     )
876
877   install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
878     DESTINATION include
879     COMPONENT llvm-headers
880     FILES_MATCHING
881     PATTERN "*.def"
882     PATTERN "*.h"
883     PATTERN "*.gen"
884     PATTERN "*.inc"
885     # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
886     PATTERN "CMakeFiles" EXCLUDE
887     PATTERN "config.h" EXCLUDE
888     PATTERN ".svn" EXCLUDE
889     )
890
891   if (NOT CMAKE_CONFIGURATION_TYPES)
892     add_custom_target(installhdrs
893                       DEPENDS ${name}
894                       COMMAND "${CMAKE_COMMAND}"
895                               -DCMAKE_INSTALL_COMPONENT=llvm-headers
896                               -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
897   endif()
898 endif()
899
900 # This must be at the end of the LLVM root CMakeLists file because it must run
901 # after all targets are created.
902 if(LLVM_DISTRIBUTION_COMPONENTS)
903   if(CMAKE_CONFIGURATION_TYPES)
904     message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)")
905   endif()
906
907   add_custom_target(distribution)
908   add_custom_target(install-distribution)
909   foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})
910     if(TARGET ${target})
911       add_dependencies(distribution ${target})
912     else()
913       message(FATAL_ERROR "Specified distribution component '${target}' doesn't have a target")
914     endif()
915
916     if(TARGET install-${target})
917       add_dependencies(install-distribution install-${target})
918     else()
919       message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target")
920     endif()
921   endforeach()
922 endif()