1 # See docs/CMake.html for instructions about how to build LLVM with CMake.
3 cmake_minimum_required(VERSION 3.4.3)
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" CACHE STRING "Build type (default 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(NOT DEFINED LLVM_VERSION_MAJOR)
24 set(LLVM_VERSION_MAJOR 3)
26 if(NOT DEFINED LLVM_VERSION_MINOR)
27 set(LLVM_VERSION_MINOR 9)
29 if(NOT DEFINED LLVM_VERSION_PATCH)
30 set(LLVM_VERSION_PATCH 0)
32 if(NOT DEFINED LLVM_VERSION_SUFFIX)
33 set(LLVM_VERSION_SUFFIX svn)
37 cmake_policy(SET CMP0048 NEW)
38 set(cmake_3_0_PROJ_VERSION
39 VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
40 set(cmake_3_0_LANGUAGES LANGUAGES)
43 if (NOT PACKAGE_VERSION)
45 "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
49 ${cmake_3_0_PROJ_VERSION}
50 ${cmake_3_0_LANGUAGES}
55 find_program(CMAKE_LIBTOOL NAMES libtool)
58 set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
59 message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
60 get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
61 foreach(lang ${languages})
62 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
63 "${CMAKE_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
68 # The following only works with the Ninja generator in CMake >= 3.0.
69 set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
70 "Define the maximum number of concurrent compilation jobs.")
71 if(LLVM_PARALLEL_COMPILE_JOBS)
72 if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
73 message(WARNING "Job pooling is only available with Ninja generators.")
75 set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
76 set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
80 set(LLVM_BUILD_GLOBAL_ISEL OFF CACHE BOOL "Experimental: Build GlobalISel")
81 if(LLVM_BUILD_GLOBAL_ISEL)
82 add_definitions(-DLLVM_BUILD_GLOBAL_ISEL)
85 set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
86 "Define the maximum number of concurrent link jobs.")
87 if(LLVM_PARALLEL_LINK_JOBS)
88 if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
89 message(WARNING "Job pooling is only available with Ninja generators.")
91 set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
92 set(CMAKE_JOB_POOL_LINK link_job_pool)
96 # Add path for custom modules
99 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
100 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
103 # Generate a CompilationDatabase (compile_commands.json file) for our build,
104 # for use by clang_complete, YouCompleteMe, etc.
105 set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
107 option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
109 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
111 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
112 if ( LLVM_USE_FOLDERS )
113 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
116 include(VersionFromVCS)
118 option(LLVM_APPEND_VC_REV
119 "Append the version control system revision id to LLVM version" OFF)
121 if( LLVM_APPEND_VC_REV )
122 add_version_info_from_vcs(PACKAGE_VERSION)
125 set(PACKAGE_NAME LLVM)
126 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
127 set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
129 set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
130 "Default URL where bug reports are to be submitted.")
133 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
134 set(CPACK_PACKAGE_VENDOR "LLVM")
135 set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
136 set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
137 set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
138 set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
139 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
140 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
141 if(WIN32 AND NOT UNIX)
142 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
143 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
144 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
145 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
146 set(CPACK_NSIS_MODIFY_PATH "ON")
147 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
148 set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
149 "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
150 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
151 "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
153 set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
158 # Sanity check our source directory to make sure that we are not trying to
159 # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
160 # sure that we don't have any stray generated files lying around in the tree
161 # (which would end up getting picked up by header search, instead of the correct
163 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
164 message(FATAL_ERROR "In-source builds are not allowed.
165 CMake would overwrite the makefiles distributed with LLVM.
166 Please create a directory and run cmake from there, passing the path
167 to this source directory as the last argument.
168 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
169 Please delete them.")
171 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
173 tablegenned_files_on_include_dir
174 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
176 tablegenned_files_on_lib_dir
177 "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
178 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
179 message(FATAL_ERROR "Apparently there is a previous in-source build,
180 probably as the result of running `configure' and `make' on
181 ${CMAKE_CURRENT_SOURCE_DIR}.
182 This may cause problems. The suspicious files are:
183 ${tablegenned_files_on_lib_dir}
184 ${tablegenned_files_on_include_dir}
185 Please clean the source directory.")
189 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
191 if (CMAKE_BUILD_TYPE AND
192 NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
193 message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
196 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
198 set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')")
199 mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)
201 # They are used as destination of target generators.
202 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
203 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
205 # DLL platform -- put DLLs into bin.
206 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
208 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
211 # Each of them corresponds to llvm-config's.
212 set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
213 set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
214 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
215 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
216 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
218 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
219 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
237 # List of targets with JIT support:
238 set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
240 set(LLVM_TARGETS_TO_BUILD "all"
241 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
243 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
244 CACHE STRING "Semicolon-separated list of experimental targets to build.")
246 option(BUILD_SHARED_LIBS
247 "Build all libraries as shared libraries instead of static" OFF)
249 option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
250 if(LLVM_ENABLE_BACKTRACES)
251 set(ENABLE_BACKTRACES 1)
254 option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
255 if(LLVM_ENABLE_CRASH_OVERRIDES)
256 set(ENABLE_CRASH_OVERRIDES 1)
259 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
260 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
261 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
263 set(LLVM_TARGET_ARCH "host"
264 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
266 option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
268 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
270 option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
272 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
273 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
276 set(LLVM_TARGETS_TO_BUILD
277 ${LLVM_TARGETS_TO_BUILD}
278 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
279 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
281 include(AddLLVMDefinitions)
283 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
284 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
285 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
286 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
287 option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)
288 option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." OFF)
290 option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)
291 option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
293 option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
294 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
295 option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
296 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
297 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
299 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
300 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
302 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
305 option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
307 set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
308 "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
310 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
311 "Set to ON to force using an old, unsupported host toolchain." OFF)
313 option(LLVM_USE_INTEL_JITEVENTS
314 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
317 if( LLVM_USE_INTEL_JITEVENTS )
318 # Verify we are on a supported platform
319 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
321 "Intel JIT API support is available on Linux and Windows only.")
323 endif( LLVM_USE_INTEL_JITEVENTS )
325 option(LLVM_USE_OPROFILE
326 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
328 option(LLVM_EXTERNALIZE_DEBUGINFO
329 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
331 # If enabled, verify we are on a platform that supports oprofile.
332 if( LLVM_USE_OPROFILE )
333 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
334 message(FATAL_ERROR "OProfile support is available on Linux only.")
335 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
336 endif( LLVM_USE_OPROFILE )
338 set(LLVM_USE_SANITIZER "" CACHE STRING
339 "Define the sanitizer used to build binaries and tests.")
341 option(LLVM_USE_SPLIT_DWARF
342 "Use -gsplit-dwarf when compiling llvm." OFF)
344 option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ON)
345 option(LLVM_POLLY_BUILD "Build LLVM with Polly" ON)
347 if (EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
348 set(POLLY_IN_TREE TRUE)
350 set(POLLY_IN_TREE FALSE)
353 if (LLVM_POLLY_BUILD AND POLLY_IN_TREE)
359 if (LLVM_POLLY_LINK_INTO_TOOLS AND WITH_POLLY)
360 set(LINK_POLLY_INTO_TOOLS ON)
362 set(LINK_POLLY_INTO_TOOLS OFF)
365 # Define an option controlling whether we should build for 32-bit on 64-bit
366 # platforms, where supported.
367 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
368 # TODO: support other platforms and toolchains.
369 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
372 # Define the default arguments to use with 'lit', and an option for the user to
374 set(LIT_ARGS_DEFAULT "-sv")
375 if (MSVC_IDE OR XCODE)
376 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
378 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
380 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
381 if( WIN32 AND NOT CYGWIN )
382 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
385 # Define options to control the inclusion and default build behavior for
386 # components which may not strictly be necessary (tools, examples, and tests).
388 # This is primarily to support building smaller or faster project files.
389 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
390 option(LLVM_BUILD_TOOLS
391 "Build the LLVM tools. If OFF, just generate build targets." ON)
393 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
394 option(LLVM_BUILD_UTILS
395 "Build LLVM utility binaries. If OFF, just generate build targets." ON)
397 option(LLVM_BUILD_RUNTIME
398 "Build the LLVM runtime libraries." ON)
399 option(LLVM_BUILD_EXAMPLES
400 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
401 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
403 option(LLVM_BUILD_TESTS
404 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
405 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
406 option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
408 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
409 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
410 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
411 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
413 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
414 "Build compiler-rt as an external project." OFF)
416 # You can configure which libraries from LLVM you want to include in the
417 # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
418 # list of LLVM components. All component names handled by llvm-config are valid.
419 if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
420 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
421 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
423 option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
424 option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
425 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
426 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
427 set(LLVM_BUILD_LLVM_DYLIB_default ON)
429 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
431 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
432 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
433 set(LLVM_USE_HOST_TOOLS ON)
436 if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900))
437 option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
439 set(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION FALSE CACHE INTERNAL "For Visual Studio 2013, manually copy natvis files to Documents\\Visual Studio 2013\\Visualizers" FORCE)
442 if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE)
443 if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
444 # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine
445 # for spining disks. Anything higher may only help on slower mediums.
446 set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
448 if(NOT LLVM_PROFILE_FILE_PATTERN)
449 if(NOT LLVM_PROFILE_DATA_DIR)
450 set(LLVM_PROFILE_FILE_PATTERN "%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw")
452 file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
457 # All options referred to from HandleLLVMOptions have to be specified
458 # BEFORE this include, otherwise options will not be correctly set on
462 string(REPLACE "Native" ${LLVM_NATIVE_ARCH}
463 LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}")
464 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
466 # By default, we target the host, but this can be overridden at CMake
468 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
469 "Default target for which LLVM will generate code." )
470 set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
472 include(HandleLLVMOptions)
474 # Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
475 # FIXME: We should support systems with only Python 3, but that requires work
477 set(Python_ADDITIONAL_VERSIONS 2.7)
478 include(FindPythonInterp)
479 if( NOT PYTHONINTERP_FOUND )
481 "Unable to find Python interpreter, required for builds and testing.
483 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
486 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
487 message(FATAL_ERROR "Python 2.7 or newer is required")
491 # LLVMBuild Integration
493 # We use llvm-build to generate all the data required by the CMake based
494 # build system in one swoop:
496 # - We generate a file (a CMake fragment) in the object root which contains
497 # all the definitions that are required by CMake.
499 # - We generate the library table used by llvm-config.
501 # - We generate the dependencies for the CMake fragment, so that we will
502 # automatically reconfigure outselves.
504 set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
505 set(LLVMCONFIGLIBRARYDEPENDENCIESINC
506 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
507 set(LLVMBUILDCMAKEFRAG
508 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
510 # Create the list of optional components that are enabled
511 if (LLVM_USE_INTEL_JITEVENTS)
512 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
513 endif (LLVM_USE_INTEL_JITEVENTS)
514 if (LLVM_USE_OPROFILE)
515 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
516 endif (LLVM_USE_OPROFILE)
518 message(STATUS "Constructing LLVMBuild project information")
520 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
521 --native-target "${LLVM_NATIVE_ARCH}"
522 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
523 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
524 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
525 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
526 OUTPUT_VARIABLE LLVMBUILDOUTPUT
527 ERROR_VARIABLE LLVMBUILDERRORS
528 OUTPUT_STRIP_TRAILING_WHITESPACE
529 ERROR_STRIP_TRAILING_WHITESPACE
530 RESULT_VARIABLE LLVMBUILDRESULT)
532 # On Win32, CMake doesn't properly handle piping the default output/error
533 # streams into the GUI console. So, we explicitly catch and report them.
534 if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
535 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
537 if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
539 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
542 # Include the generated CMake fragment. This will define properties from the
543 # LLVMBuild files in a format which is easy to consume from CMake, and will add
544 # the dependencies so that CMake will reconfigure properly when the LLVMBuild
546 include(${LLVMBUILDCMAKEFRAG})
550 # Configure all of the various header file fragments LLVM uses which depend on
551 # configuration variables.
552 set(LLVM_ENUM_TARGETS "")
553 set(LLVM_ENUM_ASM_PRINTERS "")
554 set(LLVM_ENUM_ASM_PARSERS "")
555 set(LLVM_ENUM_DISASSEMBLERS "")
556 foreach(t ${LLVM_TARGETS_TO_BUILD})
557 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
559 list(FIND LLVM_ALL_TARGETS ${t} idx)
560 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
561 if( idx LESS 0 AND idy LESS 0 )
562 message(FATAL_ERROR "The target `${t}' does not exist.
563 It should be one of\n${LLVM_ALL_TARGETS}")
565 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
568 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
570 set(LLVM_ENUM_ASM_PRINTERS
571 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
573 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
574 set(LLVM_ENUM_ASM_PARSERS
575 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
577 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
578 set(LLVM_ENUM_DISASSEMBLERS
579 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
583 # Produce the target definition files, which provide a way for clients to easily
584 # include various classes of targets.
586 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
587 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
590 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
591 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
594 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
595 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
598 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
599 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
602 # Configure the three LLVM configuration header files.
604 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
605 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
607 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
608 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
610 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
611 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
613 # They are not referenced. See set_output_directory().
614 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
615 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
616 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
618 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
620 set(CMAKE_INSTALL_NAME_DIR "@rpath")
621 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
623 if(NOT DEFINED CMAKE_INSTALL_RPATH)
624 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
625 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
626 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
627 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
629 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
632 if(APPLE AND DARWIN_LTO_LIBRARY)
633 set(CMAKE_EXE_LINKER_FLAGS
634 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
635 set(CMAKE_SHARED_LINKER_FLAGS
636 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
637 set(CMAKE_MODULE_LINKER_FLAGS
638 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
641 # Work around a broken bfd ld behavior. When linking a binary with a
642 # foo.so library, it will try to find any library that foo.so uses and
643 # check its symbols. This is wasteful (the check was done when foo.so
644 # was created) and can fail since it is not the dynamic linker and
645 # doesn't know how to handle search paths correctly.
646 if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
647 set(CMAKE_EXE_LINKER_FLAGS
648 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
651 set(CMAKE_INCLUDE_CURRENT_DIR ON)
653 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
655 # when crosscompiling import the executable targets from a file
656 if(LLVM_USE_HOST_TOOLS)
657 include(CrossCompile)
658 endif(LLVM_USE_HOST_TOOLS)
659 if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
660 # Dummy use to avoid CMake Wraning: Manually-specified variables were not used
661 # (this is a variable that CrossCompile sets on recursive invocations)
664 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
665 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
666 # with libxml2, iconv.h, etc., we must add /usr/local paths.
667 include_directories("/usr/local/include")
668 link_directories("/usr/local/lib")
669 endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
671 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
672 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
673 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
675 # Make sure we don't get -rdynamic in every binary. For those that need it,
676 # use export_executable_symbols(target).
677 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
679 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
680 "Profiling data file to use when compiling in order to improve runtime performance.")
682 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
683 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
684 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
686 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
694 # People report that -O3 is unreliable on MinGW. The traditional
695 # build also uses -O2 for that reason:
696 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
699 # Put this before tblgen. Else we have a circular dependence.
700 add_subdirectory(lib/Support)
701 add_subdirectory(lib/TableGen)
703 add_subdirectory(utils/TableGen)
705 # Force target to be built as soon as possible. Clang modules builds depend
706 # header-wise on it as they ship all headers from the umbrella folders. Building
707 # an entire module might include header, which depends on intrinsics_gen. This
708 # should be right after LLVMSupport and LLVMTableGen otherwise we introduce a
709 # circular dependence.
710 if (LLVM_ENABLE_MODULES)
711 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
712 endif(LLVM_ENABLE_MODULES)
714 add_subdirectory(include/llvm)
716 add_subdirectory(lib)
718 if( LLVM_INCLUDE_UTILS )
719 add_subdirectory(utils/FileCheck)
720 add_subdirectory(utils/PerfectShuffle)
721 add_subdirectory(utils/count)
722 add_subdirectory(utils/not)
723 add_subdirectory(utils/llvm-lit)
724 add_subdirectory(utils/yaml-bench)
726 if ( LLVM_INCLUDE_TESTS )
727 message(FATAL_ERROR "Including tests when not building utils will not work.
728 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
732 # Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
733 if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
734 add_subdirectory(utils/LLVMVisualizers)
737 if(LLVM_INCLUDE_TESTS)
738 add_subdirectory(utils/unittest)
741 foreach( binding ${LLVM_BINDINGS_LIST} )
742 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
743 add_subdirectory(bindings/${binding})
747 add_subdirectory(projects)
749 if( LLVM_INCLUDE_TOOLS )
750 add_subdirectory(tools)
753 add_subdirectory(runtimes)
755 if( LLVM_INCLUDE_EXAMPLES )
756 add_subdirectory(examples)
759 if( LLVM_INCLUDE_TESTS )
760 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
761 include(LLVMExternalProjectUtils)
762 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
768 add_subdirectory(test)
769 add_subdirectory(unittests)
771 # This utility is used to prevent crashing tests from calling Dr. Watson on
773 add_subdirectory(utils/KillTheDoctor)
776 # Add a global check rule now that all subdirectories have been traversed
777 # and we know the total set of lit testsuites.
778 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
779 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
780 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
781 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
782 add_lit_target(check-all
783 "Running all regression tests"
784 ${LLVM_LIT_TESTSUITES}
785 PARAMS ${LLVM_LIT_PARAMS}
786 DEPENDS ${LLVM_LIT_DEPENDS}
787 ARGS ${LLVM_LIT_EXTRA_ARGS}
789 add_custom_target(test-depends DEPENDS ${LLVM_LIT_DEPENDS})
790 set_target_properties(test-depends PROPERTIES FOLDER "Tests")
793 if (LLVM_INCLUDE_DOCS)
794 add_subdirectory(docs)
797 add_subdirectory(cmake/modules)
799 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
800 install(DIRECTORY include/llvm include/llvm-c
802 COMPONENT llvm-headers
808 PATTERN "LICENSE.TXT"
809 PATTERN ".svn" EXCLUDE
812 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
814 COMPONENT llvm-headers
820 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
821 PATTERN "CMakeFiles" EXCLUDE
822 PATTERN "config.h" EXCLUDE
823 PATTERN ".svn" EXCLUDE
826 if (NOT CMAKE_CONFIGURATION_TYPES)
827 add_custom_target(installhdrs
829 COMMAND "${CMAKE_COMMAND}"
830 -DCMAKE_INSTALL_COMPONENT=llvm-headers
831 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
835 # This must be at the end of the LLVM root CMakeLists file because it must run
836 # after all targets are created.
837 if(LLVM_DISTRIBUTION_COMPONENTS)
838 if(CMAKE_CONFIGURATION_TYPES)
839 message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)")
842 add_custom_target(distribution)
843 add_custom_target(install-distribution)
844 foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})
846 add_dependencies(distribution ${target})
848 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have a target")
851 if(TARGET install-${target})
852 add_dependencies(install-distribution install-${target})
854 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target")