1 # See docs/CMake.html for instructions about how to build LLVM with CMake.
4 cmake_minimum_required(VERSION 2.8)
6 # Add path for custom modules
9 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
10 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
13 set(PACKAGE_VERSION "2.9")
15 include(VersionFromVCS)
17 option(LLVM_APPEND_VC_REV
18 "Append the version control system revision id to LLVM version" OFF)
20 if( LLVM_APPEND_VC_REV )
21 add_version_info_from_vcs(PACKAGE_VERSION)
24 set(PACKAGE_NAME llvm)
25 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
26 set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
28 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
29 message(FATAL_ERROR "In-source builds are not allowed.
30 CMake would overwrite the makefiles distributed with LLVM.
31 Please create a directory and run cmake from there, passing the path
32 to this source directory as the last argument.
33 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
37 # Run-time build mode; It is used for unittests.
39 # Expect "$(Configuration)", "$(OutDir)", etc.
40 # It is expanded by msbuild or similar.
41 set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
42 elseif(NOT CMAKE_BUILD_TYPE STREQUAL "")
43 # Expect "Release" "Debug", etc.
44 # Or unittests could not run.
45 set(RUNTIME_BUILD_MODE ${CMAKE_BUILD_TYPE})
48 set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
51 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
53 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
54 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
55 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
56 set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
57 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
58 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
60 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
62 tablegenned_files_on_include_dir
63 "${LLVM_MAIN_SRC_DIR}/include/llvm/*.gen")
65 tablegenned_files_on_lib_dir
66 "${LLVM_MAIN_SRC_DIR}/lib/Target/*.inc")
67 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
68 message(FATAL_ERROR "Apparently there is a previous in-source build,
69 probably as the result of running `configure' and `make' on
71 This may cause problems. The suspicious files are:
72 ${tablegenned_files_on_lib_dir}
73 ${tablegenned_files_on_include_dir}
74 Please clean the source directory.")
97 set(LLVM_TARGETS_TO_BUILD X86
98 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
100 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
101 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
104 option(LLVM_ENABLE_CBE_PRINTF_A "Set to ON if CBE is enabled for printf %a output" ON)
105 if(LLVM_ENABLE_CBE_PRINTF_A)
106 set(ENABLE_CBE_PRINTF_A 1)
109 option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
110 if(LLVM_ENABLE_TIMESTAMPS)
111 set(ENABLE_TIMESTAMPS 1)
114 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
115 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
116 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
118 set(LLVM_TARGET_ARCH "host"
119 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
121 set(LIT_ARGS_DEFAULT "-sv")
123 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
125 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
126 CACHE STRING "Default options for lit")
128 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
130 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
131 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
134 set(LLVM_ENUM_TARGETS "")
135 foreach(c ${LLVM_TARGETS_TO_BUILD})
136 list(FIND LLVM_ALL_TARGETS ${c} idx)
138 message(FATAL_ERROR "The target `${c}' does not exist.
139 It should be one of\n${LLVM_ALL_TARGETS}")
141 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
145 # Produce llvm/Config/Targets.def
147 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
148 ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
151 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
153 include(AddLLVMDefinitions)
155 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
159 include(HandleLLVMOptions)
161 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
162 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
164 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
168 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
169 ${LLVM_BINARY_DIR}/include/llvm/Config/config.h)
172 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
173 ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h)
176 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
177 ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h)
179 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
180 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
181 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
183 # MSVC has a gazillion warnings with this.
185 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
187 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
190 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
191 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
193 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
195 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
196 SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
197 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
203 get_system_libs(LLVM_SYSTEM_LIBS_LIST)
204 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
205 set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
207 set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
208 set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
212 # People report that -O3 is unreliable on MinGW. The traditional
213 # build also uses -O2 for that reason:
214 llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
217 add_subdirectory(lib/Support)
219 # Everything else depends on Support:
220 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
222 set(LLVM_TABLEGEN "tblgen" CACHE
223 STRING "Native TableGen executable. Saves building one when cross-compiling.")
224 # Effective tblgen executable to be used:
225 set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
227 add_subdirectory(utils/TableGen)
229 if( CMAKE_CROSSCOMPILING )
230 # This adds a dependency on target `tblgen', so must go after utils/TableGen
231 include( CrossCompileLLVM )
232 endif( CMAKE_CROSSCOMPILING )
234 add_subdirectory(include/llvm)
236 add_subdirectory(lib/VMCore)
237 add_subdirectory(lib/CodeGen)
238 add_subdirectory(lib/CodeGen/SelectionDAG)
239 add_subdirectory(lib/CodeGen/AsmPrinter)
240 add_subdirectory(lib/Bitcode/Reader)
241 add_subdirectory(lib/Bitcode/Writer)
242 add_subdirectory(lib/Transforms/Utils)
243 add_subdirectory(lib/Transforms/Instrumentation)
244 add_subdirectory(lib/Transforms/InstCombine)
245 add_subdirectory(lib/Transforms/Scalar)
246 add_subdirectory(lib/Transforms/IPO)
247 add_subdirectory(lib/Transforms/Hello)
248 add_subdirectory(lib/Linker)
249 add_subdirectory(lib/Analysis)
250 add_subdirectory(lib/Analysis/IPA)
251 add_subdirectory(lib/MC)
252 add_subdirectory(lib/MC/MCParser)
253 add_subdirectory(lib/MC/MCDisassembler)
254 add_subdirectory(lib/Object)
256 add_subdirectory(utils/FileCheck)
257 add_subdirectory(utils/FileUpdate)
258 add_subdirectory(utils/count)
259 add_subdirectory(utils/not)
260 add_subdirectory(utils/llvm-lit)
262 set(LLVM_ENUM_ASM_PRINTERS "")
263 set(LLVM_ENUM_ASM_PARSERS "")
264 set(LLVM_ENUM_DISASSEMBLERS "")
265 foreach(t ${LLVM_TARGETS_TO_BUILD})
266 message(STATUS "Targeting ${t}")
267 add_subdirectory(lib/Target/${t})
268 add_subdirectory(lib/Target/${t}/TargetInfo)
269 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
270 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
272 set(LLVM_ENUM_ASM_PRINTERS
273 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
275 if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
276 add_subdirectory(lib/Target/${t}/InstPrinter)
278 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
279 add_subdirectory(lib/Target/${t}/AsmParser)
280 set(LLVM_ENUM_ASM_PARSERS
281 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
283 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
284 add_subdirectory(lib/Target/${t}/Disassembler)
285 set(LLVM_ENUM_DISASSEMBLERS
286 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
288 set(CURRENT_LLVM_TARGET)
291 # Produce llvm/Config/AsmPrinters.def
293 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
294 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
297 # Produce llvm/Config/AsmParsers.def
299 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
300 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
303 # Produce llvm/Config/Disassemblers.def
305 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
306 ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
309 add_subdirectory(lib/ExecutionEngine)
310 add_subdirectory(lib/ExecutionEngine/Interpreter)
311 add_subdirectory(lib/ExecutionEngine/JIT)
312 add_subdirectory(lib/ExecutionEngine/MCJIT)
313 add_subdirectory(lib/Target)
314 add_subdirectory(lib/AsmParser)
315 add_subdirectory(lib/Archive)
317 add_subdirectory(projects)
319 option(LLVM_BUILD_TOOLS
320 "Build the LLVM tools. If OFF, just generate build targets." ON)
321 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
322 if( LLVM_INCLUDE_TOOLS )
323 add_subdirectory(tools)
326 option(LLVM_BUILD_EXAMPLES
327 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
328 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
329 if( LLVM_INCLUDE_EXAMPLES )
330 add_subdirectory(examples)
333 option(LLVM_BUILD_TESTS
334 "Build LLVM unit tests. If OFF, just generate build targes." OFF)
335 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
336 if( LLVM_INCLUDE_TESTS )
337 add_subdirectory(test)
338 add_subdirectory(utils/unittest)
339 add_subdirectory(unittests)
341 # This utility is used to prevent chrashing tests from calling Dr. Watson on
343 add_subdirectory(utils/KillTheDoctor)
347 add_subdirectory(cmake/modules)
349 install(DIRECTORY include/
356 PATTERN ".svn" EXCLUDE
359 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
366 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
367 PATTERN "CMakeFiles" EXCLUDE
368 PATTERN ".svn" EXCLUDE
371 # TODO: make and install documentation.
373 set(CPACK_PACKAGE_VENDOR "LLVM")
374 set(CPACK_PACKAGE_VERSION_MAJOR 2)
375 set(CPACK_PACKAGE_VERSION_MINOR 9)
376 add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
379 # Workaround for MSVS10 to avoid the Dialog Hell
380 # FIXME: This could be removed with future version of CMake.
381 if(MSVC_VERSION EQUAL 1600)
382 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
383 if( EXISTS "${LLVM_SLN_FILENAME}" )
384 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")