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