blob: 95f36a2bcd532fcbf42b728a5cdfbfbe4490e55b [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)
Chris Lattner8c46e852009-01-28 17:49:03 +00005set(PACKAGE_VERSION 2.6svn)
6set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
Oscar Fuentesf7e73b92008-10-25 03:49:35 +00007set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
Oscar Fuentes3d01fc72008-09-22 01:08:49 +00008
Oscar Fuentes6326a0d2008-11-14 03:43:18 +00009if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
10 message(FATAL_ERROR "In-source builds are not allowed.
11CMake would overwrite the makefiles distributed with LLVM.
12Please create a directory and run cmake from there, passing the path
13to this source directory as the last argument.
14This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
15Please delete them.")
16endif()
17
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000018include(FindPerl)
19
20set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Oscar Fuentes980e8422008-10-29 02:33:15 +000021set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000022set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
23set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
24set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
25
Oscar Fuentes4f21c132008-11-10 01:47:07 +000026set(LLVM_ALL_TARGETS
27 Alpha
28 ARM
29 CBackend
30 CellSPU
31 CppBackend
32 IA64
33 Mips
34 MSIL
35 PIC16
36 PowerPC
37 Sparc
38 X86
39 XCore
40 )
41
Oscar Fuentes7f6f21e2008-11-15 22:51:03 +000042# List of targets whose asmprinters need to be forced to link
43# into executables on some platforms (i.e. Windows):
44set(LLVM_ASMPRINTERS_FORCE_LINK X86 PowerPC)
45
Oscar Fuentese1ad0872008-09-26 04:40:32 +000046if( MSVC )
47 set(LLVM_TARGETS_TO_BUILD X86
Oscar Fuentes4f21c132008-11-10 01:47:07 +000048 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000049else( MSVC )
Oscar Fuentes4f21c132008-11-10 01:47:07 +000050 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
51 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000052endif( MSVC )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000053
Oscar Fuentes4b442832008-11-18 23:45:21 +000054option(LLVM_ENABLE_THREADS "Use threads if available." ON)
55
Oscar Fuentes4f21c132008-11-10 01:47:07 +000056if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
57 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
58endif()
59
60foreach(c ${LLVM_TARGETS_TO_BUILD})
61 list(FIND LLVM_ALL_TARGETS ${c} idx)
62 if( idx LESS 0 )
63 message(FATAL_ERROR "The target `${c}' does not exists.
64 It should be one of\n${LLVM_ALL_TARGETS}")
65 endif()
66endforeach(c)
67
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000068set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
69
70# Add path for custom modules
71set(CMAKE_MODULE_PATH
72 ${CMAKE_MODULE_PATH}
73 "${LLVM_MAIN_SRC_DIR}/cmake"
74 "${LLVM_MAIN_SRC_DIR}/cmake/modules"
75 )
76
Oscar Fuentes9a0107d2009-04-04 22:41:07 +000077include(AddLLVMDefinitions)
78
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000079if(WIN32)
Oscar Fuentes4fd38b82008-10-30 17:15:54 +000080 if(CYGWIN)
81 set(LLVM_ON_WIN32 0)
82 set(LLVM_ON_UNIX 1)
83 else(CYGWIN)
84 set(LLVM_ON_WIN32 1)
85 set(LLVM_ON_UNIX 0)
86 endif(CYGWIN)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000087 set(LTDL_SHLIB_EXT ".dll")
88 set(EXEEXT ".exe")
89 # Maximum path length is 160 for non-unicode paths
90 set(MAXPATHLEN 160)
91else(WIN32)
92 if(UNIX)
93 set(LLVM_ON_WIN32 0)
94 set(LLVM_ON_UNIX 1)
95 set(LTDL_SHLIB_EXT ".so")
96 set(EXEEXT "")
97 # FIXME: Maximum path length is currently set to 'safe' fixed value
98 set(MAXPATHLEN 2024)
99 else(UNIX)
100 MESSAGE(SEND_ERROR "Unable to determine platform")
101 endif(UNIX)
102endif(WIN32)
103
104if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
105 set(HAVE_LLVM_CONFIG 1)
106endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000107
Oscar Fuentesde98db32008-10-25 03:29:36 +0000108include(config-ix)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000109
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000110option(LLVM_ENABLE_PIC "Build Position-Independent Code" OFF)
111
112if( LLVM_ENABLE_PIC )
113 if( SUPPORTS_FPIC_FLAG )
114 message(STATUS "Building with -fPIC")
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000115 add_llvm_definitions(-fPIC)
Oscar Fuentes64fb4c82008-11-20 19:13:51 +0000116 else( SUPPORTS_FPIC_FLAG )
117 message(STATUS "Warning: -fPIC not supported.")
118 endif()
119endif()
120
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000121set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
122set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
123set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
124
125# set(CMAKE_VERBOSE_MAKEFILE true)
126
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000127add_llvm_definitions( -D__STDC_LIMIT_MACROS )
128add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000129
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000130set(LLVM_PLO_FLAGS "" CACHE
131 STRING "Flags for creating partially linked objects.")
132
133if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
134 # TODO: support other platforms and toolchains.
Oscar Fuentes6307b942008-11-19 00:10:39 +0000135 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
136 if( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000137 message(STATUS "Building 32 bits executables and libraries.")
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000138 add_llvm_definitions( -m32 )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000139 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
140 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000141 set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
Oscar Fuentes6307b942008-11-19 00:10:39 +0000142 endif( LLVM_BUILD_32_BITS )
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000143endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
144
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000145if( MSVC )
Oscar Fuentes9a0107d2009-04-04 22:41:07 +0000146 add_llvm_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
147 add_llvm_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
148 add_llvm_definitions( -D_SCL_SECURE_NO_DEPRECATE )
149 add_llvm_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
150 add_llvm_definitions( -wd4355 -wd4715 -wd4180 -wd4345 -wd4224 )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000151endif( MSVC )
152
Oscar Fuentes980e8422008-10-29 02:33:15 +0000153include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000154
155include(AddLLVM)
156include(AddPartiallyLinkedObject)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000157include(TableGen)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000158
159add_subdirectory(lib/Support)
160add_subdirectory(lib/System)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000161
162# Everything else depends on Support and System:
163set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
164
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000165set(LLVM_TABLEGEN "tblgen" CACHE
Oscar Fuentes41bdedf2008-11-10 02:35:55 +0000166 STRING "Native TableGen executable. Saves building one when cross-compiling.")
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000167
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000168add_subdirectory(utils/TableGen)
169
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000170if( CMAKE_CROSSCOMPILING )
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000171 # This adds a dependency on target `tblgen', so must go after utils/TableGen
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000172 include( CrossCompileLLVM )
173endif( CMAKE_CROSSCOMPILING )
174
Oscar Fuentes422fcf32008-11-15 00:24:38 +0000175add_subdirectory(include/llvm)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000176
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000177add_subdirectory(lib/VMCore)
178add_subdirectory(lib/CodeGen)
179add_subdirectory(lib/CodeGen/SelectionDAG)
180add_subdirectory(lib/CodeGen/AsmPrinter)
181add_subdirectory(lib/Bitcode/Reader)
182add_subdirectory(lib/Bitcode/Writer)
183add_subdirectory(lib/Transforms/Utils)
184add_subdirectory(lib/Transforms/Instrumentation)
185add_subdirectory(lib/Transforms/Scalar)
186add_subdirectory(lib/Transforms/IPO)
187add_subdirectory(lib/Transforms/Hello)
188add_subdirectory(lib/Linker)
189add_subdirectory(lib/Analysis)
190add_subdirectory(lib/Analysis/IPA)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000191
192foreach(t ${LLVM_TARGETS_TO_BUILD})
193 message(STATUS "Targeting ${t}")
194 add_subdirectory(lib/Target/${t})
Oscar Fuentescccecb82008-11-14 22:21:02 +0000195 if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000196 add_subdirectory(lib/Target/${t}/AsmPrinter)
Oscar Fuentescccecb82008-11-14 22:21:02 +0000197 endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000198endforeach(t)
199
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000200add_subdirectory(lib/ExecutionEngine)
201add_subdirectory(lib/ExecutionEngine/Interpreter)
202add_subdirectory(lib/ExecutionEngine/JIT)
203add_subdirectory(lib/Target)
204add_subdirectory(lib/AsmParser)
205add_subdirectory(lib/Debugger)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000206add_subdirectory(lib/Archive)
207
Oscar Fuentes5c6bf652009-03-06 01:16:52 +0000208add_subdirectory(projects)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000209add_subdirectory(tools)
210
211add_subdirectory(examples)
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000212
213install(DIRECTORY include
214 DESTINATION .
215 PATTERN ".svn" EXCLUDE
216 PATTERN "*.cmake" EXCLUDE
217 PATTERN "*.in" EXCLUDE
218 )
219
220install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
221 DESTINATION .
222 )
223
224# TODO: make and install documentation.