dfdd13c36bc075af4d51e85e0e98a62a5feaa6a3
[oota-llvm.git] / CMakeLists.txt
1 project(LLVM)
2 cmake_minimum_required(VERSION 2.6.1)
3
4 set(PACKAGE_NAME llvm)
5 set(PACKAGE_VERSION svn)
6 set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
7
8 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
9   message(FATAL_ERROR "In-source builds are not allowed.
10 CMake would overwrite the makefiles distributed with LLVM.
11 Please create a directory and run cmake from there, passing the path
12 to this source directory as the last argument.
13 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
14 Please delete them.")
15 endif()
16
17 include(FindPerl)
18
19 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
20 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
21 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
22 set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
23 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
24
25 set(LLVM_ALL_TARGETS
26   Alpha
27   ARM
28   CBackend
29   CellSPU
30   CppBackend
31   IA64
32   Mips
33   MSIL
34   PIC16
35   PowerPC
36   Sparc
37   X86
38   XCore
39   )
40
41 if( MSVC )
42   set(LLVM_TARGETS_TO_BUILD X86
43     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
44 else( MSVC )
45   set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
46     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
47 endif( MSVC )
48
49 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
50   set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
51 endif()
52
53 foreach(c ${LLVM_TARGETS_TO_BUILD})
54   list(FIND LLVM_ALL_TARGETS ${c} idx)
55   if( idx LESS 0 )
56     message(FATAL_ERROR "The target `${c}' does not exists.
57     It should be one of\n${LLVM_ALL_TARGETS}")
58   endif()
59 endforeach(c)
60
61 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
62
63 # Add path for custom modules
64 set(CMAKE_MODULE_PATH
65   ${CMAKE_MODULE_PATH}
66   "${LLVM_MAIN_SRC_DIR}/cmake"
67   "${LLVM_MAIN_SRC_DIR}/cmake/modules"
68   )
69
70 if(WIN32)
71   if(CYGWIN)
72     set(LLVM_ON_WIN32 0)
73     set(LLVM_ON_UNIX 1)
74   else(CYGWIN)
75     set(LLVM_ON_WIN32 1)
76     set(LLVM_ON_UNIX 0)
77   endif(CYGWIN)
78   set(LTDL_SHLIB_EXT ".dll")
79   set(EXEEXT ".exe")
80   # Maximum path length is 160 for non-unicode paths
81   set(MAXPATHLEN 160)
82 else(WIN32)
83   if(UNIX)
84     set(LLVM_ON_WIN32 0)
85     set(LLVM_ON_UNIX 1)
86     set(LTDL_SHLIB_EXT ".so")
87     set(EXEEXT "")
88     # FIXME: Maximum path length is currently set to 'safe' fixed value
89     set(MAXPATHLEN 2024)
90   else(UNIX)
91     MESSAGE(SEND_ERROR "Unable to determine platform")
92   endif(UNIX)
93 endif(WIN32)
94
95 if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
96   set(HAVE_LLVM_CONFIG 1)
97 endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
98 # find_file(HAVE_LLVM_CONFIG llvm-config ${LLVM_TOOLS_BINARY_DIR})
99 # message(STATUS ${HAVE_LLVM_CONFIG})
100
101 include(config-ix)
102
103 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
104 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
105 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
106
107 # set(CMAKE_VERBOSE_MAKEFILE true)
108
109 add_definitions( -D__STDC_LIMIT_MACROS )
110 add_definitions( -D__STDC_CONSTANT_MACROS )
111
112 set(LLVM_PLO_FLAGS "" CACHE
113   STRING "Flags for creating partially linked objects.")
114
115 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
116   # TODO: support other platforms and toolchains.
117   option(BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
118   if( BUILD_32_BITS )
119     message(STATUS "Building 32 bits executables and libraries.")
120     add_definitions( -m32 )
121     set( CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}" )
122     set( CMAKE_LINK_LIBRARY_FLAG "-m32 ${CMAKE_LINK_LIBRARY_FLAG}" )
123     set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
124   endif( BUILD_32_BITS )
125 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
126
127 if( MSVC )
128   add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
129   add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
130   add_definitions( -D_SCL_SECURE_NO_DEPRECATE )
131   add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
132   add_definitions( -wd4355 -wd4715 )
133 endif( MSVC )
134
135 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
136 #link_directories( d:/dev/lib )
137
138 #add_subdirectory(lib)
139
140 include(AddLLVM)
141 include(AddPartiallyLinkedObject)
142 include(TableGen)
143
144 add_subdirectory(lib/Support)
145 add_subdirectory(lib/System)
146
147 # Everything else depends on Support and System:
148 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
149
150 set(LLVM_TABLEGEN "tblgen" CACHE
151   STRING "Native TableGen executable. Saves building one when cross-compiling.")
152
153 add_subdirectory(utils/TableGen)
154
155 if( CMAKE_CROSSCOMPILING )
156   # This adds a dependency on target `tblgen', so must go after utils/TableGen
157   include( CrossCompileLLVM )
158 endif( CMAKE_CROSSCOMPILING )
159
160 add_subdirectory(include/llvm)
161
162 add_subdirectory(lib/VMCore)
163 add_subdirectory(lib/CodeGen)
164 add_subdirectory(lib/CodeGen/SelectionDAG)
165 add_subdirectory(lib/CodeGen/AsmPrinter)
166 add_subdirectory(lib/Bitcode/Reader)
167 add_subdirectory(lib/Bitcode/Writer)
168 add_subdirectory(lib/Transforms/Utils)
169 add_subdirectory(lib/Transforms/Instrumentation)
170 add_subdirectory(lib/Transforms/Scalar)
171 add_subdirectory(lib/Transforms/IPO)
172 add_subdirectory(lib/Transforms/Hello)
173 add_subdirectory(lib/Linker)
174 add_subdirectory(lib/Analysis)
175 add_subdirectory(lib/Analysis/IPA)
176
177 foreach(t ${LLVM_TARGETS_TO_BUILD})
178   message(STATUS "Targeting ${t}")
179   add_subdirectory(lib/Target/${t})
180   if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
181     add_subdirectory(lib/Target/${t}/AsmPrinter)
182   endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
183 endforeach(t)
184
185 add_subdirectory(lib/ExecutionEngine)
186 add_subdirectory(lib/ExecutionEngine/Interpreter)
187 add_subdirectory(lib/ExecutionEngine/JIT)
188 add_subdirectory(lib/Target)
189 add_subdirectory(lib/AsmParser)
190 add_subdirectory(lib/Debugger)
191 add_subdirectory(lib/Archive)
192
193 add_subdirectory(tools)
194
195 add_subdirectory(examples)
196
197 install(DIRECTORY include
198   DESTINATION .
199   PATTERN ".svn" EXCLUDE
200   PATTERN "*.cmake" EXCLUDE
201   PATTERN "*.in" EXCLUDE
202   )
203
204 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
205   DESTINATION .
206   )
207
208 # TODO: make and install documentation.