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