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 # If enabled, verify we are on a platform that supports oprofile.
305 if( LLVM_USE_OPROFILE )
306 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
307 message(FATAL_ERROR "OProfile support is available on Linux only.")
308 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
309 endif( LLVM_USE_OPROFILE )
311 set(LLVM_USE_SANITIZER "" CACHE STRING
312 "Define the sanitizer used to build binaries and tests.")
314 option(LLVM_USE_SPLIT_DWARF
315 "Use -gsplit-dwarf when compiling llvm." OFF)
317 option(WITH_POLLY "Build LLVM with Polly" ON)
318 option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
320 # Define an option controlling whether we should build for 32-bit on 64-bit
321 # platforms, where supported.
322 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
323 # TODO: support other platforms and toolchains.
324 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
327 # Define the default arguments to use with 'lit', and an option for the user to
329 set(LIT_ARGS_DEFAULT "-sv")
330 if (MSVC_IDE OR XCODE)
331 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
333 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
335 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
336 if( WIN32 AND NOT CYGWIN )
337 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
340 # Define options to control the inclusion and default build behavior for
341 # components which may not strictly be necessary (tools, examples, and tests).
343 # This is primarily to support building smaller or faster project files.
344 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
345 option(LLVM_BUILD_TOOLS
346 "Build the LLVM tools. If OFF, just generate build targets." ON)
348 option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
350 option(LLVM_BUILD_RUNTIME
351 "Build the LLVM runtime libraries." ON)
352 option(LLVM_BUILD_EXAMPLES
353 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
354 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
356 option(LLVM_BUILD_TESTS
357 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
358 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
359 option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
361 option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
362 option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
363 option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
364 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
366 option (LLVM_BUILD_EXTERNAL_COMPILER_RT
367 "Build compiler-rt as an external project." OFF)
369 # You can configure which libraries from LLVM you want to include in the
370 # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
371 # list of LLVM components. All component names handled by llvm-config are valid.
372 if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
373 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
374 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
376 option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
377 option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
378 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
379 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
380 set(LLVM_BUILD_LLVM_DYLIB_default ON)
382 option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
383 set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT ON)
384 if (LLVM_LINK_LLVM_DYLIB)
385 set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT OFF)
387 option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ${LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT})
388 if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT)
389 set(DISABLE_LLVM_DYLIB_ATEXIT 1)
392 option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
393 if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
394 set(LLVM_USE_HOST_TOOLS ON)
397 # All options referred to from HandleLLVMOptions have to be specified
398 # BEFORE this include, otherwise options will not be correctly set on
402 # By default, we target the host, but this can be overridden at CMake
404 set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
405 "Default target for which LLVM will generate code." )
406 set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
408 include(HandleLLVMOptions)
410 # Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
411 # FIXME: We should support systems with only Python 3, but that requires work
413 set(Python_ADDITIONAL_VERSIONS 2.7)
414 include(FindPythonInterp)
415 if( NOT PYTHONINTERP_FOUND )
417 "Unable to find Python interpreter, required for builds and testing.
419 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
422 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
423 message(FATAL_ERROR "Python 2.7 or newer is required")
427 # LLVMBuild Integration
429 # We use llvm-build to generate all the data required by the CMake based
430 # build system in one swoop:
432 # - We generate a file (a CMake fragment) in the object root which contains
433 # all the definitions that are required by CMake.
435 # - We generate the library table used by llvm-config.
437 # - We generate the dependencies for the CMake fragment, so that we will
438 # automatically reconfigure outselves.
440 set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
441 set(LLVMCONFIGLIBRARYDEPENDENCIESINC
442 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
443 set(LLVMBUILDCMAKEFRAG
444 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
446 # Create the list of optional components that are enabled
447 if (LLVM_USE_INTEL_JITEVENTS)
448 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
449 endif (LLVM_USE_INTEL_JITEVENTS)
450 if (LLVM_USE_OPROFILE)
451 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
452 endif (LLVM_USE_OPROFILE)
454 message(STATUS "Constructing LLVMBuild project information")
456 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
457 --native-target "${LLVM_NATIVE_ARCH}"
458 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
459 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
460 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
461 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
462 OUTPUT_VARIABLE LLVMBUILDOUTPUT
463 ERROR_VARIABLE LLVMBUILDERRORS
464 OUTPUT_STRIP_TRAILING_WHITESPACE
465 ERROR_STRIP_TRAILING_WHITESPACE
466 RESULT_VARIABLE LLVMBUILDRESULT)
468 # On Win32, CMake doesn't properly handle piping the default output/error
469 # streams into the GUI console. So, we explicitly catch and report them.
470 if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
471 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
473 if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
475 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
478 # Include the generated CMake fragment. This will define properties from the
479 # LLVMBuild files in a format which is easy to consume from CMake, and will add
480 # the dependencies so that CMake will reconfigure properly when the LLVMBuild
482 include(${LLVMBUILDCMAKEFRAG})
486 # Configure all of the various header file fragments LLVM uses which depend on
487 # configuration variables.
488 set(LLVM_ENUM_TARGETS "")
489 set(LLVM_ENUM_ASM_PRINTERS "")
490 set(LLVM_ENUM_ASM_PARSERS "")
491 set(LLVM_ENUM_DISASSEMBLERS "")
492 foreach(t ${LLVM_TARGETS_TO_BUILD})
493 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
495 list(FIND LLVM_ALL_TARGETS ${t} idx)
496 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
497 if( idx LESS 0 AND idy LESS 0 )
498 message(FATAL_ERROR "The target `${t}' does not exist.
499 It should be one of\n${LLVM_ALL_TARGETS}")
501 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
504 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
506 set(LLVM_ENUM_ASM_PRINTERS
507 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
509 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
510 set(LLVM_ENUM_ASM_PARSERS
511 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
513 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
514 set(LLVM_ENUM_DISASSEMBLERS
515 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
519 # Produce the target definition files, which provide a way for clients to easily
520 # include various classes of targets.
522 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
523 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
526 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
527 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
530 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
531 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
534 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
535 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
538 # Configure the three LLVM configuration header files.
540 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
541 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
543 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
544 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
546 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
547 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
549 # They are not referenced. See set_output_directory().
550 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
551 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
552 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
554 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
556 set(CMAKE_INSTALL_NAME_DIR "@rpath")
557 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
559 if(NOT DEFINED CMAKE_INSTALL_RPATH)
560 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
561 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
562 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
563 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
565 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
568 if(APPLE AND DARWIN_LTO_LIBRARY)
569 set(CMAKE_EXE_LINKER_FLAGS
570 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
571 set(CMAKE_SHARED_LINKER_FLAGS
572 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
573 set(CMAKE_MODULE_LINKER_FLAGS
574 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
577 # Work around a broken bfd ld behavior. When linking a binary with a
578 # foo.so library, it will try to find any library that foo.so uses and
579 # check its symbols. This is wasteful (the check was done when foo.so
580 # was created) and can fail since it is not the dynamic linker and
581 # doesn't know how to handle search paths correctly.
582 if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
583 set(CMAKE_EXE_LINKER_FLAGS
584 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
587 set(CMAKE_INCLUDE_CURRENT_DIR ON)
589 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
591 # when crosscompiling import the executable targets from a file
592 if(LLVM_USE_HOST_TOOLS)
593 include(CrossCompile)
594 endif(LLVM_USE_HOST_TOOLS)
595 if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
596 # Dummy use to avoid CMake Wraning: Manually-specified variables were not used
597 # (this is a variable that CrossCompile sets on recursive invocations)
600 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
601 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
602 # with libxml2, iconv.h, etc., we must add /usr/local paths.
603 include_directories("/usr/local/include")
604 link_directories("/usr/local/lib")
605 endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
607 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
608 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
609 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
611 # Make sure we don't get -rdynamic in every binary. For those that need it,
612 # use export_executable_symbols(target).
613 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
615 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
616 "Profiling data file to use when compiling in order to improve runtime performance.")
618 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
619 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
620 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
622 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
630 # People report that -O3 is unreliable on MinGW. The traditional
631 # build also uses -O2 for that reason:
632 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
635 # Put this before tblgen. Else we have a circular dependence.
636 add_subdirectory(lib/Support)
637 add_subdirectory(lib/TableGen)
639 add_subdirectory(utils/TableGen)
641 add_subdirectory(include/llvm)
643 add_subdirectory(lib)
645 if( LLVM_INCLUDE_UTILS )
646 add_subdirectory(utils/FileCheck)
647 add_subdirectory(utils/PerfectShuffle)
648 add_subdirectory(utils/count)
649 add_subdirectory(utils/not)
650 add_subdirectory(utils/llvm-lit)
651 add_subdirectory(utils/yaml-bench)
653 if ( LLVM_INCLUDE_TESTS )
654 message(FATAL_ERROR "Including tests when not building utils will not work.
655 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
659 if(LLVM_INCLUDE_TESTS)
660 add_subdirectory(utils/unittest)
663 foreach( binding ${LLVM_BINDINGS_LIST} )
664 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
665 add_subdirectory(bindings/${binding})
669 add_subdirectory(projects)
672 if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
677 if( LLVM_INCLUDE_TOOLS )
678 add_subdirectory(tools)
681 if( LLVM_INCLUDE_EXAMPLES )
682 add_subdirectory(examples)
685 if( LLVM_INCLUDE_TESTS )
686 add_subdirectory(test)
687 add_subdirectory(unittests)
689 # This utility is used to prevent crashing tests from calling Dr. Watson on
691 add_subdirectory(utils/KillTheDoctor)
694 # Add a global check rule now that all subdirectories have been traversed
695 # and we know the total set of lit testsuites.
696 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
697 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
698 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
699 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
700 add_lit_target(check-all
701 "Running all regression tests"
702 ${LLVM_LIT_TESTSUITES}
703 PARAMS ${LLVM_LIT_PARAMS}
704 DEPENDS ${LLVM_LIT_DEPENDS}
705 ARGS ${LLVM_LIT_EXTRA_ARGS}
709 if (LLVM_INCLUDE_DOCS)
710 add_subdirectory(docs)
713 add_subdirectory(cmake/modules)
715 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
716 install(DIRECTORY include/llvm include/llvm-c
718 COMPONENT llvm-headers
724 PATTERN "LICENSE.TXT"
725 PATTERN ".svn" EXCLUDE
728 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
730 COMPONENT llvm-headers
736 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
737 PATTERN "CMakeFiles" EXCLUDE
738 PATTERN "config.h" EXCLUDE
739 PATTERN ".svn" EXCLUDE
742 if (NOT CMAKE_CONFIGURATION_TYPES)
743 add_custom_target(installhdrs
745 COMMAND "${CMAKE_COMMAND}"
746 -DCMAKE_INSTALL_COMPONENT=llvm-headers
747 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")