blob: 122c47d4a81ffe1262214108a2461afcab5c99b4 [file] [log] [blame]
Oscar Fuentesfff33a32009-04-04 22:52:02 +00001# See docs/CMake.html for instructions about how to build LLVM with CMake.
2
Chandler Carruth5aad86a2014-01-13 22:05:20 +00003cmake_minimum_required(VERSION 2.8.8)
NAKAMURA Takumi85d65ff2014-02-02 16:59:36 +00004project(LLVM)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +00005
Oscar Fuentes052c23c2010-08-03 17:28:09 +00006# Add path for custom modules
7set(CMAKE_MODULE_PATH
8 ${CMAKE_MODULE_PATH}
9 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
10 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
11 )
12
Dylan Noblesmithc6c7a582012-02-13 18:48:10 +000013set(LLVM_VERSION_MAJOR 3)
NAKAMURA Takumia5997c42013-11-20 13:11:48 +000014set(LLVM_VERSION_MINOR 5)
Dylan Noblesmithc6c7a582012-02-13 18:48:10 +000015
Hans Wennborg09d108b2013-11-21 22:47:21 +000016if (NOT PACKAGE_VERSION)
17 set(PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}svn")
18endif()
Oscar Fuentes70640352010-12-20 09:47:13 +000019
Hans Wennborg16546272013-08-24 00:20:36 +000020option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
21
Manuel Klimek13cfa002012-05-09 15:10:54 +000022option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
23if ( LLVM_USE_FOLDERS )
24 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
25endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +000026
Oscar Fuentes052c23c2010-08-03 17:28:09 +000027include(VersionFromVCS)
Oscar Fuentes70640352010-12-20 09:47:13 +000028
29option(LLVM_APPEND_VC_REV
30 "Append the version control system revision id to LLVM version" OFF)
31
32if( LLVM_APPEND_VC_REV )
33 add_version_info_from_vcs(PACKAGE_VERSION)
34endif()
Oscar Fuentes052c23c2010-08-03 17:28:09 +000035
Dylan Noblesmith67c49702011-12-18 18:50:16 +000036set(PACKAGE_NAME LLVM)
Chris Lattnerff2d99d2009-01-28 17:49:03 +000037set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Dylan Noblesmith67c49702011-12-18 18:50:16 +000038set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000039
NAKAMURA Takumif0a1ab82014-01-13 05:25:13 +000040set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
41 "Default URL where bug reports are to be submitted.")
42
Reid Klecknerc974f092013-08-29 22:09:43 +000043# Configure CPack.
Hans Wennborg09d108b2013-11-21 22:47:21 +000044set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
Reid Klecknerc974f092013-08-29 22:09:43 +000045set(CPACK_PACKAGE_VENDOR "LLVM")
46set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
47set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
Hans Wennborg09d108b2013-11-21 22:47:21 +000048set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
Reid Klecknerc974f092013-08-29 22:09:43 +000049set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
50if(WIN32 AND NOT UNIX)
Hans Wennborg09d108b2013-11-21 22:47:21 +000051 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
Reid Klecknerc974f092013-08-29 22:09:43 +000052 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
53 set(CPACK_NSIS_MODIFY_PATH "ON")
54 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
55 set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
56 "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
57 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
58 "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
59endif()
60include(CPack)
61
Daniel Dunbarad3946a2011-11-04 19:04:39 +000062# Sanity check our source directory to make sure that we are not trying to
63# generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
64# sure that we don't have any stray generated files lying around in the tree
65# (which would end up getting picked up by header search, instead of the correct
66# versions).
Oscar Fuentesa5f83562008-11-14 03:43:18 +000067if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
68 message(FATAL_ERROR "In-source builds are not allowed.
69CMake would overwrite the makefiles distributed with LLVM.
70Please create a directory and run cmake from there, passing the path
71to this source directory as the last argument.
72This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
73Please delete them.")
74endif()
Daniel Dunbarad3946a2011-11-04 19:04:39 +000075if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
76 file(GLOB_RECURSE
77 tablegenned_files_on_include_dir
78 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
79 file(GLOB_RECURSE
80 tablegenned_files_on_lib_dir
81 "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
82 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
83 message(FATAL_ERROR "Apparently there is a previous in-source build,
84probably as the result of running `configure' and `make' on
85${CMAKE_CURRENT_SOURCE_DIR}.
86This may cause problems. The suspicious files are:
87${tablegenned_files_on_lib_dir}
88${tablegenned_files_on_include_dir}
89Please clean the source directory.")
90 endif()
91endif()
Oscar Fuentesa5f83562008-11-14 03:43:18 +000092
Oscar Fuentes61338132009-06-03 15:11:25 +000093string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
94
NAKAMURA Takumi0190e942014-01-19 12:47:26 +000095# They are used as destination of target generators.
96set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
97set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib)
98
99# Each of them corresponds to llvm-config's.
NAKAMURA Takumice78b802014-01-19 12:52:10 +0000100set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
101set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
NAKAMURA Takumi0190e942014-01-19 12:47:26 +0000102set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
103set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
104set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
105
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000106set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000107set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
Oscar Fuentes46fed3b2009-06-12 02:49:53 +0000108set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000109
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000110set(LLVM_ALL_TARGETS
Tim Northover43852f22013-02-04 12:32:21 +0000111 AArch64
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000112 ARM
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000113 CppBackend
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000114 Hexagon
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000115 Mips
Richard Pennington9f3bd4a2009-07-09 20:27:09 +0000116 MSP430
Justin Holewinskiae556d32012-05-04 20:18:50 +0000117 NVPTX
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000118 PowerPC
Rafael Espindolaf6474d22013-05-22 00:35:47 +0000119 R600
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000120 Sparc
Ulrich Weigand92b20852013-05-06 16:23:07 +0000121 SystemZ
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000122 X86
123 XCore
124 )
125
Oscar Fuentes465f9362011-03-23 17:42:13 +0000126# List of targets with JIT support:
Tim Northoverc17f3f72013-05-19 19:44:56 +0000127set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
Oscar Fuentes465f9362011-03-23 17:42:13 +0000128
Tim Northover865f4bc2013-04-15 11:53:05 +0000129set(LLVM_TARGETS_TO_BUILD "all"
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000130 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000131
Victor Oliveira9d4b8f52012-08-09 01:13:59 +0000132set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
133 CACHE STRING "Semicolon-separated list of experimental targets to build.")
134
Dylan Noblesmithaf9be0b2012-02-01 14:49:39 +0000135option(BUILD_SHARED_LIBS
136 "Build all libraries as shared libraries instead of static" OFF)
137
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000138option(LLVM_ENABLE_CBE_PRINTF_A "Set to ON if CBE is enabled for printf %a output" ON)
139if(LLVM_ENABLE_CBE_PRINTF_A)
140 set(ENABLE_CBE_PRINTF_A 1)
141endif()
142
143option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
144if(LLVM_ENABLE_TIMESTAMPS)
145 set(ENABLE_TIMESTAMPS 1)
146endif()
147
Benjamin Kramer5651cbd2012-09-28 10:10:46 +0000148option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
149if(LLVM_ENABLE_BACKTRACES)
150 set(ENABLE_BACKTRACES 1)
151endif()
152
Daniel Dunbareb6c7082013-08-30 20:39:21 +0000153option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
154if(LLVM_ENABLE_CRASH_OVERRIDES)
155 set(ENABLE_CRASH_OVERRIDES 1)
156endif()
157
Oscar Fuentes64955952011-01-21 15:42:54 +0000158option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
159set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
160set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
161
Sebastian Pop82622dc2012-08-08 18:04:45 +0000162set(LLVM_TARGET_ARCH "host"
163 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000164
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000165option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000166
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000167option(LLVM_ENABLE_THREADS "Use threads if available." ON)
168
Alexey Samsonov2fb337e2013-04-23 08:28:39 +0000169option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
170
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000171if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
172 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
173endif()
174
Victor Oliveira18023e42012-08-15 22:35:36 +0000175set(LLVM_TARGETS_TO_BUILD
176 ${LLVM_TARGETS_TO_BUILD}
177 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
Rafael Espindolacf1e6572013-05-22 02:45:28 +0000178list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
Victor Oliveira18023e42012-08-15 22:35:36 +0000179
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000180include(AddLLVMDefinitions)
181
Oscar Fuentes6d61f552009-08-18 15:29:35 +0000182option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000183
Oscar Fuentes1276e322011-03-01 22:31:19 +0000184# MSVC has a gazillion warnings with this.
185if( MSVC )
186 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
187else( MSVC )
188 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
189endif()
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000190
Arnaud A. de Grandmaisonb697b532013-11-26 10:33:53 +0000191option(LLVM_ENABLE_CXX11 "Compile with C++11 enabled." OFF)
Jean-Daniel Dupasedad1b42014-01-06 18:27:27 +0000192option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
Oscar Fuentes1276e322011-03-01 22:31:19 +0000193option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
194option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000195
Duncan Sands80f122f2013-07-17 09:34:51 +0000196if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000197 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
198else()
199 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000200endif()
201
Chandler Carruth83885972014-01-13 22:21:34 +0000202option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
203 "Set to ON to force using an old, unsupported host toolchain." OFF)
204
Eli Bendersky5262ad22012-03-13 08:33:15 +0000205option(LLVM_USE_INTEL_JITEVENTS
206 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
207 OFF)
208
209if( LLVM_USE_INTEL_JITEVENTS )
210 # Verify we are on a supported platform
Andrew Kaylor5808c7d2012-09-28 17:35:20 +0000211 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
Eli Bendersky5262ad22012-03-13 08:33:15 +0000212 message(FATAL_ERROR
213 "Intel JIT API support is available on Linux and Windows only.")
214 endif()
215endif( LLVM_USE_INTEL_JITEVENTS )
216
217option(LLVM_USE_OPROFILE
218 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
219
Joel Jones54594f22012-12-13 15:25:07 +0000220# If enabled, verify we are on a platform that supports oprofile.
Eli Bendersky5262ad22012-03-13 08:33:15 +0000221if( LLVM_USE_OPROFILE )
222 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
223 message(FATAL_ERROR "OProfile support is available on Linux only.")
224 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
225endif( LLVM_USE_OPROFILE )
226
Alexey Samsonov75789a22013-03-26 07:49:46 +0000227set(LLVM_USE_SANITIZER "" CACHE STRING
228 "Define the sanitizer used to build binaries and tests.")
229
Eric Christopher39878062013-07-30 21:44:10 +0000230option(LLVM_USE_SPLIT_DWARF
231 "Use -gsplit-dwarf when compiling llvm." OFF)
232
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000233# Define an option controlling whether we should build for 32-bit on 64-bit
234# platforms, where supported.
235if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
236 # TODO: support other platforms and toolchains.
237 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
238endif()
239
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000240# Define the default arguments to use with 'lit', and an option for the user to
241# override.
242set(LIT_ARGS_DEFAULT "-sv")
243if (MSVC OR XCODE)
244 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
245endif()
246set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
247
NAKAMURA Takumiba330ae2011-12-11 03:07:53 +0000248# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
249if( WIN32 AND NOT CYGWIN )
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000250 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
251endif()
252
Daniel Dunbar511e2962011-11-04 19:04:37 +0000253# Define options to control the inclusion and default build behavior for
Chandler Carruthea564942013-10-02 15:42:23 +0000254# components which may not strictly be necessary (tools, examples, and tests).
Daniel Dunbar511e2962011-11-04 19:04:37 +0000255#
256# This is primarily to support building smaller or faster project files.
257option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
258option(LLVM_BUILD_TOOLS
259 "Build the LLVM tools. If OFF, just generate build targets." ON)
260
Alexey Samsonov693e1a52013-10-04 10:41:38 +0000261option(LLVM_BUILD_RUNTIME
262 "Build the LLVM runtime libraries." ON)
Daniel Dunbar511e2962011-11-04 19:04:37 +0000263option(LLVM_BUILD_EXAMPLES
264 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
265option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
266
267option(LLVM_BUILD_TESTS
268 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
269option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
270
Michael Gottesman4d35b902013-08-24 07:25:21 +0000271option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
272option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
273option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm documentation." OFF)
274
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000275# All options referred to from HandleLLVMOptions have to be specified
Oscar Fuentes1276e322011-03-01 22:31:19 +0000276# BEFORE this include, otherwise options will not be correctly set on
277# first cmake run
278include(config-ix)
Sebastian Popfaeca292012-08-20 19:56:52 +0000279
280# By default, we target the host, but this can be overridden at CMake
281# invocation time.
282set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
283 "Default target for which LLVM will generate code." )
NAKAMURA Takumif9573f12012-12-10 07:14:29 +0000284set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
Sebastian Popfaeca292012-08-20 19:56:52 +0000285
Oscar Fuentes1276e322011-03-01 22:31:19 +0000286include(HandleLLVMOptions)
287
Reid Kleckner63784ba2013-06-24 13:21:16 +0000288# Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
Bill Wendling8edd8f92013-10-28 21:22:23 +0000289set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
Daniel Dunbar21079ca2011-11-04 23:04:05 +0000290include(FindPythonInterp)
291if( NOT PYTHONINTERP_FOUND )
292 message(FATAL_ERROR
293"Unable to find Python interpreter, required for builds and testing.
294
295Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
296endif()
297
Daniel Dunbar64371262011-11-05 06:30:03 +0000298######
299# LLVMBuild Integration
300#
301# We use llvm-build to generate all the data required by the CMake based
302# build system in one swoop:
303#
304# - We generate a file (a CMake fragment) in the object root which contains
305# all the definitions that are required by CMake.
306#
307# - We generate the library table used by llvm-config.
308#
309# - We generate the dependencies for the CMake fragment, so that we will
310# automatically reconfigure outselves.
311
312set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
313set(LLVMCONFIGLIBRARYDEPENDENCIESINC
Daniel Dunbarab0ad4e2011-12-01 20:18:09 +0000314 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
Daniel Dunbar64371262011-11-05 06:30:03 +0000315set(LLVMBUILDCMAKEFRAG
316 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
Preston Gurde65f4e62012-05-07 19:38:40 +0000317
318# Create the list of optional components that are enabled
319if (LLVM_USE_INTEL_JITEVENTS)
320 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
321endif (LLVM_USE_INTEL_JITEVENTS)
322if (LLVM_USE_OPROFILE)
323 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
324endif (LLVM_USE_OPROFILE)
325
Daniel Dunbar64371262011-11-05 06:30:03 +0000326message(STATUS "Constructing LLVMBuild project information")
327execute_process(
328 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
Daniel Dunbar807c6e42011-11-10 01:16:48 +0000329 --native-target "${LLVM_NATIVE_ARCH}"
330 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
Preston Gurde65f4e62012-05-07 19:38:40 +0000331 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
Daniel Dunbar64371262011-11-05 06:30:03 +0000332 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
333 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
Michael Gottesman21c69482013-08-15 04:16:12 +0000334 OUTPUT_VARIABLE LLVMBUILDOUTPUT
Daniel Dunbar64371262011-11-05 06:30:03 +0000335 ERROR_VARIABLE LLVMBUILDERRORS
336 OUTPUT_STRIP_TRAILING_WHITESPACE
337 ERROR_STRIP_TRAILING_WHITESPACE
338 RESULT_VARIABLE LLVMBUILDRESULT)
339
340# On Win32, CMake doesn't properly handle piping the default output/error
341# streams into the GUI console. So, we explicitly catch and report them.
342if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
343 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
344endif()
345if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
346 message(FATAL_ERROR
347 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
348endif()
349
350# Include the generated CMake fragment. This will define properties from the
351# LLVMBuild files in a format which is easy to consume from CMake, and will add
352# the dependencies so that CMake will reconfigure properly when the LLVMBuild
353# files change.
354include(${LLVMBUILDCMAKEFRAG})
355
356######
357
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000358# Configure all of the various header file fragments LLVM uses which depend on
359# configuration variables.
Andy Gibbsf5dede12013-06-26 07:57:53 +0000360set(LLVM_ENUM_TARGETS "")
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000361set(LLVM_ENUM_ASM_PRINTERS "")
362set(LLVM_ENUM_ASM_PARSERS "")
363set(LLVM_ENUM_DISASSEMBLERS "")
364foreach(t ${LLVM_TARGETS_TO_BUILD})
365 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
Andy Gibbsf5dede12013-06-26 07:57:53 +0000366
367 list(FIND LLVM_ALL_TARGETS ${t} idx)
368 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
369 if( idx LESS 0 AND idy LESS 0 )
370 message(FATAL_ERROR "The target `${t}' does not exist.
371 It should be one of\n${LLVM_ALL_TARGETS}")
372 else()
373 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
374 endif()
375
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000376 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
377 if( asmp_file )
378 set(LLVM_ENUM_ASM_PRINTERS
379 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
380 endif()
381 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
382 set(LLVM_ENUM_ASM_PARSERS
383 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
384 endif()
385 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
386 set(LLVM_ENUM_DISASSEMBLERS
387 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
388 endif()
389endforeach(t)
390
391# Produce the target definition files, which provide a way for clients to easily
392# include various classes of targets.
393configure_file(
394 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000395 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000396 )
397configure_file(
398 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000399 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000400 )
401configure_file(
402 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000403 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000404 )
405configure_file(
406 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000407 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000408 )
409
410# Configure the three LLVM configuration header files.
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000411configure_file(
412 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000413 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000414configure_file(
415 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000416 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000417configure_file(
418 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000419 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
Oscar Fuentesedfc1842011-01-09 14:34:39 +0000420
NAKAMURA Takumi0ec65f12014-01-19 12:47:22 +0000421# They are not referenced. See set_output_directory().
422set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000423set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
424set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
425
Artyom Skrobov01c18252013-12-20 18:13:12 +0000426if( NOT DEFINED CMAKE_INSTALL_RPATH )
427 set( CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
428endif( NOT DEFINED CMAKE_INSTALL_RPATH )
Rafael Espindola6ad1b3f2013-12-19 23:13:58 +0000429
Oscar Fuentes210b06a2011-02-14 20:13:58 +0000430set(CMAKE_INCLUDE_CURRENT_DIR ON)
431
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000432include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000433
David Chisnall79450132013-02-14 15:40:44 +0000434if( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
435 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
436 # with libxml2, iconv.h, etc., we must add /usr/local paths.
437 include_directories("/usr/local/include")
438 link_directories("/usr/local/lib")
439endif( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
440
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000441if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
Oscar Fuentes2d48f652011-07-17 17:35:15 +0000442 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000443endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
444
Rafael Espindola76f92272013-04-04 01:01:32 +0000445# Make sure we don't get -rdynamic in every binary. For those that need it,
446# use set_target_properties(target PROPERTIES ENABLE_EXPORTS 1)
447set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
448
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000449include(AddLLVM)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000450include(TableGen)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000451
Michael J. Spencer7c3a5ee2010-09-11 02:13:39 +0000452if( MINGW )
Oscar Fuentes9bf25952011-01-07 20:31:03 +0000453 # People report that -O3 is unreliable on MinGW. The traditional
454 # build also uses -O2 for that reason:
455 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
456endif()
457
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000458# Put this before tblgen. Else we have a circular dependence.
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000459add_subdirectory(lib/Support)
Peter Collingbourne84c287e2011-10-01 16:41:13 +0000460add_subdirectory(lib/TableGen)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000461
Oscar Fuentese352ca02008-11-10 01:32:14 +0000462add_subdirectory(utils/TableGen)
463
Oscar Fuentesdc8d56e2008-11-15 00:24:38 +0000464add_subdirectory(include/llvm)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000465
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000466add_subdirectory(lib)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000467
Douglas Gregor289dfc52009-07-20 18:30:25 +0000468add_subdirectory(utils/FileCheck)
Michael J. Spencer01639a42010-12-09 17:54:44 +0000469add_subdirectory(utils/FileUpdate)
Daniel Dunbar00dd4482009-09-24 06:23:57 +0000470add_subdirectory(utils/count)
471add_subdirectory(utils/not)
Michael J. Spencer885611b2010-09-13 17:52:38 +0000472add_subdirectory(utils/llvm-lit)
Michael J. Spencer22120c42012-04-03 23:09:22 +0000473add_subdirectory(utils/yaml-bench)
Douglas Gregor289dfc52009-07-20 18:30:25 +0000474
NAKAMURA Takumi5a0234f2014-01-31 17:32:46 +0000475if(LLVM_INCLUDE_TESTS)
476 add_subdirectory(utils/unittest)
477endif()
478
Oscar Fuentesafbe9752009-03-06 01:16:52 +0000479add_subdirectory(projects)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000480
Oscar Fuentesbf030842010-09-25 20:43:06 +0000481if( LLVM_INCLUDE_TOOLS )
482 add_subdirectory(tools)
483endif()
Oscar Fuentesacfd9ad2009-08-16 20:56:30 +0000484
Oscar Fuentesbf030842010-09-25 20:43:06 +0000485if( LLVM_INCLUDE_EXAMPLES )
486 add_subdirectory(examples)
487endif()
Oscar Fuentes64c99622008-10-22 02:56:07 +0000488
Oscar Fuentesbf030842010-09-25 20:43:06 +0000489if( LLVM_INCLUDE_TESTS )
490 add_subdirectory(test)
Oscar Fuentesbf030842010-09-25 20:43:06 +0000491 add_subdirectory(unittests)
NAKAMURA Takumi4bb599c2010-10-26 05:08:27 +0000492 if (MSVC)
Joel Jones54594f22012-12-13 15:25:07 +0000493 # This utility is used to prevent crashing tests from calling Dr. Watson on
Michael J. Spencer279362d2010-10-11 19:55:38 +0000494 # Windows.
495 add_subdirectory(utils/KillTheDoctor)
496 endif()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000497
498 # Add a global check rule now that all subdirectories have been traversed
499 # and we know the total set of lit testsuites.
500 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
501 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
502 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
503 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
504 add_lit_target(check-all
505 "Running all regression tests"
506 ${LLVM_LIT_TESTSUITES}
507 PARAMS ${LLVM_LIT_PARAMS}
508 DEPENDS ${LLVM_LIT_DEPENDS}
509 ARGS ${LLVM_LIT_EXTRA_ARGS}
510 )
Oscar Fuentesbf030842010-09-25 20:43:06 +0000511endif()
Michael J. Spencer10d274d2010-09-24 09:01:13 +0000512
Michael Gottesman4d35b902013-08-24 07:25:21 +0000513if (LLVM_INCLUDE_DOCS)
514 add_subdirectory(docs)
515endif()
516
Oscar Fuentesa389c582010-08-09 03:26:43 +0000517add_subdirectory(cmake/modules)
518
Hans Wennborg16546272013-08-24 00:20:36 +0000519if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
520 install(DIRECTORY include/
521 DESTINATION include
522 FILES_MATCHING
523 PATTERN "*.def"
524 PATTERN "*.h"
525 PATTERN "*.td"
526 PATTERN "*.inc"
527 PATTERN "LICENSE.TXT"
528 PATTERN ".svn" EXCLUDE
529 )
Oscar Fuentes64c99622008-10-22 02:56:07 +0000530
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000531 install(DIRECTORY ${LLVM_INCLUDE_DIR}/
Hans Wennborg16546272013-08-24 00:20:36 +0000532 DESTINATION include
533 FILES_MATCHING
534 PATTERN "*.def"
535 PATTERN "*.h"
536 PATTERN "*.gen"
537 PATTERN "*.inc"
538 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
539 PATTERN "CMakeFiles" EXCLUDE
540 PATTERN ".svn" EXCLUDE
541 )
542endif()
543
NAKAMURA Takumi148b62c2010-11-19 03:19:18 +0000544# Workaround for MSVS10 to avoid the Dialog Hell
545# FIXME: This could be removed with future version of CMake.
546if(MSVC_VERSION EQUAL 1600)
547 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
548 if( EXISTS "${LLVM_SLN_FILENAME}" )
549 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
550 endif()
551endif()
Rafael Espindolafc0447b2013-10-31 22:13:41 +0000552