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")
14 include(VersionFromVCS)
15 add_version_info_from_vcs(PACKAGE_VERSION)
17 set(PACKAGE_NAME llvm)
18 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
19 set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
21 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
22 message(FATAL_ERROR "In-source builds are not allowed.
23 CMake would overwrite the makefiles distributed with LLVM.
24 Please create a directory and run cmake from there, passing the path
25 to this source directory as the last argument.
26 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
30 # Run-time build mode; It is used for unittests.
32 # Expect "$(Configuration)", "$(OutDir)", etc.
33 # It is expanded by msbuild or similar.
34 set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
35 elseif(NOT CMAKE_BUILD_TYPE STREQUAL "")
36 # Expect "Release" "Debug", etc.
37 # Or unittests could not run.
38 set(RUNTIME_BUILD_MODE ${CMAKE_BUILD_TYPE})
41 set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}")
44 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
46 set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
47 set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include)
48 set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
49 set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
50 set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
51 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
53 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
55 tablegenned_files_on_include_dir
56 "${LLVM_MAIN_SRC_DIR}/include/llvm/*.gen")
58 tablegenned_files_on_lib_dir
59 "${LLVM_MAIN_SRC_DIR}/lib/Target/*.inc")
60 if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
61 message(FATAL_ERROR "Apparently there is a previous in-source build,
62 probably as the result of running `configure' and `make' on
64 This may cause problems. The suspicious files are:
65 ${tablegenned_files_on_lib_dir}
66 ${tablegenned_files_on_include_dir}
67 Please clean the source directory.")
90 set(LLVM_TARGETS_TO_BUILD X86
91 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
93 set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS}
94 CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
97 set(CLANG_RESOURCE_DIR "" CACHE STRING
98 "Relative directory from the Clang binary to its resource files.")
100 set(C_INCLUDE_DIRS "" CACHE STRING
101 "Colon separated list of directories clang will search for headers.")
103 set(LLVM_TARGET_ARCH "host"
104 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
106 set(LIT_ARGS_DEFAULT "-sv")
108 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
110 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
111 CACHE STRING "Default options for lit")
113 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
115 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
116 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
118 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
121 if( LLVM_ENABLE_ASSERTIONS )
122 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
124 add_definitions( -D_DEBUG )
126 # On Release builds cmake automatically defines NDEBUG, so we
127 # explicitly undefine it:
128 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
129 add_definitions( -UNDEBUG )
132 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
133 add_definitions( -DNDEBUG )
137 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
138 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
141 set(LLVM_ENUM_TARGETS "")
142 foreach(c ${LLVM_TARGETS_TO_BUILD})
143 list(FIND LLVM_ALL_TARGETS ${c} idx)
145 message(FATAL_ERROR "The target `${c}' does not exist.
146 It should be one of\n${LLVM_ALL_TARGETS}")
148 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
152 # Produce llvm/Config/Targets.def
154 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
155 ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
158 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
160 include(AddLLVMDefinitions)
170 set(LTDL_SHLIB_EXT ".dll")
172 # Maximum path length is 160 for non-unicode paths
179 set(LTDL_SHLIB_EXT ".dylib")
181 set(LTDL_SHLIB_EXT ".so")
184 # FIXME: Maximum path length is currently set to 'safe' fixed value
187 MESSAGE(SEND_ERROR "Unable to determine platform")
193 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
196 if( LLVM_ENABLE_PIC )
198 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
199 # know how to disable this, so just force ENABLE_PIC off for now.
200 message(STATUS "Warning: -fPIC not supported with Xcode.")
202 if( SUPPORTS_FPIC_FLAG )
203 message(STATUS "Building with -fPIC")
204 add_llvm_definitions(-fPIC)
206 else( SUPPORTS_FPIC_FLAG )
207 message(STATUS "Warning: -fPIC not supported.")
212 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
213 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
214 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
216 # set(CMAKE_VERBOSE_MAKEFILE true)
218 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
219 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
221 # MSVC has a gazillion warnings with this.
223 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
225 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
228 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
229 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
231 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
232 # TODO: support other platforms and toolchains.
233 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
234 if( LLVM_BUILD_32_BITS )
235 message(STATUS "Building 32 bits executables and libraries.")
236 add_llvm_definitions( -m32 )
237 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
238 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
239 endif( LLVM_BUILD_32_BITS )
240 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
243 include(ChooseMSVCCRT)
245 # Add definitions that make MSVC much less annoying.
246 add_llvm_definitions(
247 # For some reason MS wants to deprecate a bunch of standard functions...
248 -D_CRT_SECURE_NO_DEPRECATE
249 -D_CRT_SECURE_NO_WARNINGS
250 -D_CRT_NONSTDC_NO_DEPRECATE
251 -D_CRT_NONSTDC_NO_WARNINGS
252 -D_SCL_SECURE_NO_DEPRECATE
253 -D_SCL_SECURE_NO_WARNINGS
255 -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
256 -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
257 -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type'
258 -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
259 -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
260 -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
261 -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
262 -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
263 -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
264 -wd4355 # Suppress ''this' : used in base member initializer list'
265 -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
266 -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
267 -wd4715 # Suppress ''function' : not all control paths return a value'
268 -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
270 -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning.
274 if (LLVM_ENABLE_WARNINGS)
275 add_llvm_definitions( /W4 /Wall )
276 if (LLVM_ENABLE_PEDANTIC)
277 # No MSVC equivalent available
278 endif (LLVM_ENABLE_PEDANTIC)
279 endif (LLVM_ENABLE_WARNINGS)
280 if (LLVM_ENABLE_WERROR)
281 add_llvm_definitions( /WX )
282 endif (LLVM_ENABLE_WERROR)
283 elseif( CMAKE_COMPILER_IS_GNUCXX )
284 if (LLVM_ENABLE_WARNINGS)
285 add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings )
286 if (LLVM_ENABLE_PEDANTIC)
287 add_llvm_definitions( -pedantic -Wno-long-long )
288 endif (LLVM_ENABLE_PEDANTIC)
289 endif (LLVM_ENABLE_WARNINGS)
290 if (LLVM_ENABLE_WERROR)
291 add_llvm_definitions( -Werror )
292 endif (LLVM_ENABLE_WERROR)
295 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
297 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
298 SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
299 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
305 get_system_libs(LLVM_SYSTEM_LIBS_LIST)
306 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
307 set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
309 set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
310 set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
313 add_subdirectory(lib/Support)
315 # Everything else depends on Support:
316 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
318 set(LLVM_TABLEGEN "tblgen" CACHE
319 STRING "Native TableGen executable. Saves building one when cross-compiling.")
320 # Effective tblgen executable to be used:
321 set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
323 add_subdirectory(utils/TableGen)
325 if( CMAKE_CROSSCOMPILING )
326 # This adds a dependency on target `tblgen', so must go after utils/TableGen
327 include( CrossCompileLLVM )
328 endif( CMAKE_CROSSCOMPILING )
330 add_subdirectory(include/llvm)
332 add_subdirectory(lib/VMCore)
333 add_subdirectory(lib/CodeGen)
334 add_subdirectory(lib/CodeGen/SelectionDAG)
335 add_subdirectory(lib/CodeGen/AsmPrinter)
336 add_subdirectory(lib/Bitcode/Reader)
337 add_subdirectory(lib/Bitcode/Writer)
338 add_subdirectory(lib/Transforms/Utils)
339 add_subdirectory(lib/Transforms/Instrumentation)
340 add_subdirectory(lib/Transforms/InstCombine)
341 add_subdirectory(lib/Transforms/Scalar)
342 add_subdirectory(lib/Transforms/IPO)
343 add_subdirectory(lib/Transforms/Hello)
344 add_subdirectory(lib/Linker)
345 add_subdirectory(lib/Analysis)
346 add_subdirectory(lib/Analysis/IPA)
347 add_subdirectory(lib/MC)
348 add_subdirectory(lib/MC/MCParser)
349 add_subdirectory(lib/MC/MCDisassembler)
350 add_subdirectory(lib/Object)
352 add_subdirectory(utils/FileCheck)
353 add_subdirectory(utils/FileUpdate)
354 add_subdirectory(utils/count)
355 add_subdirectory(utils/not)
356 add_subdirectory(utils/llvm-lit)
358 set(LLVM_ENUM_ASM_PRINTERS "")
359 set(LLVM_ENUM_ASM_PARSERS "")
360 set(LLVM_ENUM_DISASSEMBLERS "")
361 foreach(t ${LLVM_TARGETS_TO_BUILD})
362 message(STATUS "Targeting ${t}")
363 add_subdirectory(lib/Target/${t})
364 add_subdirectory(lib/Target/${t}/TargetInfo)
365 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
366 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
368 set(LLVM_ENUM_ASM_PRINTERS
369 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
371 if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
372 add_subdirectory(lib/Target/${t}/InstPrinter)
374 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
375 add_subdirectory(lib/Target/${t}/AsmParser)
376 set(LLVM_ENUM_ASM_PARSERS
377 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
379 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
380 add_subdirectory(lib/Target/${t}/Disassembler)
381 set(LLVM_ENUM_DISASSEMBLERS
382 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
384 set(CURRENT_LLVM_TARGET)
387 # Produce llvm/Config/AsmPrinters.def
389 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
390 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
393 # Produce llvm/Config/AsmParsers.def
395 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
396 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
399 # Produce llvm/Config/Disassemblers.def
401 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
402 ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
405 add_subdirectory(lib/ExecutionEngine)
406 add_subdirectory(lib/ExecutionEngine/Interpreter)
407 add_subdirectory(lib/ExecutionEngine/JIT)
408 add_subdirectory(lib/ExecutionEngine/MCJIT)
409 add_subdirectory(lib/Target)
410 add_subdirectory(lib/AsmParser)
411 add_subdirectory(lib/Archive)
413 add_subdirectory(projects)
415 option(LLVM_BUILD_TOOLS
416 "Build the LLVM tools. If OFF, just generate build targets." ON)
417 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
418 if( LLVM_INCLUDE_TOOLS )
419 add_subdirectory(tools)
422 option(LLVM_BUILD_EXAMPLES
423 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
424 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
425 if( LLVM_INCLUDE_EXAMPLES )
426 add_subdirectory(examples)
429 option(LLVM_BUILD_TESTS
430 "Build LLVM unit tests. If OFF, just generate build targes." OFF)
431 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
432 if( LLVM_INCLUDE_TESTS )
433 add_subdirectory(test)
434 add_subdirectory(utils/unittest)
435 add_subdirectory(unittests)
437 # This utility is used to prevent chrashing tests from calling Dr. Watson on
439 add_subdirectory(utils/KillTheDoctor)
443 add_subdirectory(cmake/modules)
445 install(DIRECTORY include/
452 PATTERN ".svn" EXCLUDE
455 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
462 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
463 PATTERN "CMakeFiles" EXCLUDE
464 PATTERN ".svn" EXCLUDE
467 # TODO: make and install documentation.
469 set(CPACK_PACKAGE_VENDOR "LLVM")
470 set(CPACK_PACKAGE_VERSION_MAJOR 2)
471 set(CPACK_PACKAGE_VERSION_MINOR 9)
472 add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
475 # Workaround for MSVS10 to avoid the Dialog Hell
476 # FIXME: This could be removed with future version of CMake.
477 if(MSVC_VERSION EQUAL 1600)
478 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
479 if( EXISTS "${LLVM_SLN_FILENAME}" )
480 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")