blob: ed3e1b8a07c115d8043c5d9f509a41b8115641af [file] [log] [blame]
Reid Klecknera2a07f92016-03-28 18:19:32 +00001# See docs/CMake.html for instructions about how to build LLVM with CMake.
2
Chris Bienemanb4711912016-05-31 20:21:32 +00003cmake_minimum_required(VERSION 3.4.3)
Reid Klecknera2a07f92016-03-28 18:19:32 +00004
5if (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)")
8endif()
9
10if(POLICY CMP0022)
11 cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
12endif()
13
14if (POLICY CMP0051)
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)
21endif()
22
Reid Klecknera2a07f92016-03-28 18:19:32 +000023if(NOT DEFINED LLVM_VERSION_MAJOR)
24 set(LLVM_VERSION_MAJOR 3)
25endif()
26if(NOT DEFINED LLVM_VERSION_MINOR)
27 set(LLVM_VERSION_MINOR 9)
28endif()
29if(NOT DEFINED LLVM_VERSION_PATCH)
30 set(LLVM_VERSION_PATCH 0)
31endif()
32if(NOT DEFINED LLVM_VERSION_SUFFIX)
33 set(LLVM_VERSION_SUFFIX svn)
34endif()
35
36if (POLICY CMP0048)
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)
41endif()
42
43if (NOT PACKAGE_VERSION)
44 set(PACKAGE_VERSION
45 "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
46endif()
47
48project(LLVM
49 ${cmake_3_0_PROJ_VERSION}
50 ${cmake_3_0_LANGUAGES}
51 C CXX ASM)
52
Chris Bieneman61086582016-04-28 20:14:19 +000053if(APPLE)
54 if(NOT CMAKE_LIBTOOL)
55 find_program(CMAKE_LIBTOOL NAMES libtool)
56 endif()
57 if(CMAKE_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> ")
64 endforeach()
65 endif()
66endif()
67
Reid Klecknera2a07f92016-03-28 18:19:32 +000068# The following only works with the Ninja generator in CMake >= 3.0.
69set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
70 "Define the maximum number of concurrent compilation jobs.")
71if(LLVM_PARALLEL_COMPILE_JOBS)
Chris Bieneman35c7f962016-06-08 22:38:30 +000072 if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
73 message(WARNING "Job pooling is only available with Ninja generators.")
Reid Klecknera2a07f92016-03-28 18:19:32 +000074 else()
75 set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
76 set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
77 endif()
78endif()
79
80set(LLVM_BUILD_GLOBAL_ISEL OFF CACHE BOOL "Experimental: Build GlobalISel")
81if(LLVM_BUILD_GLOBAL_ISEL)
82 add_definitions(-DLLVM_BUILD_GLOBAL_ISEL)
83endif()
84
85set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
86 "Define the maximum number of concurrent link jobs.")
87if(LLVM_PARALLEL_LINK_JOBS)
Chris Bieneman35c7f962016-06-08 22:38:30 +000088 if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
89 message(WARNING "Job pooling is only available with Ninja generators.")
Reid Klecknera2a07f92016-03-28 18:19:32 +000090 else()
91 set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
92 set(CMAKE_JOB_POOL_LINK link_job_pool)
93 endif()
94endif()
95
96# Add path for custom modules
97set(CMAKE_MODULE_PATH
98 ${CMAKE_MODULE_PATH}
99 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
100 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
101 )
102
103# Generate a CompilationDatabase (compile_commands.json file) for our build,
104# for use by clang_complete, YouCompleteMe, etc.
105set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
106
107option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
108
109option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
110
111option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
112if ( LLVM_USE_FOLDERS )
113 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
114endif()
115
116include(VersionFromVCS)
117
118option(LLVM_APPEND_VC_REV
119 "Append the version control system revision id to LLVM version" OFF)
120
121if( LLVM_APPEND_VC_REV )
122 add_version_info_from_vcs(PACKAGE_VERSION)
123endif()
124
125set(PACKAGE_NAME LLVM)
126set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
127set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
128
129set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
130 "Default URL where bug reports are to be submitted.")
131
132# Configure CPack.
133set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
134set(CPACK_PACKAGE_VENDOR "LLVM")
135set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
136set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
137set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
138set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
139set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
140set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
141if(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'")
152 if( CMAKE_CL_64 )
153 set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
154 endif()
155endif()
156include(CPack)
157
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
162# versions).
163if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
164 message(FATAL_ERROR "In-source builds are not allowed.
165CMake would overwrite the makefiles distributed with LLVM.
166Please create a directory and run cmake from there, passing the path
167to this source directory as the last argument.
168This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
169Please delete them.")
170endif()
171if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
172 file(GLOB_RECURSE
173 tablegenned_files_on_include_dir
174 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
175 file(GLOB_RECURSE
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,
180probably as the result of running `configure' and `make' on
181${CMAKE_CURRENT_SOURCE_DIR}.
182This may cause problems. The suspicious files are:
183${tablegenned_files_on_lib_dir}
184${tablegenned_files_on_include_dir}
185Please clean the source directory.")
186 endif()
187endif()
188
189string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
190
191if (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}")
194endif()
195
196set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
197
Chris Bieneman2724f142016-06-08 21:19:26 +0000198set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')")
199mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)
200
Reid Klecknera2a07f92016-03-28 18:19:32 +0000201# They are used as destination of target generators.
202set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
203set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
204if(WIN32 OR CYGWIN)
205 # DLL platform -- put DLLs into bin.
206 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
207else()
208 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
209endif()
210
211# Each of them corresponds to llvm-config's.
212set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
213set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
214set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
215set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
216set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
217
218set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
219set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
220
221set(LLVM_ALL_TARGETS
222 AArch64
223 AMDGPU
224 ARM
225 BPF
Reid Klecknera2a07f92016-03-28 18:19:32 +0000226 Hexagon
227 Mips
228 MSP430
229 NVPTX
230 PowerPC
231 Sparc
232 SystemZ
233 X86
234 XCore
235 )
236
237# List of targets with JIT support:
238set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
239
240set(LLVM_TARGETS_TO_BUILD "all"
241 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
242
243set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
244 CACHE STRING "Semicolon-separated list of experimental targets to build.")
245
246option(BUILD_SHARED_LIBS
247 "Build all libraries as shared libraries instead of static" OFF)
248
Reid Klecknera2a07f92016-03-28 18:19:32 +0000249option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
250if(LLVM_ENABLE_BACKTRACES)
251 set(ENABLE_BACKTRACES 1)
252endif()
253
254option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
255if(LLVM_ENABLE_CRASH_OVERRIDES)
256 set(ENABLE_CRASH_OVERRIDES 1)
257endif()
258
259option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
260set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
261set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
262
263set(LLVM_TARGET_ARCH "host"
264 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
265
266option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
267
268option(LLVM_ENABLE_THREADS "Use threads if available." ON)
269
270option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
271
272if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
273 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
274endif()
275
276set(LLVM_TARGETS_TO_BUILD
277 ${LLVM_TARGETS_TO_BUILD}
278 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
279list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
280
281include(AddLLVMDefinitions)
282
283option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
284option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
285option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
Adrian Prantl48e7cbd2016-06-30 01:46:49 +0000286if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Adrian Prantl9f4ef632016-06-30 17:15:44 +0000287 option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)
Adrian Prantl48e7cbd2016-06-30 01:46:49 +0000288 option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." OFF)
289else()
Adrian Prantl9f4ef632016-06-30 17:15:44 +0000290 option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)
Adrian Prantl48e7cbd2016-06-30 01:46:49 +0000291 option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
292endif()
Reid Klecknera2a07f92016-03-28 18:19:32 +0000293option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
294option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
295option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
296option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
297option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
298
299if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
300 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
301else()
302 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
303endif()
304
Filipe Cabecinhas0da99372016-04-29 15:22:48 +0000305option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
306
Reid Klecknera2a07f92016-03-28 18:19:32 +0000307set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
308 "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
309
310option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
311 "Set to ON to force using an old, unsupported host toolchain." OFF)
312
313option(LLVM_USE_INTEL_JITEVENTS
314 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
315 OFF)
316
317if( 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" )
320 message(FATAL_ERROR
321 "Intel JIT API support is available on Linux and Windows only.")
322 endif()
323endif( LLVM_USE_INTEL_JITEVENTS )
324
325option(LLVM_USE_OPROFILE
326 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
327
328option(LLVM_EXTERNALIZE_DEBUGINFO
329 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
330
331# If enabled, verify we are on a platform that supports oprofile.
332if( 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" )
336endif( LLVM_USE_OPROFILE )
337
338set(LLVM_USE_SANITIZER "" CACHE STRING
339 "Define the sanitizer used to build binaries and tests.")
340
341option(LLVM_USE_SPLIT_DWARF
342 "Use -gsplit-dwarf when compiling llvm." OFF)
343
Tobias Grosser3b326162016-05-04 20:04:40 +0000344option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ON)
345option(LLVM_POLLY_BUILD "Build LLVM with Polly" ON)
346
347if (EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
348 set(POLLY_IN_TREE TRUE)
349else()
350 set(POLLY_IN_TREE FALSE)
351endif()
352
353if (LLVM_POLLY_BUILD AND POLLY_IN_TREE)
354 set(WITH_POLLY ON)
355else()
356 set(WITH_POLLY OFF)
357endif()
358
359if (LLVM_POLLY_LINK_INTO_TOOLS AND WITH_POLLY)
360 set(LINK_POLLY_INTO_TOOLS ON)
361else()
362 set(LINK_POLLY_INTO_TOOLS OFF)
363endif()
Reid Klecknera2a07f92016-03-28 18:19:32 +0000364
365# Define an option controlling whether we should build for 32-bit on 64-bit
366# platforms, where supported.
367if( 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)
370endif()
371
372# Define the default arguments to use with 'lit', and an option for the user to
373# override.
374set(LIT_ARGS_DEFAULT "-sv")
375if (MSVC_IDE OR XCODE)
376 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
377endif()
378set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
379
380# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
381if( WIN32 AND NOT CYGWIN )
382 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
383endif()
384
385# Define options to control the inclusion and default build behavior for
386# components which may not strictly be necessary (tools, examples, and tests).
387#
388# This is primarily to support building smaller or faster project files.
389option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
390option(LLVM_BUILD_TOOLS
391 "Build the LLVM tools. If OFF, just generate build targets." ON)
392
393option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
394
395option(LLVM_BUILD_RUNTIME
396 "Build the LLVM runtime libraries." ON)
397option(LLVM_BUILD_EXAMPLES
398 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
399option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
400
401option(LLVM_BUILD_TESTS
402 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
403option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
404option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
405
406option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
407option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
408option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
409option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
410
411option (LLVM_BUILD_EXTERNAL_COMPILER_RT
412 "Build compiler-rt as an external project." OFF)
413
414# You can configure which libraries from LLVM you want to include in the
415# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
416# list of LLVM components. All component names handled by llvm-config are valid.
417if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
418 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
419 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
420endif()
421option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
422option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
423set(LLVM_BUILD_LLVM_DYLIB_default OFF)
424if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
425 set(LLVM_BUILD_LLVM_DYLIB_default ON)
426endif()
427option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
428
429option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
430if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
431 set(LLVM_USE_HOST_TOOLS ON)
432endif()
433
434if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900))
435 option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
436else()
437 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)
438endif()
439
Vedant Kumard9aed822016-06-13 23:33:48 +0000440if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE)
441 if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
442 # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine
443 # for spining disks. Anything higher may only help on slower mediums.
444 set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
445 endif()
446 if(NOT LLVM_PROFILE_FILE_PATTERN)
447 if(NOT LLVM_PROFILE_DATA_DIR)
448 set(LLVM_PROFILE_FILE_PATTERN "%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw")
449 else()
450 file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
451 endif()
452 endif()
453endif()
454
Reid Klecknera2a07f92016-03-28 18:19:32 +0000455# All options referred to from HandleLLVMOptions have to be specified
456# BEFORE this include, otherwise options will not be correctly set on
457# first cmake run
458include(config-ix)
459
460string(REPLACE "Native" ${LLVM_NATIVE_ARCH}
461 LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}")
462list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
463
464# By default, we target the host, but this can be overridden at CMake
465# invocation time.
466set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
467 "Default target for which LLVM will generate code." )
468set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
469
470include(HandleLLVMOptions)
471
472# Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
473# FIXME: We should support systems with only Python 3, but that requires work
474# on LLDB.
475set(Python_ADDITIONAL_VERSIONS 2.7)
476include(FindPythonInterp)
477if( NOT PYTHONINTERP_FOUND )
478 message(FATAL_ERROR
479"Unable to find Python interpreter, required for builds and testing.
480
481Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
482endif()
483
484if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
485 message(FATAL_ERROR "Python 2.7 or newer is required")
486endif()
487
488######
489# LLVMBuild Integration
490#
491# We use llvm-build to generate all the data required by the CMake based
492# build system in one swoop:
493#
494# - We generate a file (a CMake fragment) in the object root which contains
495# all the definitions that are required by CMake.
496#
497# - We generate the library table used by llvm-config.
498#
499# - We generate the dependencies for the CMake fragment, so that we will
500# automatically reconfigure outselves.
501
502set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
503set(LLVMCONFIGLIBRARYDEPENDENCIESINC
504 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
505set(LLVMBUILDCMAKEFRAG
506 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
507
508# Create the list of optional components that are enabled
509if (LLVM_USE_INTEL_JITEVENTS)
510 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
511endif (LLVM_USE_INTEL_JITEVENTS)
512if (LLVM_USE_OPROFILE)
513 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
514endif (LLVM_USE_OPROFILE)
515
516message(STATUS "Constructing LLVMBuild project information")
517execute_process(
518 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
519 --native-target "${LLVM_NATIVE_ARCH}"
520 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
521 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
522 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
523 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
524 OUTPUT_VARIABLE LLVMBUILDOUTPUT
525 ERROR_VARIABLE LLVMBUILDERRORS
526 OUTPUT_STRIP_TRAILING_WHITESPACE
527 ERROR_STRIP_TRAILING_WHITESPACE
528 RESULT_VARIABLE LLVMBUILDRESULT)
529
530# On Win32, CMake doesn't properly handle piping the default output/error
531# streams into the GUI console. So, we explicitly catch and report them.
532if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
533 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
534endif()
535if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
536 message(FATAL_ERROR
537 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
538endif()
539
540# Include the generated CMake fragment. This will define properties from the
541# LLVMBuild files in a format which is easy to consume from CMake, and will add
542# the dependencies so that CMake will reconfigure properly when the LLVMBuild
543# files change.
544include(${LLVMBUILDCMAKEFRAG})
545
546######
547
548# Configure all of the various header file fragments LLVM uses which depend on
549# configuration variables.
550set(LLVM_ENUM_TARGETS "")
551set(LLVM_ENUM_ASM_PRINTERS "")
552set(LLVM_ENUM_ASM_PARSERS "")
553set(LLVM_ENUM_DISASSEMBLERS "")
554foreach(t ${LLVM_TARGETS_TO_BUILD})
555 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
556
557 list(FIND LLVM_ALL_TARGETS ${t} idx)
558 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
559 if( idx LESS 0 AND idy LESS 0 )
560 message(FATAL_ERROR "The target `${t}' does not exist.
561 It should be one of\n${LLVM_ALL_TARGETS}")
562 else()
563 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
564 endif()
565
566 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
567 if( asmp_file )
568 set(LLVM_ENUM_ASM_PRINTERS
569 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
570 endif()
571 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
572 set(LLVM_ENUM_ASM_PARSERS
573 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
574 endif()
575 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
576 set(LLVM_ENUM_DISASSEMBLERS
577 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
578 endif()
579endforeach(t)
580
581# Produce the target definition files, which provide a way for clients to easily
582# include various classes of targets.
583configure_file(
584 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
585 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
586 )
587configure_file(
588 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
589 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
590 )
591configure_file(
592 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
593 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
594 )
595configure_file(
596 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
597 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
598 )
599
600# Configure the three LLVM configuration header files.
601configure_file(
602 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
603 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
604configure_file(
605 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
606 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
607configure_file(
608 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
609 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
610
611# They are not referenced. See set_output_directory().
612set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
613set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
614set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
615
616set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
617if (APPLE)
618 set(CMAKE_INSTALL_NAME_DIR "@rpath")
619 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
620else(UNIX)
621 if(NOT DEFINED CMAKE_INSTALL_RPATH)
622 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
623 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
624 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
625 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
626 endif()
627 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
628endif()
629
630if(APPLE AND DARWIN_LTO_LIBRARY)
631 set(CMAKE_EXE_LINKER_FLAGS
632 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
633 set(CMAKE_SHARED_LINKER_FLAGS
634 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
635 set(CMAKE_MODULE_LINKER_FLAGS
636 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
637endif()
638
639# Work around a broken bfd ld behavior. When linking a binary with a
640# foo.so library, it will try to find any library that foo.so uses and
641# check its symbols. This is wasteful (the check was done when foo.so
642# was created) and can fail since it is not the dynamic linker and
643# doesn't know how to handle search paths correctly.
644if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
645 set(CMAKE_EXE_LINKER_FLAGS
646 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
647endif()
648
649set(CMAKE_INCLUDE_CURRENT_DIR ON)
650
651include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
652
653# when crosscompiling import the executable targets from a file
654if(LLVM_USE_HOST_TOOLS)
655 include(CrossCompile)
656endif(LLVM_USE_HOST_TOOLS)
657if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
658# Dummy use to avoid CMake Wraning: Manually-specified variables were not used
659# (this is a variable that CrossCompile sets on recursive invocations)
660endif()
661
662if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
663 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
664 # with libxml2, iconv.h, etc., we must add /usr/local paths.
665 include_directories("/usr/local/include")
666 link_directories("/usr/local/lib")
667endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
668
669if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
670 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
671endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
672
673# Make sure we don't get -rdynamic in every binary. For those that need it,
674# use export_executable_symbols(target).
675set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
676
677set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
678 "Profiling data file to use when compiling in order to improve runtime performance.")
679
680if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
681 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
682 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
683 else()
684 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
685 endif()
686endif()
687
688include(AddLLVM)
689include(TableGen)
690
691if( MINGW )
692 # People report that -O3 is unreliable on MinGW. The traditional
693 # build also uses -O2 for that reason:
694 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
695endif()
696
697# Put this before tblgen. Else we have a circular dependence.
698add_subdirectory(lib/Support)
699add_subdirectory(lib/TableGen)
700
701add_subdirectory(utils/TableGen)
702
Vassil Vassilev488b3bd2016-06-30 20:35:56 +0000703# Force target to be built as soon as possible. Clang modules builds depend
704# header-wise on it as they ship all headers from the umbrella folders. Building
705# an entire module might include header, which depends on intrinsics_gen. This
706# should be right after LLVMSupport and LLVMTableGen otherwise we introduce a
707# circular dependence.
708if (LLVM_ENABLE_MODULES)
709 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
710endif(LLVM_ENABLE_MODULES)
711
Reid Klecknera2a07f92016-03-28 18:19:32 +0000712add_subdirectory(include/llvm)
713
714add_subdirectory(lib)
715
716if( LLVM_INCLUDE_UTILS )
717 add_subdirectory(utils/FileCheck)
718 add_subdirectory(utils/PerfectShuffle)
719 add_subdirectory(utils/count)
720 add_subdirectory(utils/not)
721 add_subdirectory(utils/llvm-lit)
722 add_subdirectory(utils/yaml-bench)
723else()
724 if ( LLVM_INCLUDE_TESTS )
725 message(FATAL_ERROR "Including tests when not building utils will not work.
726 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
727 endif()
728endif()
729
730# Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
731if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
732 add_subdirectory(utils/LLVMVisualizers)
733endif()
734
735if(LLVM_INCLUDE_TESTS)
736 add_subdirectory(utils/unittest)
737endif()
738
739foreach( binding ${LLVM_BINDINGS_LIST} )
740 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
741 add_subdirectory(bindings/${binding})
742 endif()
743endforeach()
744
745add_subdirectory(projects)
746
Reid Klecknera2a07f92016-03-28 18:19:32 +0000747if( LLVM_INCLUDE_TOOLS )
748 add_subdirectory(tools)
749endif()
750
Chris Bieneman64adae52016-06-23 22:07:21 +0000751add_subdirectory(runtimes)
752
Reid Klecknera2a07f92016-03-28 18:19:32 +0000753if( LLVM_INCLUDE_EXAMPLES )
754 add_subdirectory(examples)
755endif()
756
757if( LLVM_INCLUDE_TESTS )
758 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
759 include(LLVMExternalProjectUtils)
760 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
761 USE_TOOLCHAIN
762 EXCLUDE_FROM_ALL
Chris Bieneman64adae52016-06-23 22:07:21 +0000763 NO_INSTALL
764 ALWAYS_CLEAN)
Reid Klecknera2a07f92016-03-28 18:19:32 +0000765 endif()
766 add_subdirectory(test)
767 add_subdirectory(unittests)
768 if (MSVC)
769 # This utility is used to prevent crashing tests from calling Dr. Watson on
770 # Windows.
771 add_subdirectory(utils/KillTheDoctor)
772 endif()
773
774 # Add a global check rule now that all subdirectories have been traversed
775 # and we know the total set of lit testsuites.
776 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
777 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
778 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
779 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
780 add_lit_target(check-all
781 "Running all regression tests"
782 ${LLVM_LIT_TESTSUITES}
783 PARAMS ${LLVM_LIT_PARAMS}
784 DEPENDS ${LLVM_LIT_DEPENDS}
785 ARGS ${LLVM_LIT_EXTRA_ARGS}
786 )
787 add_custom_target(test-depends DEPENDS ${LLVM_LIT_DEPENDS})
Aaron Ballman01a98542016-04-12 15:09:14 +0000788 set_target_properties(test-depends PROPERTIES FOLDER "Tests")
Reid Klecknera2a07f92016-03-28 18:19:32 +0000789endif()
790
791if (LLVM_INCLUDE_DOCS)
792 add_subdirectory(docs)
793endif()
794
795add_subdirectory(cmake/modules)
796
797if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
798 install(DIRECTORY include/llvm include/llvm-c
799 DESTINATION include
800 COMPONENT llvm-headers
801 FILES_MATCHING
802 PATTERN "*.def"
803 PATTERN "*.h"
804 PATTERN "*.td"
805 PATTERN "*.inc"
806 PATTERN "LICENSE.TXT"
807 PATTERN ".svn" EXCLUDE
808 )
809
810 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
811 DESTINATION include
812 COMPONENT llvm-headers
813 FILES_MATCHING
814 PATTERN "*.def"
815 PATTERN "*.h"
816 PATTERN "*.gen"
817 PATTERN "*.inc"
818 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
819 PATTERN "CMakeFiles" EXCLUDE
820 PATTERN "config.h" EXCLUDE
821 PATTERN ".svn" EXCLUDE
822 )
823
824 if (NOT CMAKE_CONFIGURATION_TYPES)
825 add_custom_target(installhdrs
826 DEPENDS ${name}
827 COMMAND "${CMAKE_COMMAND}"
828 -DCMAKE_INSTALL_COMPONENT=llvm-headers
829 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
830 endif()
831endif()
832
833# This must be at the end of the LLVM root CMakeLists file because it must run
834# after all targets are created.
835if(LLVM_DISTRIBUTION_COMPONENTS)
836 if(CMAKE_CONFIGURATION_TYPES)
837 message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)")
838 endif()
839
840 add_custom_target(distribution)
841 add_custom_target(install-distribution)
842 foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})
843 if(TARGET ${target})
844 add_dependencies(distribution ${target})
845 else()
846 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have a target")
847 endif()
848
849 if(TARGET install-${target})
850 add_dependencies(install-distribution install-${target})
851 else()
852 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target")
853 endif()
854 endforeach()
855endif()