blob: 940326e732d3fcf07081b9cdf38654a3e9490cfb [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
107set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
108set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
109set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
110
111# set(CMAKE_VERBOSE_MAKEFILE true)
112
113add_definitions( -D__STDC_LIMIT_MACROS )
Oscar Fuentes0a486982008-10-30 17:21:37 +0000114add_definitions( -D__STDC_CONSTANT_MACROS )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000115
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000116set(LLVM_PLO_FLAGS "" CACHE
117 STRING "Flags for creating partially linked objects.")
118
119if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
120 # TODO: support other platforms and toolchains.
Oscar Fuentes6307b942008-11-19 00:10:39 +0000121 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
122 if( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000123 message(STATUS "Building 32 bits executables and libraries.")
124 add_definitions( -m32 )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000125 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
126 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000127 set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000128 endif( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000129endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
130
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000131if( 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 )
Oscar Fuentesa789af22008-09-24 19:27:54 +0000135 add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
136 add_definitions( -wd4355 -wd4715 )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000137endif( MSVC )
138
Oscar Fuentes980e8422008-10-29 02:33:15 +0000139include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000140
141include(AddLLVM)
142include(AddPartiallyLinkedObject)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000143include(TableGen)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000144
145add_subdirectory(lib/Support)
146add_subdirectory(lib/System)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000147
148# Everything else depends on Support and System:
149set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
150
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000151set(LLVM_TABLEGEN "tblgen" CACHE
Oscar Fuentes41bdedf2008-11-10 02:35:55 +0000152 STRING "Native TableGen executable. Saves building one when cross-compiling.")
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000153
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000154add_subdirectory(utils/TableGen)
155
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000156if( CMAKE_CROSSCOMPILING )
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000157 # This adds a dependency on target `tblgen', so must go after utils/TableGen
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000158 include( CrossCompileLLVM )
159endif( CMAKE_CROSSCOMPILING )
160
Oscar Fuentes422fcf32008-11-15 00:24:38 +0000161add_subdirectory(include/llvm)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000162
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000163add_subdirectory(lib/VMCore)
164add_subdirectory(lib/CodeGen)
165add_subdirectory(lib/CodeGen/SelectionDAG)
166add_subdirectory(lib/CodeGen/AsmPrinter)
167add_subdirectory(lib/Bitcode/Reader)
168add_subdirectory(lib/Bitcode/Writer)
169add_subdirectory(lib/Transforms/Utils)
170add_subdirectory(lib/Transforms/Instrumentation)
171add_subdirectory(lib/Transforms/Scalar)
172add_subdirectory(lib/Transforms/IPO)
173add_subdirectory(lib/Transforms/Hello)
174add_subdirectory(lib/Linker)
175add_subdirectory(lib/Analysis)
176add_subdirectory(lib/Analysis/IPA)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000177
178foreach(t ${LLVM_TARGETS_TO_BUILD})
179 message(STATUS "Targeting ${t}")
180 add_subdirectory(lib/Target/${t})
Oscar Fuentescccecb82008-11-14 22:21:02 +0000181 if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000182 add_subdirectory(lib/Target/${t}/AsmPrinter)
Oscar Fuentescccecb82008-11-14 22:21:02 +0000183 endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000184endforeach(t)
185
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000186add_subdirectory(lib/ExecutionEngine)
187add_subdirectory(lib/ExecutionEngine/Interpreter)
188add_subdirectory(lib/ExecutionEngine/JIT)
189add_subdirectory(lib/Target)
190add_subdirectory(lib/AsmParser)
191add_subdirectory(lib/Debugger)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000192add_subdirectory(lib/Archive)
193
194add_subdirectory(tools)
195
196add_subdirectory(examples)
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000197
198install(DIRECTORY include
199 DESTINATION .
200 PATTERN ".svn" EXCLUDE
201 PATTERN "*.cmake" EXCLUDE
202 PATTERN "*.in" EXCLUDE
203 )
204
205install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
206 DESTINATION .
207 )
208
209# TODO: make and install documentation.