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" 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(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 9)
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 svn)
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_BUILD_GLOBAL_ISEL OFF CACHE BOOL "Experimental: Build GlobalISel")
72 if(LLVM_BUILD_GLOBAL_ISEL)
73 add_definitions(-DLLVM_BUILD_GLOBAL_ISEL)
76 set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
77 "Define the maximum number of concurrent link jobs.")
78 if(LLVM_PARALLEL_LINK_JOBS)
79 if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
80 message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
82 set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
83 set(CMAKE_JOB_POOL_LINK link_job_pool)
87 # Add path for custom modules
90 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
91 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
94 # Generate a CompilationDatabase (compile_commands.json file) for our build,
95 # for use by clang_complete, YouCompleteMe, etc.
96 set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
98 option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
100 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
102 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
103 if ( LLVM_USE_FOLDERS )
104 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
107 include(VersionFromVCS)
109 option(LLVM_APPEND_VC_REV
110 "Append the version control system revision id to LLVM version" OFF)
112 if( LLVM_APPEND_VC_REV )
113 add_version_info_from_vcs(PACKAGE_VERSION)
116 set(PACKAGE_NAME LLVM)
117 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
118 set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
120 set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
121 "Default URL where bug reports are to be submitted.")
124 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
125 set(CPACK_PACKAGE_VENDOR "LLVM")
126 set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
127 set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
128 set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
129 set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
130 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
131 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
132 if(WIN32 AND NOT UNIX)
133 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
134 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
135 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
136 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
137 set(CPACK_NSIS_MODIFY_PATH "ON")
138 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
139 set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
140 "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
141 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
142 "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
144 set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
149 # Sanity check our source directory to make sure that we are not trying to
150 # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
151 # sure that we don't have any stray generated files lying around in the tree
152 # (which would end up getting picked up by header search, instead of the correct
154 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
155 message(FATAL_ERROR "In-source builds are not allowed.
156 CMake would overwrite the makefiles distributed with LLVM.
157 Please create a directory and run cmake from there, passing the path
158 to this source directory as the last argument.
159 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
160 Please delete them.")
162 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
164 tablegenned_files_on_include_dir
165 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
167 tablegenned_files_on_lib_dir
168 "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
169 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
170 message(FATAL_ERROR "Apparently there is a previous in-source build,
171 probably as the result of running `configure' and `make' on
172 ${CMAKE_CURRENT_SOURCE_DIR}.
173 This may cause problems. The suspicious files are:
174 ${tablegenned_files_on_lib_dir}
175 ${tablegenned_files_on_include_dir}
176 Please clean the source directory.")
180 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
182 if (CMAKE_BUILD_TYPE AND
183 NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
184 message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
187 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
189 # They are used as destination of target generators.
190 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
191 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
193 # DLL platform -- put DLLs into bin.
194 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
196 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
199 # Each of them corresponds to llvm-config's.
200 set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
201 set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
202 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
203 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
204 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
206 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
207 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
226 # List of targets with JIT support:
227 set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
229 set(LLVM_TARGETS_TO_BUILD "all"
230 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
232 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
233 CACHE STRING "Semicolon-separated list of experimental targets to build.")
235 option(BUILD_SHARED_LIBS
236 "Build all libraries as shared libraries instead of static" OFF)
238 option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
239 if(LLVM_ENABLE_TIMESTAMPS)
240 set(ENABLE_TIMESTAMPS 1)
243 option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
244 if(LLVM_ENABLE_BACKTRACES)
245 set(ENABLE_BACKTRACES 1)
248 option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
249 if(LLVM_ENABLE_CRASH_OVERRIDES)
250 set(ENABLE_CRASH_OVERRIDES 1)
253 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
254 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
255 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
257 set(LLVM_TARGET_ARCH "host"
258 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
260 option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
262 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
264 option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
266 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
267 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
270 set(LLVM_TARGETS_TO_BUILD
271 ${LLVM_TARGETS_TO_BUILD}
272 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
273 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
275 include(AddLLVMDefinitions)
277 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
278 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
279 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
280 option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
281 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
282 option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
283 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
284 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
286 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
287 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
289 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
292 set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
293 "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
295 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
296 "Set to ON to force using an old, unsupported host toolchain." OFF)
298 option(LLVM_USE_INTEL_JITEVENTS
299 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
302 if( LLVM_USE_INTEL_JITEVENTS )
303 # Verify we are on a supported platform
304 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
306 "Intel JIT API support is available on Linux and Windows only.")
308 endif( LLVM_USE_INTEL_JITEVENTS )
310 option(LLVM_USE_OPROFILE
311 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
313 option(LLVM_EXTERNALIZE_DEBUGINFO
314 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
316 # If enabled, verify we are on a platform that supports oprofile.
317 if( LLVM_USE_OPROFILE )
318 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
319 message(FATAL_ERROR "OProfile support is available on Linux only.")
320 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
321 endif( LLVM_USE_OPROFILE )
323 set(LLVM_USE_SANITIZER "" CACHE STRING
324 "Define the sanitizer used to build binaries and tests.")
326 option(LLVM_USE_SPLIT_DWARF
327 "Use -gsplit-dwarf when compiling llvm." OFF)
329 option(WITH_POLLY "Build LLVM with Polly" ON)
330 option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
332 # Define an option controlling whether we should build for 32-bit on 64-bit
333 # platforms, where supported.
334 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
335 # TODO: support other platforms and toolchains.
336 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
339 # Define the default arguments to use with 'lit', and an option for the user to
341 set(LIT_ARGS_DEFAULT "-sv")
342 if (MSVC_IDE OR XCODE)
343 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
345 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
347 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
348 if( WIN32 AND NOT CYGWIN )
349 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
352 # Define options to control the inclusion and default build behavior for
353 # components which may not strictly be necessary (tools, examples, and tests).
355 # This is primarily to support building smaller or faster project files.
356 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
357 option(LLVM_BUILD_TOOLS
358 "Build the LLVM tools. If OFF, just generate build targets." ON)
360 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
362 option(LLVM_BUILD_RUNTIME
363 "Build the LLVM runtime libraries." ON)
364 option(LLVM_BUILD_EXAMPLES
365 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
366 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
368 option(LLVM_BUILD_TESTS
369 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
370 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
371 option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
373 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
374 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
375 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
376 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
378 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
379 "Build compiler-rt as an external project." OFF)
381 # You can configure which libraries from LLVM you want to include in the
382 # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
383 # list of LLVM components. All component names handled by llvm-config are valid.
384 if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
385 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
386 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
388 option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
389 option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
390 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
391 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
392 set(LLVM_BUILD_LLVM_DYLIB_default ON)
394 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
396 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
397 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
398 set(LLVM_USE_HOST_TOOLS ON)
401 # All options referred to from HandleLLVMOptions have to be specified
402 # BEFORE this include, otherwise options will not be correctly set on
406 string(REPLACE "Native" ${LLVM_NATIVE_ARCH}
407 LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}")
408 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
410 # By default, we target the host, but this can be overridden at CMake
412 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
413 "Default target for which LLVM will generate code." )
414 set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
416 include(HandleLLVMOptions)
418 # Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
419 # FIXME: We should support systems with only Python 3, but that requires work
421 set(Python_ADDITIONAL_VERSIONS 2.7)
422 include(FindPythonInterp)
423 if( NOT PYTHONINTERP_FOUND )
425 "Unable to find Python interpreter, required for builds and testing.
427 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
430 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
431 message(FATAL_ERROR "Python 2.7 or newer is required")
435 # LLVMBuild Integration
437 # We use llvm-build to generate all the data required by the CMake based
438 # build system in one swoop:
440 # - We generate a file (a CMake fragment) in the object root which contains
441 # all the definitions that are required by CMake.
443 # - We generate the library table used by llvm-config.
445 # - We generate the dependencies for the CMake fragment, so that we will
446 # automatically reconfigure outselves.
448 set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
449 set(LLVMCONFIGLIBRARYDEPENDENCIESINC
450 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
451 set(LLVMBUILDCMAKEFRAG
452 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
454 # Create the list of optional components that are enabled
455 if (LLVM_USE_INTEL_JITEVENTS)
456 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
457 endif (LLVM_USE_INTEL_JITEVENTS)
458 if (LLVM_USE_OPROFILE)
459 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
460 endif (LLVM_USE_OPROFILE)
462 message(STATUS "Constructing LLVMBuild project information")
464 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
465 --native-target "${LLVM_NATIVE_ARCH}"
466 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
467 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
468 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
469 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
470 OUTPUT_VARIABLE LLVMBUILDOUTPUT
471 ERROR_VARIABLE LLVMBUILDERRORS
472 OUTPUT_STRIP_TRAILING_WHITESPACE
473 ERROR_STRIP_TRAILING_WHITESPACE
474 RESULT_VARIABLE LLVMBUILDRESULT)
476 # On Win32, CMake doesn't properly handle piping the default output/error
477 # streams into the GUI console. So, we explicitly catch and report them.
478 if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
479 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
481 if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
483 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
486 # Include the generated CMake fragment. This will define properties from the
487 # LLVMBuild files in a format which is easy to consume from CMake, and will add
488 # the dependencies so that CMake will reconfigure properly when the LLVMBuild
490 include(${LLVMBUILDCMAKEFRAG})
494 # Configure all of the various header file fragments LLVM uses which depend on
495 # configuration variables.
496 set(LLVM_ENUM_TARGETS "")
497 set(LLVM_ENUM_ASM_PRINTERS "")
498 set(LLVM_ENUM_ASM_PARSERS "")
499 set(LLVM_ENUM_DISASSEMBLERS "")
500 foreach(t ${LLVM_TARGETS_TO_BUILD})
501 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
503 list(FIND LLVM_ALL_TARGETS ${t} idx)
504 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
505 if( idx LESS 0 AND idy LESS 0 )
506 message(FATAL_ERROR "The target `${t}' does not exist.
507 It should be one of\n${LLVM_ALL_TARGETS}")
509 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
512 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
514 set(LLVM_ENUM_ASM_PRINTERS
515 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
517 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
518 set(LLVM_ENUM_ASM_PARSERS
519 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
521 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
522 set(LLVM_ENUM_DISASSEMBLERS
523 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
527 # Produce the target definition files, which provide a way for clients to easily
528 # include various classes of targets.
530 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
531 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
534 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
535 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
538 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
539 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
542 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
543 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
546 # Configure the three LLVM configuration header files.
548 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
549 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
551 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
552 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
554 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
555 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
557 # They are not referenced. See set_output_directory().
558 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
559 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
560 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
562 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
564 set(CMAKE_INSTALL_NAME_DIR "@rpath")
565 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
567 if(NOT DEFINED CMAKE_INSTALL_RPATH)
568 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
569 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
570 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
571 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
573 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
576 if(APPLE AND DARWIN_LTO_LIBRARY)
577 set(CMAKE_EXE_LINKER_FLAGS
578 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
579 set(CMAKE_SHARED_LINKER_FLAGS
580 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
581 set(CMAKE_MODULE_LINKER_FLAGS
582 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
585 # Work around a broken bfd ld behavior. When linking a binary with a
586 # foo.so library, it will try to find any library that foo.so uses and
587 # check its symbols. This is wasteful (the check was done when foo.so
588 # was created) and can fail since it is not the dynamic linker and
589 # doesn't know how to handle search paths correctly.
590 if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
591 set(CMAKE_EXE_LINKER_FLAGS
592 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
595 set(CMAKE_INCLUDE_CURRENT_DIR ON)
597 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
599 # when crosscompiling import the executable targets from a file
600 if(LLVM_USE_HOST_TOOLS)
601 include(CrossCompile)
602 endif(LLVM_USE_HOST_TOOLS)
603 if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
604 # Dummy use to avoid CMake Wraning: Manually-specified variables were not used
605 # (this is a variable that CrossCompile sets on recursive invocations)
608 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
609 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
610 # with libxml2, iconv.h, etc., we must add /usr/local paths.
611 include_directories("/usr/local/include")
612 link_directories("/usr/local/lib")
613 endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
615 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
616 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
617 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
619 # Make sure we don't get -rdynamic in every binary. For those that need it,
620 # use export_executable_symbols(target).
621 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
623 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
624 "Profiling data file to use when compiling in order to improve runtime performance.")
626 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
627 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
628 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
630 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
638 # People report that -O3 is unreliable on MinGW. The traditional
639 # build also uses -O2 for that reason:
640 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
643 # Put this before tblgen. Else we have a circular dependence.
644 add_subdirectory(lib/Support)
645 add_subdirectory(lib/TableGen)
647 add_subdirectory(utils/TableGen)
649 add_subdirectory(include/llvm)
651 add_subdirectory(lib)
653 if( LLVM_INCLUDE_UTILS )
654 add_subdirectory(utils/FileCheck)
655 add_subdirectory(utils/PerfectShuffle)
656 add_subdirectory(utils/count)
657 add_subdirectory(utils/not)
658 add_subdirectory(utils/llvm-lit)
659 add_subdirectory(utils/yaml-bench)
661 if ( LLVM_INCLUDE_TESTS )
662 message(FATAL_ERROR "Including tests when not building utils will not work.
663 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
667 if(LLVM_INCLUDE_TESTS)
668 add_subdirectory(utils/unittest)
671 foreach( binding ${LLVM_BINDINGS_LIST} )
672 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
673 add_subdirectory(bindings/${binding})
677 add_subdirectory(projects)
680 if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
685 if( LLVM_INCLUDE_TOOLS )
686 add_subdirectory(tools)
689 if( LLVM_INCLUDE_EXAMPLES )
690 add_subdirectory(examples)
693 if( LLVM_INCLUDE_TESTS )
694 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
695 include(LLVMExternalProjectUtils)
696 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
701 add_subdirectory(test)
702 add_subdirectory(unittests)
704 # This utility is used to prevent crashing tests from calling Dr. Watson on
706 add_subdirectory(utils/KillTheDoctor)
709 # Add a global check rule now that all subdirectories have been traversed
710 # and we know the total set of lit testsuites.
711 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
712 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
713 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
714 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
715 add_lit_target(check-all
716 "Running all regression tests"
717 ${LLVM_LIT_TESTSUITES}
718 PARAMS ${LLVM_LIT_PARAMS}
719 DEPENDS ${LLVM_LIT_DEPENDS}
720 ARGS ${LLVM_LIT_EXTRA_ARGS}
722 add_custom_target(test-depends DEPENDS ${LLVM_LIT_DEPENDS})
725 if (LLVM_INCLUDE_DOCS)
726 add_subdirectory(docs)
729 add_subdirectory(cmake/modules)
731 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
732 install(DIRECTORY include/llvm include/llvm-c
734 COMPONENT llvm-headers
740 PATTERN "LICENSE.TXT"
741 PATTERN ".svn" EXCLUDE
744 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
746 COMPONENT llvm-headers
752 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
753 PATTERN "CMakeFiles" EXCLUDE
754 PATTERN "config.h" EXCLUDE
755 PATTERN ".svn" EXCLUDE
758 if (NOT CMAKE_CONFIGURATION_TYPES)
759 add_custom_target(installhdrs
761 COMMAND "${CMAKE_COMMAND}"
762 -DCMAKE_INSTALL_COMPONENT=llvm-headers
763 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
767 # This must be at the end of the LLVM root CMakeLists file because it must run
768 # after all targets are created.
769 if(LLVM_DISTRIBUTION_COMPONENTS)
770 if(CMAKE_CONFIGURATION_TYPES)
771 message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)")
774 add_custom_target(distribution)
775 add_custom_target(install-distribution)
776 foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})
778 add_dependencies(distribution ${target})
780 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have a target")
783 if(TARGET install-${target})
784 add_dependencies(install-distribution install-${target})
786 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target")