blob: ce952f8997be7b330ecd3038570cfab642467278 [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)
Oscar Fuentes46fed3b2009-06-12 02:49:53 +000097set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000098
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000099set(LLVM_ALL_TARGETS
Tim Northover43852f22013-02-04 12:32:21 +0000100 AArch64
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000101 ARM
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000102 CppBackend
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000103 Hexagon
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000104 Mips
Richard Pennington9f3bd4a2009-07-09 20:27:09 +0000105 MSP430
Justin Holewinskiae556d32012-05-04 20:18:50 +0000106 NVPTX
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000107 PowerPC
Rafael Espindolaf6474d22013-05-22 00:35:47 +0000108 R600
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000109 Sparc
Ulrich Weigand92b20852013-05-06 16:23:07 +0000110 SystemZ
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000111 X86
112 XCore
113 )
114
Oscar Fuentes465f9362011-03-23 17:42:13 +0000115# List of targets with JIT support:
Tim Northoverc17f3f72013-05-19 19:44:56 +0000116set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
Oscar Fuentes465f9362011-03-23 17:42:13 +0000117
Tim Northover865f4bc2013-04-15 11:53:05 +0000118set(LLVM_TARGETS_TO_BUILD "all"
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000119 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000120
Victor Oliveira9d4b8f52012-08-09 01:13:59 +0000121set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
122 CACHE STRING "Semicolon-separated list of experimental targets to build.")
123
Dylan Noblesmithaf9be0b2012-02-01 14:49:39 +0000124option(BUILD_SHARED_LIBS
125 "Build all libraries as shared libraries instead of static" OFF)
126
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000127option(LLVM_ENABLE_CBE_PRINTF_A "Set to ON if CBE is enabled for printf %a output" ON)
128if(LLVM_ENABLE_CBE_PRINTF_A)
129 set(ENABLE_CBE_PRINTF_A 1)
130endif()
131
132option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
133if(LLVM_ENABLE_TIMESTAMPS)
134 set(ENABLE_TIMESTAMPS 1)
135endif()
136
Benjamin Kramer5651cbd2012-09-28 10:10:46 +0000137option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
138if(LLVM_ENABLE_BACKTRACES)
139 set(ENABLE_BACKTRACES 1)
140endif()
141
Daniel Dunbareb6c7082013-08-30 20:39:21 +0000142option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
143if(LLVM_ENABLE_CRASH_OVERRIDES)
144 set(ENABLE_CRASH_OVERRIDES 1)
145endif()
146
Oscar Fuentes64955952011-01-21 15:42:54 +0000147option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
148set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
149set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
150
Sebastian Pop82622dc2012-08-08 18:04:45 +0000151set(LLVM_TARGET_ARCH "host"
152 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000153
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000154option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000155
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000156option(LLVM_ENABLE_THREADS "Use threads if available." ON)
157
Alexey Samsonov2fb337e2013-04-23 08:28:39 +0000158option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
159
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000160if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
161 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
162endif()
163
Victor Oliveira18023e42012-08-15 22:35:36 +0000164set(LLVM_TARGETS_TO_BUILD
165 ${LLVM_TARGETS_TO_BUILD}
166 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
Rafael Espindolacf1e6572013-05-22 02:45:28 +0000167list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
Victor Oliveira18023e42012-08-15 22:35:36 +0000168
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000169set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
170
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000171include(AddLLVMDefinitions)
172
Oscar Fuentes6d61f552009-08-18 15:29:35 +0000173option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000174
Oscar Fuentes1276e322011-03-01 22:31:19 +0000175# MSVC has a gazillion warnings with this.
176if( MSVC )
177 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
178else( MSVC )
179 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
180endif()
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000181
Arnaud A. de Grandmaisonb697b532013-11-26 10:33:53 +0000182option(LLVM_ENABLE_CXX11 "Compile with C++11 enabled." OFF)
Oscar Fuentes1276e322011-03-01 22:31:19 +0000183option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
184option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000185
Duncan Sands80f122f2013-07-17 09:34:51 +0000186if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000187 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
188else()
189 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000190endif()
191
Eli Bendersky5262ad22012-03-13 08:33:15 +0000192option(LLVM_USE_INTEL_JITEVENTS
193 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
194 OFF)
195
196if( LLVM_USE_INTEL_JITEVENTS )
197 # Verify we are on a supported platform
Andrew Kaylor5808c7d2012-09-28 17:35:20 +0000198 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
Eli Bendersky5262ad22012-03-13 08:33:15 +0000199 message(FATAL_ERROR
200 "Intel JIT API support is available on Linux and Windows only.")
201 endif()
202endif( LLVM_USE_INTEL_JITEVENTS )
203
204option(LLVM_USE_OPROFILE
205 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
206
Joel Jones54594f22012-12-13 15:25:07 +0000207# If enabled, verify we are on a platform that supports oprofile.
Eli Bendersky5262ad22012-03-13 08:33:15 +0000208if( LLVM_USE_OPROFILE )
209 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
210 message(FATAL_ERROR "OProfile support is available on Linux only.")
211 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
212endif( LLVM_USE_OPROFILE )
213
Alexey Samsonov75789a22013-03-26 07:49:46 +0000214set(LLVM_USE_SANITIZER "" CACHE STRING
215 "Define the sanitizer used to build binaries and tests.")
216
Eric Christopher39878062013-07-30 21:44:10 +0000217option(LLVM_USE_SPLIT_DWARF
218 "Use -gsplit-dwarf when compiling llvm." OFF)
219
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000220# Define an option controlling whether we should build for 32-bit on 64-bit
221# platforms, where supported.
222if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
223 # TODO: support other platforms and toolchains.
224 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
225endif()
226
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000227# Define the default arguments to use with 'lit', and an option for the user to
228# override.
229set(LIT_ARGS_DEFAULT "-sv")
230if (MSVC OR XCODE)
231 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
232endif()
233set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
234
NAKAMURA Takumiba330ae2011-12-11 03:07:53 +0000235# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
236if( WIN32 AND NOT CYGWIN )
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000237 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
238endif()
239
Daniel Dunbar511e2962011-11-04 19:04:37 +0000240# Define options to control the inclusion and default build behavior for
Chandler Carruthea564942013-10-02 15:42:23 +0000241# components which may not strictly be necessary (tools, examples, and tests).
Daniel Dunbar511e2962011-11-04 19:04:37 +0000242#
243# This is primarily to support building smaller or faster project files.
244option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
245option(LLVM_BUILD_TOOLS
246 "Build the LLVM tools. If OFF, just generate build targets." ON)
247
Alexey Samsonov693e1a52013-10-04 10:41:38 +0000248option(LLVM_BUILD_RUNTIME
249 "Build the LLVM runtime libraries." ON)
Daniel Dunbar511e2962011-11-04 19:04:37 +0000250option(LLVM_BUILD_EXAMPLES
251 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
252option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
253
254option(LLVM_BUILD_TESTS
255 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
256option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
257
Michael Gottesman4d35b902013-08-24 07:25:21 +0000258option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
259option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
260option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm documentation." OFF)
261
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000262# All options referred to from HandleLLVMOptions have to be specified
Oscar Fuentes1276e322011-03-01 22:31:19 +0000263# BEFORE this include, otherwise options will not be correctly set on
264# first cmake run
265include(config-ix)
Sebastian Popfaeca292012-08-20 19:56:52 +0000266
267# By default, we target the host, but this can be overridden at CMake
268# invocation time.
269set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
270 "Default target for which LLVM will generate code." )
NAKAMURA Takumif9573f12012-12-10 07:14:29 +0000271set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
Sebastian Popfaeca292012-08-20 19:56:52 +0000272
Oscar Fuentes1276e322011-03-01 22:31:19 +0000273include(HandleLLVMOptions)
274
Reid Kleckner63784ba2013-06-24 13:21:16 +0000275# Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
Bill Wendling8edd8f92013-10-28 21:22:23 +0000276set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
Daniel Dunbar21079ca2011-11-04 23:04:05 +0000277include(FindPythonInterp)
278if( NOT PYTHONINTERP_FOUND )
279 message(FATAL_ERROR
280"Unable to find Python interpreter, required for builds and testing.
281
282Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
283endif()
284
Daniel Dunbar64371262011-11-05 06:30:03 +0000285######
286# LLVMBuild Integration
287#
288# We use llvm-build to generate all the data required by the CMake based
289# build system in one swoop:
290#
291# - We generate a file (a CMake fragment) in the object root which contains
292# all the definitions that are required by CMake.
293#
294# - We generate the library table used by llvm-config.
295#
296# - We generate the dependencies for the CMake fragment, so that we will
297# automatically reconfigure outselves.
298
299set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
300set(LLVMCONFIGLIBRARYDEPENDENCIESINC
Daniel Dunbarab0ad4e2011-12-01 20:18:09 +0000301 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
Daniel Dunbar64371262011-11-05 06:30:03 +0000302set(LLVMBUILDCMAKEFRAG
303 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
Preston Gurde65f4e62012-05-07 19:38:40 +0000304
305# Create the list of optional components that are enabled
306if (LLVM_USE_INTEL_JITEVENTS)
307 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
308endif (LLVM_USE_INTEL_JITEVENTS)
309if (LLVM_USE_OPROFILE)
310 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
311endif (LLVM_USE_OPROFILE)
312
Daniel Dunbar64371262011-11-05 06:30:03 +0000313message(STATUS "Constructing LLVMBuild project information")
314execute_process(
315 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
Daniel Dunbar807c6e42011-11-10 01:16:48 +0000316 --native-target "${LLVM_NATIVE_ARCH}"
317 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
Preston Gurde65f4e62012-05-07 19:38:40 +0000318 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
Daniel Dunbar64371262011-11-05 06:30:03 +0000319 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
320 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
Michael Gottesman21c69482013-08-15 04:16:12 +0000321 OUTPUT_VARIABLE LLVMBUILDOUTPUT
Daniel Dunbar64371262011-11-05 06:30:03 +0000322 ERROR_VARIABLE LLVMBUILDERRORS
323 OUTPUT_STRIP_TRAILING_WHITESPACE
324 ERROR_STRIP_TRAILING_WHITESPACE
325 RESULT_VARIABLE LLVMBUILDRESULT)
326
327# On Win32, CMake doesn't properly handle piping the default output/error
328# streams into the GUI console. So, we explicitly catch and report them.
329if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
330 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
331endif()
332if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
333 message(FATAL_ERROR
334 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
335endif()
336
337# Include the generated CMake fragment. This will define properties from the
338# LLVMBuild files in a format which is easy to consume from CMake, and will add
339# the dependencies so that CMake will reconfigure properly when the LLVMBuild
340# files change.
341include(${LLVMBUILDCMAKEFRAG})
342
343######
344
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000345# Configure all of the various header file fragments LLVM uses which depend on
346# configuration variables.
Andy Gibbsf5dede12013-06-26 07:57:53 +0000347set(LLVM_ENUM_TARGETS "")
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000348set(LLVM_ENUM_ASM_PRINTERS "")
349set(LLVM_ENUM_ASM_PARSERS "")
350set(LLVM_ENUM_DISASSEMBLERS "")
351foreach(t ${LLVM_TARGETS_TO_BUILD})
352 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
Andy Gibbsf5dede12013-06-26 07:57:53 +0000353
354 list(FIND LLVM_ALL_TARGETS ${t} idx)
355 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
356 if( idx LESS 0 AND idy LESS 0 )
357 message(FATAL_ERROR "The target `${t}' does not exist.
358 It should be one of\n${LLVM_ALL_TARGETS}")
359 else()
360 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
361 endif()
362
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000363 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
364 if( asmp_file )
365 set(LLVM_ENUM_ASM_PRINTERS
366 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
367 endif()
368 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
369 set(LLVM_ENUM_ASM_PARSERS
370 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
371 endif()
372 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
373 set(LLVM_ENUM_DISASSEMBLERS
374 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
375 endif()
376endforeach(t)
377
378# Produce the target definition files, which provide a way for clients to easily
379# include various classes of targets.
380configure_file(
381 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
382 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
383 )
384configure_file(
385 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
386 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
387 )
388configure_file(
389 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
390 ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
391 )
392configure_file(
393 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
394 ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
395 )
396
397# Configure the three LLVM configuration header files.
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000398configure_file(
399 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
400 ${LLVM_BINARY_DIR}/include/llvm/Config/config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000401configure_file(
402 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
403 ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000404configure_file(
405 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
406 ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h)
Oscar Fuentesedfc1842011-01-09 14:34:39 +0000407
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000408set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
409set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
410set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
411
Oscar Fuentes210b06a2011-02-14 20:13:58 +0000412set(CMAKE_INCLUDE_CURRENT_DIR ON)
413
Oscar Fuentes2500aae2008-10-29 02:33:15 +0000414include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000415
David Chisnall79450132013-02-14 15:40:44 +0000416if( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
417 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
418 # with libxml2, iconv.h, etc., we must add /usr/local paths.
419 include_directories("/usr/local/include")
420 link_directories("/usr/local/lib")
421endif( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
422
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000423if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
Oscar Fuentes2d48f652011-07-17 17:35:15 +0000424 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000425endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
426
Rafael Espindola76f92272013-04-04 01:01:32 +0000427# Make sure we don't get -rdynamic in every binary. For those that need it,
428# use set_target_properties(target PROPERTIES ENABLE_EXPORTS 1)
429set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
430
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000431include(AddLLVM)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000432include(TableGen)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000433
Michael J. Spencer7c3a5ee2010-09-11 02:13:39 +0000434if( MINGW )
Oscar Fuentes9bf25952011-01-07 20:31:03 +0000435 # People report that -O3 is unreliable on MinGW. The traditional
436 # build also uses -O2 for that reason:
437 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
438endif()
439
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000440# Put this before tblgen. Else we have a circular dependence.
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000441add_subdirectory(lib/Support)
Peter Collingbourne84c287e2011-10-01 16:41:13 +0000442add_subdirectory(lib/TableGen)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000443
Oscar Fuentese352ca02008-11-10 01:32:14 +0000444add_subdirectory(utils/TableGen)
445
Oscar Fuentesdc8d56e2008-11-15 00:24:38 +0000446add_subdirectory(include/llvm)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000447
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000448add_subdirectory(lib)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000449
Douglas Gregor289dfc52009-07-20 18:30:25 +0000450add_subdirectory(utils/FileCheck)
Michael J. Spencer01639a42010-12-09 17:54:44 +0000451add_subdirectory(utils/FileUpdate)
Daniel Dunbar00dd4482009-09-24 06:23:57 +0000452add_subdirectory(utils/count)
453add_subdirectory(utils/not)
Michael J. Spencer885611b2010-09-13 17:52:38 +0000454add_subdirectory(utils/llvm-lit)
Michael J. Spencer22120c42012-04-03 23:09:22 +0000455add_subdirectory(utils/yaml-bench)
Douglas Gregor289dfc52009-07-20 18:30:25 +0000456
Oscar Fuentesafbe9752009-03-06 01:16:52 +0000457add_subdirectory(projects)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000458
Oscar Fuentesbf030842010-09-25 20:43:06 +0000459if( LLVM_INCLUDE_TOOLS )
460 add_subdirectory(tools)
461endif()
Oscar Fuentesacfd9ad2009-08-16 20:56:30 +0000462
Oscar Fuentesbf030842010-09-25 20:43:06 +0000463if( LLVM_INCLUDE_EXAMPLES )
464 add_subdirectory(examples)
465endif()
Oscar Fuentes64c99622008-10-22 02:56:07 +0000466
Oscar Fuentesbf030842010-09-25 20:43:06 +0000467if( LLVM_INCLUDE_TESTS )
468 add_subdirectory(test)
469 add_subdirectory(utils/unittest)
470 add_subdirectory(unittests)
NAKAMURA Takumi4bb599c2010-10-26 05:08:27 +0000471 if (MSVC)
Joel Jones54594f22012-12-13 15:25:07 +0000472 # This utility is used to prevent crashing tests from calling Dr. Watson on
Michael J. Spencer279362d2010-10-11 19:55:38 +0000473 # Windows.
474 add_subdirectory(utils/KillTheDoctor)
475 endif()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000476
477 # Add a global check rule now that all subdirectories have been traversed
478 # and we know the total set of lit testsuites.
479 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
480 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
481 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
482 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
483 add_lit_target(check-all
484 "Running all regression tests"
485 ${LLVM_LIT_TESTSUITES}
486 PARAMS ${LLVM_LIT_PARAMS}
487 DEPENDS ${LLVM_LIT_DEPENDS}
488 ARGS ${LLVM_LIT_EXTRA_ARGS}
489 )
Oscar Fuentesbf030842010-09-25 20:43:06 +0000490endif()
Michael J. Spencer10d274d2010-09-24 09:01:13 +0000491
Michael Gottesman4d35b902013-08-24 07:25:21 +0000492if (LLVM_INCLUDE_DOCS)
493 add_subdirectory(docs)
494endif()
495
Oscar Fuentesa389c582010-08-09 03:26:43 +0000496add_subdirectory(cmake/modules)
497
Hans Wennborg16546272013-08-24 00:20:36 +0000498if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
499 install(DIRECTORY include/
500 DESTINATION include
501 FILES_MATCHING
502 PATTERN "*.def"
503 PATTERN "*.h"
504 PATTERN "*.td"
505 PATTERN "*.inc"
506 PATTERN "LICENSE.TXT"
507 PATTERN ".svn" EXCLUDE
508 )
Oscar Fuentes64c99622008-10-22 02:56:07 +0000509
Hans Wennborg16546272013-08-24 00:20:36 +0000510 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
511 DESTINATION include
512 FILES_MATCHING
513 PATTERN "*.def"
514 PATTERN "*.h"
515 PATTERN "*.gen"
516 PATTERN "*.inc"
517 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
518 PATTERN "CMakeFiles" EXCLUDE
519 PATTERN ".svn" EXCLUDE
520 )
521endif()
522
NAKAMURA Takumi148b62c2010-11-19 03:19:18 +0000523# Workaround for MSVS10 to avoid the Dialog Hell
524# FIXME: This could be removed with future version of CMake.
525if(MSVC_VERSION EQUAL 1600)
526 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
527 if( EXISTS "${LLVM_SLN_FILENAME}" )
528 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
529 endif()
530endif()
Rafael Espindolafc0447b2013-10-31 22:13:41 +0000531