blob: 15dcf7fa2bf7ef9bd97df8f41b9d2cd89aaf8675 [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
8include(FindPerl)
9
10set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Oscar Fuentes980e8422008-10-29 02:33:15 +000011set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000012set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
13set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
14set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
15
Oscar Fuentes4f21c132008-11-10 01:47:07 +000016set(LLVM_ALL_TARGETS
17 Alpha
18 ARM
19 CBackend
20 CellSPU
21 CppBackend
22 IA64
23 Mips
24 MSIL
25 PIC16
26 PowerPC
27 Sparc
28 X86
29 XCore
30 )
31
Oscar Fuentese1ad0872008-09-26 04:40:32 +000032if( MSVC )
33 set(LLVM_TARGETS_TO_BUILD X86
Oscar Fuentes4f21c132008-11-10 01:47:07 +000034 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000035else( MSVC )
Oscar Fuentes4f21c132008-11-10 01:47:07 +000036 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
37 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
Oscar Fuentese1ad0872008-09-26 04:40:32 +000038endif( MSVC )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000039
Oscar Fuentes4f21c132008-11-10 01:47:07 +000040if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
41 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
42endif()
43
44foreach(c ${LLVM_TARGETS_TO_BUILD})
45 list(FIND LLVM_ALL_TARGETS ${c} idx)
46 if( idx LESS 0 )
47 message(FATAL_ERROR "The target `${c}' does not exists.
48 It should be one of\n${LLVM_ALL_TARGETS}")
49 endif()
50endforeach(c)
51
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000052set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
53
54# Add path for custom modules
55set(CMAKE_MODULE_PATH
56 ${CMAKE_MODULE_PATH}
57 "${LLVM_MAIN_SRC_DIR}/cmake"
58 "${LLVM_MAIN_SRC_DIR}/cmake/modules"
59 )
60
61if(WIN32)
Oscar Fuentes4fd38b82008-10-30 17:15:54 +000062 if(CYGWIN)
63 set(LLVM_ON_WIN32 0)
64 set(LLVM_ON_UNIX 1)
65 else(CYGWIN)
66 set(LLVM_ON_WIN32 1)
67 set(LLVM_ON_UNIX 0)
68 endif(CYGWIN)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000069 set(LTDL_SHLIB_EXT ".dll")
70 set(EXEEXT ".exe")
71 # Maximum path length is 160 for non-unicode paths
72 set(MAXPATHLEN 160)
73else(WIN32)
74 if(UNIX)
75 set(LLVM_ON_WIN32 0)
76 set(LLVM_ON_UNIX 1)
77 set(LTDL_SHLIB_EXT ".so")
78 set(EXEEXT "")
79 # FIXME: Maximum path length is currently set to 'safe' fixed value
80 set(MAXPATHLEN 2024)
81 else(UNIX)
82 MESSAGE(SEND_ERROR "Unable to determine platform")
83 endif(UNIX)
84endif(WIN32)
85
86if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
87 set(HAVE_LLVM_CONFIG 1)
88endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
89# find_file(HAVE_LLVM_CONFIG llvm-config ${LLVM_TOOLS_BINARY_DIR})
90# message(STATUS ${HAVE_LLVM_CONFIG})
91
Oscar Fuentesde98db32008-10-25 03:29:36 +000092include(config-ix)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000093
94set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
95set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
96set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
97
98# set(CMAKE_VERBOSE_MAKEFILE true)
99
100add_definitions( -D__STDC_LIMIT_MACROS )
Oscar Fuentes0a486982008-10-30 17:21:37 +0000101add_definitions( -D__STDC_CONSTANT_MACROS )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000102
Oscar Fuentesb0c56992008-11-04 03:27:24 +0000103set(LLVM_PLO_FLAGS "" CACHE
104 STRING "Flags for creating partially linked objects.")
105
106if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
107 # TODO: support other platforms and toolchains.
108 option(BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
109 if( BUILD_32_BITS )
110 message(STATUS "Building 32 bits executables and libraries.")
111 add_definitions( -m32 )
112 set( CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}" )
113 set( CMAKE_LINK_LIBRARY_FLAG "-m32 ${CMAKE_LINK_LIBRARY_FLAG}" )
114 set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
115 endif( BUILD_32_BITS )
116endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
117
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000118if( MSVC )
119 add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
120 add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
121 add_definitions( -D_SCL_SECURE_NO_DEPRECATE )
Oscar Fuentesa789af22008-09-24 19:27:54 +0000122 add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
123 add_definitions( -wd4355 -wd4715 )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000124endif( MSVC )
125
Oscar Fuentes980e8422008-10-29 02:33:15 +0000126include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000127#link_directories( d:/dev/lib )
128
129#add_subdirectory(lib)
130
131include(AddLLVM)
132include(AddPartiallyLinkedObject)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000133include(TableGen)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000134
135add_subdirectory(lib/Support)
136add_subdirectory(lib/System)
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000137
138# Everything else depends on Support and System:
139set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
140
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000141set(LLVM_TABLEGEN "tblgen" CACHE
Oscar Fuentes41bdedf2008-11-10 02:35:55 +0000142 STRING "Native TableGen executable. Saves building one when cross-compiling.")
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000143
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000144add_subdirectory(utils/TableGen)
145
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000146if( CMAKE_CROSSCOMPILING )
Oscar Fuentes02516ba2008-11-10 01:32:14 +0000147 # This adds a dependency on target `tblgen', so must go after utils/TableGen
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000148 include( CrossCompileLLVM )
149endif( CMAKE_CROSSCOMPILING )
150
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000151add_custom_command(OUTPUT ${llvm_builded_incs_dir}/Intrinsics.gen
Oscar Fuentes3ab40ca2008-11-09 18:53:19 +0000152 COMMAND ${LLVM_TABLEGEN} -gen-intrinsic -I ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}/llvm/Intrinsics.td -o ${llvm_builded_incs_dir}/Intrinsics.gen
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000153 DEPENDS tblgen
154 COMMENT "Building intrinsics.gen...")
155
156add_custom_target(intrinsics_gen ALL
157 DEPENDS ${llvm_builded_incs_dir}/Intrinsics.gen)
158
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +0000159set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} intrinsics_gen )
160
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000161add_subdirectory(lib/VMCore)
162add_subdirectory(lib/CodeGen)
163add_subdirectory(lib/CodeGen/SelectionDAG)
164add_subdirectory(lib/CodeGen/AsmPrinter)
165add_subdirectory(lib/Bitcode/Reader)
166add_subdirectory(lib/Bitcode/Writer)
167add_subdirectory(lib/Transforms/Utils)
168add_subdirectory(lib/Transforms/Instrumentation)
169add_subdirectory(lib/Transforms/Scalar)
170add_subdirectory(lib/Transforms/IPO)
171add_subdirectory(lib/Transforms/Hello)
172add_subdirectory(lib/Linker)
173add_subdirectory(lib/Analysis)
174add_subdirectory(lib/Analysis/IPA)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000175
176foreach(t ${LLVM_TARGETS_TO_BUILD})
177 message(STATUS "Targeting ${t}")
178 add_subdirectory(lib/Target/${t})
179 if( EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
180 add_subdirectory(lib/Target/${t}/AsmPrinter)
181 endif( EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt )
182endforeach(t)
183
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000184add_subdirectory(lib/ExecutionEngine)
185add_subdirectory(lib/ExecutionEngine/Interpreter)
186add_subdirectory(lib/ExecutionEngine/JIT)
187add_subdirectory(lib/Target)
188add_subdirectory(lib/AsmParser)
189add_subdirectory(lib/Debugger)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000190add_subdirectory(lib/Archive)
191
192add_subdirectory(tools)
193
194add_subdirectory(examples)
Oscar Fuentes1dc97162008-10-22 02:56:07 +0000195
196install(DIRECTORY include
197 DESTINATION .
198 PATTERN ".svn" EXCLUDE
199 PATTERN "*.cmake" EXCLUDE
200 PATTERN "*.in" EXCLUDE
201 )
202
203install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
204 DESTINATION .
205 )
206
207# TODO: make and install documentation.