CMake: Option for enabling/disabling threads.
[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 # List of targets whose asmprinters need to be forced to link
42 # into executables on some platforms (i.e. Windows):
43 set(LLVM_ASMPRINTERS_FORCE_LINK X86 PowerPC)
44
45 if( MSVC )
46   set(LLVM_TARGETS_TO_BUILD X86
47     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
48 else( MSVC )
49   set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
50     CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
51 endif( MSVC )
52
53 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
54
55 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
56   set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
57 endif()
58
59 foreach(c ${LLVM_TARGETS_TO_BUILD})
60   list(FIND LLVM_ALL_TARGETS ${c} idx)
61   if( idx LESS 0 )
62     message(FATAL_ERROR "The target `${c}' does not exists.
63     It should be one of\n${LLVM_ALL_TARGETS}")
64   endif()
65 endforeach(c)
66
67 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
68
69 # Add path for custom modules
70 set(CMAKE_MODULE_PATH
71   ${CMAKE_MODULE_PATH}
72   "${LLVM_MAIN_SRC_DIR}/cmake"
73   "${LLVM_MAIN_SRC_DIR}/cmake/modules"
74   )
75
76 if(WIN32)
77   if(CYGWIN)
78     set(LLVM_ON_WIN32 0)
79     set(LLVM_ON_UNIX 1)
80   else(CYGWIN)
81     set(LLVM_ON_WIN32 1)
82     set(LLVM_ON_UNIX 0)
83   endif(CYGWIN)
84   set(LTDL_SHLIB_EXT ".dll")
85   set(EXEEXT ".exe")
86   # Maximum path length is 160 for non-unicode paths
87   set(MAXPATHLEN 160)
88 else(WIN32)
89   if(UNIX)
90     set(LLVM_ON_WIN32 0)
91     set(LLVM_ON_UNIX 1)
92     set(LTDL_SHLIB_EXT ".so")
93     set(EXEEXT "")
94     # FIXME: Maximum path length is currently set to 'safe' fixed value
95     set(MAXPATHLEN 2024)
96   else(UNIX)
97     MESSAGE(SEND_ERROR "Unable to determine platform")
98   endif(UNIX)
99 endif(WIN32)
100
101 if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
102   set(HAVE_LLVM_CONFIG 1)
103 endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
104
105 include(config-ix)
106
107 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
108 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
109 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
110
111 # set(CMAKE_VERBOSE_MAKEFILE true)
112
113 add_definitions( -D__STDC_LIMIT_MACROS )
114 add_definitions( -D__STDC_CONSTANT_MACROS )
115
116 set(LLVM_PLO_FLAGS "" CACHE
117   STRING "Flags for creating partially linked objects.")
118
119 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
120   # TODO: support other platforms and toolchains.
121   option(BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
122   if( BUILD_32_BITS )
123     message(STATUS "Building 32 bits executables and libraries.")
124     add_definitions( -m32 )
125     set( CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}" )
126     set( CMAKE_LINK_LIBRARY_FLAG "-m32 ${CMAKE_LINK_LIBRARY_FLAG}" )
127     set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
128   endif( BUILD_32_BITS )
129 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
130
131 if( MSVC )
132   add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
133   add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
134   add_definitions( -D_SCL_SECURE_NO_DEPRECATE )
135   add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
136   add_definitions( -wd4355 -wd4715 )
137 endif( MSVC )
138
139 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
140
141 include(AddLLVM)
142 include(AddPartiallyLinkedObject)
143 include(TableGen)
144
145 add_subdirectory(lib/Support)
146 add_subdirectory(lib/System)
147
148 # Everything else depends on Support and System:
149 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
150
151 set(LLVM_TABLEGEN "tblgen" CACHE
152   STRING "Native TableGen executable. Saves building one when cross-compiling.")
153
154 add_subdirectory(utils/TableGen)
155
156 if( CMAKE_CROSSCOMPILING )
157   # This adds a dependency on target `tblgen', so must go after utils/TableGen
158   include( CrossCompileLLVM )
159 endif( CMAKE_CROSSCOMPILING )
160
161 add_subdirectory(include/llvm)
162
163 add_subdirectory(lib/VMCore)
164 add_subdirectory(lib/CodeGen)
165 add_subdirectory(lib/CodeGen/SelectionDAG)
166 add_subdirectory(lib/CodeGen/AsmPrinter)
167 add_subdirectory(lib/Bitcode/Reader)
168 add_subdirectory(lib/Bitcode/Writer)
169 add_subdirectory(lib/Transforms/Utils)
170 add_subdirectory(lib/Transforms/Instrumentation)
171 add_subdirectory(lib/Transforms/Scalar)
172 add_subdirectory(lib/Transforms/IPO)
173 add_subdirectory(lib/Transforms/Hello)
174 add_subdirectory(lib/Linker)
175 add_subdirectory(lib/Analysis)
176 add_subdirectory(lib/Analysis/IPA)
177
178 foreach(t ${LLVM_TARGETS_TO_BUILD})
179   message(STATUS "Targeting ${t}")
180   add_subdirectory(lib/Target/${t})
181   if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
182     add_subdirectory(lib/Target/${t}/AsmPrinter)
183   endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
184 endforeach(t)
185
186 add_subdirectory(lib/ExecutionEngine)
187 add_subdirectory(lib/ExecutionEngine/Interpreter)
188 add_subdirectory(lib/ExecutionEngine/JIT)
189 add_subdirectory(lib/Target)
190 add_subdirectory(lib/AsmParser)
191 add_subdirectory(lib/Debugger)
192 add_subdirectory(lib/Archive)
193
194 add_subdirectory(tools)
195
196 add_subdirectory(examples)
197
198 install(DIRECTORY include
199   DESTINATION .
200   PATTERN ".svn" EXCLUDE
201   PATTERN "*.cmake" EXCLUDE
202   PATTERN "*.in" EXCLUDE
203   )
204
205 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
206   DESTINATION .
207   )
208
209 # TODO: make and install documentation.