blob: 771bce1f15262fb7209735c8616763d71d17774e [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
307set(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
344option(WITH_POLLY "Build LLVM with Polly" ON)
Tobias Grosserda2998482016-04-29 12:38:24 +0000345option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
Reid Klecknera2a07f92016-03-28 18:19:32 +0000346
347# Define an option controlling whether we should build for 32-bit on 64-bit
348# platforms, where supported.
349if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
350 # TODO: support other platforms and toolchains.
351 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
352endif()
353
354# Define the default arguments to use with 'lit', and an option for the user to
355# override.
356set(LIT_ARGS_DEFAULT "-sv")
357if (MSVC_IDE OR XCODE)
358 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
359endif()
360set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
361
362# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
363if( WIN32 AND NOT CYGWIN )
364 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
365endif()
366
367# Define options to control the inclusion and default build behavior for
368# components which may not strictly be necessary (tools, examples, and tests).
369#
370# This is primarily to support building smaller or faster project files.
371option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
372option(LLVM_BUILD_TOOLS
373 "Build the LLVM tools. If OFF, just generate build targets." ON)
374
375option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
376
377option(LLVM_BUILD_RUNTIME
378 "Build the LLVM runtime libraries." ON)
379option(LLVM_BUILD_EXAMPLES
380 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
381option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
382
383option(LLVM_BUILD_TESTS
384 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
385option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
386option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
387
388option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
389option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
390option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
391option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
392
393option (LLVM_BUILD_EXTERNAL_COMPILER_RT
394 "Build compiler-rt as an external project." OFF)
395
396# You can configure which libraries from LLVM you want to include in the
397# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
398# list of LLVM components. All component names handled by llvm-config are valid.
399if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
400 set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
401 "Semicolon-separated list of components to include in libLLVM, or \"all\".")
402endif()
403option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
404option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
405set(LLVM_BUILD_LLVM_DYLIB_default OFF)
406if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
407 set(LLVM_BUILD_LLVM_DYLIB_default ON)
408endif()
409option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
410
411option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
412if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
413 set(LLVM_USE_HOST_TOOLS ON)
414endif()
415
416if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900))
417 option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
418else()
419 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)
420endif()
421
422# All options referred to from HandleLLVMOptions have to be specified
423# BEFORE this include, otherwise options will not be correctly set on
424# first cmake run
425include(config-ix)
426
427string(REPLACE "Native" ${LLVM_NATIVE_ARCH}
428 LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}")
429list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
430
431# By default, we target the host, but this can be overridden at CMake
432# invocation time.
433set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
434 "Default target for which LLVM will generate code." )
435set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
436
437include(HandleLLVMOptions)
438
439# Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
440# FIXME: We should support systems with only Python 3, but that requires work
441# on LLDB.
442set(Python_ADDITIONAL_VERSIONS 2.7)
443include(FindPythonInterp)
444if( NOT PYTHONINTERP_FOUND )
445 message(FATAL_ERROR
446"Unable to find Python interpreter, required for builds and testing.
447
448Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
449endif()
450
451if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
452 message(FATAL_ERROR "Python 2.7 or newer is required")
453endif()
454
455######
456# LLVMBuild Integration
457#
458# We use llvm-build to generate all the data required by the CMake based
459# build system in one swoop:
460#
461# - We generate a file (a CMake fragment) in the object root which contains
462# all the definitions that are required by CMake.
463#
464# - We generate the library table used by llvm-config.
465#
466# - We generate the dependencies for the CMake fragment, so that we will
467# automatically reconfigure outselves.
468
469set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
470set(LLVMCONFIGLIBRARYDEPENDENCIESINC
471 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
472set(LLVMBUILDCMAKEFRAG
473 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
474
475# Create the list of optional components that are enabled
476if (LLVM_USE_INTEL_JITEVENTS)
477 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
478endif (LLVM_USE_INTEL_JITEVENTS)
479if (LLVM_USE_OPROFILE)
480 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
481endif (LLVM_USE_OPROFILE)
482
483message(STATUS "Constructing LLVMBuild project information")
484execute_process(
485 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
486 --native-target "${LLVM_NATIVE_ARCH}"
487 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
488 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
489 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
490 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
491 OUTPUT_VARIABLE LLVMBUILDOUTPUT
492 ERROR_VARIABLE LLVMBUILDERRORS
493 OUTPUT_STRIP_TRAILING_WHITESPACE
494 ERROR_STRIP_TRAILING_WHITESPACE
495 RESULT_VARIABLE LLVMBUILDRESULT)
496
497# On Win32, CMake doesn't properly handle piping the default output/error
498# streams into the GUI console. So, we explicitly catch and report them.
499if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
500 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
501endif()
502if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
503 message(FATAL_ERROR
504 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
505endif()
506
507# Include the generated CMake fragment. This will define properties from the
508# LLVMBuild files in a format which is easy to consume from CMake, and will add
509# the dependencies so that CMake will reconfigure properly when the LLVMBuild
510# files change.
511include(${LLVMBUILDCMAKEFRAG})
512
513######
514
515# Configure all of the various header file fragments LLVM uses which depend on
516# configuration variables.
517set(LLVM_ENUM_TARGETS "")
518set(LLVM_ENUM_ASM_PRINTERS "")
519set(LLVM_ENUM_ASM_PARSERS "")
520set(LLVM_ENUM_DISASSEMBLERS "")
521foreach(t ${LLVM_TARGETS_TO_BUILD})
522 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
523
524 list(FIND LLVM_ALL_TARGETS ${t} idx)
525 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
526 if( idx LESS 0 AND idy LESS 0 )
527 message(FATAL_ERROR "The target `${t}' does not exist.
528 It should be one of\n${LLVM_ALL_TARGETS}")
529 else()
530 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
531 endif()
532
533 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
534 if( asmp_file )
535 set(LLVM_ENUM_ASM_PRINTERS
536 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
537 endif()
538 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
539 set(LLVM_ENUM_ASM_PARSERS
540 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
541 endif()
542 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
543 set(LLVM_ENUM_DISASSEMBLERS
544 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
545 endif()
546endforeach(t)
547
548# Produce the target definition files, which provide a way for clients to easily
549# include various classes of targets.
550configure_file(
551 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
552 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
553 )
554configure_file(
555 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
556 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
557 )
558configure_file(
559 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
560 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
561 )
562configure_file(
563 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
564 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
565 )
566
567# Configure the three LLVM configuration header files.
568configure_file(
569 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
570 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
571configure_file(
572 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
573 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
574configure_file(
575 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
576 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
577
578# They are not referenced. See set_output_directory().
579set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
580set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
581set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
582
583set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
584if (APPLE)
585 set(CMAKE_INSTALL_NAME_DIR "@rpath")
586 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
587else(UNIX)
588 if(NOT DEFINED CMAKE_INSTALL_RPATH)
589 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
590 if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
591 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
592 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
593 endif()
594 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
595endif()
596
597if(APPLE AND DARWIN_LTO_LIBRARY)
598 set(CMAKE_EXE_LINKER_FLAGS
599 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
600 set(CMAKE_SHARED_LINKER_FLAGS
601 "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
602 set(CMAKE_MODULE_LINKER_FLAGS
603 "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
604endif()
605
606# Work around a broken bfd ld behavior. When linking a binary with a
607# foo.so library, it will try to find any library that foo.so uses and
608# check its symbols. This is wasteful (the check was done when foo.so
609# was created) and can fail since it is not the dynamic linker and
610# doesn't know how to handle search paths correctly.
611if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
612 set(CMAKE_EXE_LINKER_FLAGS
613 "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
614endif()
615
616set(CMAKE_INCLUDE_CURRENT_DIR ON)
617
618include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
619
620# when crosscompiling import the executable targets from a file
621if(LLVM_USE_HOST_TOOLS)
622 include(CrossCompile)
623endif(LLVM_USE_HOST_TOOLS)
624if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
625# Dummy use to avoid CMake Wraning: Manually-specified variables were not used
626# (this is a variable that CrossCompile sets on recursive invocations)
627endif()
628
629if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
630 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
631 # with libxml2, iconv.h, etc., we must add /usr/local paths.
632 include_directories("/usr/local/include")
633 link_directories("/usr/local/lib")
634endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
635
636if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
637 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
638endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
639
640# Make sure we don't get -rdynamic in every binary. For those that need it,
641# use export_executable_symbols(target).
642set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
643
644set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
645 "Profiling data file to use when compiling in order to improve runtime performance.")
646
647if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
648 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
649 add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
650 else()
651 message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
652 endif()
653endif()
654
655include(AddLLVM)
656include(TableGen)
657
658if( MINGW )
659 # People report that -O3 is unreliable on MinGW. The traditional
660 # build also uses -O2 for that reason:
661 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
662endif()
663
664# Put this before tblgen. Else we have a circular dependence.
665add_subdirectory(lib/Support)
666add_subdirectory(lib/TableGen)
667
668add_subdirectory(utils/TableGen)
669
670add_subdirectory(include/llvm)
671
672add_subdirectory(lib)
673
674if( LLVM_INCLUDE_UTILS )
675 add_subdirectory(utils/FileCheck)
676 add_subdirectory(utils/PerfectShuffle)
677 add_subdirectory(utils/count)
678 add_subdirectory(utils/not)
679 add_subdirectory(utils/llvm-lit)
680 add_subdirectory(utils/yaml-bench)
681else()
682 if ( LLVM_INCLUDE_TESTS )
683 message(FATAL_ERROR "Including tests when not building utils will not work.
684 Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
685 endif()
686endif()
687
688# Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
689if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
690 add_subdirectory(utils/LLVMVisualizers)
691endif()
692
693if(LLVM_INCLUDE_TESTS)
694 add_subdirectory(utils/unittest)
695endif()
696
697foreach( binding ${LLVM_BINDINGS_LIST} )
698 if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
699 add_subdirectory(bindings/${binding})
700 endif()
701endforeach()
702
703add_subdirectory(projects)
704
705if(WITH_POLLY)
706 if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
707 set(WITH_POLLY OFF)
708 endif()
709endif(WITH_POLLY)
710
711if( LLVM_INCLUDE_TOOLS )
712 add_subdirectory(tools)
713endif()
714
715if( LLVM_INCLUDE_EXAMPLES )
716 add_subdirectory(examples)
717endif()
718
719if( LLVM_INCLUDE_TESTS )
720 if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
721 include(LLVMExternalProjectUtils)
722 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
723 USE_TOOLCHAIN
724 EXCLUDE_FROM_ALL
725 NO_INSTALL)
726 endif()
727 add_subdirectory(test)
728 add_subdirectory(unittests)
729 if (MSVC)
730 # This utility is used to prevent crashing tests from calling Dr. Watson on
731 # Windows.
732 add_subdirectory(utils/KillTheDoctor)
733 endif()
734
735 # Add a global check rule now that all subdirectories have been traversed
736 # and we know the total set of lit testsuites.
737 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
738 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
739 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
740 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
741 add_lit_target(check-all
742 "Running all regression tests"
743 ${LLVM_LIT_TESTSUITES}
744 PARAMS ${LLVM_LIT_PARAMS}
745 DEPENDS ${LLVM_LIT_DEPENDS}
746 ARGS ${LLVM_LIT_EXTRA_ARGS}
747 )
748 add_custom_target(test-depends DEPENDS ${LLVM_LIT_DEPENDS})
Aaron Ballman01a98542016-04-12 15:09:14 +0000749 set_target_properties(test-depends PROPERTIES FOLDER "Tests")
Reid Klecknera2a07f92016-03-28 18:19:32 +0000750endif()
751
752if (LLVM_INCLUDE_DOCS)
753 add_subdirectory(docs)
754endif()
755
756add_subdirectory(cmake/modules)
757
758if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
759 install(DIRECTORY include/llvm include/llvm-c
760 DESTINATION include
761 COMPONENT llvm-headers
762 FILES_MATCHING
763 PATTERN "*.def"
764 PATTERN "*.h"
765 PATTERN "*.td"
766 PATTERN "*.inc"
767 PATTERN "LICENSE.TXT"
768 PATTERN ".svn" EXCLUDE
769 )
770
771 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
772 DESTINATION include
773 COMPONENT llvm-headers
774 FILES_MATCHING
775 PATTERN "*.def"
776 PATTERN "*.h"
777 PATTERN "*.gen"
778 PATTERN "*.inc"
779 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
780 PATTERN "CMakeFiles" EXCLUDE
781 PATTERN "config.h" EXCLUDE
782 PATTERN ".svn" EXCLUDE
783 )
784
785 if (NOT CMAKE_CONFIGURATION_TYPES)
786 add_custom_target(installhdrs
787 DEPENDS ${name}
788 COMMAND "${CMAKE_COMMAND}"
789 -DCMAKE_INSTALL_COMPONENT=llvm-headers
790 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
791 endif()
792endif()
793
794# This must be at the end of the LLVM root CMakeLists file because it must run
795# after all targets are created.
796if(LLVM_DISTRIBUTION_COMPONENTS)
797 if(CMAKE_CONFIGURATION_TYPES)
798 message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)")
799 endif()
800
801 add_custom_target(distribution)
802 add_custom_target(install-distribution)
803 foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})
804 if(TARGET ${target})
805 add_dependencies(distribution ${target})
806 else()
807 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have a target")
808 endif()
809
810 if(TARGET install-${target})
811 add_dependencies(install-distribution install-${target})
812 else()
813 message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target")
814 endif()
815 endforeach()
816endif()