1 # See docs/CMake.html for instructions about how to build LLVM with CMake.
3 cmake_minimum_required(VERSION 2.8.12.2)
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")
11 cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
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)
23 if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
24 set(cmake_3_2_USES_TERMINAL)
26 set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
29 if(NOT DEFINED LLVM_VERSION_MAJOR)
30 set(LLVM_VERSION_MAJOR 3)
32 if(NOT DEFINED LLVM_VERSION_MINOR)
33 set(LLVM_VERSION_MINOR 8)
35 if(NOT DEFINED LLVM_VERSION_PATCH)
36 set(LLVM_VERSION_PATCH 0)
38 if(NOT DEFINED LLVM_VERSION_SUFFIX)
39 set(LLVM_VERSION_SUFFIX "")
43 cmake_policy(SET CMP0048 NEW)
44 set(cmake_3_0_PROJ_VERSION
45 VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
46 set(cmake_3_0_LANGUAGES LANGUAGES)
49 if (NOT PACKAGE_VERSION)
51 "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
55 ${cmake_3_0_PROJ_VERSION}
56 ${cmake_3_0_LANGUAGES}
59 # The following only works with the Ninja generator in CMake >= 3.0.
60 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
61 "Define the maximum number of concurrent compilation jobs.")
62 if(LLVM_PARALLEL_COMPILE_JOBS)
63 if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
64 message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
66 set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
67 set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
71 set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
72 "Define the maximum number of concurrent link jobs.")
73 if(LLVM_PARALLEL_LINK_JOBS)
74 if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
75 message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
77 set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
78 set(CMAKE_JOB_POOL_LINK link_job_pool)
82 # Add path for custom modules
85 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
86 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
89 # Generate a CompilationDatabase (compile_commands.json file) for our build,
90 # for use by clang_complete, YouCompleteMe, etc.
91 set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
93 option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
95 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
97 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
98 if ( LLVM_USE_FOLDERS )
99 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
102 include(VersionFromVCS)
104 option(LLVM_APPEND_VC_REV
105 "Append the version control system revision id to LLVM version" OFF)
107 if( LLVM_APPEND_VC_REV )
108 add_version_info_from_vcs(PACKAGE_VERSION)
111 set(PACKAGE_NAME LLVM)
112 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
113 set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
115 set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
116 "Default URL where bug reports are to be submitted.")
119 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
120 set(CPACK_PACKAGE_VENDOR "LLVM")
121 set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
122 set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
123 set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
124 set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
125 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
126 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
127 if(WIN32 AND NOT UNIX)
128 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
129 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
130 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
131 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
132 set(CPACK_NSIS_MODIFY_PATH "ON")
133 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
134 set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
135 "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
136 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
137 "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
139 set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
144 # Sanity check our source directory to make sure that we are not trying to
145 # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
146 # sure that we don't have any stray generated files lying around in the tree
147 # (which would end up getting picked up by header search, instead of the correct
149 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
150 message(FATAL_ERROR "In-source builds are not allowed.
151 CMake would overwrite the makefiles distributed with LLVM.
152 Please create a directory and run cmake from there, passing the path
153 to this source directory as the last argument.
154 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
155 Please delete them.")
157 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
159 tablegenned_files_on_include_dir
160 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
162 tablegenned_files_on_lib_dir
163 "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
164 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
165 message(FATAL_ERROR "Apparently there is a previous in-source build,
166 probably as the result of running `configure' and `make' on
167 ${CMAKE_CURRENT_SOURCE_DIR}.
168 This may cause problems. The suspicious files are:
169 ${tablegenned_files_on_lib_dir}
170 ${tablegenned_files_on_include_dir}
171 Please clean the source directory.")
175 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
177 if (CMAKE_BUILD_TYPE AND
178 NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
179 message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
182 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
184 # They are used as destination of target generators.
185 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
186 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
188 # DLL platform -- put DLLs into bin.
189 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
191 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
194 # Each of them corresponds to llvm-config's.
195 set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
196 set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
197 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
198 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
199 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
201 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
202 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
221 # List of targets with JIT support:
222 set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
224 set(LLVM_TARGETS_TO_BUILD "all"
225 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
227 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
228 CACHE STRING "Semicolon-separated list of experimental targets to build.")
230 option(BUILD_SHARED_LIBS
231 "Build all libraries as shared libraries instead of static" OFF)
233 option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
234 if(LLVM_ENABLE_TIMESTAMPS)
235 set(ENABLE_TIMESTAMPS 1)
238 option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
239 if(LLVM_ENABLE_BACKTRACES)
240 set(ENABLE_BACKTRACES 1)
243 option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
244 if(LLVM_ENABLE_CRASH_OVERRIDES)
245 set(ENABLE_CRASH_OVERRIDES 1)
248 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
249 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
250 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
252 set(LLVM_TARGET_ARCH "host"
253 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
255 option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
257 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
259 option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
261 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
262 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
265 set(LLVM_TARGETS_TO_BUILD
266 ${LLVM_TARGETS_TO_BUILD}
267 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
268 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
270 include(AddLLVMDefinitions)
272 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
273 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
274 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
275 option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
276 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
277 option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
278 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
279 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
281 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
282 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
284 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
287 set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
288 "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
290 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
291 "Set to ON to force using an old, unsupported host toolchain." OFF)
293 option(LLVM_USE_INTEL_JITEVENTS
294 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
297 if( LLVM_USE_INTEL_JITEVENTS )
298 # Verify we are on a supported platform
299 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
301 "Intel JIT API support is available on Linux and Windows only.")
303 endif( LLVM_USE_INTEL_JITEVENTS )
305 option(LLVM_USE_OPROFILE
306 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
308 option(LLVM_EXTERNALIZE_DEBUGINFO
309 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
311 # If enabled, verify we are on a platform that supports oprofile.
312 if( LLVM_USE_OPROFILE )
313 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
314 message(FATAL_ERROR "OProfile support is available on Linux only.")
315 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
316 endif( LLVM_USE_OPROFILE )
318 set(LLVM_USE_SANITIZER "" CACHE STRING
319 "Define the sanitizer used to build binaries and tests.")
321 option(LLVM_USE_SPLIT_DWARF
322 "Use -gsplit-dwarf when compiling llvm." OFF)
324 option(WITH_POLLY "Build LLVM with Polly" ON)
325 option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
327 # Define an option controlling whether we should build for 32-bit on 64-bit
328 # platforms, where supported.
329 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
330 # TODO: support other platforms and toolchains.
331 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
334 # Define the default arguments to use with 'lit', and an option for the user to
336 set(LIT_ARGS_DEFAULT "-sv")
337 if (MSVC_IDE OR XCODE)
338 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
340 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
342 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
343 if( WIN32 AND NOT CYGWIN )
344 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
347 # Define options to control the inclusion and default build behavior for
348 # components which may not strictly be necessary (tools, examples, and tests).
350 # This is primarily to support building smaller or faster project files.
351 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
352 option(LLVM_BUILD_TOOLS
353 "Build the LLVM tools. If OFF, just generate build targets." ON)
355 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
357 option(LLVM_BUILD_RUNTIME
358 "Build the LLVM runtime libraries." ON)
359 option(LLVM_BUILD_EXAMPLES
360 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
361 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
363 option(LLVM_BUILD_TESTS
364 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
365 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
366 option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
368 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
369 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
370 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
371 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
373 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
374 "Build compiler-rt as an external project." OFF)
376 # You can configure which libraries from LLVM you want to include in the
377 # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
378 # list of LLVM components. All component names handled by llvm-config are valid.
379 if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
380 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
381 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
383 option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
384 option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
385 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
386 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
387 set(LLVM_BUILD_LLVM_DYLIB_default ON)
389 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
390 set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT ON)
391 if (LLVM_LINK_LLVM_DYLIB)
392 set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT OFF)
394 option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ${LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT})
395 if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT)
396 set(DISABLE_LLVM_DYLIB_ATEXIT 1)
399 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
400 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
401 set(LLVM_USE_HOST_TOOLS ON)
404 # All options referred to from HandleLLVMOptions have to be specified
405 # BEFORE this include, otherwise options will not be correctly set on
409 # By default, we target the host, but this can be overridden at CMake
411 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
412 "Default target for which LLVM will generate code." )
413 set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
415 include(HandleLLVMOptions)
417 # Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
418 # FIXME: We should support systems with only Python 3, but that requires work
420 set(Python_ADDITIONAL_VERSIONS 2.7)
421 include(FindPythonInterp)
422 if( NOT PYTHONINTERP_FOUND )
424 "Unable to find Python interpreter, required for builds and testing.
426 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
429 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
430 message(FATAL_ERROR "Python 2.7 or newer is required")
434 # LLVMBuild Integration
436 # We use llvm-build to generate all the data required by the CMake based
437 # build system in one swoop:
439 # - We generate a file (a CMake fragment) in the object root which contains
440 # all the definitions that are required by CMake.
442 # - We generate the library table used by llvm-config.
444 # - We generate the dependencies for the CMake fragment, so that we will
445 # automatically reconfigure outselves.
447 set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
448 set(LLVMCONFIGLIBRARYDEPENDENCIESINC
449 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
450 set(LLVMBUILDCMAKEFRAG
451 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
453 # Create the list of optional components that are enabled
454 if (LLVM_USE_INTEL_JITEVENTS)
455 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
456 endif (LLVM_USE_INTEL_JITEVENTS)
457 if (LLVM_USE_OPROFILE)
458 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
459 endif (LLVM_USE_OPROFILE)
461 message(STATUS "Constructing LLVMBuild project information")
463 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
464 --native-target "${LLVM_NATIVE_ARCH}"
465 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
466 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
467 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
468 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
469 OUTPUT_VARIABLE LLVMBUILDOUTPUT
470 ERROR_VARIABLE LLVMBUILDERRORS
471 OUTPUT_STRIP_TRAILING_WHITESPACE
472 ERROR_STRIP_TRAILING_WHITESPACE
473 RESULT_VARIABLE LLVMBUILDRESULT)
475 # On Win32, CMake doesn't properly handle piping the default output/error
476 # streams into the GUI console. So, we explicitly catch and report them.
477 if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
478 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
480 if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
482 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
485 # Include the generated CMake fragment. This will define properties from the
486 # LLVMBuild files in a format which is easy to consume from CMake, and will add
487 # the dependencies so that CMake will reconfigure properly when the LLVMBuild
489 include(${LLVMBUILDCMAKEFRAG})
493 # Configure all of the various header file fragments LLVM uses which depend on
494 # configuration variables.
495 set(LLVM_ENUM_TARGETS "")
496 set(LLVM_ENUM_ASM_PRINTERS "")
497 set(LLVM_ENUM_ASM_PARSERS "")
498 set(LLVM_ENUM_DISASSEMBLERS "")
499 foreach(t ${LLVM_TARGETS_TO_BUILD})
500 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
502 list(FIND LLVM_ALL_TARGETS ${t} idx)
503 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
504 if( idx LESS 0 AND idy LESS 0 )
505 message(FATAL_ERROR "The target `${t}' does not exist.
506 It should be one of\n${LLVM_ALL_TARGETS}")
508 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
511 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
513 set(LLVM_ENUM_ASM_PRINTERS
514 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
516 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
517 set(LLVM_ENUM_ASM_PARSERS
518 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
520 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
521 set(LLVM_ENUM_DISASSEMBLERS
522 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
526 # Produce the target definition files, which provide a way for clients to easily
527 # include various classes of targets.
529 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
530 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
533 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
534 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
537 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
538 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
541 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
542 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
545 # Configure the three LLVM configuration header files.
547 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
548 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
550 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
551 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
553 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
554 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
556 # They are not referenced. See set_output_directory().
557 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
558 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
559 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
561 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
563 set(CMAKE_INSTALL_NAME_DIR "@rpath")
564 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
566 if(NOT DEFINED CMAKE_INSTALL_RPATH)
567 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
568 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
569 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
570 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
572 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
575 if(APPLE AND DARWIN_LTO_LIBRARY)
576 set(CMAKE_EXE_LINKER_FLAGS
577 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
578 set(CMAKE_SHARED_LINKER_FLAGS
579 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
580 set(CMAKE_MODULE_LINKER_FLAGS
581 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
584 # Work around a broken bfd ld behavior. When linking a binary with a
585 # foo.so library, it will try to find any library that foo.so uses and
586 # check its symbols. This is wasteful (the check was done when foo.so
587 # was created) and can fail since it is not the dynamic linker and
588 # doesn't know how to handle search paths correctly.
589 if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
590 set(CMAKE_EXE_LINKER_FLAGS
591 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
594 set(CMAKE_INCLUDE_CURRENT_DIR ON)
596 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
598 # when crosscompiling import the executable targets from a file
599 if(LLVM_USE_HOST_TOOLS)
600 include(CrossCompile)
601 endif(LLVM_USE_HOST_TOOLS)
602 if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
603 # Dummy use to avoid CMake Wraning: Manually-specified variables were not used
604 # (this is a variable that CrossCompile sets on recursive invocations)
607 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
608 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
609 # with libxml2, iconv.h, etc., we must add /usr/local paths.
610 include_directories("/usr/local/include")
611 link_directories("/usr/local/lib")
612 endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
614 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
615 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
616 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
618 # Make sure we don't get -rdynamic in every binary. For those that need it,
619 # use export_executable_symbols(target).
620 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
622 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
623 "Profiling data file to use when compiling in order to improve runtime performance.")
625 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
626 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
627 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
629 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
637 # People report that -O3 is unreliable on MinGW. The traditional
638 # build also uses -O2 for that reason:
639 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
642 # Put this before tblgen. Else we have a circular dependence.
643 add_subdirectory(lib/Support)
644 add_subdirectory(lib/TableGen)
646 add_subdirectory(utils/TableGen)
648 add_subdirectory(include/llvm)
650 add_subdirectory(lib)
652 if( LLVM_INCLUDE_UTILS )
653 add_subdirectory(utils/FileCheck)
654 add_subdirectory(utils/PerfectShuffle)
655 add_subdirectory(utils/count)
656 add_subdirectory(utils/not)
657 add_subdirectory(utils/llvm-lit)
658 add_subdirectory(utils/yaml-bench)
660 if ( LLVM_INCLUDE_TESTS )
661 message(FATAL_ERROR "Including tests when not building utils will not work.
662 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
666 if(LLVM_INCLUDE_TESTS)
667 add_subdirectory(utils/unittest)
670 foreach( binding ${LLVM_BINDINGS_LIST} )
671 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
672 add_subdirectory(bindings/${binding})
676 add_subdirectory(projects)
679 if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
684 if( LLVM_INCLUDE_TOOLS )
685 add_subdirectory(tools)
688 if( LLVM_INCLUDE_EXAMPLES )
689 add_subdirectory(examples)
692 if( LLVM_INCLUDE_TESTS )
693 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
694 include(LLVMExternalProjectUtils)
695 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
700 add_subdirectory(test)
701 add_subdirectory(unittests)
703 # This utility is used to prevent crashing tests from calling Dr. Watson on
705 add_subdirectory(utils/KillTheDoctor)
708 # Add a global check rule now that all subdirectories have been traversed
709 # and we know the total set of lit testsuites.
710 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
711 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
712 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
713 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
714 add_lit_target(check-all
715 "Running all regression tests"
716 ${LLVM_LIT_TESTSUITES}
717 PARAMS ${LLVM_LIT_PARAMS}
718 DEPENDS ${LLVM_LIT_DEPENDS}
719 ARGS ${LLVM_LIT_EXTRA_ARGS}
723 if (LLVM_INCLUDE_DOCS)
724 add_subdirectory(docs)
727 add_subdirectory(cmake/modules)
729 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
730 install(DIRECTORY include/llvm include/llvm-c
732 COMPONENT llvm-headers
738 PATTERN "LICENSE.TXT"
739 PATTERN ".svn" EXCLUDE
742 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
744 COMPONENT llvm-headers
750 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
751 PATTERN "CMakeFiles" EXCLUDE
752 PATTERN "config.h" EXCLUDE
753 PATTERN ".svn" EXCLUDE
756 if (NOT CMAKE_CONFIGURATION_TYPES)
757 add_custom_target(installhdrs
759 COMMAND "${CMAKE_COMMAND}"
760 -DCMAKE_INSTALL_COMPONENT=llvm-headers
761 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")