[TableGen] Remove unused function. NFC
[oota-llvm.git] / CMakeLists.txt
1 # See docs/CMake.html for instructions about how to build LLVM with CMake.
2
3 cmake_minimum_required(VERSION 2.8.12.2)
4
5 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
6   message(STATUS "No build type selected, default to Debug")
7   set(CMAKE_BUILD_TYPE "Debug")
8 endif()
9
10 if(POLICY CMP0022)
11   cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
12 endif()
13
14 if (POLICY CMP0051)
15   # CMake 3.1 and higher include generator expressions of the form
16   # $<TARGETLIB:obj> in the SOURCES property.  These need to be
17   # stripped everywhere that access the SOURCES property, so we just
18   # defer to the OLD behavior of not including generator expressions
19   # in the output for now.
20   cmake_policy(SET CMP0051 OLD)
21 endif()
22
23 if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
24   set(cmake_3_2_USES_TERMINAL)
25 else()
26   set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
27 endif()
28
29 project(LLVM)
30
31 # The following only works with the Ninja generator in CMake >= 3.0.
32 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
33   "Define the maximum number of concurrent compilation jobs.")
34 if(LLVM_PARALLEL_COMPILE_JOBS)
35   if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja$")
36     message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
37   else()
38     set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
39     set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
40   endif()
41 endif()
42
43 set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
44   "Define the maximum number of concurrent link jobs.")
45 if(LLVM_PARALLEL_LINK_JOBS)
46   if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja$")
47     message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
48   else()
49     set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
50     set(CMAKE_JOB_POOL_LINK link_job_pool)
51   endif()
52 endif()
53
54 # Add path for custom modules
55 set(CMAKE_MODULE_PATH
56   ${CMAKE_MODULE_PATH}
57   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
58   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
59   )
60
61 set(LLVM_VERSION_MAJOR 3)
62 set(LLVM_VERSION_MINOR 7)
63 set(LLVM_VERSION_PATCH 0)
64 set(LLVM_VERSION_SUFFIX svn)
65
66 if (NOT PACKAGE_VERSION)
67   set(PACKAGE_VERSION
68     "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
69 endif()
70
71 option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
72
73 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
74
75 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
76 if ( LLVM_USE_FOLDERS )
77   set_property(GLOBAL PROPERTY USE_FOLDERS ON)
78 endif()
79
80 include(VersionFromVCS)
81
82 option(LLVM_APPEND_VC_REV
83   "Append the version control system revision id to LLVM version" OFF)
84
85 if( LLVM_APPEND_VC_REV )
86   add_version_info_from_vcs(PACKAGE_VERSION)
87 endif()
88
89 set(PACKAGE_NAME LLVM)
90 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
91 set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
92
93 set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
94   "Default URL where bug reports are to be submitted.")
95
96 # Configure CPack.
97 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
98 set(CPACK_PACKAGE_VENDOR "LLVM")
99 set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
100 set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
101 set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
102 set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
103 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
104 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
105 if(WIN32 AND NOT UNIX)
106   set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
107   set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
108   set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
109   set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
110   set(CPACK_NSIS_MODIFY_PATH "ON")
111   set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
112   set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
113     "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
114   set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
115     "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
116   if( CMAKE_CL_64 )
117     set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
118   endif()
119 endif()
120 include(CPack)
121
122 # Sanity check our source directory to make sure that we are not trying to
123 # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
124 # sure that we don't have any stray generated files lying around in the tree
125 # (which would end up getting picked up by header search, instead of the correct
126 # versions).
127 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
128   message(FATAL_ERROR "In-source builds are not allowed.
129 CMake would overwrite the makefiles distributed with LLVM.
130 Please create a directory and run cmake from there, passing the path
131 to this source directory as the last argument.
132 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
133 Please delete them.")
134 endif()
135 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
136   file(GLOB_RECURSE
137     tablegenned_files_on_include_dir
138     "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
139   file(GLOB_RECURSE
140     tablegenned_files_on_lib_dir
141     "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
142   if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
143     message(FATAL_ERROR "Apparently there is a previous in-source build,
144 probably as the result of running `configure' and `make' on
145 ${CMAKE_CURRENT_SOURCE_DIR}.
146 This may cause problems. The suspicious files are:
147 ${tablegenned_files_on_lib_dir}
148 ${tablegenned_files_on_include_dir}
149 Please clean the source directory.")
150   endif()
151 endif()
152
153 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
154
155 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
156
157 # They are used as destination of target generators.
158 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
159 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
160 if(WIN32 OR CYGWIN)
161   # DLL platform -- put DLLs into bin.
162   set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
163 else()
164   set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
165 endif()
166
167 # Each of them corresponds to llvm-config's.
168 set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
169 set(LLVM_LIBRARY_DIR      ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
170 set(LLVM_MAIN_SRC_DIR     ${CMAKE_CURRENT_SOURCE_DIR}  ) # --src-root
171 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
172 set(LLVM_BINARY_DIR       ${CMAKE_CURRENT_BINARY_DIR}  ) # --prefix
173
174 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
175 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
176
177 set(LLVM_ALL_TARGETS
178   AArch64
179   ARM
180   CppBackend
181   Hexagon
182   Mips
183   MSP430
184   NVPTX
185   PowerPC
186   R600
187   Sparc
188   SystemZ
189   X86
190   XCore
191   )
192
193 # List of targets with JIT support:
194 set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
195
196 set(LLVM_TARGETS_TO_BUILD "all"
197     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
198
199 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
200   CACHE STRING "Semicolon-separated list of experimental targets to build.")
201
202 option(BUILD_SHARED_LIBS
203   "Build all libraries as shared libraries instead of static" OFF)
204
205 option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
206 if(LLVM_ENABLE_TIMESTAMPS)
207   set(ENABLE_TIMESTAMPS 1)
208 endif()
209
210 option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
211 if(LLVM_ENABLE_BACKTRACES)
212   set(ENABLE_BACKTRACES 1)
213 endif()
214
215 option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
216 if(LLVM_ENABLE_CRASH_OVERRIDES)
217   set(ENABLE_CRASH_OVERRIDES 1)
218 endif()
219
220 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
221 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
222 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
223
224 set(LLVM_TARGET_ARCH "host"
225   CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
226
227 option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
228
229 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
230
231 option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
232
233 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
234   set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
235 endif()
236
237 set(LLVM_TARGETS_TO_BUILD
238    ${LLVM_TARGETS_TO_BUILD}
239    ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
240 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
241
242 include(AddLLVMDefinitions)
243
244 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
245 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
246 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
247 option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
248 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
249 option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
250 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
251 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
252
253 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
254   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
255 else()
256   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
257 endif()
258
259 set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
260   "Enable abi-breaking checks.  Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
261
262 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
263        "Set to ON to force using an old, unsupported host toolchain." OFF)
264
265 option(LLVM_USE_INTEL_JITEVENTS
266   "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
267   OFF)
268
269 if( LLVM_USE_INTEL_JITEVENTS )
270   # Verify we are on a supported platform
271   if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
272     message(FATAL_ERROR
273       "Intel JIT API support is available on Linux and Windows only.")
274   endif()
275 endif( LLVM_USE_INTEL_JITEVENTS )
276
277 option(LLVM_USE_OPROFILE
278   "Use opagent JIT interface to inform OProfile about JIT code" OFF)
279
280 # If enabled, verify we are on a platform that supports oprofile.
281 if( LLVM_USE_OPROFILE )
282   if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
283     message(FATAL_ERROR "OProfile support is available on Linux only.")
284   endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
285 endif( LLVM_USE_OPROFILE )
286
287 set(LLVM_USE_SANITIZER "" CACHE STRING
288   "Define the sanitizer used to build binaries and tests.")
289
290 option(LLVM_USE_SPLIT_DWARF
291   "Use -gsplit-dwarf when compiling llvm." OFF)
292
293 option(WITH_POLLY "Build LLVM with Polly" ON)
294 option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
295
296 # Define an option controlling whether we should build for 32-bit on 64-bit
297 # platforms, where supported.
298 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
299   # TODO: support other platforms and toolchains.
300   option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
301 endif()
302
303 # Define the default arguments to use with 'lit', and an option for the user to
304 # override.
305 set(LIT_ARGS_DEFAULT "-sv")
306 if (MSVC OR XCODE)
307   set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
308 endif()
309 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
310
311 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
312 if( WIN32 AND NOT CYGWIN )
313   set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
314 endif()
315
316 # Define options to control the inclusion and default build behavior for
317 # components which may not strictly be necessary (tools, examples, and tests).
318 #
319 # This is primarily to support building smaller or faster project files.
320 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
321 option(LLVM_BUILD_TOOLS
322   "Build the LLVM tools. If OFF, just generate build targets." ON)
323
324 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
325
326 option(LLVM_BUILD_RUNTIME
327   "Build the LLVM runtime libraries." ON)
328 option(LLVM_BUILD_EXAMPLES
329   "Build the LLVM example programs. If OFF, just generate build targets." OFF)
330 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
331
332 option(LLVM_BUILD_TESTS
333   "Build LLVM unit tests. If OFF, just generate build targets." OFF)
334 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
335
336 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
337 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
338 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
339 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
340
341 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
342   "Build compiler-rt as an external project." OFF)
343
344 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" OFF)
345 option(LLVM_DYLIB_EXPORT_ALL "Export all symbols from libLLVM.dylib (default is C API only" OFF)
346 option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ON)
347 if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT)
348   set(DISABLE_LLVM_DYLIB_ATEXIT 1)
349 endif()
350
351 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
352 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
353   set(LLVM_USE_HOST_TOOLS ON)
354 endif()
355
356 # All options referred to from HandleLLVMOptions have to be specified
357 # BEFORE this include, otherwise options will not be correctly set on
358 # first cmake run
359 include(config-ix)
360
361 # By default, we target the host, but this can be overridden at CMake
362 # invocation time.
363 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
364   "Default target for which LLVM will generate code." )
365 set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
366
367 include(HandleLLVMOptions)
368
369 # Verify that we can find a Python 2 interpreter.  Python 3 is unsupported.
370 # FIXME: We should support systems with only Python 3, but that requires work
371 # on LLDB.
372 set(Python_ADDITIONAL_VERSIONS 2.7)
373 include(FindPythonInterp)
374 if( NOT PYTHONINTERP_FOUND )
375   message(FATAL_ERROR
376 "Unable to find Python interpreter, required for builds and testing.
377
378 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
379 endif()
380
381 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
382   message(FATAL_ERROR "Python 2.7 or newer is required")
383 endif()
384
385 ######
386 # LLVMBuild Integration
387 #
388 # We use llvm-build to generate all the data required by the CMake based
389 # build system in one swoop:
390 #
391 #  - We generate a file (a CMake fragment) in the object root which contains
392 #    all the definitions that are required by CMake.
393 #
394 #  - We generate the library table used by llvm-config.
395 #
396 #  - We generate the dependencies for the CMake fragment, so that we will
397 #    automatically reconfigure outselves.
398
399 set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
400 set(LLVMCONFIGLIBRARYDEPENDENCIESINC
401   "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
402 set(LLVMBUILDCMAKEFRAG
403   "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
404
405 # Create the list of optional components that are enabled
406 if (LLVM_USE_INTEL_JITEVENTS)
407   set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
408 endif (LLVM_USE_INTEL_JITEVENTS)
409 if (LLVM_USE_OPROFILE)
410   set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
411 endif (LLVM_USE_OPROFILE)
412
413 message(STATUS "Constructing LLVMBuild project information")
414 execute_process(
415   COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
416             --native-target "${LLVM_NATIVE_ARCH}"
417             --enable-targets "${LLVM_TARGETS_TO_BUILD}"
418             --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
419             --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
420             --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
421             OUTPUT_VARIABLE LLVMBUILDOUTPUT
422             ERROR_VARIABLE LLVMBUILDERRORS
423             OUTPUT_STRIP_TRAILING_WHITESPACE
424             ERROR_STRIP_TRAILING_WHITESPACE
425   RESULT_VARIABLE LLVMBUILDRESULT)
426
427 # On Win32, CMake doesn't properly handle piping the default output/error
428 # streams into the GUI console. So, we explicitly catch and report them.
429 if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
430   message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
431 endif()
432 if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
433   message(FATAL_ERROR
434     "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
435 endif()
436
437 # Include the generated CMake fragment. This will define properties from the
438 # LLVMBuild files in a format which is easy to consume from CMake, and will add
439 # the dependencies so that CMake will reconfigure properly when the LLVMBuild
440 # files change.
441 include(${LLVMBUILDCMAKEFRAG})
442
443 ######
444
445 # Configure all of the various header file fragments LLVM uses which depend on
446 # configuration variables.
447 set(LLVM_ENUM_TARGETS "")
448 set(LLVM_ENUM_ASM_PRINTERS "")
449 set(LLVM_ENUM_ASM_PARSERS "")
450 set(LLVM_ENUM_DISASSEMBLERS "")
451 foreach(t ${LLVM_TARGETS_TO_BUILD})
452   set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
453
454   list(FIND LLVM_ALL_TARGETS ${t} idx)
455   list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
456   if( idx LESS 0 AND idy LESS 0 )
457     message(FATAL_ERROR "The target `${t}' does not exist.
458     It should be one of\n${LLVM_ALL_TARGETS}")
459   else()
460     set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
461   endif()
462
463   file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
464   if( asmp_file )
465     set(LLVM_ENUM_ASM_PRINTERS
466       "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
467   endif()
468   if( EXISTS ${td}/AsmParser/CMakeLists.txt )
469     set(LLVM_ENUM_ASM_PARSERS
470       "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
471   endif()
472   if( EXISTS ${td}/Disassembler/CMakeLists.txt )
473     set(LLVM_ENUM_DISASSEMBLERS
474       "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
475   endif()
476 endforeach(t)
477
478 # Produce the target definition files, which provide a way for clients to easily
479 # include various classes of targets.
480 configure_file(
481   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
482   ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
483   )
484 configure_file(
485   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
486   ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
487   )
488 configure_file(
489   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
490   ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
491   )
492 configure_file(
493   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
494   ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
495   )
496
497 # Configure the three LLVM configuration header files.
498 configure_file(
499   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
500   ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
501 configure_file(
502   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
503   ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
504 configure_file(
505   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
506   ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
507
508 # They are not referenced. See set_output_directory().
509 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
510 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
511 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
512
513 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
514 if (APPLE)
515   set(CMAKE_INSTALL_NAME_DIR "@rpath")
516   set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
517 else(UNIX)
518   if(NOT DEFINED CMAKE_INSTALL_RPATH)
519     set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
520     if (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD)
521       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
522       set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
523     endif()
524   endif(NOT DEFINED CMAKE_INSTALL_RPATH)
525 endif()
526
527 # Work around a broken bfd ld behavior. When linking a binary with a
528 # foo.so library, it will try to find any library that foo.so uses and
529 # check its symbols. This is wasteful (the check was done when foo.so
530 # was created) and can fail since it is not the dynamic linker and
531 # doesn't know how to handle search paths correctly.
532 if (UNIX AND NOT APPLE)
533   set(CMAKE_EXE_LINKER_FLAGS
534       "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
535 endif()
536
537 set(CMAKE_INCLUDE_CURRENT_DIR ON)
538
539 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
540
541 # when crosscompiling import the executable targets from a file
542 if(LLVM_USE_HOST_TOOLS)
543   include(CrossCompile)
544 endif(LLVM_USE_HOST_TOOLS)
545
546 if( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
547   # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
548   # with libxml2, iconv.h, etc., we must add /usr/local paths.
549   include_directories("/usr/local/include")
550   link_directories("/usr/local/lib")
551 endif( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
552
553 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
554    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
555 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
556
557 # Make sure we don't get -rdynamic in every binary. For those that need it,
558 # use export_executable_symbols(target).
559 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
560
561 include(AddLLVM)
562 include(TableGen)
563
564 if( MINGW )
565   # People report that -O3 is unreliable on MinGW. The traditional
566   # build also uses -O2 for that reason:
567   llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
568 endif()
569
570 # Put this before tblgen. Else we have a circular dependence.
571 add_subdirectory(lib/Support)
572 add_subdirectory(lib/TableGen)
573
574 add_subdirectory(utils/TableGen)
575
576 add_subdirectory(include/llvm)
577
578 add_subdirectory(lib)
579
580 if( LLVM_INCLUDE_UTILS )
581   add_subdirectory(utils/FileCheck)
582   add_subdirectory(utils/PerfectShuffle)
583   add_subdirectory(utils/count)
584   add_subdirectory(utils/not)
585   add_subdirectory(utils/llvm-lit)
586   add_subdirectory(utils/yaml-bench)
587 else()
588   if ( LLVM_INCLUDE_TESTS )
589     message(FATAL_ERROR "Including tests when not building utils will not work.
590     Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
591   endif()
592 endif()
593
594 if(LLVM_INCLUDE_TESTS)
595   add_subdirectory(utils/unittest)
596 endif()
597
598 foreach( binding ${LLVM_BINDINGS_LIST} )
599   if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
600     add_subdirectory(bindings/${binding})
601   endif()
602 endforeach()
603
604 add_subdirectory(projects)
605
606 if(WITH_POLLY)
607   if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
608     set(WITH_POLLY OFF)
609   endif()
610 endif(WITH_POLLY)
611
612 if( LLVM_INCLUDE_TOOLS )
613   add_subdirectory(tools)
614 endif()
615
616 if( LLVM_INCLUDE_EXAMPLES )
617   add_subdirectory(examples)
618 endif()
619
620 if( LLVM_INCLUDE_TESTS )
621   add_subdirectory(test)
622   add_subdirectory(unittests)
623   if (MSVC)
624     # This utility is used to prevent crashing tests from calling Dr. Watson on
625     # Windows.
626     add_subdirectory(utils/KillTheDoctor)
627   endif()
628
629   # Add a global check rule now that all subdirectories have been traversed
630   # and we know the total set of lit testsuites.
631   get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
632   get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
633   get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
634   get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
635   add_lit_target(check-all
636     "Running all regression tests"
637     ${LLVM_LIT_TESTSUITES}
638     PARAMS ${LLVM_LIT_PARAMS}
639     DEPENDS ${LLVM_LIT_DEPENDS}
640     ARGS ${LLVM_LIT_EXTRA_ARGS}
641     )
642 endif()
643
644 if (LLVM_INCLUDE_DOCS)
645   add_subdirectory(docs)
646 endif()
647
648 add_subdirectory(cmake/modules)
649
650 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
651   install(DIRECTORY include/llvm include/llvm-c
652     DESTINATION include
653     COMPONENT llvm-headers
654     FILES_MATCHING
655     PATTERN "*.def"
656     PATTERN "*.h"
657     PATTERN "*.td"
658     PATTERN "*.inc"
659     PATTERN "LICENSE.TXT"
660     PATTERN ".svn" EXCLUDE
661     )
662
663   install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
664     DESTINATION include
665     COMPONENT llvm-headers
666     FILES_MATCHING
667     PATTERN "*.def"
668     PATTERN "*.h"
669     PATTERN "*.gen"
670     PATTERN "*.inc"
671     # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
672     PATTERN "CMakeFiles" EXCLUDE
673     PATTERN "config.h" EXCLUDE
674     PATTERN ".svn" EXCLUDE
675     )
676
677   if (NOT CMAKE_CONFIGURATION_TYPES)
678     add_custom_target(installhdrs
679                       DEPENDS ${name}
680                       COMMAND "${CMAKE_COMMAND}"
681                               -DCMAKE_INSTALL_COMPONENT=llvm-headers
682                               -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
683   endif()
684 endif()