blob: 2072c703715d959407d318c2375df69433179fd1 [file] [log] [blame]
Cedric Venet1d083f42008-10-30 21:22:00 +00001project(LLVM)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +00002cmake_minimum_required(VERSION 2.6.1)
3
4set(PACKAGE_NAME llvm)
5set(PACKAGE_VERSION svn)
Oscar Fuentesf7e73b92008-10-25 03:49:35 +00006set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
Oscar Fuentes3d01fc72008-09-22 01:08:49 +00007
Oscar Fuentes6326a0d2008-11-14 03:43:18 +00008if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
9 message(FATAL_ERROR "In-source builds are not allowed.
10CMake would overwrite the makefiles distributed with LLVM.
11Please create a directory and run cmake from there, passing the path
12to this source directory as the last argument.
13This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
14Please delete them.")
15endif()
16
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000017include(FindPerl)
18
19set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Oscar Fuentes980e8422008-10-29 02:33:15 +000020set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000021set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
22set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
23set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
24
Oscar Fuentes4f21c132008-11-10 01:47:07 +000025set(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
Oscar Fuentes7f6f21e2008-11-15 22:51:03 +000041# List of targets whose asmprinters need to be forced to link
42# into executables on some platforms (i.e. Windows):
43set(LLVM_ASMPRINTERS_FORCE_LINK X86 PowerPC)
44
Oscar Fuentese1ad0872008-09-26 04:40:32 +000045if( MSVC )
46 set(LLVM_TARGETS_TO_BUILD X86
Oscar Fuentes4f21c132008-11-10 01:47:07 +000047 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000048else( MSVC )
Oscar Fuentes4f21c132008-11-10 01:47:07 +000049 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
50 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000051endif( MSVC )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000052
Oscar Fuentes4b442832008-11-18 23:45:21 +000053option(LLVM_ENABLE_THREADS "Use threads if available." ON)
54
Oscar Fuentes4f21c132008-11-10 01:47:07 +000055if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
56 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
57endif()
58
59foreach(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()
65endforeach(c)
66
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000067set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
68
69# Add path for custom modules
70set(CMAKE_MODULE_PATH
71 ${CMAKE_MODULE_PATH}
72 "${LLVM_MAIN_SRC_DIR}/cmake"
73 "${LLVM_MAIN_SRC_DIR}/cmake/modules"
74 )
75
76if(WIN32)
Oscar Fuentes4fd38b82008-10-30 17:15:54 +000077 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)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000084 set(LTDL_SHLIB_EXT ".dll")
85 set(EXEEXT ".exe")
86 # Maximum path length is 160 for non-unicode paths
87 set(MAXPATHLEN 160)
88else(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)
99endif(WIN32)
100
101if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
102 set(HAVE_LLVM_CONFIG 1)
103endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000104
Oscar Fuentesde98db32008-10-25 03:29:36 +0000105include(config-ix)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000106
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000107option(LLVM_ENABLE_PIC "Build Position-Independent Code" OFF)
108
109if( LLVM_ENABLE_PIC )
110 if( SUPPORTS_FPIC_FLAG )
111 message(STATUS "Building with -fPIC")
112 add_definitions(-fPIC)
113 else( SUPPORTS_FPIC_FLAG )
114 message(STATUS "Warning: -fPIC not supported.")
115 endif()
116endif()
117
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000118set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
119set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
120set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
121
122# set(CMAKE_VERBOSE_MAKEFILE true)
123
124add_definitions( -D__STDC_LIMIT_MACROS )
Oscar Fuentes0a486982008-10-30 17:21:37 +0000125add_definitions( -D__STDC_CONSTANT_MACROS )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000126
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000127set(LLVM_PLO_FLAGS "" CACHE
128 STRING "Flags for creating partially linked objects.")
129
130if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
131 # TODO: support other platforms and toolchains.
Oscar Fuentes6307b942008-11-19 00:10:39 +0000132 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
133 if( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000134 message(STATUS "Building 32 bits executables and libraries.")
135 add_definitions( -m32 )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000136 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
137 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000138 set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000139 endif( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000140endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
141
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000142if( MSVC )
143 add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
144 add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
145 add_definitions( -D_SCL_SECURE_NO_DEPRECATE )
Oscar Fuentesa789af22008-09-24 19:27:54 +0000146 add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
147 add_definitions( -wd4355 -wd4715 )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000148endif( MSVC )
149
Oscar Fuentes980e8422008-10-29 02:33:15 +0000150include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000151
152include(AddLLVM)
153include(AddPartiallyLinkedObject)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000154include(TableGen)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000155
156add_subdirectory(lib/Support)
157add_subdirectory(lib/System)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000158
159# Everything else depends on Support and System:
160set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
161
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000162set(LLVM_TABLEGEN "tblgen" CACHE
Oscar Fuentes41bdedf2008-11-10 02:35:55 +0000163 STRING "Native TableGen executable. Saves building one when cross-compiling.")
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000164
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000165add_subdirectory(utils/TableGen)
166
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000167if( CMAKE_CROSSCOMPILING )
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000168 # This adds a dependency on target `tblgen', so must go after utils/TableGen
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000169 include( CrossCompileLLVM )
170endif( CMAKE_CROSSCOMPILING )
171
Oscar Fuentes422fcf32008-11-15 00:24:38 +0000172add_subdirectory(include/llvm)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000173
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000174add_subdirectory(lib/VMCore)
175add_subdirectory(lib/CodeGen)
176add_subdirectory(lib/CodeGen/SelectionDAG)
177add_subdirectory(lib/CodeGen/AsmPrinter)
178add_subdirectory(lib/Bitcode/Reader)
179add_subdirectory(lib/Bitcode/Writer)
180add_subdirectory(lib/Transforms/Utils)
181add_subdirectory(lib/Transforms/Instrumentation)
182add_subdirectory(lib/Transforms/Scalar)
183add_subdirectory(lib/Transforms/IPO)
184add_subdirectory(lib/Transforms/Hello)
185add_subdirectory(lib/Linker)
186add_subdirectory(lib/Analysis)
187add_subdirectory(lib/Analysis/IPA)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000188
189foreach(t ${LLVM_TARGETS_TO_BUILD})
190 message(STATUS "Targeting ${t}")
191 add_subdirectory(lib/Target/${t})
Oscar Fuentescccecb82008-11-14 22:21:02 +0000192 if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000193 add_subdirectory(lib/Target/${t}/AsmPrinter)
Oscar Fuentescccecb82008-11-14 22:21:02 +0000194 endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000195endforeach(t)
196
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000197add_subdirectory(lib/ExecutionEngine)
198add_subdirectory(lib/ExecutionEngine/Interpreter)
199add_subdirectory(lib/ExecutionEngine/JIT)
200add_subdirectory(lib/Target)
201add_subdirectory(lib/AsmParser)
202add_subdirectory(lib/Debugger)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000203add_subdirectory(lib/Archive)
204
205add_subdirectory(tools)
206
207add_subdirectory(examples)
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000208
209install(DIRECTORY include
210 DESTINATION .
211 PATTERN ".svn" EXCLUDE
212 PATTERN "*.cmake" EXCLUDE
213 PATTERN "*.in" EXCLUDE
214 )
215
216install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
217 DESTINATION .
218 )
219
220# TODO: make and install documentation.