blob: f4b05e8586d3e81fcd8b49dcc6388d6c6ee51ad4 [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)
Hans Wennborgc714d7c2016-07-18 17:51:04 +000024 set(LLVM_VERSION_MAJOR 4)
Reid Klecknera2a07f92016-03-28 18:19:32 +000025endif()
26if(NOT DEFINED LLVM_VERSION_MINOR)
Hans Wennborgc714d7c2016-07-18 17:51:04 +000027 set(LLVM_VERSION_MINOR 0)
Reid Klecknera2a07f92016-03-28 18:19:32 +000028endif()
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
Quentin Colombetc8df88c2016-07-21 17:26:45 +000080option(LLVM_BUILD_GLOBAL_ISEL "Experimental: Build GlobalISel" OFF)
Reid Klecknera2a07f92016-03-28 18:19:32 +000081if(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)
Michael Gottesmanbe5b7872016-07-10 02:43:47 +0000394option(LLVM_BUILD_UTILS
395 "Build LLVM utility binaries. If OFF, just generate build targets." ON)
Reid Klecknera2a07f92016-03-28 18:19:32 +0000396
397option(LLVM_BUILD_RUNTIME
398 "Build the LLVM runtime libraries." ON)
399option(LLVM_BUILD_EXAMPLES
400 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
401option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
402
403option(LLVM_BUILD_TESTS
404 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
405option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
406option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
407
408option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
409option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
410option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
411option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
412
413option (LLVM_BUILD_EXTERNAL_COMPILER_RT
414 "Build compiler-rt as an external project." OFF)
415
416# You can configure which libraries from LLVM you want to include in the
417# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
418# list of LLVM components. All component names handled by llvm-config are valid.
419if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
420 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
421 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
422endif()
423option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
424option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
425set(LLVM_BUILD_LLVM_DYLIB_default OFF)
426if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
427 set(LLVM_BUILD_LLVM_DYLIB_default ON)
428endif()
429option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
430
431option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
432if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
433 set(LLVM_USE_HOST_TOOLS ON)
434endif()
435
436if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900))
437 option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
438else()
439 set(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION FALSE CACHE INTERNAL "For Visual Studio 2013, manually copy natvis files to Documents\\Visual Studio 2013\\Visualizers" FORCE)
440endif()
441
Vedant Kumard9aed822016-06-13 23:33:48 +0000442if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE)
443 if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
444 # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine
445 # for spining disks. Anything higher may only help on slower mediums.
446 set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
447 endif()
448 if(NOT LLVM_PROFILE_FILE_PATTERN)
449 if(NOT LLVM_PROFILE_DATA_DIR)
Vedant Kumar401d0312016-07-23 00:38:11 +0000450 file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
Vedant Kumard9aed822016-06-13 23:33:48 +0000451 else()
452 file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
453 endif()
454 endif()
455endif()
456
Reid Klecknera2a07f92016-03-28 18:19:32 +0000457# All options referred to from HandleLLVMOptions have to be specified
458# BEFORE this include, otherwise options will not be correctly set on
459# first cmake run
460include(config-ix)
461
462string(REPLACE "Native" ${LLVM_NATIVE_ARCH}
463 LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}")
464list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
465
466# By default, we target the host, but this can be overridden at CMake
467# invocation time.
468set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
469 "Default target for which LLVM will generate code." )
470set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
471
472include(HandleLLVMOptions)
473
474# Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
475# FIXME: We should support systems with only Python 3, but that requires work
476# on LLDB.
477set(Python_ADDITIONAL_VERSIONS 2.7)
478include(FindPythonInterp)
479if( NOT PYTHONINTERP_FOUND )
480 message(FATAL_ERROR
481"Unable to find Python interpreter, required for builds and testing.
482
483Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
484endif()
485
486if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
487 message(FATAL_ERROR "Python 2.7 or newer is required")
488endif()
489
490######
491# LLVMBuild Integration
492#
493# We use llvm-build to generate all the data required by the CMake based
494# build system in one swoop:
495#
496# - We generate a file (a CMake fragment) in the object root which contains
497# all the definitions that are required by CMake.
498#
499# - We generate the library table used by llvm-config.
500#
501# - We generate the dependencies for the CMake fragment, so that we will
502# automatically reconfigure outselves.
503
504set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
505set(LLVMCONFIGLIBRARYDEPENDENCIESINC
506 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
507set(LLVMBUILDCMAKEFRAG
508 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
509
510# Create the list of optional components that are enabled
511if (LLVM_USE_INTEL_JITEVENTS)
512 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
513endif (LLVM_USE_INTEL_JITEVENTS)
514if (LLVM_USE_OPROFILE)
515 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
516endif (LLVM_USE_OPROFILE)
517
518message(STATUS "Constructing LLVMBuild project information")
519execute_process(
520 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
521 --native-target "${LLVM_NATIVE_ARCH}"
522 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
523 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
524 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
525 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
526 OUTPUT_VARIABLE LLVMBUILDOUTPUT
527 ERROR_VARIABLE LLVMBUILDERRORS
528 OUTPUT_STRIP_TRAILING_WHITESPACE
529 ERROR_STRIP_TRAILING_WHITESPACE
530 RESULT_VARIABLE LLVMBUILDRESULT)
531
532# On Win32, CMake doesn't properly handle piping the default output/error
533# streams into the GUI console. So, we explicitly catch and report them.
534if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
535 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
536endif()
537if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
538 message(FATAL_ERROR
539 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
540endif()
541
542# Include the generated CMake fragment. This will define properties from the
543# LLVMBuild files in a format which is easy to consume from CMake, and will add
544# the dependencies so that CMake will reconfigure properly when the LLVMBuild
545# files change.
546include(${LLVMBUILDCMAKEFRAG})
547
548######
549
550# Configure all of the various header file fragments LLVM uses which depend on
551# configuration variables.
552set(LLVM_ENUM_TARGETS "")
553set(LLVM_ENUM_ASM_PRINTERS "")
554set(LLVM_ENUM_ASM_PARSERS "")
555set(LLVM_ENUM_DISASSEMBLERS "")
556foreach(t ${LLVM_TARGETS_TO_BUILD})
557 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
558
559 list(FIND LLVM_ALL_TARGETS ${t} idx)
560 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
561 if( idx LESS 0 AND idy LESS 0 )
562 message(FATAL_ERROR "The target `${t}' does not exist.
563 It should be one of\n${LLVM_ALL_TARGETS}")
564 else()
565 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
566 endif()
567
568 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
569 if( asmp_file )
570 set(LLVM_ENUM_ASM_PRINTERS
571 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
572 endif()
573 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
574 set(LLVM_ENUM_ASM_PARSERS
575 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
576 endif()
577 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
578 set(LLVM_ENUM_DISASSEMBLERS
579 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
580 endif()
581endforeach(t)
582
583# Produce the target definition files, which provide a way for clients to easily
584# include various classes of targets.
585configure_file(
586 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
587 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
588 )
589configure_file(
590 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
591 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
592 )
593configure_file(
594 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
595 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
596 )
597configure_file(
598 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
599 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
600 )
601
602# Configure the three LLVM configuration header files.
603configure_file(
604 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
605 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
606configure_file(
607 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
608 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
609configure_file(
610 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
611 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
612
613# They are not referenced. See set_output_directory().
614set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
615set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
616set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
617
618set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
619if (APPLE)
620 set(CMAKE_INSTALL_NAME_DIR "@rpath")
621 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
622else(UNIX)
623 if(NOT DEFINED CMAKE_INSTALL_RPATH)
624 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
625 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
626 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
627 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
628 endif()
629 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
630endif()
631
632if(APPLE AND DARWIN_LTO_LIBRARY)
633 set(CMAKE_EXE_LINKER_FLAGS
634 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
635 set(CMAKE_SHARED_LINKER_FLAGS
636 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
637 set(CMAKE_MODULE_LINKER_FLAGS
638 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
639endif()
640
641# Work around a broken bfd ld behavior. When linking a binary with a
642# foo.so library, it will try to find any library that foo.so uses and
643# check its symbols. This is wasteful (the check was done when foo.so
644# was created) and can fail since it is not the dynamic linker and
645# doesn't know how to handle search paths correctly.
Chandler Carruth2aff7502016-07-19 22:46:39 +0000646if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS|AIX")
Reid Klecknera2a07f92016-03-28 18:19:32 +0000647 set(CMAKE_EXE_LINKER_FLAGS
648 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
649endif()
650
651set(CMAKE_INCLUDE_CURRENT_DIR ON)
652
653include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
654
655# when crosscompiling import the executable targets from a file
656if(LLVM_USE_HOST_TOOLS)
657 include(CrossCompile)
658endif(LLVM_USE_HOST_TOOLS)
659if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
660# Dummy use to avoid CMake Wraning: Manually-specified variables were not used
661# (this is a variable that CrossCompile sets on recursive invocations)
662endif()
663
664if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
665 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
666 # with libxml2, iconv.h, etc., we must add /usr/local paths.
667 include_directories("/usr/local/include")
668 link_directories("/usr/local/lib")
669endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
670
671if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
672 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
673endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
674
675# Make sure we don't get -rdynamic in every binary. For those that need it,
676# use export_executable_symbols(target).
677set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
678
679set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
680 "Profiling data file to use when compiling in order to improve runtime performance.")
681
682if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
683 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
684 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
685 else()
686 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
687 endif()
688endif()
689
690include(AddLLVM)
691include(TableGen)
692
693if( MINGW )
694 # People report that -O3 is unreliable on MinGW. The traditional
695 # build also uses -O2 for that reason:
696 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
697endif()
698
699# Put this before tblgen. Else we have a circular dependence.
700add_subdirectory(lib/Support)
701add_subdirectory(lib/TableGen)
702
703add_subdirectory(utils/TableGen)
704
Vassil Vassilev488b3bd2016-06-30 20:35:56 +0000705# Force target to be built as soon as possible. Clang modules builds depend
706# header-wise on it as they ship all headers from the umbrella folders. Building
707# an entire module might include header, which depends on intrinsics_gen. This
708# should be right after LLVMSupport and LLVMTableGen otherwise we introduce a
709# circular dependence.
710if (LLVM_ENABLE_MODULES)
711 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
712endif(LLVM_ENABLE_MODULES)
713
Reid Klecknera2a07f92016-03-28 18:19:32 +0000714add_subdirectory(include/llvm)
715
716add_subdirectory(lib)
717
718if( LLVM_INCLUDE_UTILS )
719 add_subdirectory(utils/FileCheck)
720 add_subdirectory(utils/PerfectShuffle)
721 add_subdirectory(utils/count)
722 add_subdirectory(utils/not)
723 add_subdirectory(utils/llvm-lit)
724 add_subdirectory(utils/yaml-bench)
Michael Gottesman66ddd152016-07-21 21:35:23 +0000725 add_subdirectory(utils/unittest)
Reid Klecknera2a07f92016-03-28 18:19:32 +0000726else()
727 if ( LLVM_INCLUDE_TESTS )
728 message(FATAL_ERROR "Including tests when not building utils will not work.
729 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
730 endif()
731endif()
732
733# Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
734if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
735 add_subdirectory(utils/LLVMVisualizers)
736endif()
737
Reid Klecknera2a07f92016-03-28 18:19:32 +0000738foreach( binding ${LLVM_BINDINGS_LIST} )
739 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
740 add_subdirectory(bindings/${binding})
741 endif()
742endforeach()
743
744add_subdirectory(projects)
745
Reid Klecknera2a07f92016-03-28 18:19:32 +0000746if( LLVM_INCLUDE_TOOLS )
747 add_subdirectory(tools)
748endif()
749
Chris Bieneman64adae52016-06-23 22:07:21 +0000750add_subdirectory(runtimes)
751
Reid Klecknera2a07f92016-03-28 18:19:32 +0000752if( LLVM_INCLUDE_EXAMPLES )
753 add_subdirectory(examples)
754endif()
755
756if( LLVM_INCLUDE_TESTS )
757 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
758 include(LLVMExternalProjectUtils)
759 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
760 USE_TOOLCHAIN
761 EXCLUDE_FROM_ALL
Chris Bieneman64adae52016-06-23 22:07:21 +0000762 NO_INSTALL
763 ALWAYS_CLEAN)
Reid Klecknera2a07f92016-03-28 18:19:32 +0000764 endif()
765 add_subdirectory(test)
766 add_subdirectory(unittests)
767 if (MSVC)
768 # This utility is used to prevent crashing tests from calling Dr. Watson on
769 # Windows.
770 add_subdirectory(utils/KillTheDoctor)
771 endif()
772
773 # Add a global check rule now that all subdirectories have been traversed
774 # and we know the total set of lit testsuites.
775 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
776 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
777 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
778 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
779 add_lit_target(check-all
780 "Running all regression tests"
781 ${LLVM_LIT_TESTSUITES}
782 PARAMS ${LLVM_LIT_PARAMS}
783 DEPENDS ${LLVM_LIT_DEPENDS}
784 ARGS ${LLVM_LIT_EXTRA_ARGS}
785 )
786 add_custom_target(test-depends DEPENDS ${LLVM_LIT_DEPENDS})
Aaron Ballman01a98542016-04-12 15:09:14 +0000787 set_target_properties(test-depends PROPERTIES FOLDER "Tests")
Reid Klecknera2a07f92016-03-28 18:19:32 +0000788endif()
789
790if (LLVM_INCLUDE_DOCS)
791 add_subdirectory(docs)
792endif()
793
794add_subdirectory(cmake/modules)
795
796if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
797 install(DIRECTORY include/llvm include/llvm-c
798 DESTINATION include
799 COMPONENT llvm-headers
800 FILES_MATCHING
801 PATTERN "*.def"
802 PATTERN "*.h"
803 PATTERN "*.td"
804 PATTERN "*.inc"
805 PATTERN "LICENSE.TXT"
806 PATTERN ".svn" EXCLUDE
807 )
808
809 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
810 DESTINATION include
811 COMPONENT llvm-headers
812 FILES_MATCHING
813 PATTERN "*.def"
814 PATTERN "*.h"
815 PATTERN "*.gen"
816 PATTERN "*.inc"
817 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
818 PATTERN "CMakeFiles" EXCLUDE
819 PATTERN "config.h" EXCLUDE
820 PATTERN ".svn" EXCLUDE
821 )
822
823 if (NOT CMAKE_CONFIGURATION_TYPES)
824 add_custom_target(installhdrs
825 DEPENDS ${name}
826 COMMAND "${CMAKE_COMMAND}"
827 -DCMAKE_INSTALL_COMPONENT=llvm-headers
828 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
829 endif()
830endif()
831
832# This must be at the end of the LLVM root CMakeLists file because it must run
833# after all targets are created.
834if(LLVM_DISTRIBUTION_COMPONENTS)
835 if(CMAKE_CONFIGURATION_TYPES)
836 message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)")
837 endif()
838
839 add_custom_target(distribution)
840 add_custom_target(install-distribution)
841 foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})
842 if(TARGET ${target})
843 add_dependencies(distribution ${target})
844 else()
845 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have a target")
846 endif()
847
848 if(TARGET install-${target})
849 add_dependencies(install-distribution install-${target})
850 else()
851 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target")
852 endif()
853 endforeach()
854endif()