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