Instcombine: Fix pattern where the sext did not dominate the icmp using it
[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 set(C_INCLUDE_DIRS "" CACHE STRING
108   "Colon separated list of directories clang will search for headers.")
109
110 set(LLVM_TARGET_ARCH "host"
111   CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
112
113 set(LIT_ARGS_DEFAULT "-sv")
114 if (MSVC OR XCODE)
115   set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
116 endif()
117 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
118     CACHE STRING "Default options for lit")
119
120 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
121
122 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
123   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
124 else()
125   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
126 endif()
127
128 if( LLVM_ENABLE_ASSERTIONS )
129   # MSVC doesn't like _DEBUG on release builds. See PR 4379.
130   if( NOT MSVC )
131     add_definitions( -D_DEBUG )
132   endif()
133   # 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()
138 else()
139   if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
140     add_definitions( -DNDEBUG )
141   endif()
142 endif()
143
144 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
145   set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
146 endif()
147
148 set(LLVM_ENUM_TARGETS "")
149 foreach(c ${LLVM_TARGETS_TO_BUILD})
150   list(FIND LLVM_ALL_TARGETS ${c} idx)
151   if( idx LESS 0 )
152     message(FATAL_ERROR "The target `${c}' does not exist.
153     It should be one of\n${LLVM_ALL_TARGETS}")
154   else()
155     set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
156   endif()
157 endforeach(c)
158
159 # Produce llvm/Config/Targets.def
160 configure_file(
161   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
162   ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
163   )
164
165 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
166
167 include(AddLLVMDefinitions)
168
169 if(WIN32)
170   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)
177   set(LTDL_SHLIB_EXT ".dll")
178   set(EXEEXT ".exe")
179   # Maximum path length is 160 for non-unicode paths
180   set(MAXPATHLEN 160)
181 else(WIN32)
182   if(UNIX)
183     set(LLVM_ON_WIN32 0)
184     set(LLVM_ON_UNIX 1)
185     if(APPLE)
186       set(LTDL_SHLIB_EXT ".dylib")
187     else(APPLE)
188       set(LTDL_SHLIB_EXT ".so")
189     endif(APPLE)
190     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)
196 endif(WIN32)
197
198 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
199
200 if( LLVM_ENABLE_PIC )
201   if( XCODE )
202     # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
203     # know how to disable this, so just force ENABLE_PIC off for now.
204     message(WARNING "-fPIC not supported with Xcode.")
205   elseif( WIN32 )
206     # On Windows all code is PIC. MinGW warns if -fPIC is used.
207   else()
208     include(CheckCXXCompilerFlag)
209     check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
210     if( SUPPORTS_FPIC_FLAG )
211       message(STATUS "Building with -fPIC")
212       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
213     else( SUPPORTS_FPIC_FLAG )
214       message(WARNING "-fPIC not supported.")
215     endif()
216   endif()
217 endif()
218
219 include(config-ix)
220
221 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
222 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
223 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
224
225 # set(CMAKE_VERBOSE_MAKEFILE true)
226
227 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
228 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
229
230 # MSVC has a gazillion warnings with this.
231 if( MSVC )
232   option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
233 else( MSVC )
234   option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
235 endif()
236
237 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
238 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
239
240 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
241   # TODO: support other platforms and toolchains.
242   option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
243   if( LLVM_BUILD_32_BITS )
244     message(STATUS "Building 32 bits executables and libraries.")
245     add_llvm_definitions( -m32 )
246     list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
247     list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
248   endif( LLVM_BUILD_32_BITS )
249 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
250
251 if( MSVC )
252   include(ChooseMSVCCRT)
253
254   # Add definitions that make MSVC much less annoying.
255   add_llvm_definitions(
256     # For some reason MS wants to deprecate a bunch of standard functions...
257     -D_CRT_SECURE_NO_DEPRECATE
258     -D_CRT_SECURE_NO_WARNINGS
259     -D_CRT_NONSTDC_NO_DEPRECATE
260     -D_CRT_NONSTDC_NO_WARNINGS
261     -D_SCL_SECURE_NO_DEPRECATE
262     -D_SCL_SECURE_NO_WARNINGS
263
264     -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
265     -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
266     -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type'
267     -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
268     -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
269     -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
270     -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
271     -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
272     -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
273     -wd4355 # Suppress ''this' : used in base member initializer list'
274     -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
275     -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
276     -wd4715 # Suppress ''function' : not all control paths return a value'
277     -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
278
279     -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning.
280     )
281
282   # Enable warnings
283   if (LLVM_ENABLE_WARNINGS)
284     add_llvm_definitions( /W4 /Wall )
285     if (LLVM_ENABLE_PEDANTIC)
286       # No MSVC equivalent available
287     endif (LLVM_ENABLE_PEDANTIC)
288   endif (LLVM_ENABLE_WARNINGS)
289   if (LLVM_ENABLE_WERROR)
290     add_llvm_definitions( /WX )
291   endif (LLVM_ENABLE_WERROR)
292 elseif( CMAKE_COMPILER_IS_GNUCXX )
293   if (LLVM_ENABLE_WARNINGS)
294     add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings )
295     if (LLVM_ENABLE_PEDANTIC)
296       add_llvm_definitions( -pedantic -Wno-long-long )
297     endif (LLVM_ENABLE_PEDANTIC)
298   endif (LLVM_ENABLE_WARNINGS)
299   if (LLVM_ENABLE_WERROR)
300     add_llvm_definitions( -Werror )
301   endif (LLVM_ENABLE_WERROR)
302 endif( MSVC )
303
304 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
305
306 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
307    SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
308 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
309
310 include(AddLLVM)
311 include(TableGen)
312
313 if( MINGW )
314   get_system_libs(LLVM_SYSTEM_LIBS_LIST)
315   foreach(l ${LLVM_SYSTEM_LIBS_LIST})
316     set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
317   endforeach()
318   set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
319   set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
320 endif()
321
322 if( MINGW )
323   # People report that -O3 is unreliable on MinGW. The traditional
324   # build also uses -O2 for that reason:
325   llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
326 endif()
327
328 add_subdirectory(lib/Support)
329
330 # Everything else depends on Support:
331 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
332
333 set(LLVM_TABLEGEN "tblgen" CACHE
334   STRING "Native TableGen executable. Saves building one when cross-compiling.")
335 # Effective tblgen executable to be used:
336 set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
337
338 add_subdirectory(utils/TableGen)
339
340 if( CMAKE_CROSSCOMPILING )
341   # This adds a dependency on target `tblgen', so must go after utils/TableGen
342   include( CrossCompileLLVM )
343 endif( CMAKE_CROSSCOMPILING )
344
345 add_subdirectory(include/llvm)
346
347 add_subdirectory(lib/VMCore)
348 add_subdirectory(lib/CodeGen)
349 add_subdirectory(lib/CodeGen/SelectionDAG)
350 add_subdirectory(lib/CodeGen/AsmPrinter)
351 add_subdirectory(lib/Bitcode/Reader)
352 add_subdirectory(lib/Bitcode/Writer)
353 add_subdirectory(lib/Transforms/Utils)
354 add_subdirectory(lib/Transforms/Instrumentation)
355 add_subdirectory(lib/Transforms/InstCombine)
356 add_subdirectory(lib/Transforms/Scalar)
357 add_subdirectory(lib/Transforms/IPO)
358 add_subdirectory(lib/Transforms/Hello)
359 add_subdirectory(lib/Linker)
360 add_subdirectory(lib/Analysis)
361 add_subdirectory(lib/Analysis/IPA)
362 add_subdirectory(lib/MC)
363 add_subdirectory(lib/MC/MCParser)
364 add_subdirectory(lib/MC/MCDisassembler)
365 add_subdirectory(lib/Object)
366
367 add_subdirectory(utils/FileCheck)
368 add_subdirectory(utils/FileUpdate)
369 add_subdirectory(utils/count)
370 add_subdirectory(utils/not)
371 add_subdirectory(utils/llvm-lit)
372
373 set(LLVM_ENUM_ASM_PRINTERS "")
374 set(LLVM_ENUM_ASM_PARSERS "")
375 set(LLVM_ENUM_DISASSEMBLERS "")
376 foreach(t ${LLVM_TARGETS_TO_BUILD})
377   message(STATUS "Targeting ${t}")
378   add_subdirectory(lib/Target/${t})
379   add_subdirectory(lib/Target/${t}/TargetInfo)
380   set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
381   file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
382   if( asmp_file )
383     set(LLVM_ENUM_ASM_PRINTERS
384       "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
385   endif()
386   if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
387     add_subdirectory(lib/Target/${t}/InstPrinter)
388   endif()
389   if( EXISTS ${td}/AsmParser/CMakeLists.txt )
390     add_subdirectory(lib/Target/${t}/AsmParser)
391     set(LLVM_ENUM_ASM_PARSERS
392       "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
393   endif()
394   if( EXISTS ${td}/Disassembler/CMakeLists.txt )
395     add_subdirectory(lib/Target/${t}/Disassembler)
396     set(LLVM_ENUM_DISASSEMBLERS
397       "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
398   endif()
399   set(CURRENT_LLVM_TARGET)
400 endforeach(t)
401
402 # Produce llvm/Config/AsmPrinters.def
403 configure_file(
404   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
405   ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
406   )
407
408 # Produce llvm/Config/AsmParsers.def
409 configure_file(
410   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
411   ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
412   )
413
414 # Produce llvm/Config/Disassemblers.def
415 configure_file(
416   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
417   ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
418   )
419
420 add_subdirectory(lib/ExecutionEngine)
421 add_subdirectory(lib/ExecutionEngine/Interpreter)
422 add_subdirectory(lib/ExecutionEngine/JIT)
423 add_subdirectory(lib/ExecutionEngine/MCJIT)
424 add_subdirectory(lib/Target)
425 add_subdirectory(lib/AsmParser)
426 add_subdirectory(lib/Archive)
427
428 add_subdirectory(projects)
429
430 option(LLVM_BUILD_TOOLS
431   "Build the LLVM tools. If OFF, just generate build targets." ON)
432 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
433 if( LLVM_INCLUDE_TOOLS )
434   add_subdirectory(tools)
435 endif()
436
437 option(LLVM_BUILD_EXAMPLES
438   "Build the LLVM example programs. If OFF, just generate build targets." OFF)
439 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
440 if( LLVM_INCLUDE_EXAMPLES )
441   add_subdirectory(examples)
442 endif()
443
444 option(LLVM_BUILD_TESTS
445   "Build LLVM unit tests. If OFF, just generate build targes." OFF)
446 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
447 if( LLVM_INCLUDE_TESTS )
448   add_subdirectory(test)
449   add_subdirectory(utils/unittest)
450   add_subdirectory(unittests)
451   if (MSVC)
452     # This utility is used to prevent chrashing tests from calling Dr. Watson on
453     # Windows.
454     add_subdirectory(utils/KillTheDoctor)
455   endif()
456 endif()
457
458 add_subdirectory(cmake/modules)
459
460 install(DIRECTORY include/
461   DESTINATION include
462   FILES_MATCHING
463   PATTERN "*.def"
464   PATTERN "*.h"
465   PATTERN "*.td"
466   PATTERN "*.inc"
467   PATTERN ".svn" EXCLUDE
468   )
469
470 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
471   DESTINATION include
472   FILES_MATCHING
473   PATTERN "*.def"
474   PATTERN "*.h"
475   PATTERN "*.gen"
476   PATTERN "*.inc"
477   # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
478   PATTERN "CMakeFiles" EXCLUDE
479   PATTERN ".svn" EXCLUDE
480   )
481
482 # TODO: make and install documentation.
483
484 set(CPACK_PACKAGE_VENDOR "LLVM")
485 set(CPACK_PACKAGE_VERSION_MAJOR 2)
486 set(CPACK_PACKAGE_VERSION_MINOR 9)
487 add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
488 include(CPack)
489
490 # Workaround for MSVS10 to avoid the Dialog Hell
491 # FIXME: This could be removed with future version of CMake.
492 if(MSVC_VERSION EQUAL 1600)
493   set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
494   if( EXISTS "${LLVM_SLN_FILENAME}" )
495     file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")
496   endif()
497 endif()