blob: 2ce214aabfcd25744b5396ea14103bf16a7c3194 [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 Takumi9cd9ad62014-02-26 06:45:11 +00004
5# FIXME: It may be removed when we use 2.8.12.
6if(CMAKE_VERSION VERSION_LESS 2.8.12)
7 # Invalidate a couple of keywords.
8 set(cmake_2_8_12_INTERFACE)
9 set(cmake_2_8_12_PRIVATE)
10else()
11 # Use ${cmake_2_8_12_KEYWORD} intead of KEYWORD in target_link_libraries().
12 set(cmake_2_8_12_INTERFACE INTERFACE)
13 set(cmake_2_8_12_PRIVATE PRIVATE)
14 if(POLICY CMP0022)
15 cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
16 endif()
17endif()
18
NAKAMURA Takumi85d65ff2014-02-02 16:59:36 +000019project(LLVM)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000020
Oscar Fuentes052c23c2010-08-03 17:28:09 +000021# Add path for custom modules
22set(CMAKE_MODULE_PATH
23 ${CMAKE_MODULE_PATH}
24 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
25 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
26 )
27
Dylan Noblesmithc6c7a582012-02-13 18:48:10 +000028set(LLVM_VERSION_MAJOR 3)
NAKAMURA Takumia5997c42013-11-20 13:11:48 +000029set(LLVM_VERSION_MINOR 5)
Dylan Noblesmithc6c7a582012-02-13 18:48:10 +000030
Hans Wennborg09d108b2013-11-21 22:47:21 +000031if (NOT PACKAGE_VERSION)
32 set(PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}svn")
33endif()
Oscar Fuentes70640352010-12-20 09:47:13 +000034
Hans Wennborg16546272013-08-24 00:20:36 +000035option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
36
Manuel Klimek13cfa002012-05-09 15:10:54 +000037option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
38if ( LLVM_USE_FOLDERS )
39 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
40endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +000041
Oscar Fuentes052c23c2010-08-03 17:28:09 +000042include(VersionFromVCS)
Oscar Fuentes70640352010-12-20 09:47:13 +000043
44option(LLVM_APPEND_VC_REV
45 "Append the version control system revision id to LLVM version" OFF)
46
47if( LLVM_APPEND_VC_REV )
48 add_version_info_from_vcs(PACKAGE_VERSION)
49endif()
Oscar Fuentes052c23c2010-08-03 17:28:09 +000050
Dylan Noblesmith67c49702011-12-18 18:50:16 +000051set(PACKAGE_NAME LLVM)
Chris Lattnerff2d99d2009-01-28 17:49:03 +000052set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Dylan Noblesmith67c49702011-12-18 18:50:16 +000053set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000054
NAKAMURA Takumif0a1ab82014-01-13 05:25:13 +000055set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
56 "Default URL where bug reports are to be submitted.")
57
Reid Klecknerc974f092013-08-29 22:09:43 +000058# Configure CPack.
Hans Wennborg09d108b2013-11-21 22:47:21 +000059set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
Reid Klecknerc974f092013-08-29 22:09:43 +000060set(CPACK_PACKAGE_VENDOR "LLVM")
61set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
62set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
Hans Wennborg09d108b2013-11-21 22:47:21 +000063set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
Reid Klecknerc974f092013-08-29 22:09:43 +000064set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
65if(WIN32 AND NOT UNIX)
Hans Wennborg09d108b2013-11-21 22:47:21 +000066 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
Reid Klecknerc974f092013-08-29 22:09:43 +000067 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
68 set(CPACK_NSIS_MODIFY_PATH "ON")
69 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
70 set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
71 "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
72 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
73 "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
74endif()
75include(CPack)
76
Daniel Dunbarad3946a2011-11-04 19:04:39 +000077# Sanity check our source directory to make sure that we are not trying to
78# generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
79# sure that we don't have any stray generated files lying around in the tree
80# (which would end up getting picked up by header search, instead of the correct
81# versions).
Oscar Fuentesa5f83562008-11-14 03:43:18 +000082if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
83 message(FATAL_ERROR "In-source builds are not allowed.
84CMake would overwrite the makefiles distributed with LLVM.
85Please create a directory and run cmake from there, passing the path
86to this source directory as the last argument.
87This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
88Please delete them.")
89endif()
Daniel Dunbarad3946a2011-11-04 19:04:39 +000090if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
91 file(GLOB_RECURSE
92 tablegenned_files_on_include_dir
93 "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
94 file(GLOB_RECURSE
95 tablegenned_files_on_lib_dir
96 "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
97 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
98 message(FATAL_ERROR "Apparently there is a previous in-source build,
99probably as the result of running `configure' and `make' on
100${CMAKE_CURRENT_SOURCE_DIR}.
101This may cause problems. The suspicious files are:
102${tablegenned_files_on_lib_dir}
103${tablegenned_files_on_include_dir}
104Please clean the source directory.")
105 endif()
106endif()
Oscar Fuentesa5f83562008-11-14 03:43:18 +0000107
Oscar Fuentes61338132009-06-03 15:11:25 +0000108string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
109
NAKAMURA Takumi0190e942014-01-19 12:47:26 +0000110# They are used as destination of target generators.
111set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
112set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib)
113
114# Each of them corresponds to llvm-config's.
NAKAMURA Takumice78b802014-01-19 12:52:10 +0000115set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
116set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
NAKAMURA Takumi0190e942014-01-19 12:47:26 +0000117set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
118set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
119set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
120
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000121set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000122set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
Oscar Fuentes46fed3b2009-06-12 02:49:53 +0000123set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000124
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000125set(LLVM_ALL_TARGETS
Tim Northover43852f22013-02-04 12:32:21 +0000126 AArch64
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000127 ARM
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000128 CppBackend
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000129 Hexagon
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000130 Mips
Richard Pennington9f3bd4a2009-07-09 20:27:09 +0000131 MSP430
Justin Holewinskiae556d32012-05-04 20:18:50 +0000132 NVPTX
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000133 PowerPC
Rafael Espindolaf6474d22013-05-22 00:35:47 +0000134 R600
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000135 Sparc
Ulrich Weigand92b20852013-05-06 16:23:07 +0000136 SystemZ
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000137 X86
138 XCore
139 )
140
Oscar Fuentes465f9362011-03-23 17:42:13 +0000141# List of targets with JIT support:
Tim Northoverc17f3f72013-05-19 19:44:56 +0000142set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
Oscar Fuentes465f9362011-03-23 17:42:13 +0000143
Tim Northover865f4bc2013-04-15 11:53:05 +0000144set(LLVM_TARGETS_TO_BUILD "all"
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000145 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000146
Victor Oliveira9d4b8f52012-08-09 01:13:59 +0000147set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
148 CACHE STRING "Semicolon-separated list of experimental targets to build.")
149
Dylan Noblesmithaf9be0b2012-02-01 14:49:39 +0000150option(BUILD_SHARED_LIBS
151 "Build all libraries as shared libraries instead of static" OFF)
152
Oscar Fuentesc8cb58e2011-01-11 12:31:54 +0000153option(LLVM_ENABLE_CBE_PRINTF_A "Set to ON if CBE is enabled for printf %a output" ON)
154if(LLVM_ENABLE_CBE_PRINTF_A)
155 set(ENABLE_CBE_PRINTF_A 1)
156endif()
157
158option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
159if(LLVM_ENABLE_TIMESTAMPS)
160 set(ENABLE_TIMESTAMPS 1)
161endif()
162
Benjamin Kramer5651cbd2012-09-28 10:10:46 +0000163option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
164if(LLVM_ENABLE_BACKTRACES)
165 set(ENABLE_BACKTRACES 1)
166endif()
167
Daniel Dunbareb6c7082013-08-30 20:39:21 +0000168option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
169if(LLVM_ENABLE_CRASH_OVERRIDES)
170 set(ENABLE_CRASH_OVERRIDES 1)
171endif()
172
Oscar Fuentes64955952011-01-21 15:42:54 +0000173option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
174set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
175set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
176
Sebastian Pop82622dc2012-08-08 18:04:45 +0000177set(LLVM_TARGET_ARCH "host"
178 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
Oscar Fuentesb9a78132009-09-13 22:18:38 +0000179
Chandler Carruthf11f1e42013-08-12 09:49:17 +0000180option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
Chandler Carruthcad7e5e2013-08-07 08:47:36 +0000181
Oscar Fuentes366fbb72008-11-18 23:45:21 +0000182option(LLVM_ENABLE_THREADS "Use threads if available." ON)
183
Alexey Samsonov2fb337e2013-04-23 08:28:39 +0000184option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
185
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000186if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
187 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
188endif()
189
Victor Oliveira18023e42012-08-15 22:35:36 +0000190set(LLVM_TARGETS_TO_BUILD
191 ${LLVM_TARGETS_TO_BUILD}
192 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
Rafael Espindolacf1e6572013-05-22 02:45:28 +0000193list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
Victor Oliveira18023e42012-08-15 22:35:36 +0000194
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000195include(AddLLVMDefinitions)
196
Oscar Fuentes6d61f552009-08-18 15:29:35 +0000197option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000198
Oscar Fuentes1276e322011-03-01 22:31:19 +0000199# MSVC has a gazillion warnings with this.
200if( MSVC )
201 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
202else( MSVC )
203 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
204endif()
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000205
Arnaud A. de Grandmaisonb697b532013-11-26 10:33:53 +0000206option(LLVM_ENABLE_CXX11 "Compile with C++11 enabled." OFF)
Jean-Daniel Dupasedad1b42014-01-06 18:27:27 +0000207option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
Oscar Fuentes1276e322011-03-01 22:31:19 +0000208option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
209option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000210
Duncan Sands80f122f2013-07-17 09:34:51 +0000211if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000212 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
213else()
214 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000215endif()
216
Chandler Carruth83885972014-01-13 22:21:34 +0000217option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
218 "Set to ON to force using an old, unsupported host toolchain." OFF)
219
Eli Bendersky5262ad22012-03-13 08:33:15 +0000220option(LLVM_USE_INTEL_JITEVENTS
221 "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
222 OFF)
223
224if( LLVM_USE_INTEL_JITEVENTS )
225 # Verify we are on a supported platform
Andrew Kaylor5808c7d2012-09-28 17:35:20 +0000226 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
Eli Bendersky5262ad22012-03-13 08:33:15 +0000227 message(FATAL_ERROR
228 "Intel JIT API support is available on Linux and Windows only.")
229 endif()
230endif( LLVM_USE_INTEL_JITEVENTS )
231
232option(LLVM_USE_OPROFILE
233 "Use opagent JIT interface to inform OProfile about JIT code" OFF)
234
Joel Jones54594f22012-12-13 15:25:07 +0000235# If enabled, verify we are on a platform that supports oprofile.
Eli Bendersky5262ad22012-03-13 08:33:15 +0000236if( LLVM_USE_OPROFILE )
237 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
238 message(FATAL_ERROR "OProfile support is available on Linux only.")
239 endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
240endif( LLVM_USE_OPROFILE )
241
Alexey Samsonov75789a22013-03-26 07:49:46 +0000242set(LLVM_USE_SANITIZER "" CACHE STRING
243 "Define the sanitizer used to build binaries and tests.")
244
Eric Christopher39878062013-07-30 21:44:10 +0000245option(LLVM_USE_SPLIT_DWARF
246 "Use -gsplit-dwarf when compiling llvm." OFF)
247
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000248# Define an option controlling whether we should build for 32-bit on 64-bit
249# platforms, where supported.
250if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
251 # TODO: support other platforms and toolchains.
252 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
253endif()
254
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000255# Define the default arguments to use with 'lit', and an option for the user to
256# override.
257set(LIT_ARGS_DEFAULT "-sv")
258if (MSVC OR XCODE)
259 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
260endif()
261set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
262
NAKAMURA Takumiba330ae2011-12-11 03:07:53 +0000263# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
264if( WIN32 AND NOT CYGWIN )
Daniel Dunbar10fa2df2011-11-04 19:04:35 +0000265 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
266endif()
267
Daniel Dunbar511e2962011-11-04 19:04:37 +0000268# Define options to control the inclusion and default build behavior for
Chandler Carruthea564942013-10-02 15:42:23 +0000269# components which may not strictly be necessary (tools, examples, and tests).
Daniel Dunbar511e2962011-11-04 19:04:37 +0000270#
271# This is primarily to support building smaller or faster project files.
272option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
273option(LLVM_BUILD_TOOLS
274 "Build the LLVM tools. If OFF, just generate build targets." ON)
275
Alexey Samsonov693e1a52013-10-04 10:41:38 +0000276option(LLVM_BUILD_RUNTIME
277 "Build the LLVM runtime libraries." ON)
Daniel Dunbar511e2962011-11-04 19:04:37 +0000278option(LLVM_BUILD_EXAMPLES
279 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
280option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
281
282option(LLVM_BUILD_TESTS
283 "Build LLVM unit tests. If OFF, just generate build targets." OFF)
284option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
285
Michael Gottesman4d35b902013-08-24 07:25:21 +0000286option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
287option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
288option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm documentation." OFF)
289
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000290# All options referred to from HandleLLVMOptions have to be specified
Oscar Fuentes1276e322011-03-01 22:31:19 +0000291# BEFORE this include, otherwise options will not be correctly set on
292# first cmake run
293include(config-ix)
Sebastian Popfaeca292012-08-20 19:56:52 +0000294
295# By default, we target the host, but this can be overridden at CMake
296# invocation time.
297set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
298 "Default target for which LLVM will generate code." )
NAKAMURA Takumif9573f12012-12-10 07:14:29 +0000299set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
Sebastian Popfaeca292012-08-20 19:56:52 +0000300
Oscar Fuentes1276e322011-03-01 22:31:19 +0000301include(HandleLLVMOptions)
302
Reid Kleckner63784ba2013-06-24 13:21:16 +0000303# Verify that we can find a Python 2 interpreter. Python 3 is unsupported.
Bill Wendling8edd8f92013-10-28 21:22:23 +0000304set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5)
Daniel Dunbar21079ca2011-11-04 23:04:05 +0000305include(FindPythonInterp)
306if( NOT PYTHONINTERP_FOUND )
307 message(FATAL_ERROR
308"Unable to find Python interpreter, required for builds and testing.
309
310Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
311endif()
312
Daniel Dunbar64371262011-11-05 06:30:03 +0000313######
314# LLVMBuild Integration
315#
316# We use llvm-build to generate all the data required by the CMake based
317# build system in one swoop:
318#
319# - We generate a file (a CMake fragment) in the object root which contains
320# all the definitions that are required by CMake.
321#
322# - We generate the library table used by llvm-config.
323#
324# - We generate the dependencies for the CMake fragment, so that we will
325# automatically reconfigure outselves.
326
327set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
328set(LLVMCONFIGLIBRARYDEPENDENCIESINC
Daniel Dunbarab0ad4e2011-12-01 20:18:09 +0000329 "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
Daniel Dunbar64371262011-11-05 06:30:03 +0000330set(LLVMBUILDCMAKEFRAG
331 "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
Preston Gurde65f4e62012-05-07 19:38:40 +0000332
333# Create the list of optional components that are enabled
334if (LLVM_USE_INTEL_JITEVENTS)
335 set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
336endif (LLVM_USE_INTEL_JITEVENTS)
337if (LLVM_USE_OPROFILE)
338 set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
339endif (LLVM_USE_OPROFILE)
340
Daniel Dunbar64371262011-11-05 06:30:03 +0000341message(STATUS "Constructing LLVMBuild project information")
342execute_process(
343 COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
Daniel Dunbar807c6e42011-11-10 01:16:48 +0000344 --native-target "${LLVM_NATIVE_ARCH}"
345 --enable-targets "${LLVM_TARGETS_TO_BUILD}"
Preston Gurde65f4e62012-05-07 19:38:40 +0000346 --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
Daniel Dunbar64371262011-11-05 06:30:03 +0000347 --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
348 --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
Michael Gottesman21c69482013-08-15 04:16:12 +0000349 OUTPUT_VARIABLE LLVMBUILDOUTPUT
Daniel Dunbar64371262011-11-05 06:30:03 +0000350 ERROR_VARIABLE LLVMBUILDERRORS
351 OUTPUT_STRIP_TRAILING_WHITESPACE
352 ERROR_STRIP_TRAILING_WHITESPACE
353 RESULT_VARIABLE LLVMBUILDRESULT)
354
355# On Win32, CMake doesn't properly handle piping the default output/error
356# streams into the GUI console. So, we explicitly catch and report them.
357if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
358 message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
359endif()
360if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
361 message(FATAL_ERROR
362 "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
363endif()
364
365# Include the generated CMake fragment. This will define properties from the
366# LLVMBuild files in a format which is easy to consume from CMake, and will add
367# the dependencies so that CMake will reconfigure properly when the LLVMBuild
368# files change.
369include(${LLVMBUILDCMAKEFRAG})
370
371######
372
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000373# Configure all of the various header file fragments LLVM uses which depend on
374# configuration variables.
Andy Gibbsf5dede12013-06-26 07:57:53 +0000375set(LLVM_ENUM_TARGETS "")
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000376set(LLVM_ENUM_ASM_PRINTERS "")
377set(LLVM_ENUM_ASM_PARSERS "")
378set(LLVM_ENUM_DISASSEMBLERS "")
379foreach(t ${LLVM_TARGETS_TO_BUILD})
380 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
Andy Gibbsf5dede12013-06-26 07:57:53 +0000381
382 list(FIND LLVM_ALL_TARGETS ${t} idx)
383 list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
384 if( idx LESS 0 AND idy LESS 0 )
385 message(FATAL_ERROR "The target `${t}' does not exist.
386 It should be one of\n${LLVM_ALL_TARGETS}")
387 else()
388 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
389 endif()
390
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000391 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
392 if( asmp_file )
393 set(LLVM_ENUM_ASM_PRINTERS
394 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
395 endif()
396 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
397 set(LLVM_ENUM_ASM_PARSERS
398 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
399 endif()
400 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
401 set(LLVM_ENUM_DISASSEMBLERS
402 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
403 endif()
404endforeach(t)
405
406# Produce the target definition files, which provide a way for clients to easily
407# include various classes of targets.
408configure_file(
409 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000410 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000411 )
412configure_file(
413 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000414 ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000415 )
416configure_file(
417 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000418 ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000419 )
420configure_file(
421 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000422 ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
Daniel Dunbar4a2eab02011-11-04 19:04:42 +0000423 )
424
425# Configure the three LLVM configuration header files.
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000426configure_file(
427 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000428 ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000429configure_file(
430 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000431 ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
Oscar Fuentesf4202ba2011-02-03 20:57:36 +0000432configure_file(
433 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000434 ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
Oscar Fuentesedfc1842011-01-09 14:34:39 +0000435
NAKAMURA Takumi0ec65f12014-01-19 12:47:22 +0000436# They are not referenced. See set_output_directory().
437set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000438set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
439set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
440
Rafael Espindola478873c2014-02-22 13:29:31 +0000441set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
442if (APPLE)
443 set(CMAKE_INSTALL_NAME_DIR "@rpath")
444 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
445else(UNIX)
Bernard Ogden301bafe2014-02-24 22:23:43 +0000446 if(NOT DEFINED CMAKE_INSTALL_RPATH)
447 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
448 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
Rafael Espindola478873c2014-02-22 13:29:31 +0000449endif()
Rafael Espindola6ad1b3f2013-12-19 23:13:58 +0000450
Oscar Fuentes210b06a2011-02-14 20:13:58 +0000451set(CMAKE_INCLUDE_CURRENT_DIR ON)
452
NAKAMURA Takumi03932fb2013-12-16 15:05:39 +0000453include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000454
David Chisnall79450132013-02-14 15:40:44 +0000455if( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
456 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
457 # with libxml2, iconv.h, etc., we must add /usr/local paths.
458 include_directories("/usr/local/include")
459 link_directories("/usr/local/lib")
460endif( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
461
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000462if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
Oscar Fuentes2d48f652011-07-17 17:35:15 +0000463 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000464endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
465
Rafael Espindola76f92272013-04-04 01:01:32 +0000466# Make sure we don't get -rdynamic in every binary. For those that need it,
467# use set_target_properties(target PROPERTIES ENABLE_EXPORTS 1)
468set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
469
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000470include(AddLLVM)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000471include(TableGen)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000472
Michael J. Spencer7c3a5ee2010-09-11 02:13:39 +0000473if( MINGW )
Oscar Fuentes9bf25952011-01-07 20:31:03 +0000474 # People report that -O3 is unreliable on MinGW. The traditional
475 # build also uses -O2 for that reason:
476 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
477endif()
478
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000479# Put this before tblgen. Else we have a circular dependence.
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000480add_subdirectory(lib/Support)
Peter Collingbourne84c287e2011-10-01 16:41:13 +0000481add_subdirectory(lib/TableGen)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000482
Oscar Fuentese352ca02008-11-10 01:32:14 +0000483add_subdirectory(utils/TableGen)
484
Oscar Fuentesdc8d56e2008-11-15 00:24:38 +0000485add_subdirectory(include/llvm)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000486
Oscar Fuentes5ed96262011-02-18 22:06:14 +0000487add_subdirectory(lib)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000488
Douglas Gregor289dfc52009-07-20 18:30:25 +0000489add_subdirectory(utils/FileCheck)
Michael J. Spencer01639a42010-12-09 17:54:44 +0000490add_subdirectory(utils/FileUpdate)
Daniel Dunbar00dd4482009-09-24 06:23:57 +0000491add_subdirectory(utils/count)
492add_subdirectory(utils/not)
Michael J. Spencer885611b2010-09-13 17:52:38 +0000493add_subdirectory(utils/llvm-lit)
Michael J. Spencer22120c42012-04-03 23:09:22 +0000494add_subdirectory(utils/yaml-bench)
Douglas Gregor289dfc52009-07-20 18:30:25 +0000495
NAKAMURA Takumi5a0234f2014-01-31 17:32:46 +0000496if(LLVM_INCLUDE_TESTS)
497 add_subdirectory(utils/unittest)
498endif()
499
Oscar Fuentesafbe9752009-03-06 01:16:52 +0000500add_subdirectory(projects)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000501
Oscar Fuentesbf030842010-09-25 20:43:06 +0000502if( LLVM_INCLUDE_TOOLS )
503 add_subdirectory(tools)
504endif()
Oscar Fuentesacfd9ad2009-08-16 20:56:30 +0000505
Oscar Fuentesbf030842010-09-25 20:43:06 +0000506if( LLVM_INCLUDE_EXAMPLES )
507 add_subdirectory(examples)
508endif()
Oscar Fuentes64c99622008-10-22 02:56:07 +0000509
Oscar Fuentesbf030842010-09-25 20:43:06 +0000510if( LLVM_INCLUDE_TESTS )
511 add_subdirectory(test)
Oscar Fuentesbf030842010-09-25 20:43:06 +0000512 add_subdirectory(unittests)
NAKAMURA Takumi4bb599c2010-10-26 05:08:27 +0000513 if (MSVC)
Joel Jones54594f22012-12-13 15:25:07 +0000514 # This utility is used to prevent crashing tests from calling Dr. Watson on
Michael J. Spencer279362d2010-10-11 19:55:38 +0000515 # Windows.
516 add_subdirectory(utils/KillTheDoctor)
517 endif()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000518
519 # Add a global check rule now that all subdirectories have been traversed
520 # and we know the total set of lit testsuites.
521 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
522 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
523 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
524 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
525 add_lit_target(check-all
526 "Running all regression tests"
527 ${LLVM_LIT_TESTSUITES}
528 PARAMS ${LLVM_LIT_PARAMS}
529 DEPENDS ${LLVM_LIT_DEPENDS}
530 ARGS ${LLVM_LIT_EXTRA_ARGS}
531 )
Oscar Fuentesbf030842010-09-25 20:43:06 +0000532endif()
Michael J. Spencer10d274d2010-09-24 09:01:13 +0000533
Michael Gottesman4d35b902013-08-24 07:25:21 +0000534if (LLVM_INCLUDE_DOCS)
535 add_subdirectory(docs)
536endif()
537
Oscar Fuentesa389c582010-08-09 03:26:43 +0000538add_subdirectory(cmake/modules)
539
Hans Wennborg16546272013-08-24 00:20:36 +0000540if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
NAKAMURA Takumic70006e2014-02-10 10:50:55 +0000541 install(DIRECTORY include/llvm include/llvm-c
Hans Wennborg16546272013-08-24 00:20:36 +0000542 DESTINATION include
543 FILES_MATCHING
544 PATTERN "*.def"
545 PATTERN "*.h"
546 PATTERN "*.td"
547 PATTERN "*.inc"
548 PATTERN "LICENSE.TXT"
549 PATTERN ".svn" EXCLUDE
550 )
Oscar Fuentes64c99622008-10-22 02:56:07 +0000551
NAKAMURA Takumic70006e2014-02-10 10:50:55 +0000552 install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
Hans Wennborg16546272013-08-24 00:20:36 +0000553 DESTINATION include
554 FILES_MATCHING
555 PATTERN "*.def"
556 PATTERN "*.h"
557 PATTERN "*.gen"
558 PATTERN "*.inc"
559 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
560 PATTERN "CMakeFiles" EXCLUDE
561 PATTERN ".svn" EXCLUDE
562 )
563endif()
564
NAKAMURA Takumi148b62c2010-11-19 03:19:18 +0000565# Workaround for MSVS10 to avoid the Dialog Hell
566# FIXME: This could be removed with future version of CMake.
567if(MSVC_VERSION EQUAL 1600)
568 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
569 if( EXISTS "${LLVM_SLN_FILENAME}" )
570 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
571 endif()
572endif()
Rafael Espindolafc0447b2013-10-31 22:13:41 +0000573