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 set(CLANG_RESOURCE_DIR "" CACHE STRING
105 "Relative directory from the Clang binary to its resource files.")
107 set(C_INCLUDE_DIRS "" CACHE STRING
108 "Colon separated list of directories clang will search for headers.")
110 set(LLVM_TARGET_ARCH "host"
111 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
113 set(LIT_ARGS_DEFAULT "-sv")
115 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
117 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
118 CACHE STRING "Default options for lit")
120 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
122 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
123 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
125 option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
128 if( LLVM_ENABLE_ASSERTIONS )
129 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
131 add_definitions( -D_DEBUG )
133 # On Release builds cmake automatically defines NDEBUG, so we
134 # explicitly undefine it:
135 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
136 add_definitions( -UNDEBUG )
139 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
140 add_definitions( -DNDEBUG )
144 if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
145 set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
148 set(LLVM_ENUM_TARGETS "")
149 foreach(c ${LLVM_TARGETS_TO_BUILD})
150 list(FIND LLVM_ALL_TARGETS ${c} idx)
152 message(FATAL_ERROR "The target `${c}' does not exist.
153 It should be one of\n${LLVM_ALL_TARGETS}")
155 set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n")
159 # Produce llvm/Config/Targets.def
161 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
162 ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def
165 set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
167 include(AddLLVMDefinitions)
177 set(LTDL_SHLIB_EXT ".dll")
179 # Maximum path length is 160 for non-unicode paths
186 set(LTDL_SHLIB_EXT ".dylib")
188 set(LTDL_SHLIB_EXT ".so")
191 # FIXME: Maximum path length is currently set to 'safe' fixed value
194 MESSAGE(SEND_ERROR "Unable to determine platform")
200 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
203 if( LLVM_ENABLE_PIC )
205 # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
206 # know how to disable this, so just force ENABLE_PIC off for now.
207 message(STATUS "Warning: -fPIC not supported with Xcode.")
209 if( SUPPORTS_FPIC_FLAG )
210 message(STATUS "Building with -fPIC")
211 add_llvm_definitions(-fPIC)
213 else( SUPPORTS_FPIC_FLAG )
214 message(STATUS "Warning: -fPIC not supported.")
219 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
220 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
221 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
223 # set(CMAKE_VERBOSE_MAKEFILE true)
225 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
226 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
228 # MSVC has a gazillion warnings with this.
230 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
232 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
235 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
236 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
238 if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
239 # TODO: support other platforms and toolchains.
240 option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
241 if( LLVM_BUILD_32_BITS )
242 message(STATUS "Building 32 bits executables and libraries.")
243 add_llvm_definitions( -m32 )
244 list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
245 list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
246 endif( LLVM_BUILD_32_BITS )
247 endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
250 include(ChooseMSVCCRT)
252 # Add definitions that make MSVC much less annoying.
253 add_llvm_definitions(
254 # For some reason MS wants to deprecate a bunch of standard functions...
255 -D_CRT_SECURE_NO_DEPRECATE
256 -D_CRT_SECURE_NO_WARNINGS
257 -D_CRT_NONSTDC_NO_DEPRECATE
258 -D_CRT_NONSTDC_NO_WARNINGS
259 -D_SCL_SECURE_NO_DEPRECATE
260 -D_SCL_SECURE_NO_WARNINGS
262 -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
263 -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
264 -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type'
265 -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
266 -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
267 -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
268 -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
269 -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
270 -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
271 -wd4355 # Suppress ''this' : used in base member initializer list'
272 -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
273 -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
274 -wd4715 # Suppress ''function' : not all control paths return a value'
275 -wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
277 -w14062 # Promote "enumerator in switch of enum is not handled" to level 1 warning.
281 if (LLVM_ENABLE_WARNINGS)
282 add_llvm_definitions( /W4 /Wall )
283 if (LLVM_ENABLE_PEDANTIC)
284 # No MSVC equivalent available
285 endif (LLVM_ENABLE_PEDANTIC)
286 endif (LLVM_ENABLE_WARNINGS)
287 if (LLVM_ENABLE_WERROR)
288 add_llvm_definitions( /WX )
289 endif (LLVM_ENABLE_WERROR)
290 elseif( CMAKE_COMPILER_IS_GNUCXX )
291 if (LLVM_ENABLE_WARNINGS)
292 add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings )
293 if (LLVM_ENABLE_PEDANTIC)
294 add_llvm_definitions( -pedantic -Wno-long-long )
295 endif (LLVM_ENABLE_PEDANTIC)
296 endif (LLVM_ENABLE_WARNINGS)
297 if (LLVM_ENABLE_WERROR)
298 add_llvm_definitions( -Werror )
299 endif (LLVM_ENABLE_WERROR)
302 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
304 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
305 SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
306 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
312 get_system_libs(LLVM_SYSTEM_LIBS_LIST)
313 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
314 set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}")
316 set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
317 set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}")
320 add_subdirectory(lib/Support)
322 # Everything else depends on Support:
323 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
325 set(LLVM_TABLEGEN "tblgen" CACHE
326 STRING "Native TableGen executable. Saves building one when cross-compiling.")
327 # Effective tblgen executable to be used:
328 set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN})
330 add_subdirectory(utils/TableGen)
332 if( CMAKE_CROSSCOMPILING )
333 # This adds a dependency on target `tblgen', so must go after utils/TableGen
334 include( CrossCompileLLVM )
335 endif( CMAKE_CROSSCOMPILING )
337 add_subdirectory(include/llvm)
339 add_subdirectory(lib/VMCore)
340 add_subdirectory(lib/CodeGen)
341 add_subdirectory(lib/CodeGen/SelectionDAG)
342 add_subdirectory(lib/CodeGen/AsmPrinter)
343 add_subdirectory(lib/Bitcode/Reader)
344 add_subdirectory(lib/Bitcode/Writer)
345 add_subdirectory(lib/Transforms/Utils)
346 add_subdirectory(lib/Transforms/Instrumentation)
347 add_subdirectory(lib/Transforms/InstCombine)
348 add_subdirectory(lib/Transforms/Scalar)
349 add_subdirectory(lib/Transforms/IPO)
350 add_subdirectory(lib/Transforms/Hello)
351 add_subdirectory(lib/Linker)
352 add_subdirectory(lib/Analysis)
353 add_subdirectory(lib/Analysis/IPA)
354 add_subdirectory(lib/MC)
355 add_subdirectory(lib/MC/MCParser)
356 add_subdirectory(lib/MC/MCDisassembler)
357 add_subdirectory(lib/Object)
359 add_subdirectory(utils/FileCheck)
360 add_subdirectory(utils/FileUpdate)
361 add_subdirectory(utils/count)
362 add_subdirectory(utils/not)
363 add_subdirectory(utils/llvm-lit)
365 set(LLVM_ENUM_ASM_PRINTERS "")
366 set(LLVM_ENUM_ASM_PARSERS "")
367 set(LLVM_ENUM_DISASSEMBLERS "")
368 foreach(t ${LLVM_TARGETS_TO_BUILD})
369 message(STATUS "Targeting ${t}")
370 add_subdirectory(lib/Target/${t})
371 add_subdirectory(lib/Target/${t}/TargetInfo)
372 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
373 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
375 set(LLVM_ENUM_ASM_PRINTERS
376 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
378 if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
379 add_subdirectory(lib/Target/${t}/InstPrinter)
381 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
382 add_subdirectory(lib/Target/${t}/AsmParser)
383 set(LLVM_ENUM_ASM_PARSERS
384 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
386 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
387 add_subdirectory(lib/Target/${t}/Disassembler)
388 set(LLVM_ENUM_DISASSEMBLERS
389 "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
391 set(CURRENT_LLVM_TARGET)
394 # Produce llvm/Config/AsmPrinters.def
396 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
397 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def
400 # Produce llvm/Config/AsmParsers.def
402 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
403 ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def
406 # Produce llvm/Config/Disassemblers.def
408 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
409 ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def
412 add_subdirectory(lib/ExecutionEngine)
413 add_subdirectory(lib/ExecutionEngine/Interpreter)
414 add_subdirectory(lib/ExecutionEngine/JIT)
415 add_subdirectory(lib/ExecutionEngine/MCJIT)
416 add_subdirectory(lib/Target)
417 add_subdirectory(lib/AsmParser)
418 add_subdirectory(lib/Archive)
420 add_subdirectory(projects)
422 option(LLVM_BUILD_TOOLS
423 "Build the LLVM tools. If OFF, just generate build targets." ON)
424 option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
425 if( LLVM_INCLUDE_TOOLS )
426 add_subdirectory(tools)
429 option(LLVM_BUILD_EXAMPLES
430 "Build the LLVM example programs. If OFF, just generate build targets." OFF)
431 option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
432 if( LLVM_INCLUDE_EXAMPLES )
433 add_subdirectory(examples)
436 option(LLVM_BUILD_TESTS
437 "Build LLVM unit tests. If OFF, just generate build targes." OFF)
438 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
439 if( LLVM_INCLUDE_TESTS )
440 add_subdirectory(test)
441 add_subdirectory(utils/unittest)
442 add_subdirectory(unittests)
444 # This utility is used to prevent chrashing tests from calling Dr. Watson on
446 add_subdirectory(utils/KillTheDoctor)
450 add_subdirectory(cmake/modules)
452 install(DIRECTORY include/
459 PATTERN ".svn" EXCLUDE
462 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
469 # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
470 PATTERN "CMakeFiles" EXCLUDE
471 PATTERN ".svn" EXCLUDE
474 # TODO: make and install documentation.
476 set(CPACK_PACKAGE_VENDOR "LLVM")
477 set(CPACK_PACKAGE_VERSION_MAJOR 2)
478 set(CPACK_PACKAGE_VERSION_MINOR 9)
479 add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH)
482 # Workaround for MSVS10 to avoid the Dialog Hell
483 # FIXME: This could be removed with future version of CMake.
484 if(MSVC_VERSION EQUAL 1600)
485 set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln")
486 if( EXISTS "${LLVM_SLN_FILENAME}" )
487 file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n")