blob: 62a08b250a6f76255d0661eebbfbc8858c215237 [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)
Oscar Fuentes758f71a2010-08-03 15:07:17 +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
Douglas Gregor381f98e2010-09-23 14:19:21 +000013set(PACKAGE_VERSION "2.9")
Oscar Fuentes052c23c2010-08-03 17:28:09 +000014include(VersionFromVCS)
15add_version_info_from_vcs(PACKAGE_VERSION)
16
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000017set(PACKAGE_NAME llvm)
Chris Lattnerff2d99d2009-01-28 17:49:03 +000018set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Oscar Fuentes24617b72008-10-25 03:49:35 +000019set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000020
Oscar Fuentesa5f83562008-11-14 03:43:18 +000021if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
22 message(FATAL_ERROR "In-source builds are not allowed.
23CMake would overwrite the makefiles distributed with LLVM.
24Please create a directory and run cmake from there, passing the path
25to this source directory as the last argument.
26This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
27Please delete them.")
28endif()
29
Oscar Fuentes61338132009-06-03 15:11:25 +000030string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
31
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000032set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Oscar Fuentes2500aae2008-10-29 02:33:15 +000033set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000034set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
35set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
36set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
Oscar Fuentes46fed3b2009-06-12 02:49:53 +000037set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000038
Oscar Fuentes304396a2009-07-13 21:58:44 +000039if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
40 file(GLOB_RECURSE
41 tablegenned_files_on_include_dir
42 "${LLVM_MAIN_SRC_DIR}/include/llvm/*.gen")
43 file(GLOB_RECURSE
44 tablegenned_files_on_lib_dir
45 "${LLVM_MAIN_SRC_DIR}/lib/Target/*.inc")
46 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
47 message(FATAL_ERROR "Apparently there is a previous in-source build,
48probably as the result of running `configure' and `make' on
49${LLVM_MAIN_SRC_DIR}.
50This may cause problems. The suspicious files are:
51${tablegenned_files_on_lib_dir}
52${tablegenned_files_on_include_dir}
53Please clean the source directory.")
54 endif()
55endif()
56
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000057set(LLVM_ALL_TARGETS
58 Alpha
59 ARM
Jakob Stoklund Olesen526e8032009-08-02 17:32:37 +000060 Blackfin
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000061 CBackend
62 CellSPU
63 CppBackend
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000064 Mips
Wesley Peckb0578bf2010-03-05 15:15:55 +000065 MBlaze
Richard Pennington9f3bd4a2009-07-09 20:27:09 +000066 MSP430
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000067 PowerPC
Oscar Fuentesb35856e32010-09-28 14:02:36 +000068 PTX
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000069 Sparc
Daniel Dunbar88f35c82009-07-20 00:24:17 +000070 SystemZ
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000071 X86
72 XCore
73 )
74
Oscar Fuentescdc95492008-09-26 04:40:32 +000075if( MSVC )
76 set(LLVM_TARGETS_TO_BUILD X86
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000077 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentescdc95492008-09-26 04:40:32 +000078else( MSVC )
Oscar Fuentese9edc2c2008-11-10 01:47:07 +000079 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
80 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentescdc95492008-09-26 04:40:32 +000081endif( MSVC )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000082
Chandler Carruthffae4a62010-10-19 08:21:25 +000083set(CLANG_RESOURCE_DIR "" CACHE STRING
84 "Relative directory from the Clang binary to its resource files.")
85
Oscar Fuentes700205c2009-11-12 06:48:09 +000086set(C_INCLUDE_DIRS "" CACHE STRING
87 "Colon separated list of directories clang will search for headers.")
88
Oscar Fuentesb9a78132009-09-13 22:18:38 +000089set(LLVM_TARGET_ARCH "host"
90 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
91
NAKAMURA Takumif7910072010-11-11 04:09:35 +000092set(LIT_ARGS_DEFAULT "-sv")
93if (MSVC OR XCODE)
94 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
95endif()
96set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
97 CACHE STRING "Default options for lit")
98
Oscar Fuentes366fbb72008-11-18 23:45:21 +000099option(LLVM_ENABLE_THREADS "Use threads if available." ON)
100
Oscar Fuentes61338132009-06-03 15:11:25 +0000101if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
Oscar Fuentes208a8732009-06-04 09:26:16 +0000102 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
Oscar Fuentes61338132009-06-03 15:11:25 +0000103else()
Oscar Fuentes208a8732009-06-04 09:26:16 +0000104 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
Oscar Fuentes61338132009-06-03 15:11:25 +0000105endif()
106
Oscar Fuentes208a8732009-06-04 09:26:16 +0000107if( LLVM_ENABLE_ASSERTIONS )
Oscar Fuentes56745312009-07-05 18:43:52 +0000108 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
Oscar Fuentesc296b892009-07-05 23:58:20 +0000109 if( NOT MSVC )
Oscar Fuentes56745312009-07-05 18:43:52 +0000110 add_definitions( -D_DEBUG )
111 endif()
Oscar Fuentes208a8732009-06-04 09:26:16 +0000112 # On Release builds cmake automatically defines NDEBUG, so we
113 # explicitly undefine it:
114 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
115 add_definitions( -UNDEBUG )
116 endif()
117else()
118 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
119 add_definitions( -DNDEBUG )
120 endif()
Oscar Fuentes61338132009-06-03 15:11:25 +0000121endif()
122
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000123if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
124 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
125endif()
126
Douglas Gregor1b731d52009-06-16 20:12:29 +0000127set(LLVM_ENUM_TARGETS "")
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000128foreach(c ${LLVM_TARGETS_TO_BUILD})
129 list(FIND LLVM_ALL_TARGETS ${c} idx)
130 if( idx LESS 0 )
Gabor Greif27c7a9d2009-08-12 08:37:37 +0000131 message(FATAL_ERROR "The target `${c}' does not exist.
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000132 It should be one of\n${LLVM_ALL_TARGETS}")
Douglas Gregor1b731d52009-06-16 20:12:29 +0000133 else()
134 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
Oscar Fuentese9edc2c2008-11-10 01:47:07 +0000135 endif()
136endforeach(c)
137
Douglas Gregor1b731d52009-06-16 20:12:29 +0000138# Produce llvm/Config/Targets.def
139configure_file(
140 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
141 ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
142 )
143
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000144set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
145
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000146include(AddLLVMDefinitions)
147
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000148if(WIN32)
Oscar Fuentes876aa172008-10-30 17:15:54 +0000149 if(CYGWIN)
150 set(LLVM_ON_WIN32 0)
151 set(LLVM_ON_UNIX 1)
152 else(CYGWIN)
153 set(LLVM_ON_WIN32 1)
154 set(LLVM_ON_UNIX 0)
155 endif(CYGWIN)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000156 set(LTDL_SHLIB_EXT ".dll")
157 set(EXEEXT ".exe")
158 # Maximum path length is 160 for non-unicode paths
159 set(MAXPATHLEN 160)
160else(WIN32)
161 if(UNIX)
162 set(LLVM_ON_WIN32 0)
163 set(LLVM_ON_UNIX 1)
Daniel Dunbar6ce1ab12009-09-22 06:09:37 +0000164 if(APPLE)
165 set(LTDL_SHLIB_EXT ".dylib")
166 else(APPLE)
167 set(LTDL_SHLIB_EXT ".so")
168 endif(APPLE)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000169 set(EXEEXT "")
170 # FIXME: Maximum path length is currently set to 'safe' fixed value
171 set(MAXPATHLEN 2024)
172 else(UNIX)
173 MESSAGE(SEND_ERROR "Unable to determine platform")
174 endif(UNIX)
175endif(WIN32)
176
Oscar Fuentesa9ac9092008-10-25 03:29:36 +0000177include(config-ix)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000178
Oscar Fuentes6d61f552009-08-18 15:29:35 +0000179option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000180
Douglas Gregor5f11afc2009-06-05 23:46:34 +0000181set(ENABLE_PIC 0)
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000182if( LLVM_ENABLE_PIC )
Daniel Dunbar3908a402009-11-08 00:34:22 +0000183 if( XCODE )
184 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
185 # know how to disable this, so just force ENABLE_PIC off for now.
186 message(STATUS "Warning: -fPIC not supported with Xcode.")
187 else( XCODE )
188 if( SUPPORTS_FPIC_FLAG )
189 message(STATUS "Building with -fPIC")
190 add_llvm_definitions(-fPIC)
191 set(ENABLE_PIC 1)
192 else( SUPPORTS_FPIC_FLAG )
193 message(STATUS "Warning: -fPIC not supported.")
194 endif()
195 endif()
Oscar Fuentes073b0b12008-11-20 19:13:51 +0000196endif()
197
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000198set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
199set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
200set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
201
202# set(CMAKE_VERBOSE_MAKEFILE true)
203
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000204add_llvm_definitions( -D__STDC_LIMIT_MACROS )
205add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000206
Daniel Dunbar04433fe2009-12-01 19:11:36 +0000207# MSVC has a gazillion warnings with this.
208if( MSVC )
209 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
210else( MSVC )
211 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
212endif()
213
Oscar Fuentes5c600b52009-12-01 02:21:51 +0000214option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
215option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
216
Oscar Fuentes7751a7b2008-11-04 03:27:24 +0000217if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
218 # TODO: support other platforms and toolchains.
Oscar Fuentes32581492008-11-19 00:10:39 +0000219 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
220 if( LLVM_BUILD_32_BITS )
Oscar Fuentes7751a7b2008-11-04 03:27:24 +0000221 message(STATUS "Building 32 bits executables and libraries.")
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000222 add_llvm_definitions( -m32 )
Oscar Fuentes32581492008-11-19 00:10:39 +0000223 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
224 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
Oscar Fuentes32581492008-11-19 00:10:39 +0000225 endif( LLVM_BUILD_32_BITS )
Oscar Fuentes7751a7b2008-11-04 03:27:24 +0000226endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
227
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000228if( MSVC )
Oscar Fuentes396cc7d2010-08-05 01:25:48 +0000229 include(ChooseMSVCCRT)
Stefanus Du Toit6b602ad2009-06-08 21:18:31 +0000230
Oscar Fuentesbda403b2009-04-04 22:41:07 +0000231 add_llvm_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
232 add_llvm_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
233 add_llvm_definitions( -D_SCL_SECURE_NO_DEPRECATE )
234 add_llvm_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
Francois Pichetc56f5b92010-10-12 00:01:36 +0000235 add_llvm_definitions( -wd4355 -wd4715 -wd4180 -wd4345 -wd4224 -wd4267 )
Stefanus Du Toit6b602ad2009-06-08 21:18:31 +0000236
Daniel Dunbaracd56a02009-07-19 01:35:10 +0000237 # Suppress 'new behavior: elements of array 'array' will be default initialized'
238 add_llvm_definitions( -wd4351 )
239
Oscar Fuentes5c600b52009-12-01 02:21:51 +0000240 # Enable warnings
241 if (LLVM_ENABLE_WARNINGS)
242 add_llvm_definitions( /W4 /Wall )
243 if (LLVM_ENABLE_PEDANTIC)
244 # No MSVC equivalent available
245 endif (LLVM_ENABLE_PEDANTIC)
246 endif (LLVM_ENABLE_WARNINGS)
247 if (LLVM_ENABLE_WERROR)
248 add_llvm_definitions( /WX )
249 endif (LLVM_ENABLE_WERROR)
Oscar Fuentescc717832009-11-30 23:50:14 +0000250elseif( CMAKE_COMPILER_IS_GNUCXX )
Oscar Fuentes5c600b52009-12-01 02:21:51 +0000251 if (LLVM_ENABLE_WARNINGS)
252 add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings )
253 if (LLVM_ENABLE_PEDANTIC)
254 add_llvm_definitions( -pedantic -Wno-long-long )
255 endif (LLVM_ENABLE_PEDANTIC)
256 endif (LLVM_ENABLE_WARNINGS)
257 if (LLVM_ENABLE_WERROR)
258 add_llvm_definitions( -Werror )
259 endif (LLVM_ENABLE_WERROR)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000260endif( MSVC )
261
Oscar Fuentes2500aae2008-10-29 02:33:15 +0000262include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000263
Edward O'Callaghan396ed2b2009-10-12 04:00:11 +0000264if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
265 SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/System/Solaris.h")
266endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
267
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000268include(AddLLVM)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000269include(TableGen)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000270
Michael J. Spencer7c3a5ee2010-09-11 02:13:39 +0000271if( MINGW )
272 get_system_libs(LLVM_SYSTEM_LIBS_LIST)
273 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
274 set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
275 endforeach()
276 set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
277 set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
278endif()
279
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000280add_subdirectory(lib/Support)
281add_subdirectory(lib/System)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000282
283# Everything else depends on Support and System:
284set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
285
Oscar Fuentesb45a43a2008-11-09 18:53:19 +0000286set(LLVM_TABLEGEN "tblgen" CACHE
Oscar Fuentes9530edd2008-11-10 02:35:55 +0000287 STRING "Native TableGen executable. Saves building one when cross-compiling.")
Oscar Fuentescaa7a942009-06-11 04:16:10 +0000288# Effective tblgen executable to be used:
289set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
Oscar Fuentesb45a43a2008-11-09 18:53:19 +0000290
Oscar Fuentese352ca02008-11-10 01:32:14 +0000291add_subdirectory(utils/TableGen)
292
Oscar Fuentesb45a43a2008-11-09 18:53:19 +0000293if( CMAKE_CROSSCOMPILING )
Oscar Fuentese352ca02008-11-10 01:32:14 +0000294 # This adds a dependency on target `tblgen', so must go after utils/TableGen
Oscar Fuentesb45a43a2008-11-09 18:53:19 +0000295 include( CrossCompileLLVM )
296endif( CMAKE_CROSSCOMPILING )
297
Oscar Fuentesdc8d56e2008-11-15 00:24:38 +0000298add_subdirectory(include/llvm)
Oscar Fuentes8807bdd2008-09-22 18:21:51 +0000299
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000300add_subdirectory(lib/VMCore)
301add_subdirectory(lib/CodeGen)
302add_subdirectory(lib/CodeGen/SelectionDAG)
303add_subdirectory(lib/CodeGen/AsmPrinter)
304add_subdirectory(lib/Bitcode/Reader)
305add_subdirectory(lib/Bitcode/Writer)
306add_subdirectory(lib/Transforms/Utils)
307add_subdirectory(lib/Transforms/Instrumentation)
Douglas Gregor5b88b8a2010-01-04 21:58:55 +0000308add_subdirectory(lib/Transforms/InstCombine)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000309add_subdirectory(lib/Transforms/Scalar)
310add_subdirectory(lib/Transforms/IPO)
311add_subdirectory(lib/Transforms/Hello)
312add_subdirectory(lib/Linker)
313add_subdirectory(lib/Analysis)
314add_subdirectory(lib/Analysis/IPA)
Daniel Dunbarca29e4d2009-06-23 22:01:43 +0000315add_subdirectory(lib/MC)
Daniel Dunbar4dcd3b22010-01-22 02:04:33 +0000316add_subdirectory(lib/MC/MCParser)
Chris Lattner979634b2010-07-20 18:25:19 +0000317add_subdirectory(lib/MC/MCDisassembler)
Michael J. Spencerfe5ee802010-11-15 03:21:41 +0000318add_subdirectory(lib/Object)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000319
Douglas Gregor289dfc52009-07-20 18:30:25 +0000320add_subdirectory(utils/FileCheck)
Daniel Dunbar00dd4482009-09-24 06:23:57 +0000321add_subdirectory(utils/count)
322add_subdirectory(utils/not)
Michael J. Spencer885611b2010-09-13 17:52:38 +0000323add_subdirectory(utils/llvm-lit)
Douglas Gregor289dfc52009-07-20 18:30:25 +0000324
Oscar Fuentes7a87d662009-08-14 04:55:21 +0000325set(LLVM_ENUM_ASM_PRINTERS "")
326set(LLVM_ENUM_ASM_PARSERS "")
Daniel Dunbarf4721292009-11-25 04:30:13 +0000327set(LLVM_ENUM_DISASSEMBLERS "")
Oscar Fuentes7a87d662009-08-14 04:55:21 +0000328foreach(t ${LLVM_TARGETS_TO_BUILD})
Oscar Fuentescdc95492008-09-26 04:40:32 +0000329 message(STATUS "Targeting ${t}")
330 add_subdirectory(lib/Target/${t})
Daniel Dunbarb3ec4882009-07-15 07:04:27 +0000331 add_subdirectory(lib/Target/${t}/TargetInfo)
Oscar Fuentesedf0a1d2010-11-14 21:17:13 +0000332 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
333 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
334 if( asmp_file )
Chris Lattnera4113462010-11-14 19:12:57 +0000335 set(LLVM_ENUM_ASM_PRINTERS
336 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
Oscar Fuentes4d39cc42010-11-14 20:15:05 +0000337 endif()
Oscar Fuentesedf0a1d2010-11-14 21:17:13 +0000338 if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
Oscar Fuentesbd762762010-10-02 02:38:42 +0000339 add_subdirectory(lib/Target/${t}/InstPrinter)
Oscar Fuentesedf0a1d2010-11-14 21:17:13 +0000340 endif()
341 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
Oscar Fuentes7a87d662009-08-14 04:55:21 +0000342 add_subdirectory(lib/Target/${t}/AsmParser)
Daniel Dunbar71475772009-07-17 20:42:00 +0000343 set(LLVM_ENUM_ASM_PARSERS
Oscar Fuentes7a87d662009-08-14 04:55:21 +0000344 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
Oscar Fuentesedf0a1d2010-11-14 21:17:13 +0000345 endif()
346 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
Daniel Dunbarf4721292009-11-25 04:30:13 +0000347 add_subdirectory(lib/Target/${t}/Disassembler)
348 set(LLVM_ENUM_DISASSEMBLERS
349 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
Oscar Fuentesedf0a1d2010-11-14 21:17:13 +0000350 endif()
Oscar Fuentes8160d282009-08-16 05:16:43 +0000351 set(CURRENT_LLVM_TARGET)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000352endforeach(t)
353
Douglas Gregor1b731d52009-06-16 20:12:29 +0000354# Produce llvm/Config/AsmPrinters.def
355configure_file(
356 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
357 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
358 )
359
Daniel Dunbar71475772009-07-17 20:42:00 +0000360# Produce llvm/Config/AsmParsers.def
361configure_file(
362 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
363 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
364 )
365
Daniel Dunbarf4721292009-11-25 04:30:13 +0000366# Produce llvm/Config/Disassemblers.def
367configure_file(
368 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
369 ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
370 )
371
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000372add_subdirectory(lib/ExecutionEngine)
373add_subdirectory(lib/ExecutionEngine/Interpreter)
374add_subdirectory(lib/ExecutionEngine/JIT)
Wesley Peckeef03fb2010-11-17 23:35:07 +0000375add_subdirectory(lib/ExecutionEngine/MCJIT)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000376add_subdirectory(lib/Target)
377add_subdirectory(lib/AsmParser)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000378add_subdirectory(lib/Archive)
379
Oscar Fuentesafbe9752009-03-06 01:16:52 +0000380add_subdirectory(projects)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000381
Oscar Fuentesbf030842010-09-25 20:43:06 +0000382option(LLVM_BUILD_TOOLS
383 "Build the LLVM tools. If OFF, just generate build targets." ON)
384option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
385if( LLVM_INCLUDE_TOOLS )
386 add_subdirectory(tools)
387endif()
Oscar Fuentesacfd9ad2009-08-16 20:56:30 +0000388
Oscar Fuentesbf030842010-09-25 20:43:06 +0000389option(LLVM_BUILD_EXAMPLES
390 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
391option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
392if( LLVM_INCLUDE_EXAMPLES )
393 add_subdirectory(examples)
394endif()
Oscar Fuentes64c99622008-10-22 02:56:07 +0000395
Oscar Fuentesbf030842010-09-25 20:43:06 +0000396option(LLVM_BUILD_TESTS
397 "Build LLVM unit tests. If OFF, just generate build targes." OFF)
398option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
399if( LLVM_INCLUDE_TESTS )
400 add_subdirectory(test)
401 add_subdirectory(utils/unittest)
402 add_subdirectory(unittests)
NAKAMURA Takumi4bb599c2010-10-26 05:08:27 +0000403 if (MSVC)
Michael J. Spencer279362d2010-10-11 19:55:38 +0000404 # This utility is used to prevent chrashing tests from calling Dr. Watson on
405 # Windows.
406 add_subdirectory(utils/KillTheDoctor)
407 endif()
Oscar Fuentesbf030842010-09-25 20:43:06 +0000408endif()
Michael J. Spencer10d274d2010-09-24 09:01:13 +0000409
Oscar Fuentesa389c582010-08-09 03:26:43 +0000410add_subdirectory(cmake/modules)
411
Oscar Fuentes6997c642009-10-27 19:57:29 +0000412install(DIRECTORY include/
413 DESTINATION include
414 FILES_MATCHING
Oscar Fuentes15716f62009-10-30 11:42:08 +0000415 PATTERN "*.def"
Oscar Fuentes6997c642009-10-27 19:57:29 +0000416 PATTERN "*.h"
417 PATTERN "*.td"
Oscar Fuentes08875d12009-10-27 20:04:22 +0000418 PATTERN "*.inc"
Oscar Fuentes64c99622008-10-22 02:56:07 +0000419 PATTERN ".svn" EXCLUDE
Oscar Fuentes64c99622008-10-22 02:56:07 +0000420 )
421
Oscar Fuentes6997c642009-10-27 19:57:29 +0000422install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
423 DESTINATION include
424 FILES_MATCHING
425 PATTERN "*.def"
426 PATTERN "*.h"
427 PATTERN "*.gen"
Oscar Fuentes08875d12009-10-27 20:04:22 +0000428 PATTERN "*.inc"
Oscar Fuentes6997c642009-10-27 19:57:29 +0000429 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
430 PATTERN "CMakeFiles" EXCLUDE
431 PATTERN ".svn" EXCLUDE
Oscar Fuentes64c99622008-10-22 02:56:07 +0000432 )
433
434# TODO: make and install documentation.
Oscar Fuentes49f72b62010-10-14 21:11:51 +0000435
436set(CPACK_PACKAGE_VENDOR "LLVM")
437set(CPACK_PACKAGE_VERSION_MAJOR 2)
438set(CPACK_PACKAGE_VERSION_MINOR 9)
439add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
440include(CPack)
NAKAMURA Takumi148b62c2010-11-19 03:19:18 +0000441
442# Workaround for MSVS10 to avoid the Dialog Hell
443# FIXME: This could be removed with future version of CMake.
444if(MSVC_VERSION EQUAL 1600)
445 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
446 if( EXISTS "${LLVM_SLN_FILENAME}" )
447 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
448 endif()
449endif()