blob: 81333987bed880d44e76210011b3cd7dffbbdda0 [file] [log] [blame]
Oscar Fuentes34fc5172009-04-04 22:52:02 +00001# See docs/CMake.html for instructions about how to build LLVM with CMake.
2
Cedric Venet1d083f42008-10-30 21:22:00 +00003project(LLVM)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +00004cmake_minimum_required(VERSION 2.6.1)
5
6set(PACKAGE_NAME llvm)
Chris Lattner8c46e852009-01-28 17:49:03 +00007set(PACKAGE_VERSION 2.6svn)
8set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Oscar Fuentesf7e73b92008-10-25 03:49:35 +00009set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000010
Oscar Fuentes6326a0d2008-11-14 03:43:18 +000011if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
12 message(FATAL_ERROR "In-source builds are not allowed.
13CMake would overwrite the makefiles distributed with LLVM.
14Please create a directory and run cmake from there, passing the path
15to this source directory as the last argument.
16This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
17Please delete them.")
18endif()
19
Oscar Fuentes81a87552009-06-03 15:11:25 +000020string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
21
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000022include(FindPerl)
23
24set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Oscar Fuentes980e8422008-10-29 02:33:15 +000025set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000026set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
27set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
28set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
29
Oscar Fuentes4f21c132008-11-10 01:47:07 +000030set(LLVM_ALL_TARGETS
31 Alpha
32 ARM
33 CBackend
34 CellSPU
35 CppBackend
36 IA64
37 Mips
38 MSIL
39 PIC16
40 PowerPC
41 Sparc
42 X86
43 XCore
44 )
45
Oscar Fuentes7f6f21e2008-11-15 22:51:03 +000046# List of targets whose asmprinters need to be forced to link
47# into executables on some platforms (i.e. Windows):
48set(LLVM_ASMPRINTERS_FORCE_LINK X86 PowerPC)
49
Oscar Fuentese1ad0872008-09-26 04:40:32 +000050if( MSVC )
51 set(LLVM_TARGETS_TO_BUILD X86
Oscar Fuentes4f21c132008-11-10 01:47:07 +000052 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000053else( MSVC )
Oscar Fuentes4f21c132008-11-10 01:47:07 +000054 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
55 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000056endif( MSVC )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000057
Oscar Fuentes4b442832008-11-18 23:45:21 +000058option(LLVM_ENABLE_THREADS "Use threads if available." ON)
59
Oscar Fuentes81a87552009-06-03 15:11:25 +000060if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
Oscar Fuentes76941b22009-06-04 09:26:16 +000061 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
Oscar Fuentes81a87552009-06-03 15:11:25 +000062else()
Oscar Fuentes76941b22009-06-04 09:26:16 +000063 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
Oscar Fuentes81a87552009-06-03 15:11:25 +000064endif()
65
Oscar Fuentes76941b22009-06-04 09:26:16 +000066if( LLVM_ENABLE_ASSERTIONS )
67 add_definitions( -D_DEBUG )
68 # On Release builds cmake automatically defines NDEBUG, so we
69 # explicitly undefine it:
70 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
71 add_definitions( -UNDEBUG )
72 endif()
73else()
74 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
75 add_definitions( -DNDEBUG )
76 endif()
Oscar Fuentes81a87552009-06-03 15:11:25 +000077endif()
78
Oscar Fuentes4f21c132008-11-10 01:47:07 +000079if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
80 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
81endif()
82
83foreach(c ${LLVM_TARGETS_TO_BUILD})
84 list(FIND LLVM_ALL_TARGETS ${c} idx)
85 if( idx LESS 0 )
86 message(FATAL_ERROR "The target `${c}' does not exists.
87 It should be one of\n${LLVM_ALL_TARGETS}")
88 endif()
89endforeach(c)
90
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000091set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
92
Douglas Gregor8eeb96d2009-06-04 19:53:37 +000093# The USE_EXPLICIT_DEPENDENCIES variable will be TRUE to indicate that
94# we should use the library dependencies explicitly specified in the
95# CMakeLists.txt files rather than those determined by
96# llvm-config. This value must be true for non-make and IDE
97# generators.
98if (MSVC_IDE)
99 set(DEFAULT_USE_EXPLICIT_DEPENDENCIES ON)
100elseif (XCODE)
101 set(DEFAULT_USE_EXPLICIT_DEPENDENCIES ON)
102else ()
103 set(DEFAULT_USE_EXPLICIT_DEPENDENCIES OFF)
104endif ()
105
106option(USE_EXPLICIT_DEPENDENCIES
107 "Use explicit dependencies instead of llvm-config"
108 ${DEFAULT_USE_EXPLICIT_DEPENDENCIES})
109mark_as_advanced(USE_EXPLICIT_DEPENDENCIES)
110
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000111# Add path for custom modules
112set(CMAKE_MODULE_PATH
113 ${CMAKE_MODULE_PATH}
114 "${LLVM_MAIN_SRC_DIR}/cmake"
115 "${LLVM_MAIN_SRC_DIR}/cmake/modules"
116 )
117
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000118include(AddLLVMDefinitions)
119
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000120if(WIN32)
Oscar Fuentes4fd38b82008-10-30 17:15:54 +0000121 if(CYGWIN)
122 set(LLVM_ON_WIN32 0)
123 set(LLVM_ON_UNIX 1)
124 else(CYGWIN)
125 set(LLVM_ON_WIN32 1)
126 set(LLVM_ON_UNIX 0)
127 endif(CYGWIN)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000128 set(LTDL_SHLIB_EXT ".dll")
129 set(EXEEXT ".exe")
130 # Maximum path length is 160 for non-unicode paths
131 set(MAXPATHLEN 160)
132else(WIN32)
133 if(UNIX)
134 set(LLVM_ON_WIN32 0)
135 set(LLVM_ON_UNIX 1)
136 set(LTDL_SHLIB_EXT ".so")
137 set(EXEEXT "")
138 # FIXME: Maximum path length is currently set to 'safe' fixed value
139 set(MAXPATHLEN 2024)
140 else(UNIX)
141 MESSAGE(SEND_ERROR "Unable to determine platform")
142 endif(UNIX)
143endif(WIN32)
144
145if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
146 set(HAVE_LLVM_CONFIG 1)
147endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000148
Oscar Fuentesde98db32008-10-25 03:29:36 +0000149include(config-ix)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000150
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000151option(LLVM_ENABLE_PIC "Build Position-Independent Code" OFF)
152
Douglas Gregor318de602009-06-05 23:46:34 +0000153set(ENABLE_PIC 0)
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000154if( LLVM_ENABLE_PIC )
155 if( SUPPORTS_FPIC_FLAG )
156 message(STATUS "Building with -fPIC")
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000157 add_llvm_definitions(-fPIC)
Douglas Gregor318de602009-06-05 23:46:34 +0000158 set(ENABLE_PIC 1)
159 else( SUPPORTS_FPIC_FLAG )
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000160 message(STATUS "Warning: -fPIC not supported.")
161 endif()
162endif()
163
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000164set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
165set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
166set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
167
168# set(CMAKE_VERBOSE_MAKEFILE true)
169
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000170add_llvm_definitions( -D__STDC_LIMIT_MACROS )
171add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000172
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000173set(LLVM_PLO_FLAGS "" CACHE
174 STRING "Flags for creating partially linked objects.")
175
176if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
177 # TODO: support other platforms and toolchains.
Oscar Fuentes6307b942008-11-19 00:10:39 +0000178 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
179 if( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000180 message(STATUS "Building 32 bits executables and libraries.")
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000181 add_llvm_definitions( -m32 )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000182 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
183 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000184 set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000185 endif( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000186endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
187
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000188if( MSVC )
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000189 add_llvm_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
190 add_llvm_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
191 add_llvm_definitions( -D_SCL_SECURE_NO_DEPRECATE )
192 add_llvm_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
193 add_llvm_definitions( -wd4355 -wd4715 -wd4180 -wd4345 -wd4224 )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000194endif( MSVC )
195
Oscar Fuentes980e8422008-10-29 02:33:15 +0000196include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000197
198include(AddLLVM)
199include(AddPartiallyLinkedObject)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000200include(TableGen)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000201
202add_subdirectory(lib/Support)
203add_subdirectory(lib/System)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000204
205# Everything else depends on Support and System:
206set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
207
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000208set(LLVM_TABLEGEN "tblgen" CACHE
Oscar Fuentes41bdedf2008-11-10 02:35:55 +0000209 STRING "Native TableGen executable. Saves building one when cross-compiling.")
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000210
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000211add_subdirectory(utils/TableGen)
212
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000213if( CMAKE_CROSSCOMPILING )
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000214 # This adds a dependency on target `tblgen', so must go after utils/TableGen
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000215 include( CrossCompileLLVM )
216endif( CMAKE_CROSSCOMPILING )
217
Oscar Fuentes422fcf32008-11-15 00:24:38 +0000218add_subdirectory(include/llvm)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000219
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000220add_subdirectory(lib/VMCore)
221add_subdirectory(lib/CodeGen)
222add_subdirectory(lib/CodeGen/SelectionDAG)
223add_subdirectory(lib/CodeGen/AsmPrinter)
224add_subdirectory(lib/Bitcode/Reader)
225add_subdirectory(lib/Bitcode/Writer)
226add_subdirectory(lib/Transforms/Utils)
227add_subdirectory(lib/Transforms/Instrumentation)
228add_subdirectory(lib/Transforms/Scalar)
229add_subdirectory(lib/Transforms/IPO)
230add_subdirectory(lib/Transforms/Hello)
231add_subdirectory(lib/Linker)
232add_subdirectory(lib/Analysis)
233add_subdirectory(lib/Analysis/IPA)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000234
235foreach(t ${LLVM_TARGETS_TO_BUILD})
236 message(STATUS "Targeting ${t}")
237 add_subdirectory(lib/Target/${t})
Oscar Fuentescccecb82008-11-14 22:21:02 +0000238 if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000239 add_subdirectory(lib/Target/${t}/AsmPrinter)
Oscar Fuentescccecb82008-11-14 22:21:02 +0000240 endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000241endforeach(t)
242
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000243add_subdirectory(lib/ExecutionEngine)
244add_subdirectory(lib/ExecutionEngine/Interpreter)
245add_subdirectory(lib/ExecutionEngine/JIT)
246add_subdirectory(lib/Target)
247add_subdirectory(lib/AsmParser)
248add_subdirectory(lib/Debugger)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000249add_subdirectory(lib/Archive)
250
Oscar Fuentes5c6bf652009-03-06 01:16:52 +0000251add_subdirectory(projects)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000252add_subdirectory(tools)
253
254add_subdirectory(examples)
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000255
256install(DIRECTORY include
257 DESTINATION .
258 PATTERN ".svn" EXCLUDE
259 PATTERN "*.cmake" EXCLUDE
260 PATTERN "*.in" EXCLUDE
261 )
262
263install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
264 DESTINATION .
265 )
266
267# TODO: make and install documentation.