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