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 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_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 option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
91 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
93 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
94 if ( LLVM_USE_FOLDERS )
95 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
98 include(VersionFromVCS)
100 option(LLVM_APPEND_VC_REV
101 "Append the version control system revision id to LLVM version" OFF)
103 if( LLVM_APPEND_VC_REV )
104 add_version_info_from_vcs(PACKAGE_VERSION)
107 set(PACKAGE_NAME LLVM)
108 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
109 set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
111 set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
112 "Default URL where bug reports are to be submitted.")
115 set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
116 set(CPACK_PACKAGE_VENDOR "LLVM")
117 set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
118 set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
119 set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
120 set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
121 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
122 set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
123 if(WIN32 AND NOT UNIX)
124 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
125 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
126 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
127 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
128 set(CPACK_NSIS_MODIFY_PATH "ON")
129 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
130 set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
131 "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
132 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
133 "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
135 set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
140 # Sanity check our source directory to make sure that we are not trying to
141 # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
142 # sure that we don't have any stray generated files lying around in the tree
143 # (which would end up getting picked up by header search, instead of the correct
145 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
146 message(FATAL_ERROR "In-source builds are not allowed.
147 CMake would overwrite the makefiles distributed with LLVM.
148 Please create a directory and run cmake from there, passing the path
149 to this source directory as the last argument.
150 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
151 Please delete them.")
153 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
155 tablegenned_files_on_include_dir
156 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
158 tablegenned_files_on_lib_dir
159 "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
160 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
161 message(FATAL_ERROR "Apparently there is a previous in-source build,
162 probably as the result of running `configure' and `make' on
163 ${CMAKE_CURRENT_SOURCE_DIR}.
164 This may cause problems. The suspicious files are:
165 ${tablegenned_files_on_lib_dir}
166 ${tablegenned_files_on_include_dir}
167 Please clean the source directory.")
171 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
173 if (CMAKE_BUILD_TYPE AND
174 NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
175 message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
178 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
180 # They are used as destination of target generators.
181 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
182 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
184 # DLL platform -- put DLLs into bin.
185 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
187 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
190 # Each of them corresponds to llvm-config's.
191 set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
192 set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
193 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
194 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
195 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
197 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
198 set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
217 # List of targets with JIT support:
218 set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
220 set(LLVM_TARGETS_TO_BUILD "all"
221 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
223 set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
224 CACHE STRING "Semicolon-separated list of experimental targets to build.")
226 option(BUILD_SHARED_LIBS
227 "Build all libraries as shared libraries instead of static" OFF)
229 option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
230 if(LLVM_ENABLE_TIMESTAMPS)
231 set(ENABLE_TIMESTAMPS 1)
234 option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
235 if(LLVM_ENABLE_BACKTRACES)
236 set(ENABLE_BACKTRACES 1)
239 option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
240 if(LLVM_ENABLE_CRASH_OVERRIDES)
241 set(ENABLE_CRASH_OVERRIDES 1)
244 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
245 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
246 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
248 set(LLVM_TARGET_ARCH "host"
249 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
251 option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
253 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
255 option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
257 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
258 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
261 set(LLVM_TARGETS_TO_BUILD
262 ${LLVM_TARGETS_TO_BUILD}
263 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
264 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
266 include(AddLLVMDefinitions)
268 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
269 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
270 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
271 option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
272 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
273 option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
274 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
275 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
277 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
278 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
280 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
283 set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
284 "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
286 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
287 "Set to ON to force using an old, unsupported host toolchain." OFF)
289 option(LLVM_USE_INTEL_JITEVENTS
290 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
293 if( LLVM_USE_INTEL_JITEVENTS )
294 # Verify we are on a supported platform
295 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
297 "Intel JIT API support is available on Linux and Windows only.")
299 endif( LLVM_USE_INTEL_JITEVENTS )
301 option(LLVM_USE_OPROFILE
302 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
304 option(LLVM_EXTERNALIZE_DEBUGINFO
305 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
307 # If enabled, verify we are on a platform that supports oprofile.
308 if( LLVM_USE_OPROFILE )
309 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
310 message(FATAL_ERROR "OProfile support is available on Linux only.")
311 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
312 endif( LLVM_USE_OPROFILE )
314 set(LLVM_USE_SANITIZER "" CACHE STRING
315 "Define the sanitizer used to build binaries and tests.")
317 option(LLVM_USE_SPLIT_DWARF
318 "Use -gsplit-dwarf when compiling llvm." OFF)
320 option(WITH_POLLY "Build LLVM with Polly" ON)
321 option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
323 # Define an option controlling whether we should build for 32-bit on 64-bit
324 # platforms, where supported.
325 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
326 # TODO: support other platforms and toolchains.
327 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
330 # Define the default arguments to use with 'lit', and an option for the user to
332 set(LIT_ARGS_DEFAULT "-sv")
333 if (MSVC_IDE OR XCODE)
334 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
336 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
338 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
339 if( WIN32 AND NOT CYGWIN )
340 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
343 # Define options to control the inclusion and default build behavior for
344 # components which may not strictly be necessary (tools, examples, and tests).
346 # This is primarily to support building smaller or faster project files.
347 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
348 option(LLVM_BUILD_TOOLS
349 "Build the LLVM tools. If OFF, just generate build targets." ON)
351 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
353 option(LLVM_BUILD_RUNTIME
354 "Build the LLVM runtime libraries." ON)
355 option(LLVM_BUILD_EXAMPLES
356 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
357 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
359 option(LLVM_BUILD_TESTS
360 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
361 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
362 option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
364 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
365 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
366 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
367 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
369 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
370 "Build compiler-rt as an external project." OFF)
372 # You can configure which libraries from LLVM you want to include in the
373 # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
374 # list of LLVM components. All component names handled by llvm-config are valid.
375 if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
376 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
377 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
379 option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
380 option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
381 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
382 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
383 set(LLVM_BUILD_LLVM_DYLIB_default ON)
385 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
386 set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT ON)
387 if (LLVM_LINK_LLVM_DYLIB)
388 set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT OFF)
390 option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ${LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT})
391 if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT)
392 set(DISABLE_LLVM_DYLIB_ATEXIT 1)
395 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
396 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
397 set(LLVM_USE_HOST_TOOLS ON)
400 # All options referred to from HandleLLVMOptions have to be specified
401 # BEFORE this include, otherwise options will not be correctly set on
405 # By default, we target the host, but this can be overridden at CMake
407 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
408 "Default target for which LLVM will generate code." )
409 set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
411 include(HandleLLVMOptions)
413 # Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
414 # FIXME: We should support systems with only Python 3, but that requires work
416 set(Python_ADDITIONAL_VERSIONS 2.7)
417 include(FindPythonInterp)
418 if( NOT PYTHONINTERP_FOUND )
420 "Unable to find Python interpreter, required for builds and testing.
422 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
425 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
426 message(FATAL_ERROR "Python 2.7 or newer is required")
430 # LLVMBuild Integration
432 # We use llvm-build to generate all the data required by the CMake based
433 # build system in one swoop:
435 # - We generate a file (a CMake fragment) in the object root which contains
436 # all the definitions that are required by CMake.
438 # - We generate the library table used by llvm-config.
440 # - We generate the dependencies for the CMake fragment, so that we will
441 # automatically reconfigure outselves.
443 set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
444 set(LLVMCONFIGLIBRARYDEPENDENCIESINC
445 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
446 set(LLVMBUILDCMAKEFRAG
447 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
449 # Create the list of optional components that are enabled
450 if (LLVM_USE_INTEL_JITEVENTS)
451 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
452 endif (LLVM_USE_INTEL_JITEVENTS)
453 if (LLVM_USE_OPROFILE)
454 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
455 endif (LLVM_USE_OPROFILE)
457 message(STATUS "Constructing LLVMBuild project information")
459 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
460 --native-target "${LLVM_NATIVE_ARCH}"
461 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
462 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
463 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
464 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
465 OUTPUT_VARIABLE LLVMBUILDOUTPUT
466 ERROR_VARIABLE LLVMBUILDERRORS
467 OUTPUT_STRIP_TRAILING_WHITESPACE
468 ERROR_STRIP_TRAILING_WHITESPACE
469 RESULT_VARIABLE LLVMBUILDRESULT)
471 # On Win32, CMake doesn't properly handle piping the default output/error
472 # streams into the GUI console. So, we explicitly catch and report them.
473 if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
474 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
476 if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
478 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
481 # Include the generated CMake fragment. This will define properties from the
482 # LLVMBuild files in a format which is easy to consume from CMake, and will add
483 # the dependencies so that CMake will reconfigure properly when the LLVMBuild
485 include(${LLVMBUILDCMAKEFRAG})
489 # Configure all of the various header file fragments LLVM uses which depend on
490 # configuration variables.
491 set(LLVM_ENUM_TARGETS "")
492 set(LLVM_ENUM_ASM_PRINTERS "")
493 set(LLVM_ENUM_ASM_PARSERS "")
494 set(LLVM_ENUM_DISASSEMBLERS "")
495 foreach(t ${LLVM_TARGETS_TO_BUILD})
496 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
498 list(FIND LLVM_ALL_TARGETS ${t} idx)
499 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
500 if( idx LESS 0 AND idy LESS 0 )
501 message(FATAL_ERROR "The target `${t}' does not exist.
502 It should be one of\n${LLVM_ALL_TARGETS}")
504 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
507 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
509 set(LLVM_ENUM_ASM_PRINTERS
510 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
512 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
513 set(LLVM_ENUM_ASM_PARSERS
514 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
516 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
517 set(LLVM_ENUM_DISASSEMBLERS
518 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
522 # Produce the target definition files, which provide a way for clients to easily
523 # include various classes of targets.
525 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
526 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
529 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
530 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
533 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
534 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
537 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
538 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
541 # Configure the three LLVM configuration header files.
543 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
544 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
546 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
547 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
549 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
550 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
552 # They are not referenced. See set_output_directory().
553 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
554 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
555 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
557 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
559 set(CMAKE_INSTALL_NAME_DIR "@rpath")
560 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
562 if(NOT DEFINED CMAKE_INSTALL_RPATH)
563 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
564 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
565 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
566 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
568 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
571 if(APPLE AND DARWIN_LTO_LIBRARY)
572 set(CMAKE_EXE_LINKER_FLAGS
573 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
574 set(CMAKE_SHARED_LINKER_FLAGS
575 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
576 set(CMAKE_MODULE_LINKER_FLAGS
577 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
580 # Work around a broken bfd ld behavior. When linking a binary with a
581 # foo.so library, it will try to find any library that foo.so uses and
582 # check its symbols. This is wasteful (the check was done when foo.so
583 # was created) and can fail since it is not the dynamic linker and
584 # doesn't know how to handle search paths correctly.
585 if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
586 set(CMAKE_EXE_LINKER_FLAGS
587 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
590 set(CMAKE_INCLUDE_CURRENT_DIR ON)
592 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
594 # when crosscompiling import the executable targets from a file
595 if(LLVM_USE_HOST_TOOLS)
596 include(CrossCompile)
597 endif(LLVM_USE_HOST_TOOLS)
598 if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
599 # Dummy use to avoid CMake Wraning: Manually-specified variables were not used
600 # (this is a variable that CrossCompile sets on recursive invocations)
603 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
604 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
605 # with libxml2, iconv.h, etc., we must add /usr/local paths.
606 include_directories("/usr/local/include")
607 link_directories("/usr/local/lib")
608 endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
610 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
611 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
612 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
614 # Make sure we don't get -rdynamic in every binary. For those that need it,
615 # use export_executable_symbols(target).
616 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
618 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
619 "Profiling data file to use when compiling in order to improve runtime performance.")
621 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
622 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
623 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
625 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
633 # People report that -O3 is unreliable on MinGW. The traditional
634 # build also uses -O2 for that reason:
635 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
638 # Put this before tblgen. Else we have a circular dependence.
639 add_subdirectory(lib/Support)
640 add_subdirectory(lib/TableGen)
642 add_subdirectory(utils/TableGen)
644 add_subdirectory(include/llvm)
646 add_subdirectory(lib)
648 if( LLVM_INCLUDE_UTILS )
649 add_subdirectory(utils/FileCheck)
650 add_subdirectory(utils/PerfectShuffle)
651 add_subdirectory(utils/count)
652 add_subdirectory(utils/not)
653 add_subdirectory(utils/llvm-lit)
654 add_subdirectory(utils/yaml-bench)
656 if ( LLVM_INCLUDE_TESTS )
657 message(FATAL_ERROR "Including tests when not building utils will not work.
658 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
662 if(LLVM_INCLUDE_TESTS)
663 add_subdirectory(utils/unittest)
666 foreach( binding ${LLVM_BINDINGS_LIST} )
667 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
668 add_subdirectory(bindings/${binding})
672 add_subdirectory(projects)
675 if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
680 if( LLVM_INCLUDE_TOOLS )
681 add_subdirectory(tools)
684 if( LLVM_INCLUDE_EXAMPLES )
685 add_subdirectory(examples)
688 if( LLVM_INCLUDE_TESTS )
689 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
690 include(LLVMExternalProjectUtils)
691 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
696 add_subdirectory(test)
697 add_subdirectory(unittests)
699 # This utility is used to prevent crashing tests from calling Dr. Watson on
701 add_subdirectory(utils/KillTheDoctor)
704 # Add a global check rule now that all subdirectories have been traversed
705 # and we know the total set of lit testsuites.
706 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
707 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
708 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
709 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
710 add_lit_target(check-all
711 "Running all regression tests"
712 ${LLVM_LIT_TESTSUITES}
713 PARAMS ${LLVM_LIT_PARAMS}
714 DEPENDS ${LLVM_LIT_DEPENDS}
715 ARGS ${LLVM_LIT_EXTRA_ARGS}
719 if (LLVM_INCLUDE_DOCS)
720 add_subdirectory(docs)
723 add_subdirectory(cmake/modules)
725 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
726 install(DIRECTORY include/llvm include/llvm-c
728 COMPONENT llvm-headers
734 PATTERN "LICENSE.TXT"
735 PATTERN ".svn" EXCLUDE
738 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
740 COMPONENT llvm-headers
746 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
747 PATTERN "CMakeFiles" EXCLUDE
748 PATTERN "config.h" EXCLUDE
749 PATTERN ".svn" EXCLUDE
752 if (NOT CMAKE_CONFIGURATION_TYPES)
753 add_custom_target(installhdrs
755 COMMAND "${CMAKE_COMMAND}"
756 -DCMAKE_INSTALL_COMPONENT=llvm-headers
757 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")