blob: c218b3a7ab760ce9c42c75b3deb182f1b3f4dffa [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
Cedric Venet6c9f3ec2008-10-30 21:22:00 +00003project(LLVM)
Tim Northover1c82f3e2013-02-18 11:53:37 +00004cmake_minimum_required(VERSION 2.8)
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
Reid Klecknerc974f092013-08-29 22:09:43 +000040# Configure CPack.
Hans Wennborg09d108b2013-11-21 22:47:21 +000041set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
Reid Klecknerc974f092013-08-29 22:09:43 +000042set(CPACK_PACKAGE_VENDOR "LLVM")
43set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
44set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
Hans Wennborg09d108b2013-11-21 22:47:21 +000045set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
Reid Klecknerc974f092013-08-29 22:09:43 +000046set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
47if(WIN32 AND NOT UNIX)
Hans Wennborg09d108b2013-11-21 22:47:21 +000048 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
Reid Klecknerc974f092013-08-29 22:09:43 +000049 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
50 set(CPACK_NSIS_MODIFY_PATH "ON")
51 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
52 set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
53 "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
54 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
55 "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
56endif()
57include(CPack)
58
Daniel Dunbarad3946a2011-11-04 19:04:39 +000059# Sanity check our source directory to make sure that we are not trying to
60# generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
61# sure that we don't have any stray generated files lying around in the tree
62# (which would end up getting picked up by header search, instead of the correct
63# versions).
Oscar Fuentesa5f83562008-11-14 03:43:18 +000064if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
65 message(FATAL_ERROR "In-source builds are not allowed.
66CMake would overwrite the makefiles distributed with LLVM.
67Please create a directory and run cmake from there, passing the path
68to this source directory as the last argument.
69This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
70Please delete them.")
71endif()
Daniel Dunbarad3946a2011-11-04 19:04:39 +000072if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
73 file(GLOB_RECURSE
74 tablegenned_files_on_include_dir
75 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
76 file(GLOB_RECURSE
77 tablegenned_files_on_lib_dir
78 "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
79 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
80 message(FATAL_ERROR "Apparently there is a previous in-source build,
81probably as the result of running `configure' and `make' on
82${CMAKE_CURRENT_SOURCE_DIR}.
83This may cause problems. The suspicious files are:
84${tablegenned_files_on_lib_dir}
85${tablegenned_files_on_include_dir}
86Please clean the source directory.")
87 endif()
88endif()
Oscar Fuentesa5f83562008-11-14 03:43:18 +000089
Oscar Fuentes61338132009-06-03 15:11:25 +000090string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
91
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000092set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Oscar Fuentes2500aae2008-10-29 02:33:15 +000093set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000094set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
95set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
96set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +000097set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
Oscar Fuentes46fed3b2009-06-12 02:49:53 +000098set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000099
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000100set(LLVM_ALL_TARGETS
Tim Northover43852f22013-02-04 12:32:21 +0000101 AArch64
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000102 ARM
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000103 CppBackend
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000104 Hexagon
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000105 Mips
Richard Pennington9f3bd4a2009-07-09 20:27:09 +0000106 MSP430
Justin Holewinskiae556d32012-05-04 20:18:50 +0000107 NVPTX
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000108 PowerPC
Rafael Espindolaf6474d22013-05-22 00:35:47 +0000109 R600
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000110 Sparc
Ulrich Weigand92b20852013-05-06 16:23:07 +0000111 SystemZ
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000112 X86
113 XCore
114 )
115
Oscar Fuentes465f9362011-03-23 17:42:13 +0000116# List of targets with JIT support:
Tim Northoverc17f3f72013-05-19 19:44:56 +0000117set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
Oscar Fuentes465f9362011-03-23 17:42:13 +0000118
Tim Northover865f4bc2013-04-15 11:53:05 +0000119set(LLVM_TARGETS_TO_BUILD "all"
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000120 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000121
Victor Oliveira9d4b8f52012-08-09 01:13:59 +0000122set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
123 CACHE STRING "Semicolon-separated list of experimental targets to build.")
124
Dylan Noblesmithaf9be0b2012-02-01 14:49:39 +0000125option(BUILD_SHARED_LIBS
126 "Build all libraries as shared libraries instead of static" OFF)
127
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000128option(LLVM_ENABLE_CBE_PRINTF_A "Set to ON if CBE is enabled for printf %a output" ON)
129if(LLVM_ENABLE_CBE_PRINTF_A)
130 set(ENABLE_CBE_PRINTF_A 1)
131endif()
132
133option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
134if(LLVM_ENABLE_TIMESTAMPS)
135 set(ENABLE_TIMESTAMPS 1)
136endif()
137
Benjamin Kramer5651cbd2012-09-28 10:10:46 +0000138option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
139if(LLVM_ENABLE_BACKTRACES)
140 set(ENABLE_BACKTRACES 1)
141endif()
142
Daniel Dunbareb6c7082013-08-30 20:39:21 +0000143option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
144if(LLVM_ENABLE_CRASH_OVERRIDES)
145 set(ENABLE_CRASH_OVERRIDES 1)
146endif()
147
Oscar Fuentes64955952011-01-21 15:42:54 +0000148option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
149set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
150set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
151
Sebastian Pop82622dc2012-08-08 18:04:45 +0000152set(LLVM_TARGET_ARCH "host"
153 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000154
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000155option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000156
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000157option(LLVM_ENABLE_THREADS "Use threads if available." ON)
158
Alexey Samsonov2fb337e2013-04-23 08:28:39 +0000159option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
160
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000161if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
162 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
163endif()
164
Victor Oliveira18023e42012-08-15 22:35:36 +0000165set(LLVM_TARGETS_TO_BUILD
166 ${LLVM_TARGETS_TO_BUILD}
167 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
Rafael Espindolacf1e6572013-05-22 02:45:28 +0000168list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
Victor Oliveira18023e42012-08-15 22:35:36 +0000169
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000170include(AddLLVMDefinitions)
171
Oscar Fuentes6d61f552009-08-18 15:29:35 +0000172option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000173
Oscar Fuentes1276e322011-03-01 22:31:19 +0000174# MSVC has a gazillion warnings with this.
175if( MSVC )
176 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
177else( MSVC )
178 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
179endif()
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000180
Arnaud A. de Grandmaisonb697b532013-11-26 10:33:53 +0000181option(LLVM_ENABLE_CXX11 "Compile with C++11 enabled." OFF)
Oscar Fuentes1276e322011-03-01 22:31:19 +0000182option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
183option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000184
Duncan Sands80f122f2013-07-17 09:34:51 +0000185if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000186 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
187else()
188 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000189endif()
190
Eli Bendersky5262ad22012-03-13 08:33:15 +0000191option(LLVM_USE_INTEL_JITEVENTS
192 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
193 OFF)
194
195if( LLVM_USE_INTEL_JITEVENTS )
196 # Verify we are on a supported platform
Andrew Kaylor5808c7d2012-09-28 17:35:20 +0000197 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
Eli Bendersky5262ad22012-03-13 08:33:15 +0000198 message(FATAL_ERROR
199 "Intel JIT API support is available on Linux and Windows only.")
200 endif()
201endif( LLVM_USE_INTEL_JITEVENTS )
202
203option(LLVM_USE_OPROFILE
204 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
205
Joel Jones54594f22012-12-13 15:25:07 +0000206# If enabled, verify we are on a platform that supports oprofile.
Eli Bendersky5262ad22012-03-13 08:33:15 +0000207if( LLVM_USE_OPROFILE )
208 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
209 message(FATAL_ERROR "OProfile support is available on Linux only.")
210 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
211endif( LLVM_USE_OPROFILE )
212
Alexey Samsonov75789a22013-03-26 07:49:46 +0000213set(LLVM_USE_SANITIZER "" CACHE STRING
214 "Define the sanitizer used to build binaries and tests.")
215
Eric Christopher39878062013-07-30 21:44:10 +0000216option(LLVM_USE_SPLIT_DWARF
217 "Use -gsplit-dwarf when compiling llvm." OFF)
218
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000219# Define an option controlling whether we should build for 32-bit on 64-bit
220# platforms, where supported.
221if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
222 # TODO: support other platforms and toolchains.
223 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
224endif()
225
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000226# Define the default arguments to use with 'lit', and an option for the user to
227# override.
228set(LIT_ARGS_DEFAULT "-sv")
229if (MSVC OR XCODE)
230 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
231endif()
232set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
233
NAKAMURA Takumiba330ae2011-12-11 03:07:53 +0000234# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
235if( WIN32 AND NOT CYGWIN )
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000236 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
237endif()
238
Daniel Dunbar511e2962011-11-04 19:04:37 +0000239# Define options to control the inclusion and default build behavior for
Chandler Carruthea564942013-10-02 15:42:23 +0000240# components which may not strictly be necessary (tools, examples, and tests).
Daniel Dunbar511e2962011-11-04 19:04:37 +0000241#
242# This is primarily to support building smaller or faster project files.
243option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
244option(LLVM_BUILD_TOOLS
245 "Build the LLVM tools. If OFF, just generate build targets." ON)
246
Alexey Samsonov693e1a52013-10-04 10:41:38 +0000247option(LLVM_BUILD_RUNTIME
248 "Build the LLVM runtime libraries." ON)
Daniel Dunbar511e2962011-11-04 19:04:37 +0000249option(LLVM_BUILD_EXAMPLES
250 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
251option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
252
253option(LLVM_BUILD_TESTS
254 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
255option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
256
Michael Gottesman4d35b902013-08-24 07:25:21 +0000257option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
258option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
259option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm documentation." OFF)
260
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000261# All options referred to from HandleLLVMOptions have to be specified
Oscar Fuentes1276e322011-03-01 22:31:19 +0000262# BEFORE this include, otherwise options will not be correctly set on
263# first cmake run
264include(config-ix)
Sebastian Popfaeca292012-08-20 19:56:52 +0000265
266# By default, we target the host, but this can be overridden at CMake
267# invocation time.
268set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
269 "Default target for which LLVM will generate code." )
NAKAMURA Takumif9573f12012-12-10 07:14:29 +0000270set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
Sebastian Popfaeca292012-08-20 19:56:52 +0000271
Oscar Fuentes1276e322011-03-01 22:31:19 +0000272include(HandleLLVMOptions)
273
Reid Kleckner63784ba2013-06-24 13:21:16 +0000274# Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
Bill Wendling8edd8f92013-10-28 21:22:23 +0000275set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
Daniel Dunbar21079ca2011-11-04 23:04:05 +0000276include(FindPythonInterp)
277if( NOT PYTHONINTERP_FOUND )
278 message(FATAL_ERROR
279"Unable to find Python interpreter, required for builds and testing.
280
281Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
282endif()
283
Daniel Dunbar64371262011-11-05 06:30:03 +0000284######
285# LLVMBuild Integration
286#
287# We use llvm-build to generate all the data required by the CMake based
288# build system in one swoop:
289#
290# - We generate a file (a CMake fragment) in the object root which contains
291# all the definitions that are required by CMake.
292#
293# - We generate the library table used by llvm-config.
294#
295# - We generate the dependencies for the CMake fragment, so that we will
296# automatically reconfigure outselves.
297
298set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
299set(LLVMCONFIGLIBRARYDEPENDENCIESINC
Daniel Dunbarab0ad4e2011-12-01 20:18:09 +0000300 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
Daniel Dunbar64371262011-11-05 06:30:03 +0000301set(LLVMBUILDCMAKEFRAG
302 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
Preston Gurde65f4e62012-05-07 19:38:40 +0000303
304# Create the list of optional components that are enabled
305if (LLVM_USE_INTEL_JITEVENTS)
306 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
307endif (LLVM_USE_INTEL_JITEVENTS)
308if (LLVM_USE_OPROFILE)
309 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
310endif (LLVM_USE_OPROFILE)
311
Daniel Dunbar64371262011-11-05 06:30:03 +0000312message(STATUS "Constructing LLVMBuild project information")
313execute_process(
314 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
Daniel Dunbar807c6e42011-11-10 01:16:48 +0000315 --native-target "${LLVM_NATIVE_ARCH}"
316 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
Preston Gurde65f4e62012-05-07 19:38:40 +0000317 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
Daniel Dunbar64371262011-11-05 06:30:03 +0000318 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
319 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
Michael Gottesman21c69482013-08-15 04:16:12 +0000320 OUTPUT_VARIABLE LLVMBUILDOUTPUT
Daniel Dunbar64371262011-11-05 06:30:03 +0000321 ERROR_VARIABLE LLVMBUILDERRORS
322 OUTPUT_STRIP_TRAILING_WHITESPACE
323 ERROR_STRIP_TRAILING_WHITESPACE
324 RESULT_VARIABLE LLVMBUILDRESULT)
325
326# On Win32, CMake doesn't properly handle piping the default output/error
327# streams into the GUI console. So, we explicitly catch and report them.
328if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
329 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
330endif()
331if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
332 message(FATAL_ERROR
333 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
334endif()
335
336# Include the generated CMake fragment. This will define properties from the
337# LLVMBuild files in a format which is easy to consume from CMake, and will add
338# the dependencies so that CMake will reconfigure properly when the LLVMBuild
339# files change.
340include(${LLVMBUILDCMAKEFRAG})
341
342######
343
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000344# Configure all of the various header file fragments LLVM uses which depend on
345# configuration variables.
Andy Gibbsf5dede12013-06-26 07:57:53 +0000346set(LLVM_ENUM_TARGETS "")
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000347set(LLVM_ENUM_ASM_PRINTERS "")
348set(LLVM_ENUM_ASM_PARSERS "")
349set(LLVM_ENUM_DISASSEMBLERS "")
350foreach(t ${LLVM_TARGETS_TO_BUILD})
351 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
Andy Gibbsf5dede12013-06-26 07:57:53 +0000352
353 list(FIND LLVM_ALL_TARGETS ${t} idx)
354 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
355 if( idx LESS 0 AND idy LESS 0 )
356 message(FATAL_ERROR "The target `${t}' does not exist.
357 It should be one of\n${LLVM_ALL_TARGETS}")
358 else()
359 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
360 endif()
361
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000362 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
363 if( asmp_file )
364 set(LLVM_ENUM_ASM_PRINTERS
365 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
366 endif()
367 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
368 set(LLVM_ENUM_ASM_PARSERS
369 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
370 endif()
371 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
372 set(LLVM_ENUM_DISASSEMBLERS
373 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
374 endif()
375endforeach(t)
376
377# Produce the target definition files, which provide a way for clients to easily
378# include various classes of targets.
379configure_file(
380 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000381 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000382 )
383configure_file(
384 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000385 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000386 )
387configure_file(
388 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000389 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000390 )
391configure_file(
392 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000393 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000394 )
395
396# Configure the three LLVM configuration header files.
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000397configure_file(
398 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000399 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000400configure_file(
401 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000402 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000403configure_file(
404 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000405 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
Oscar Fuentesedfc1842011-01-09 14:34:39 +0000406
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000407set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
408set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
409set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
410
Oscar Fuentes210b06a2011-02-14 20:13:58 +0000411set(CMAKE_INCLUDE_CURRENT_DIR ON)
412
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000413include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000414
David Chisnall79450132013-02-14 15:40:44 +0000415if( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
416 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
417 # with libxml2, iconv.h, etc., we must add /usr/local paths.
418 include_directories("/usr/local/include")
419 link_directories("/usr/local/lib")
420endif( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
421
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000422if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
Oscar Fuentes2d48f652011-07-17 17:35:15 +0000423 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000424endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
425
Rafael Espindola76f92272013-04-04 01:01:32 +0000426# Make sure we don't get -rdynamic in every binary. For those that need it,
427# use set_target_properties(target PROPERTIES ENABLE_EXPORTS 1)
428set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
429
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000430include(AddLLVM)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000431include(TableGen)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000432
Michael J. Spencer7c3a5ee2010-09-11 02:13:39 +0000433if( MINGW )
Oscar Fuentes9bf25952011-01-07 20:31:03 +0000434 # People report that -O3 is unreliable on MinGW. The traditional
435 # build also uses -O2 for that reason:
436 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
437endif()
438
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000439# Put this before tblgen. Else we have a circular dependence.
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000440add_subdirectory(lib/Support)
Peter Collingbourne84c287e2011-10-01 16:41:13 +0000441add_subdirectory(lib/TableGen)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000442
Oscar Fuentese352ca02008-11-10 01:32:14 +0000443add_subdirectory(utils/TableGen)
444
Oscar Fuentesdc8d56e2008-11-15 00:24:38 +0000445add_subdirectory(include/llvm)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000446
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000447add_subdirectory(lib)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000448
Douglas Gregor289dfc52009-07-20 18:30:25 +0000449add_subdirectory(utils/FileCheck)
Michael J. Spencer01639a42010-12-09 17:54:44 +0000450add_subdirectory(utils/FileUpdate)
Daniel Dunbar00dd4482009-09-24 06:23:57 +0000451add_subdirectory(utils/count)
452add_subdirectory(utils/not)
Michael J. Spencer885611b2010-09-13 17:52:38 +0000453add_subdirectory(utils/llvm-lit)
Michael J. Spencer22120c42012-04-03 23:09:22 +0000454add_subdirectory(utils/yaml-bench)
Douglas Gregor289dfc52009-07-20 18:30:25 +0000455
Oscar Fuentesafbe9752009-03-06 01:16:52 +0000456add_subdirectory(projects)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000457
Oscar Fuentesbf030842010-09-25 20:43:06 +0000458if( LLVM_INCLUDE_TOOLS )
459 add_subdirectory(tools)
460endif()
Oscar Fuentesacfd9ad2009-08-16 20:56:30 +0000461
Oscar Fuentesbf030842010-09-25 20:43:06 +0000462if( LLVM_INCLUDE_EXAMPLES )
463 add_subdirectory(examples)
464endif()
Oscar Fuentes64c99622008-10-22 02:56:07 +0000465
Oscar Fuentesbf030842010-09-25 20:43:06 +0000466if( LLVM_INCLUDE_TESTS )
467 add_subdirectory(test)
468 add_subdirectory(utils/unittest)
469 add_subdirectory(unittests)
NAKAMURA Takumi4bb599c2010-10-26 05:08:27 +0000470 if (MSVC)
Joel Jones54594f22012-12-13 15:25:07 +0000471 # This utility is used to prevent crashing tests from calling Dr. Watson on
Michael J. Spencer279362d2010-10-11 19:55:38 +0000472 # Windows.
473 add_subdirectory(utils/KillTheDoctor)
474 endif()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000475
476 # Add a global check rule now that all subdirectories have been traversed
477 # and we know the total set of lit testsuites.
478 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
479 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
480 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
481 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
482 add_lit_target(check-all
483 "Running all regression tests"
484 ${LLVM_LIT_TESTSUITES}
485 PARAMS ${LLVM_LIT_PARAMS}
486 DEPENDS ${LLVM_LIT_DEPENDS}
487 ARGS ${LLVM_LIT_EXTRA_ARGS}
488 )
Oscar Fuentesbf030842010-09-25 20:43:06 +0000489endif()
Michael J. Spencer10d274d2010-09-24 09:01:13 +0000490
Michael Gottesman4d35b902013-08-24 07:25:21 +0000491if (LLVM_INCLUDE_DOCS)
492 add_subdirectory(docs)
493endif()
494
Oscar Fuentesa389c582010-08-09 03:26:43 +0000495add_subdirectory(cmake/modules)
496
Hans Wennborg16546272013-08-24 00:20:36 +0000497if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
498 install(DIRECTORY include/
499 DESTINATION include
500 FILES_MATCHING
501 PATTERN "*.def"
502 PATTERN "*.h"
503 PATTERN "*.td"
504 PATTERN "*.inc"
505 PATTERN "LICENSE.TXT"
506 PATTERN ".svn" EXCLUDE
507 )
Oscar Fuentes64c99622008-10-22 02:56:07 +0000508
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000509 install(DIRECTORY ${LLVM_INCLUDE_DIR}/
Hans Wennborg16546272013-08-24 00:20:36 +0000510 DESTINATION include
511 FILES_MATCHING
512 PATTERN "*.def"
513 PATTERN "*.h"
514 PATTERN "*.gen"
515 PATTERN "*.inc"
516 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
517 PATTERN "CMakeFiles" EXCLUDE
518 PATTERN ".svn" EXCLUDE
519 )
520endif()
521
NAKAMURA Takumi148b62c2010-11-19 03:19:18 +0000522# Workaround for MSVS10 to avoid the Dialog Hell
523# FIXME: This could be removed with future version of CMake.
524if(MSVC_VERSION EQUAL 1600)
525 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
526 if( EXISTS "${LLVM_SLN_FILENAME}" )
527 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
528 endif()
529endif()
Rafael Espindolafc0447b2013-10-31 22:13:41 +0000530