blob: 5e27c6f82e4703b0b7059c8c7a19ab4b3db55734 [file] [log] [blame]
Oscar Fuentes34fc5172009-04-04 22:52:02 +00001# See docs/CMake.html for instructions about how to build LLVM with CMake.
2
Cedric Venet1d083f42008-10-30 21:22:00 +00003project(LLVM)
Oscar Fuentesc677c5d2010-08-03 15:07:17 +00004cmake_minimum_required(VERSION 2.8)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +00005
Oscar Fuentesee993172010-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
Douglas Gregor6b5db952010-09-23 14:19:21 +000013set(PACKAGE_VERSION "2.9")
Oscar Fuentes784a1762010-12-20 09:47:13 +000014
Oscar Fuentesee993172010-08-03 17:28:09 +000015include(VersionFromVCS)
Oscar Fuentes784a1762010-12-20 09:47:13 +000016
17option(LLVM_APPEND_VC_REV
18 "Append the version control system revision id to LLVM version" OFF)
19
20if( LLVM_APPEND_VC_REV )
21 add_version_info_from_vcs(PACKAGE_VERSION)
22endif()
Oscar Fuentesee993172010-08-03 17:28:09 +000023
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000024set(PACKAGE_NAME llvm)
Chris Lattner8c46e852009-01-28 17:49:03 +000025set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Oscar Fuentesf7e73b92008-10-25 03:49:35 +000026set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000027
Oscar Fuentes6326a0d2008-11-14 03:43:18 +000028if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
29 message(FATAL_ERROR "In-source builds are not allowed.
30CMake would overwrite the makefiles distributed with LLVM.
31Please create a directory and run cmake from there, passing the path
32to this source directory as the last argument.
33This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
34Please delete them.")
35endif()
36
NAKAMURA Takumid420e7b2010-11-27 13:10:11 +000037# Run-time build mode; It is used for unittests.
38if(MSVC_IDE)
39 # Expect "$(Configuration)", "$(OutDir)", etc.
40 # It is expanded by msbuild or similar.
41 set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
42elseif(NOT CMAKE_BUILD_TYPE STREQUAL "")
43 # Expect "Release" "Debug", etc.
44 # Or unittests could not run.
45 set(RUNTIME_BUILD_MODE ${CMAKE_BUILD_TYPE})
46else()
47 # It might be "."
48 set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
49endif()
50
Oscar Fuentes81a87552009-06-03 15:11:25 +000051string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
52
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000053set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Oscar Fuentes980e8422008-10-29 02:33:15 +000054set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000055set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
56set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
57set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
Oscar Fuentesaf0f65f2009-06-12 02:49:53 +000058set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000059
Oscar Fuentes6761c5d2009-07-13 21:58:44 +000060if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
61 file(GLOB_RECURSE
62 tablegenned_files_on_include_dir
63 "${LLVM_MAIN_SRC_DIR}/include/llvm/*.gen")
64 file(GLOB_RECURSE
65 tablegenned_files_on_lib_dir
66 "${LLVM_MAIN_SRC_DIR}/lib/Target/*.inc")
67 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
68 message(FATAL_ERROR "Apparently there is a previous in-source build,
69probably as the result of running `configure' and `make' on
70${LLVM_MAIN_SRC_DIR}.
71This may cause problems. The suspicious files are:
72${tablegenned_files_on_lib_dir}
73${tablegenned_files_on_include_dir}
74Please clean the source directory.")
75 endif()
76endif()
77
Oscar Fuentes4f21c132008-11-10 01:47:07 +000078set(LLVM_ALL_TARGETS
79 Alpha
80 ARM
Jakob Stoklund Olesen73b7bb72009-08-02 17:32:37 +000081 Blackfin
Oscar Fuentes4f21c132008-11-10 01:47:07 +000082 CBackend
83 CellSPU
84 CppBackend
Oscar Fuentes4f21c132008-11-10 01:47:07 +000085 Mips
Wesley Peckc84a9562010-03-05 15:15:55 +000086 MBlaze
Richard Penningtona51984b2009-07-09 20:27:09 +000087 MSP430
Oscar Fuentes4f21c132008-11-10 01:47:07 +000088 PowerPC
Oscar Fuentesb2c70cf2010-09-28 14:02:36 +000089 PTX
Oscar Fuentes4f21c132008-11-10 01:47:07 +000090 Sparc
Daniel Dunbar3f189a32009-07-20 00:24:17 +000091 SystemZ
Oscar Fuentes4f21c132008-11-10 01:47:07 +000092 X86
93 XCore
94 )
95
Oscar Fuentese1ad0872008-09-26 04:40:32 +000096if( MSVC )
97 set(LLVM_TARGETS_TO_BUILD X86
Oscar Fuentes4f21c132008-11-10 01:47:07 +000098 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000099else( MSVC )
Oscar Fuentes4f21c132008-11-10 01:47:07 +0000100 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
101 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000102endif( MSVC )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000103
Chandler Carruth6b241162010-10-19 08:21:25 +0000104set(CLANG_RESOURCE_DIR "" CACHE STRING
105 "Relative directory from the Clang binary to its resource files.")
106
Oscar Fuentes8e3c1692009-11-12 06:48:09 +0000107set(C_INCLUDE_DIRS "" CACHE STRING
108 "Colon separated list of directories clang will search for headers.")
109
Oscar Fuentesa9ff1392009-09-13 22:18:38 +0000110set(LLVM_TARGET_ARCH "host"
111 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
112
NAKAMURA Takumie7ae70b2010-11-11 04:09:35 +0000113set(LIT_ARGS_DEFAULT "-sv")
114if (MSVC OR XCODE)
115 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
116endif()
117set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
118 CACHE STRING "Default options for lit")
119
Oscar Fuentes4b442832008-11-18 23:45:21 +0000120option(LLVM_ENABLE_THREADS "Use threads if available." ON)
121
Oscar Fuentes81a87552009-06-03 15:11:25 +0000122if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
Oscar Fuentes76941b22009-06-04 09:26:16 +0000123 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
Oscar Fuentes81a87552009-06-03 15:11:25 +0000124else()
Oscar Fuentes76941b22009-06-04 09:26:16 +0000125 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
Oscar Fuentes81a87552009-06-03 15:11:25 +0000126endif()
127
Oscar Fuentes76941b22009-06-04 09:26:16 +0000128if( LLVM_ENABLE_ASSERTIONS )
Oscar Fuentesaf109102009-07-05 18:43:52 +0000129 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
Oscar Fuentese8c81ea2009-07-05 23:58:20 +0000130 if( NOT MSVC )
Oscar Fuentesaf109102009-07-05 18:43:52 +0000131 add_definitions( -D_DEBUG )
132 endif()
Oscar Fuentes76941b22009-06-04 09:26:16 +0000133 # On Release builds cmake automatically defines NDEBUG, so we
134 # explicitly undefine it:
135 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
136 add_definitions( -UNDEBUG )
137 endif()
138else()
139 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
140 add_definitions( -DNDEBUG )
141 endif()
Oscar Fuentes81a87552009-06-03 15:11:25 +0000142endif()
143
Oscar Fuentes4f21c132008-11-10 01:47:07 +0000144if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
145 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
146endif()
147
Douglas Gregor1555a232009-06-16 20:12:29 +0000148set(LLVM_ENUM_TARGETS "")
Oscar Fuentes4f21c132008-11-10 01:47:07 +0000149foreach(c ${LLVM_TARGETS_TO_BUILD})
150 list(FIND LLVM_ALL_TARGETS ${c} idx)
151 if( idx LESS 0 )
Gabor Greif9befba82009-08-12 08:37:37 +0000152 message(FATAL_ERROR "The target `${c}' does not exist.
Oscar Fuentes4f21c132008-11-10 01:47:07 +0000153 It should be one of\n${LLVM_ALL_TARGETS}")
Douglas Gregor1555a232009-06-16 20:12:29 +0000154 else()
155 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
Oscar Fuentes4f21c132008-11-10 01:47:07 +0000156 endif()
157endforeach(c)
158
Douglas Gregor1555a232009-06-16 20:12:29 +0000159# Produce llvm/Config/Targets.def
160configure_file(
161 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
162 ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
163 )
164
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000165set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
166
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000167include(AddLLVMDefinitions)
168
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000169if(WIN32)
Oscar Fuentes4fd38b82008-10-30 17:15:54 +0000170 if(CYGWIN)
171 set(LLVM_ON_WIN32 0)
172 set(LLVM_ON_UNIX 1)
173 else(CYGWIN)
174 set(LLVM_ON_WIN32 1)
175 set(LLVM_ON_UNIX 0)
176 endif(CYGWIN)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000177 set(LTDL_SHLIB_EXT ".dll")
178 set(EXEEXT ".exe")
179 # Maximum path length is 160 for non-unicode paths
180 set(MAXPATHLEN 160)
181else(WIN32)
182 if(UNIX)
183 set(LLVM_ON_WIN32 0)
184 set(LLVM_ON_UNIX 1)
Daniel Dunbar05dafd82009-09-22 06:09:37 +0000185 if(APPLE)
186 set(LTDL_SHLIB_EXT ".dylib")
187 else(APPLE)
188 set(LTDL_SHLIB_EXT ".so")
189 endif(APPLE)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000190 set(EXEEXT "")
191 # FIXME: Maximum path length is currently set to 'safe' fixed value
192 set(MAXPATHLEN 2024)
193 else(UNIX)
194 MESSAGE(SEND_ERROR "Unable to determine platform")
195 endif(UNIX)
196endif(WIN32)
197
Oscar Fuentesde98db32008-10-25 03:29:36 +0000198include(config-ix)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000199
Oscar Fuentes1e02bf02009-08-18 15:29:35 +0000200option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000201
Douglas Gregor318de602009-06-05 23:46:34 +0000202set(ENABLE_PIC 0)
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000203if( LLVM_ENABLE_PIC )
Daniel Dunbar36206182009-11-08 00:34:22 +0000204 if( XCODE )
205 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
206 # know how to disable this, so just force ENABLE_PIC off for now.
207 message(STATUS "Warning: -fPIC not supported with Xcode.")
208 else( XCODE )
209 if( SUPPORTS_FPIC_FLAG )
210 message(STATUS "Building with -fPIC")
211 add_llvm_definitions(-fPIC)
212 set(ENABLE_PIC 1)
213 else( SUPPORTS_FPIC_FLAG )
214 message(STATUS "Warning: -fPIC not supported.")
215 endif()
216 endif()
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000217endif()
218
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000219set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
220set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
221set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
222
223# set(CMAKE_VERBOSE_MAKEFILE true)
224
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000225add_llvm_definitions( -D__STDC_LIMIT_MACROS )
226add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000227
Daniel Dunbar9ea3a2c2009-12-01 19:11:36 +0000228# MSVC has a gazillion warnings with this.
229if( MSVC )
230 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
231else( MSVC )
232 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
233endif()
234
Oscar Fuentesf12a9002009-12-01 02:21:51 +0000235option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
236option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
237
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000238if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
239 # TODO: support other platforms and toolchains.
Oscar Fuentes6307b942008-11-19 00:10:39 +0000240 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
241 if( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000242 message(STATUS "Building 32 bits executables and libraries.")
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000243 add_llvm_definitions( -m32 )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000244 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
245 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
Oscar Fuentes6307b942008-11-19 00:10:39 +0000246 endif( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000247endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
248
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000249if( MSVC )
Oscar Fuentes02a8f762010-08-05 01:25:48 +0000250 include(ChooseMSVCCRT)
Stefanus Du Toit4ba3a0e2009-06-08 21:18:31 +0000251
Michael J. Spencer57e91042010-12-18 00:18:58 +0000252 # Add definitions that make MSVC much less annoying.
253 add_llvm_definitions(
254 # For some reason MS wants to deprecate a bunch of standard functions...
255 -D_CRT_SECURE_NO_DEPRECATE
256 -D_CRT_SECURE_NO_WARNINGS
257 -D_CRT_NONSTDC_NO_DEPRECATE
258 -D_CRT_NONSTDC_NO_WARNINGS
259 -D_SCL_SECURE_NO_DEPRECATE
260 -D_SCL_SECURE_NO_WARNINGS
Stefanus Du Toit4ba3a0e2009-06-08 21:18:31 +0000261
Michael J. Spencer57e91042010-12-18 00:18:58 +0000262 -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
263 -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
264 -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type'
265 -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
266 -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
267 -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
268 -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
269 -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
270 -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
271 -wd4355 # Suppress ''this' : used in base member initializer list'
272 -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
273 -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
274 -wd4715 # Suppress ''function' : not all control paths return a value'
275 -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
276
277 -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning.
278 )
Daniel Dunbar2c4df5a2009-07-19 01:35:10 +0000279
Oscar Fuentesf12a9002009-12-01 02:21:51 +0000280 # Enable warnings
281 if (LLVM_ENABLE_WARNINGS)
282 add_llvm_definitions( /W4 /Wall )
283 if (LLVM_ENABLE_PEDANTIC)
284 # No MSVC equivalent available
285 endif (LLVM_ENABLE_PEDANTIC)
286 endif (LLVM_ENABLE_WARNINGS)
287 if (LLVM_ENABLE_WERROR)
288 add_llvm_definitions( /WX )
289 endif (LLVM_ENABLE_WERROR)
Oscar Fuentes2343b102009-11-30 23:50:14 +0000290elseif( CMAKE_COMPILER_IS_GNUCXX )
Oscar Fuentesf12a9002009-12-01 02:21:51 +0000291 if (LLVM_ENABLE_WARNINGS)
292 add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings )
293 if (LLVM_ENABLE_PEDANTIC)
294 add_llvm_definitions( -pedantic -Wno-long-long )
295 endif (LLVM_ENABLE_PEDANTIC)
296 endif (LLVM_ENABLE_WARNINGS)
297 if (LLVM_ENABLE_WERROR)
298 add_llvm_definitions( -Werror )
299 endif (LLVM_ENABLE_WERROR)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000300endif( MSVC )
301
Oscar Fuentes980e8422008-10-29 02:33:15 +0000302include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000303
Edward O'Callaghanc6cf5fe2009-10-12 04:00:11 +0000304if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000305 SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
Edward O'Callaghanc6cf5fe2009-10-12 04:00:11 +0000306endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
307
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000308include(AddLLVM)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000309include(TableGen)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000310
Michael J. Spencer1c4e9342010-09-11 02:13:39 +0000311if( MINGW )
312 get_system_libs(LLVM_SYSTEM_LIBS_LIST)
313 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
314 set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
315 endforeach()
316 set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
317 set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
318endif()
319
Oscar Fuentes53bf3ee2011-01-07 20:31:03 +0000320if( MINGW )
321 # People report that -O3 is unreliable on MinGW. The traditional
322 # build also uses -O2 for that reason:
323 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
324endif()
325
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000326add_subdirectory(lib/Support)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000327
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000328# Everything else depends on Support:
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000329set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
330
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000331set(LLVM_TABLEGEN "tblgen" CACHE
Oscar Fuentes41bdedf2008-11-10 02:35:55 +0000332 STRING "Native TableGen executable. Saves building one when cross-compiling.")
Oscar Fuentes99b94892009-06-11 04:16:10 +0000333# Effective tblgen executable to be used:
334set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000335
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000336add_subdirectory(utils/TableGen)
337
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000338if( CMAKE_CROSSCOMPILING )
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000339 # This adds a dependency on target `tblgen', so must go after utils/TableGen
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000340 include( CrossCompileLLVM )
341endif( CMAKE_CROSSCOMPILING )
342
Oscar Fuentes422fcf32008-11-15 00:24:38 +0000343add_subdirectory(include/llvm)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000344
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000345add_subdirectory(lib/VMCore)
346add_subdirectory(lib/CodeGen)
347add_subdirectory(lib/CodeGen/SelectionDAG)
348add_subdirectory(lib/CodeGen/AsmPrinter)
349add_subdirectory(lib/Bitcode/Reader)
350add_subdirectory(lib/Bitcode/Writer)
351add_subdirectory(lib/Transforms/Utils)
352add_subdirectory(lib/Transforms/Instrumentation)
Douglas Gregorf1c3a862010-01-04 21:58:55 +0000353add_subdirectory(lib/Transforms/InstCombine)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000354add_subdirectory(lib/Transforms/Scalar)
355add_subdirectory(lib/Transforms/IPO)
356add_subdirectory(lib/Transforms/Hello)
357add_subdirectory(lib/Linker)
358add_subdirectory(lib/Analysis)
359add_subdirectory(lib/Analysis/IPA)
Daniel Dunbarecc63f82009-06-23 22:01:43 +0000360add_subdirectory(lib/MC)
Daniel Dunbar4bd8dc32010-01-22 02:04:33 +0000361add_subdirectory(lib/MC/MCParser)
Chris Lattner847da552010-07-20 18:25:19 +0000362add_subdirectory(lib/MC/MCDisassembler)
Michael J. Spencer68b3f0c2010-11-15 03:21:41 +0000363add_subdirectory(lib/Object)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000364
Douglas Gregor4d20c242009-07-20 18:30:25 +0000365add_subdirectory(utils/FileCheck)
Michael J. Spencer014e1892010-12-09 17:54:44 +0000366add_subdirectory(utils/FileUpdate)
Daniel Dunbar48f7ce82009-09-24 06:23:57 +0000367add_subdirectory(utils/count)
368add_subdirectory(utils/not)
Michael J. Spencerbecf3922010-09-13 17:52:38 +0000369add_subdirectory(utils/llvm-lit)
Douglas Gregor4d20c242009-07-20 18:30:25 +0000370
Oscar Fuentes75caad42009-08-14 04:55:21 +0000371set(LLVM_ENUM_ASM_PRINTERS "")
372set(LLVM_ENUM_ASM_PARSERS "")
Daniel Dunbarfa3f0b92009-11-25 04:30:13 +0000373set(LLVM_ENUM_DISASSEMBLERS "")
Oscar Fuentes75caad42009-08-14 04:55:21 +0000374foreach(t ${LLVM_TARGETS_TO_BUILD})
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000375 message(STATUS "Targeting ${t}")
376 add_subdirectory(lib/Target/${t})
Daniel Dunbarb5a8c082009-07-15 07:04:27 +0000377 add_subdirectory(lib/Target/${t}/TargetInfo)
Oscar Fuentesdb2c5092010-11-14 21:17:13 +0000378 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
379 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
380 if( asmp_file )
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000381 set(LLVM_ENUM_ASM_PRINTERS
Chris Lattneraeafb892010-11-14 19:12:57 +0000382 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
Oscar Fuentes14b0c052010-11-14 20:15:05 +0000383 endif()
Oscar Fuentesdb2c5092010-11-14 21:17:13 +0000384 if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
Oscar Fuentesbab2b012010-10-02 02:38:42 +0000385 add_subdirectory(lib/Target/${t}/InstPrinter)
Oscar Fuentesdb2c5092010-11-14 21:17:13 +0000386 endif()
387 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
Oscar Fuentes75caad42009-08-14 04:55:21 +0000388 add_subdirectory(lib/Target/${t}/AsmParser)
Michael J. Spencer1f6efa32010-11-29 18:16:10 +0000389 set(LLVM_ENUM_ASM_PARSERS
Oscar Fuentes75caad42009-08-14 04:55:21 +0000390 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
Oscar Fuentesdb2c5092010-11-14 21:17:13 +0000391 endif()
392 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
Daniel Dunbarfa3f0b92009-11-25 04:30:13 +0000393 add_subdirectory(lib/Target/${t}/Disassembler)
394 set(LLVM_ENUM_DISASSEMBLERS
395 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
Oscar Fuentesdb2c5092010-11-14 21:17:13 +0000396 endif()
Oscar Fuentesb78829e2009-08-16 05:16:43 +0000397 set(CURRENT_LLVM_TARGET)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000398endforeach(t)
399
Douglas Gregor1555a232009-06-16 20:12:29 +0000400# Produce llvm/Config/AsmPrinters.def
401configure_file(
402 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
403 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
404 )
405
Daniel Dunbar092a9dd2009-07-17 20:42:00 +0000406# Produce llvm/Config/AsmParsers.def
407configure_file(
408 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
409 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
410 )
411
Daniel Dunbarfa3f0b92009-11-25 04:30:13 +0000412# Produce llvm/Config/Disassemblers.def
413configure_file(
414 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
415 ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
416 )
417
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000418add_subdirectory(lib/ExecutionEngine)
419add_subdirectory(lib/ExecutionEngine/Interpreter)
420add_subdirectory(lib/ExecutionEngine/JIT)
Wesley Peckb977f042010-11-17 23:35:07 +0000421add_subdirectory(lib/ExecutionEngine/MCJIT)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000422add_subdirectory(lib/Target)
423add_subdirectory(lib/AsmParser)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000424add_subdirectory(lib/Archive)
425
Oscar Fuentes5c6bf652009-03-06 01:16:52 +0000426add_subdirectory(projects)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000427
Oscar Fuentesa6c1dbd2010-09-25 20:43:06 +0000428option(LLVM_BUILD_TOOLS
429 "Build the LLVM tools. If OFF, just generate build targets." ON)
430option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
431if( LLVM_INCLUDE_TOOLS )
432 add_subdirectory(tools)
433endif()
Oscar Fuentesc81f56d2009-08-16 20:56:30 +0000434
Oscar Fuentesa6c1dbd2010-09-25 20:43:06 +0000435option(LLVM_BUILD_EXAMPLES
436 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
437option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
438if( LLVM_INCLUDE_EXAMPLES )
439 add_subdirectory(examples)
440endif()
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000441
Oscar Fuentesa6c1dbd2010-09-25 20:43:06 +0000442option(LLVM_BUILD_TESTS
443 "Build LLVM unit tests. If OFF, just generate build targes." OFF)
444option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
445if( LLVM_INCLUDE_TESTS )
446 add_subdirectory(test)
447 add_subdirectory(utils/unittest)
448 add_subdirectory(unittests)
NAKAMURA Takumi15b337c2010-10-26 05:08:27 +0000449 if (MSVC)
Michael J. Spencerbbb9ea72010-10-11 19:55:38 +0000450 # This utility is used to prevent chrashing tests from calling Dr. Watson on
451 # Windows.
452 add_subdirectory(utils/KillTheDoctor)
453 endif()
Oscar Fuentesa6c1dbd2010-09-25 20:43:06 +0000454endif()
Michael J. Spenceree6944f2010-09-24 09:01:13 +0000455
Oscar Fuentes6252e982010-08-09 03:26:43 +0000456add_subdirectory(cmake/modules)
457
Oscar Fuentes1d7c43b2009-10-27 19:57:29 +0000458install(DIRECTORY include/
459 DESTINATION include
460 FILES_MATCHING
Oscar Fuentesbc2eb132009-10-30 11:42:08 +0000461 PATTERN "*.def"
Oscar Fuentes1d7c43b2009-10-27 19:57:29 +0000462 PATTERN "*.h"
463 PATTERN "*.td"
Oscar Fuentesa2281e72009-10-27 20:04:22 +0000464 PATTERN "*.inc"
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000465 PATTERN ".svn" EXCLUDE
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000466 )
467
Oscar Fuentes1d7c43b2009-10-27 19:57:29 +0000468install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
469 DESTINATION include
470 FILES_MATCHING
471 PATTERN "*.def"
472 PATTERN "*.h"
473 PATTERN "*.gen"
Oscar Fuentesa2281e72009-10-27 20:04:22 +0000474 PATTERN "*.inc"
Oscar Fuentes1d7c43b2009-10-27 19:57:29 +0000475 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
476 PATTERN "CMakeFiles" EXCLUDE
477 PATTERN ".svn" EXCLUDE
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000478 )
479
480# TODO: make and install documentation.
Oscar Fuentes4d156d32010-10-14 21:11:51 +0000481
482set(CPACK_PACKAGE_VENDOR "LLVM")
483set(CPACK_PACKAGE_VERSION_MAJOR 2)
484set(CPACK_PACKAGE_VERSION_MINOR 9)
485add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
486include(CPack)
NAKAMURA Takumi4c8710d2010-11-19 03:19:18 +0000487
488# Workaround for MSVS10 to avoid the Dialog Hell
489# FIXME: This could be removed with future version of CMake.
490if(MSVC_VERSION EQUAL 1600)
491 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
492 if( EXISTS "${LLVM_SLN_FILENAME}" )
493 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
494 endif()
495endif()