aaf6e9cb9a71f18719f5a45276e17dfd17888d61
[oota-llvm.git] / CMakeLists.txt
1 # See docs/CMake.html for instructions about how to build LLVM with CMake.
2
3 project(LLVM)
4 cmake_minimum_required(VERSION 2.8)
5
6 # Add path for custom modules
7 set(CMAKE_MODULE_PATH
8   ${CMAKE_MODULE_PATH}
9   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
10   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
11   )
12
13 set(PACKAGE_VERSION "2.9")
14
15 include(VersionFromVCS)
16
17 option(LLVM_APPEND_VC_REV
18   "Append the version control system revision id to LLVM version" OFF)
19
20 if( LLVM_APPEND_VC_REV )
21   add_version_info_from_vcs(PACKAGE_VERSION)
22 endif()
23
24 set(PACKAGE_NAME llvm)
25 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
26 set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
27
28 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
29   message(FATAL_ERROR "In-source builds are not allowed.
30 CMake would overwrite the makefiles distributed with LLVM.
31 Please create a directory and run cmake from there, passing the path
32 to this source directory as the last argument.
33 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
34 Please delete them.")
35 endif()
36
37 # Run-time build mode; It is used for unittests.
38 if(MSVC_IDE)
39   # Expect "$(Configuration)", "$(OutDir)", etc.
40   # It is expanded by msbuild or similar.
41   set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
42 elseif(NOT CMAKE_BUILD_TYPE STREQUAL "")
43   # Expect "Release" "Debug", etc.
44   # Or unittests could not run.
45   set(RUNTIME_BUILD_MODE ${CMAKE_BUILD_TYPE})
46 else()
47   # It might be "."
48   set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
49 endif()
50
51 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
52
53 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
54 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
55 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
56 set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
57 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
58 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
59
60 if( 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,
69 probably as the result of running `configure' and `make' on
70 ${LLVM_MAIN_SRC_DIR}.
71 This may cause problems. The suspicious files are:
72 ${tablegenned_files_on_lib_dir}
73 ${tablegenned_files_on_include_dir}
74 Please clean the source directory.")
75   endif()
76 endif()
77
78 set(LLVM_ALL_TARGETS
79   Alpha
80   ARM
81   Blackfin
82   CBackend
83   CellSPU
84   CppBackend
85   Mips
86   MBlaze
87   MSP430
88   PowerPC
89   PTX
90   Sparc
91   SystemZ
92   X86
93   XCore
94   )
95
96 if( MSVC )
97   set(LLVM_TARGETS_TO_BUILD X86
98     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
99 else( MSVC )
100   set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
101     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
102 endif( MSVC )
103
104 set(CLANG_RESOURCE_DIR "" CACHE STRING
105   "Relative directory from the Clang binary to its resource files.")
106
107 option(LLVM_ENABLE_CBE_PRINTF_A "Set to ON if CBE is enabled for printf %a output" ON)
108 if(LLVM_ENABLE_CBE_PRINTF_A)
109   set(ENABLE_CBE_PRINTF_A 1)
110 endif()
111
112 option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
113 if(LLVM_ENABLE_TIMESTAMPS)
114   set(ENABLE_TIMESTAMPS 1)
115 endif()
116
117 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
118 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
119 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
120
121 set(C_INCLUDE_DIRS "" CACHE STRING
122   "Colon separated list of directories clang will search for headers.")
123
124 set(LLVM_TARGET_ARCH "host"
125   CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
126
127 set(LIT_ARGS_DEFAULT "-sv")
128 if (MSVC OR XCODE)
129   set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
130 endif()
131 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
132     CACHE STRING "Default options for lit")
133
134 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
135
136 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
137   set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
138 endif()
139
140 set(LLVM_ENUM_TARGETS "")
141 foreach(c ${LLVM_TARGETS_TO_BUILD})
142   list(FIND LLVM_ALL_TARGETS ${c} idx)
143   if( idx LESS 0 )
144     message(FATAL_ERROR "The target `${c}' does not exist.
145     It should be one of\n${LLVM_ALL_TARGETS}")
146   else()
147     set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
148   endif()
149 endforeach(c)
150
151 # Produce llvm/Config/Targets.def
152 configure_file(
153   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
154   ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
155   )
156
157 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
158
159 include(AddLLVMDefinitions)
160
161 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
162
163 include(config-ix)
164
165 include(HandleLLVMOptions)
166
167 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
168   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
169 else()
170   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
171 endif()
172
173 configure_file(
174   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
175   ${LLVM_BINARY_DIR}/include/llvm/Config/config.h)
176
177 configure_file(
178   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
179   ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h)
180
181 configure_file(
182   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
183   ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h)
184
185 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
186 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
187 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
188
189 # MSVC has a gazillion warnings with this.
190 if( MSVC )
191   option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
192 else( MSVC )
193   option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
194 endif()
195
196 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
197 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
198
199 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
200
201 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
202    SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
203 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
204
205 include(AddLLVM)
206 include(TableGen)
207
208 if( MINGW )
209   get_system_libs(LLVM_SYSTEM_LIBS_LIST)
210   foreach(l ${LLVM_SYSTEM_LIBS_LIST})
211     set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
212   endforeach()
213   set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
214   set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
215 endif()
216
217 if( MINGW )
218   # People report that -O3 is unreliable on MinGW. The traditional
219   # build also uses -O2 for that reason:
220   llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
221 endif()
222
223 add_subdirectory(lib/Support)
224
225 # Everything else depends on Support:
226 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
227
228 set(LLVM_TABLEGEN "tblgen" CACHE
229   STRING "Native TableGen executable. Saves building one when cross-compiling.")
230 # Effective tblgen executable to be used:
231 set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
232
233 add_subdirectory(utils/TableGen)
234
235 if( CMAKE_CROSSCOMPILING )
236   # This adds a dependency on target `tblgen', so must go after utils/TableGen
237   include( CrossCompileLLVM )
238 endif( CMAKE_CROSSCOMPILING )
239
240 add_subdirectory(include/llvm)
241
242 add_subdirectory(lib/VMCore)
243 add_subdirectory(lib/CodeGen)
244 add_subdirectory(lib/CodeGen/SelectionDAG)
245 add_subdirectory(lib/CodeGen/AsmPrinter)
246 add_subdirectory(lib/Bitcode/Reader)
247 add_subdirectory(lib/Bitcode/Writer)
248 add_subdirectory(lib/Transforms/Utils)
249 add_subdirectory(lib/Transforms/Instrumentation)
250 add_subdirectory(lib/Transforms/InstCombine)
251 add_subdirectory(lib/Transforms/Scalar)
252 add_subdirectory(lib/Transforms/IPO)
253 add_subdirectory(lib/Transforms/Hello)
254 add_subdirectory(lib/Linker)
255 add_subdirectory(lib/Analysis)
256 add_subdirectory(lib/Analysis/IPA)
257 add_subdirectory(lib/MC)
258 add_subdirectory(lib/MC/MCParser)
259 add_subdirectory(lib/MC/MCDisassembler)
260 add_subdirectory(lib/Object)
261
262 add_subdirectory(utils/FileCheck)
263 add_subdirectory(utils/FileUpdate)
264 add_subdirectory(utils/count)
265 add_subdirectory(utils/not)
266 add_subdirectory(utils/llvm-lit)
267
268 set(LLVM_ENUM_ASM_PRINTERS "")
269 set(LLVM_ENUM_ASM_PARSERS "")
270 set(LLVM_ENUM_DISASSEMBLERS "")
271 foreach(t ${LLVM_TARGETS_TO_BUILD})
272   message(STATUS "Targeting ${t}")
273   add_subdirectory(lib/Target/${t})
274   add_subdirectory(lib/Target/${t}/TargetInfo)
275   set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
276   file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
277   if( asmp_file )
278     set(LLVM_ENUM_ASM_PRINTERS
279       "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
280   endif()
281   if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
282     add_subdirectory(lib/Target/${t}/InstPrinter)
283   endif()
284   if( EXISTS ${td}/AsmParser/CMakeLists.txt )
285     add_subdirectory(lib/Target/${t}/AsmParser)
286     set(LLVM_ENUM_ASM_PARSERS
287       "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
288   endif()
289   if( EXISTS ${td}/Disassembler/CMakeLists.txt )
290     add_subdirectory(lib/Target/${t}/Disassembler)
291     set(LLVM_ENUM_DISASSEMBLERS
292       "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
293   endif()
294   set(CURRENT_LLVM_TARGET)
295 endforeach(t)
296
297 # Produce llvm/Config/AsmPrinters.def
298 configure_file(
299   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
300   ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
301   )
302
303 # Produce llvm/Config/AsmParsers.def
304 configure_file(
305   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
306   ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
307   )
308
309 # Produce llvm/Config/Disassemblers.def
310 configure_file(
311   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
312   ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
313   )
314
315 add_subdirectory(lib/ExecutionEngine)
316 add_subdirectory(lib/ExecutionEngine/Interpreter)
317 add_subdirectory(lib/ExecutionEngine/JIT)
318 add_subdirectory(lib/ExecutionEngine/MCJIT)
319 add_subdirectory(lib/Target)
320 add_subdirectory(lib/AsmParser)
321 add_subdirectory(lib/Archive)
322
323 add_subdirectory(projects)
324
325 option(LLVM_BUILD_TOOLS
326   "Build the LLVM tools. If OFF, just generate build targets." ON)
327 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
328 if( LLVM_INCLUDE_TOOLS )
329   add_subdirectory(tools)
330 endif()
331
332 option(LLVM_BUILD_EXAMPLES
333   "Build the LLVM example programs. If OFF, just generate build targets." OFF)
334 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
335 if( LLVM_INCLUDE_EXAMPLES )
336   add_subdirectory(examples)
337 endif()
338
339 option(LLVM_BUILD_TESTS
340   "Build LLVM unit tests. If OFF, just generate build targes." OFF)
341 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
342 if( LLVM_INCLUDE_TESTS )
343   add_subdirectory(test)
344   add_subdirectory(utils/unittest)
345   add_subdirectory(unittests)
346   if (MSVC)
347     # This utility is used to prevent chrashing tests from calling Dr. Watson on
348     # Windows.
349     add_subdirectory(utils/KillTheDoctor)
350   endif()
351 endif()
352
353 add_subdirectory(cmake/modules)
354
355 install(DIRECTORY include/
356   DESTINATION include
357   FILES_MATCHING
358   PATTERN "*.def"
359   PATTERN "*.h"
360   PATTERN "*.td"
361   PATTERN "*.inc"
362   PATTERN ".svn" EXCLUDE
363   )
364
365 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
366   DESTINATION include
367   FILES_MATCHING
368   PATTERN "*.def"
369   PATTERN "*.h"
370   PATTERN "*.gen"
371   PATTERN "*.inc"
372   # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
373   PATTERN "CMakeFiles" EXCLUDE
374   PATTERN ".svn" EXCLUDE
375   )
376
377 # TODO: make and install documentation.
378
379 set(CPACK_PACKAGE_VENDOR "LLVM")
380 set(CPACK_PACKAGE_VERSION_MAJOR 2)
381 set(CPACK_PACKAGE_VERSION_MINOR 9)
382 add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
383 include(CPack)
384
385 # Workaround for MSVS10 to avoid the Dialog Hell
386 # FIXME: This could be removed with future version of CMake.
387 if(MSVC_VERSION EQUAL 1600)
388   set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
389   if( EXISTS "${LLVM_SLN_FILENAME}" )
390     file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
391   endif()
392 endif()