[AVX] Add some utilities to insert and extract 128-bit subvectors.
[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 option(LLVM_ENABLE_CBE_PRINTF_A "Set to ON if CBE is enabled for printf %a output" ON)
105 if(LLVM_ENABLE_CBE_PRINTF_A)
106   set(ENABLE_CBE_PRINTF_A 1)
107 endif()
108
109 option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
110 if(LLVM_ENABLE_TIMESTAMPS)
111   set(ENABLE_TIMESTAMPS 1)
112 endif()
113
114 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
115 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
116 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
117
118 set(LLVM_TARGET_ARCH "host"
119   CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
120
121 set(LIT_ARGS_DEFAULT "-sv")
122 if (MSVC OR XCODE)
123   set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
124 endif()
125 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
126     CACHE STRING "Default options for lit")
127
128 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
129
130 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
131   set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
132 endif()
133
134 set(LLVM_ENUM_TARGETS "")
135 foreach(c ${LLVM_TARGETS_TO_BUILD})
136   list(FIND LLVM_ALL_TARGETS ${c} idx)
137   if( idx LESS 0 )
138     message(FATAL_ERROR "The target `${c}' does not exist.
139     It should be one of\n${LLVM_ALL_TARGETS}")
140   else()
141     set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
142   endif()
143 endforeach(c)
144
145 # Produce llvm/Config/Targets.def
146 configure_file(
147   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
148   ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
149   )
150
151 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
152
153 include(AddLLVMDefinitions)
154
155 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
156
157 include(config-ix)
158
159 include(HandleLLVMOptions)
160
161 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
162   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
163 else()
164   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
165 endif()
166
167 configure_file(
168   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
169   ${LLVM_BINARY_DIR}/include/llvm/Config/config.h)
170
171 configure_file(
172   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
173   ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h)
174
175 configure_file(
176   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
177   ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h)
178
179 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
180 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
181 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
182
183 # MSVC has a gazillion warnings with this.
184 if( MSVC )
185   option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
186 else( MSVC )
187   option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
188 endif()
189
190 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
191 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
192
193 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
194
195 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
196    SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
197 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
198
199 include(AddLLVM)
200 include(TableGen)
201
202 if( MINGW )
203   get_system_libs(LLVM_SYSTEM_LIBS_LIST)
204   foreach(l ${LLVM_SYSTEM_LIBS_LIST})
205     set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
206   endforeach()
207   set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
208   set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
209 endif()
210
211 if( MINGW )
212   # People report that -O3 is unreliable on MinGW. The traditional
213   # build also uses -O2 for that reason:
214   llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
215 endif()
216
217 add_subdirectory(lib/Support)
218
219 # Everything else depends on Support:
220 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
221
222 set(LLVM_TABLEGEN "tblgen" CACHE
223   STRING "Native TableGen executable. Saves building one when cross-compiling.")
224 # Effective tblgen executable to be used:
225 set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
226
227 add_subdirectory(utils/TableGen)
228
229 if( CMAKE_CROSSCOMPILING )
230   # This adds a dependency on target `tblgen', so must go after utils/TableGen
231   include( CrossCompileLLVM )
232 endif( CMAKE_CROSSCOMPILING )
233
234 add_subdirectory(include/llvm)
235
236 add_subdirectory(lib/VMCore)
237 add_subdirectory(lib/CodeGen)
238 add_subdirectory(lib/CodeGen/SelectionDAG)
239 add_subdirectory(lib/CodeGen/AsmPrinter)
240 add_subdirectory(lib/Bitcode/Reader)
241 add_subdirectory(lib/Bitcode/Writer)
242 add_subdirectory(lib/Transforms/Utils)
243 add_subdirectory(lib/Transforms/Instrumentation)
244 add_subdirectory(lib/Transforms/InstCombine)
245 add_subdirectory(lib/Transforms/Scalar)
246 add_subdirectory(lib/Transforms/IPO)
247 add_subdirectory(lib/Transforms/Hello)
248 add_subdirectory(lib/Linker)
249 add_subdirectory(lib/Analysis)
250 add_subdirectory(lib/Analysis/IPA)
251 add_subdirectory(lib/MC)
252 add_subdirectory(lib/MC/MCParser)
253 add_subdirectory(lib/MC/MCDisassembler)
254 add_subdirectory(lib/Object)
255
256 add_subdirectory(utils/FileCheck)
257 add_subdirectory(utils/FileUpdate)
258 add_subdirectory(utils/count)
259 add_subdirectory(utils/not)
260 add_subdirectory(utils/llvm-lit)
261
262 set(LLVM_ENUM_ASM_PRINTERS "")
263 set(LLVM_ENUM_ASM_PARSERS "")
264 set(LLVM_ENUM_DISASSEMBLERS "")
265 foreach(t ${LLVM_TARGETS_TO_BUILD})
266   message(STATUS "Targeting ${t}")
267   add_subdirectory(lib/Target/${t})
268   add_subdirectory(lib/Target/${t}/TargetInfo)
269   set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
270   file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
271   if( asmp_file )
272     set(LLVM_ENUM_ASM_PRINTERS
273       "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
274   endif()
275   if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
276     add_subdirectory(lib/Target/${t}/InstPrinter)
277   endif()
278   if( EXISTS ${td}/AsmParser/CMakeLists.txt )
279     add_subdirectory(lib/Target/${t}/AsmParser)
280     set(LLVM_ENUM_ASM_PARSERS
281       "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
282   endif()
283   if( EXISTS ${td}/Disassembler/CMakeLists.txt )
284     add_subdirectory(lib/Target/${t}/Disassembler)
285     set(LLVM_ENUM_DISASSEMBLERS
286       "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
287   endif()
288   set(CURRENT_LLVM_TARGET)
289 endforeach(t)
290
291 # Produce llvm/Config/AsmPrinters.def
292 configure_file(
293   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
294   ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
295   )
296
297 # Produce llvm/Config/AsmParsers.def
298 configure_file(
299   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
300   ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
301   )
302
303 # Produce llvm/Config/Disassemblers.def
304 configure_file(
305   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
306   ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
307   )
308
309 add_subdirectory(lib/ExecutionEngine)
310 add_subdirectory(lib/ExecutionEngine/Interpreter)
311 add_subdirectory(lib/ExecutionEngine/JIT)
312 add_subdirectory(lib/ExecutionEngine/MCJIT)
313 add_subdirectory(lib/Target)
314 add_subdirectory(lib/AsmParser)
315 add_subdirectory(lib/Archive)
316
317 add_subdirectory(projects)
318
319 option(LLVM_BUILD_TOOLS
320   "Build the LLVM tools. If OFF, just generate build targets." ON)
321 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
322 if( LLVM_INCLUDE_TOOLS )
323   add_subdirectory(tools)
324 endif()
325
326 option(LLVM_BUILD_EXAMPLES
327   "Build the LLVM example programs. If OFF, just generate build targets." OFF)
328 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
329 if( LLVM_INCLUDE_EXAMPLES )
330   add_subdirectory(examples)
331 endif()
332
333 option(LLVM_BUILD_TESTS
334   "Build LLVM unit tests. If OFF, just generate build targes." OFF)
335 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
336 if( LLVM_INCLUDE_TESTS )
337   add_subdirectory(test)
338   add_subdirectory(utils/unittest)
339   add_subdirectory(unittests)
340   if (MSVC)
341     # This utility is used to prevent chrashing tests from calling Dr. Watson on
342     # Windows.
343     add_subdirectory(utils/KillTheDoctor)
344   endif()
345 endif()
346
347 add_subdirectory(cmake/modules)
348
349 install(DIRECTORY include/
350   DESTINATION include
351   FILES_MATCHING
352   PATTERN "*.def"
353   PATTERN "*.h"
354   PATTERN "*.td"
355   PATTERN "*.inc"
356   PATTERN ".svn" EXCLUDE
357   )
358
359 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
360   DESTINATION include
361   FILES_MATCHING
362   PATTERN "*.def"
363   PATTERN "*.h"
364   PATTERN "*.gen"
365   PATTERN "*.inc"
366   # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
367   PATTERN "CMakeFiles" EXCLUDE
368   PATTERN ".svn" EXCLUDE
369   )
370
371 # TODO: make and install documentation.
372
373 set(CPACK_PACKAGE_VENDOR "LLVM")
374 set(CPACK_PACKAGE_VERSION_MAJOR 2)
375 set(CPACK_PACKAGE_VERSION_MINOR 9)
376 add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
377 include(CPack)
378
379 # Workaround for MSVS10 to avoid the Dialog Hell
380 # FIXME: This could be removed with future version of CMake.
381 if(MSVC_VERSION EQUAL 1600)
382   set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
383   if( EXISTS "${LLVM_SLN_FILENAME}" )
384     file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
385   endif()
386 endif()