OSDN Git Service

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