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