CMakeLists.txt 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. # See docs/CMake.html for instructions about how to build LLVM with CMake.
  2. cmake_minimum_required(VERSION 3.4.3)
  3. if(POLICY CMP0068)
  4. cmake_policy(SET CMP0068 NEW)
  5. set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
  6. endif()
  7. if(POLICY CMP0075)
  8. cmake_policy(SET CMP0075 NEW)
  9. endif()
  10. if(POLICY CMP0077)
  11. cmake_policy(SET CMP0077 NEW)
  12. endif()
  13. if(NOT DEFINED LLVM_VERSION_MAJOR)
  14. set(LLVM_VERSION_MAJOR 10)
  15. endif()
  16. if(NOT DEFINED LLVM_VERSION_MINOR)
  17. set(LLVM_VERSION_MINOR 0)
  18. endif()
  19. if(NOT DEFINED LLVM_VERSION_PATCH)
  20. set(LLVM_VERSION_PATCH 0)
  21. endif()
  22. if(NOT DEFINED LLVM_VERSION_SUFFIX)
  23. set(LLVM_VERSION_SUFFIX svn)
  24. endif()
  25. if (NOT PACKAGE_VERSION)
  26. set(PACKAGE_VERSION
  27. "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
  28. endif()
  29. if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))
  30. message(WARNING "Visual Studio generators use the x86 host compiler by "
  31. "default, even for 64-bit targets. This can result in linker "
  32. "instability and out of memory errors. To use the 64-bit "
  33. "host compiler, pass -Thost=x64 on the CMake command line.")
  34. endif()
  35. if (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_OSX_ARCHITECTURES)
  36. # Some CMake features like object libraries get confused if you don't
  37. # explicitly specify an architecture setting with the Xcode generator.
  38. set(CMAKE_OSX_ARCHITECTURES "x86_64")
  39. endif()
  40. project(LLVM
  41. VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
  42. LANGUAGES C CXX ASM)
  43. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  44. message(STATUS "No build type selected, default to Debug")
  45. set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (default Debug)" FORCE)
  46. endif()
  47. # Side-by-side subprojects layout: automatically set the
  48. # LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS
  49. # This allows an easy way of setting up a build directory for llvm and another
  50. # one for llvm+clang+... using the same sources.
  51. set(LLVM_ALL_PROJECTS "clang;clang-tools-extra;compiler-rt;debuginfo-tests;libc;libclc;libcxx;libcxxabi;libunwind;lld;lldb;llgo;openmp;parallel-libs;polly;pstl")
  52. set(LLVM_ENABLE_PROJECTS "" CACHE STRING
  53. "Semicolon-separated list of projects to build (${LLVM_ALL_PROJECTS}), or \"all\".")
  54. if( LLVM_ENABLE_PROJECTS STREQUAL "all" )
  55. set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS})
  56. endif()
  57. # LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
  58. # `LLVM_ENABLE_PROJECTS` CMake cache variable. This exists for
  59. # several reasons:
  60. #
  61. # * As an indicator that the `LLVM_ENABLE_PROJECTS` list is now the single
  62. # source of truth for which projects to build. This means we will ignore user
  63. # supplied `LLVM_TOOL_<project>_BUILD` CMake cache variables and overwrite
  64. # them.
  65. #
  66. # * The case where the user previously had `LLVM_ENABLE_PROJECTS` set to a
  67. # non-empty list but now the user wishes to disable building all other projects
  68. # by setting `LLVM_ENABLE_PROJECTS` to an empty string. In that case we still
  69. # need to set the `LLVM_TOOL_${upper_proj}_BUILD` variables so that we disable
  70. # building all the projects that were previously enabled.
  71. set(LLVM_ENABLE_PROJECTS_USED OFF CACHE BOOL "")
  72. mark_as_advanced(LLVM_ENABLE_PROJECTS_USED)
  73. if (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "")
  74. set(LLVM_ENABLE_PROJECTS_USED ON CACHE BOOL "" FORCE)
  75. foreach(proj ${LLVM_ALL_PROJECTS} ${LLVM_EXTERNAL_PROJECTS})
  76. string(TOUPPER "${proj}" upper_proj)
  77. string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})
  78. if ("${proj}" IN_LIST LLVM_ENABLE_PROJECTS)
  79. message(STATUS "${proj} project is enabled")
  80. set(SHOULD_ENABLE_PROJECT TRUE)
  81. set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
  82. if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")
  83. message(FATAL_ERROR "LLVM_ENABLE_PROJECTS requests ${proj} but directory not found: ${PROJ_DIR}")
  84. endif()
  85. if( LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" )
  86. set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "" FORCE)
  87. else()
  88. set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "")
  89. endif()
  90. elseif ("${proj}" IN_LIST LLVM_EXTERNAL_PROJECTS)
  91. message(STATUS "${proj} project is enabled")
  92. set(SHOULD_ENABLE_PROJECT TRUE)
  93. else()
  94. message(STATUS "${proj} project is disabled")
  95. set(SHOULD_ENABLE_PROJECT FALSE)
  96. endif()
  97. # Force `LLVM_TOOL_${upper_proj}_BUILD` variables to have values that
  98. # corresponds with `LLVM_ENABLE_PROJECTS`. This prevents the user setting
  99. # `LLVM_TOOL_${upper_proj}_BUILD` variables externally. At some point
  100. # we should deprecate allowing users to set these variables by turning them
  101. # into normal CMake variables rather than cache variables.
  102. set(LLVM_TOOL_${upper_proj}_BUILD
  103. ${SHOULD_ENABLE_PROJECT}
  104. CACHE
  105. BOOL "Whether to build ${upper_proj} as part of LLVM" FORCE
  106. )
  107. endforeach()
  108. endif()
  109. unset(SHOULD_ENABLE_PROJECT)
  110. # Build llvm with ccache if the package is present
  111. set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
  112. if(LLVM_CCACHE_BUILD)
  113. find_program(CCACHE_PROGRAM ccache)
  114. if(CCACHE_PROGRAM)
  115. set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
  116. set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
  117. set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
  118. CACHE STRING "Parameters to pass through to ccache")
  119. set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
  120. if (LLVM_CCACHE_MAXSIZE)
  121. set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
  122. endif()
  123. if (LLVM_CCACHE_DIR)
  124. set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")
  125. endif()
  126. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
  127. else()
  128. message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")
  129. endif()
  130. endif()
  131. option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF)
  132. # Some features of the LLVM build may be disallowed when dependency debugging is
  133. # enabled. In particular you cannot use ccache because we want to force compile
  134. # operations to always happen.
  135. if(LLVM_DEPENDENCY_DEBUGGING)
  136. if(NOT CMAKE_HOST_APPLE)
  137. message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.")
  138. endif()
  139. if(LLVM_CCACHE_BUILD)
  140. message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.")
  141. endif()
  142. endif()
  143. option(LLVM_ENABLE_DAGISEL_COV "Debug: Prints tablegen patterns that were used for selecting" OFF)
  144. option(LLVM_ENABLE_GISEL_COV "Enable collection of GlobalISel rule coverage" OFF)
  145. if(LLVM_ENABLE_GISEL_COV)
  146. set(LLVM_GISEL_COV_PREFIX "${CMAKE_BINARY_DIR}/gisel-coverage-" CACHE STRING "Provide a filename prefix to collect the GlobalISel rule coverage")
  147. endif()
  148. # Add path for custom modules
  149. set(CMAKE_MODULE_PATH
  150. ${CMAKE_MODULE_PATH}
  151. "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
  152. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
  153. )
  154. # Generate a CompilationDatabase (compile_commands.json file) for our build,
  155. # for use by clang_complete, YouCompleteMe, etc.
  156. set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
  157. option(LLVM_INSTALL_BINUTILS_SYMLINKS
  158. "Install symlinks from the binutils tool names to the corresponding LLVM tools." OFF)
  159. option(LLVM_INSTALL_CCTOOLS_SYMLINKS
  160. "Install symlinks from the cctools tool names to the corresponding LLVM tools." OFF)
  161. option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
  162. option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
  163. # Unfortunatly Clang is too eager to search directories for module maps, which can cause the
  164. # installed version of the maps to be found when building LLVM from source. Therefore we turn off
  165. # the installation by default. See llvm.org/PR31905.
  166. option(LLVM_INSTALL_MODULEMAPS "Install the modulemap files in the 'install' target." OFF)
  167. option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
  168. if ( LLVM_USE_FOLDERS )
  169. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  170. endif()
  171. include(VersionFromVCS)
  172. option(LLVM_APPEND_VC_REV
  173. "Embed the version control system revision in LLVM" ON)
  174. set(PACKAGE_NAME LLVM)
  175. set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
  176. set(PACKAGE_BUGREPORT "https://bugs.llvm.org/")
  177. set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
  178. "Default URL where bug reports are to be submitted.")
  179. # Configure CPack.
  180. set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
  181. set(CPACK_PACKAGE_VENDOR "LLVM")
  182. set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
  183. set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
  184. set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
  185. set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
  186. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
  187. set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
  188. if(WIN32 AND NOT UNIX)
  189. set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
  190. set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
  191. set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
  192. set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
  193. set(CPACK_NSIS_MODIFY_PATH "ON")
  194. set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
  195. if( CMAKE_CL_64 )
  196. set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
  197. endif()
  198. endif()
  199. include(CPack)
  200. # Sanity check our source directory to make sure that we are not trying to
  201. # generate an in-source build (unless on MSVC_IDE, where it is ok), and to make
  202. # sure that we don't have any stray generated files lying around in the tree
  203. # (which would end up getting picked up by header search, instead of the correct
  204. # versions).
  205. if( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE )
  206. message(FATAL_ERROR "In-source builds are not allowed.
  207. Please create a directory and run cmake from there, passing the path
  208. to this source directory as the last argument.
  209. This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
  210. Please delete them.")
  211. endif()
  212. string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
  213. if (CMAKE_BUILD_TYPE AND
  214. NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
  215. message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
  216. endif()
  217. set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
  218. set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')")
  219. mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)
  220. set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING
  221. "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)")
  222. mark_as_advanced(LLVM_UTILS_INSTALL_DIR)
  223. # They are used as destination of target generators.
  224. set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
  225. set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
  226. if(WIN32 OR CYGWIN)
  227. # DLL platform -- put DLLs into bin.
  228. set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
  229. else()
  230. set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
  231. endif()
  232. # Each of them corresponds to llvm-config's.
  233. set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
  234. set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
  235. set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
  236. set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
  237. set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
  238. # Note: LLVM_CMAKE_PATH does not include generated files
  239. set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
  240. set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
  241. set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
  242. # List of all targets to be built by default:
  243. set(LLVM_ALL_TARGETS
  244. AArch64
  245. AMDGPU
  246. ARM
  247. BPF
  248. Hexagon
  249. Lanai
  250. Mips
  251. MSP430
  252. NVPTX
  253. PowerPC
  254. RISCV
  255. Sparc
  256. SystemZ
  257. WebAssembly
  258. X86
  259. XCore
  260. )
  261. # List of targets with JIT support:
  262. set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
  263. set(LLVM_TARGETS_TO_BUILD "all"
  264. CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
  265. set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
  266. CACHE STRING "Semicolon-separated list of experimental targets to build.")
  267. option(BUILD_SHARED_LIBS
  268. "Build all libraries as shared libraries instead of static" OFF)
  269. option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
  270. if(LLVM_ENABLE_BACKTRACES)
  271. set(ENABLE_BACKTRACES 1)
  272. endif()
  273. option(LLVM_ENABLE_UNWIND_TABLES "Emit unwind tables for the libraries" ON)
  274. option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
  275. if(LLVM_ENABLE_CRASH_OVERRIDES)
  276. set(ENABLE_CRASH_OVERRIDES 1)
  277. endif()
  278. option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF)
  279. option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
  280. set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
  281. set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
  282. set(LLVM_TARGET_ARCH "host"
  283. CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
  284. option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
  285. set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")
  286. option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)
  287. option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON)
  288. option(LLVM_ENABLE_THREADS "Use threads if available." ON)
  289. option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
  290. set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")
  291. find_package(Z3 4.7.1)
  292. if (LLVM_Z3_INSTALL_DIR)
  293. if (NOT Z3_FOUND)
  294. message(FATAL_ERROR "Z3 >= 4.7.1 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.")
  295. endif()
  296. endif()
  297. set(LLVM_ENABLE_Z3_SOLVER_DEFAULT "${Z3_FOUND}")
  298. option(LLVM_ENABLE_Z3_SOLVER
  299. "Enable Support for the Z3 constraint solver in LLVM."
  300. ${LLVM_ENABLE_Z3_SOLVER_DEFAULT}
  301. )
  302. if (LLVM_ENABLE_Z3_SOLVER)
  303. if (NOT Z3_FOUND)
  304. message(FATAL_ERROR "LLVM_ENABLE_Z3_SOLVER cannot be enabled when Z3 is not available.")
  305. endif()
  306. set(LLVM_WITH_Z3 1)
  307. endif()
  308. if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
  309. set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
  310. endif()
  311. set(LLVM_TARGETS_TO_BUILD
  312. ${LLVM_TARGETS_TO_BUILD}
  313. ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
  314. list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
  315. option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
  316. option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
  317. option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
  318. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  319. option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)
  320. option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." OFF)
  321. else()
  322. option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)
  323. option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
  324. endif()
  325. option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
  326. option(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF)
  327. option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
  328. option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
  329. option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
  330. option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
  331. if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
  332. option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
  333. else()
  334. option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
  335. endif()
  336. option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
  337. set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
  338. "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
  339. option(LLVM_FORCE_USE_OLD_TOOLCHAIN
  340. "Set to ON to force using an old, unsupported host toolchain." OFF)
  341. option(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN
  342. "Set to ON to only warn when using a toolchain which is about to be deprecated, instead of emitting an error." OFF)
  343. option(LLVM_USE_INTEL_JITEVENTS
  344. "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
  345. OFF)
  346. if( LLVM_USE_INTEL_JITEVENTS )
  347. # Verify we are on a supported platform
  348. if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  349. message(FATAL_ERROR
  350. "Intel JIT API support is available on Linux and Windows only.")
  351. endif()
  352. endif( LLVM_USE_INTEL_JITEVENTS )
  353. option(LLVM_USE_OPROFILE
  354. "Use opagent JIT interface to inform OProfile about JIT code" OFF)
  355. option(LLVM_EXTERNALIZE_DEBUGINFO
  356. "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
  357. set(LLVM_CODESIGNING_IDENTITY "" CACHE STRING
  358. "Sign executables and dylibs with the given identity or skip if empty (Darwin Only)")
  359. # If enabled, verify we are on a platform that supports oprofile.
  360. if( LLVM_USE_OPROFILE )
  361. if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  362. message(FATAL_ERROR "OProfile support is available on Linux only.")
  363. endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  364. endif( LLVM_USE_OPROFILE )
  365. option(LLVM_USE_PERF
  366. "Use perf JIT interface to inform perf about JIT code" OFF)
  367. # If enabled, verify we are on a platform that supports perf.
  368. if( LLVM_USE_PERF )
  369. if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  370. message(FATAL_ERROR "perf support is available on Linux only.")
  371. endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  372. endif( LLVM_USE_PERF )
  373. set(LLVM_USE_SANITIZER "" CACHE STRING
  374. "Define the sanitizer used to build binaries and tests.")
  375. option(LLVM_OPTIMIZE_SANITIZED_BUILDS "Pass -O1 on debug sanitizer builds" ON)
  376. set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH
  377. "Path to fuzzing library for linking with fuzz targets")
  378. option(LLVM_USE_SPLIT_DWARF
  379. "Use -gsplit-dwarf when compiling llvm." OFF)
  380. option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ON)
  381. option(LLVM_POLLY_BUILD "Build LLVM with Polly" ON)
  382. if (EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
  383. set(POLLY_IN_TREE TRUE)
  384. elseif(LLVM_EXTERNAL_POLLY_SOURCE_DIR)
  385. set(POLLY_IN_TREE TRUE)
  386. else()
  387. set(POLLY_IN_TREE FALSE)
  388. endif()
  389. if (LLVM_POLLY_BUILD AND POLLY_IN_TREE)
  390. set(WITH_POLLY ON)
  391. else()
  392. set(WITH_POLLY OFF)
  393. endif()
  394. if (LLVM_POLLY_LINK_INTO_TOOLS AND WITH_POLLY)
  395. set(LINK_POLLY_INTO_TOOLS ON)
  396. else()
  397. set(LINK_POLLY_INTO_TOOLS OFF)
  398. endif()
  399. # Define an option controlling whether we should build for 32-bit on 64-bit
  400. # platforms, where supported.
  401. if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
  402. # TODO: support other platforms and toolchains.
  403. option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
  404. endif()
  405. # Define the default arguments to use with 'lit', and an option for the user to
  406. # override.
  407. set(LIT_ARGS_DEFAULT "-sv")
  408. if (MSVC_IDE OR XCODE)
  409. set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
  410. endif()
  411. set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
  412. # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
  413. if( WIN32 AND NOT CYGWIN )
  414. set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
  415. endif()
  416. # Define options to control the inclusion and default build behavior for
  417. # components which may not strictly be necessary (tools, examples, and tests).
  418. #
  419. # This is primarily to support building smaller or faster project files.
  420. option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
  421. option(LLVM_BUILD_TOOLS
  422. "Build the LLVM tools. If OFF, just generate build targets." ON)
  423. option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
  424. option(LLVM_BUILD_UTILS
  425. "Build LLVM utility binaries. If OFF, just generate build targets." ON)
  426. option(LLVM_INCLUDE_RUNTIMES "Generate build targets for the LLVM runtimes." ON)
  427. option(LLVM_BUILD_RUNTIMES
  428. "Build the LLVM runtimes. If OFF, just generate build targets." ON)
  429. option(LLVM_BUILD_RUNTIME
  430. "Build the LLVM runtime libraries." ON)
  431. option(LLVM_BUILD_EXAMPLES
  432. "Build the LLVM example programs. If OFF, just generate build targets." OFF)
  433. option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
  434. option(LLVM_BUILD_TESTS
  435. "Build LLVM unit tests. If OFF, just generate build targets." OFF)
  436. option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
  437. option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
  438. option(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default
  439. targets. If OFF, benchmarks still could be built using Benchmarks target." OFF)
  440. option(LLVM_INCLUDE_BENCHMARKS "Generate benchmark targets. If OFF, benchmarks can't be built." ON)
  441. option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
  442. option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
  443. option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
  444. option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
  445. option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
  446. option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
  447. set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html"
  448. CACHE STRING "Doxygen-generated HTML documentation install directory")
  449. set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html"
  450. CACHE STRING "OCamldoc-generated HTML documentation install directory")
  451. option (LLVM_BUILD_EXTERNAL_COMPILER_RT
  452. "Build compiler-rt as an external project." OFF)
  453. option (LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO
  454. "Show target and host info when tools are invoked with --version." ON)
  455. # You can configure which libraries from LLVM you want to include in the
  456. # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
  457. # list of LLVM components. All component names handled by llvm-config are valid.
  458. if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
  459. set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
  460. "Semicolon-separated list of components to include in libLLVM, or \"all\".")
  461. endif()
  462. option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
  463. if(MSVC)
  464. option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" ON)
  465. else()
  466. option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)
  467. endif()
  468. set(LLVM_BUILD_LLVM_DYLIB_default OFF)
  469. if(LLVM_LINK_LLVM_DYLIB OR (LLVM_BUILD_LLVM_C_DYLIB AND NOT MSVC))
  470. set(LLVM_BUILD_LLVM_DYLIB_default ON)
  471. endif()
  472. option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
  473. option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
  474. if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES)))
  475. set(LLVM_USE_HOST_TOOLS ON)
  476. endif()
  477. if (MSVC_IDE)
  478. option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE)
  479. endif()
  480. if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE OR
  481. LLVM_ENABLE_IR_PGO)
  482. if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
  483. # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine
  484. # for spining disks. Anything higher may only help on slower mediums.
  485. set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
  486. endif()
  487. if(NOT LLVM_PROFILE_FILE_PATTERN)
  488. if(NOT LLVM_PROFILE_DATA_DIR)
  489. file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles" LLVM_PROFILE_DATA_DIR)
  490. endif()
  491. file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
  492. endif()
  493. if(NOT LLVM_CSPROFILE_FILE_PATTERN)
  494. if(NOT LLVM_CSPROFILE_DATA_DIR)
  495. file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/csprofiles" LLVM_CSPROFILE_DATA_DIR)
  496. endif()
  497. file(TO_NATIVE_PATH "${LLVM_CSPROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_CSPROFILE_FILE_PATTERN)
  498. endif()
  499. endif()
  500. if (LLVM_BUILD_STATIC)
  501. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
  502. endif()
  503. # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
  504. if(CMAKE_HOST_APPLE AND APPLE)
  505. include(UseLibtool)
  506. endif()
  507. # Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
  508. set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")
  509. mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
  510. set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL
  511. "Enable per-target runtimes directory")
  512. set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
  513. "Profiling data file to use when compiling in order to improve runtime performance.")
  514. # All options referred to from HandleLLVMOptions have to be specified
  515. # BEFORE this include, otherwise options will not be correctly set on
  516. # first cmake run
  517. include(config-ix)
  518. string(REPLACE "Native" ${LLVM_NATIVE_ARCH}
  519. LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}")
  520. list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
  521. # By default, we target the host, but this can be overridden at CMake
  522. # invocation time.
  523. set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
  524. "Default target for which LLVM will generate code." )
  525. set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
  526. message(STATUS "LLVM host triple: ${LLVM_HOST_TRIPLE}")
  527. message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")
  528. if(WIN32 OR CYGWIN)
  529. if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
  530. set(LLVM_ENABLE_PLUGINS_default ON)
  531. else()
  532. set(LLVM_ENABLE_PLUGINS_default OFF)
  533. endif()
  534. else()
  535. set(LLVM_ENABLE_PLUGINS_default ${LLVM_ENABLE_PIC})
  536. endif()
  537. option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})
  538. include(HandleLLVMOptions)
  539. include(FindPythonInterp)
  540. if( NOT PYTHONINTERP_FOUND )
  541. message(FATAL_ERROR
  542. "Unable to find Python interpreter, required for builds and testing.
  543. Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
  544. endif()
  545. if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
  546. message(FATAL_ERROR "Python 2.7 or newer is required")
  547. endif()
  548. ######
  549. # LLVMBuild Integration
  550. #
  551. # We use llvm-build to generate all the data required by the CMake based
  552. # build system in one swoop:
  553. #
  554. # - We generate a file (a CMake fragment) in the object root which contains
  555. # all the definitions that are required by CMake.
  556. #
  557. # - We generate the library table used by llvm-config.
  558. #
  559. # - We generate the dependencies for the CMake fragment, so that we will
  560. # automatically reconfigure ourselves.
  561. set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
  562. set(LLVMCONFIGLIBRARYDEPENDENCIESINC
  563. "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
  564. set(LLVMBUILDCMAKEFRAG
  565. "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
  566. # Create the list of optional components that are enabled
  567. if (LLVM_USE_INTEL_JITEVENTS)
  568. set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
  569. endif (LLVM_USE_INTEL_JITEVENTS)
  570. if (LLVM_USE_OPROFILE)
  571. set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
  572. endif (LLVM_USE_OPROFILE)
  573. if (LLVM_USE_PERF)
  574. set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} PerfJITEvents)
  575. endif (LLVM_USE_PERF)
  576. message(STATUS "Constructing LLVMBuild project information")
  577. execute_process(
  578. COMMAND ${PYTHON_EXECUTABLE} -B ${LLVMBUILDTOOL}
  579. --native-target "${LLVM_NATIVE_ARCH}"
  580. --enable-targets "${LLVM_TARGETS_TO_BUILD}"
  581. --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
  582. --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
  583. --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
  584. OUTPUT_VARIABLE LLVMBUILDOUTPUT
  585. ERROR_VARIABLE LLVMBUILDERRORS
  586. OUTPUT_STRIP_TRAILING_WHITESPACE
  587. ERROR_STRIP_TRAILING_WHITESPACE
  588. RESULT_VARIABLE LLVMBUILDRESULT)
  589. # On Win32, CMake doesn't properly handle piping the default output/error
  590. # streams into the GUI console. So, we explicitly catch and report them.
  591. if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
  592. message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
  593. endif()
  594. if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
  595. message(FATAL_ERROR
  596. "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
  597. endif()
  598. # Include the generated CMake fragment. This will define properties from the
  599. # LLVMBuild files in a format which is easy to consume from CMake, and will add
  600. # the dependencies so that CMake will reconfigure properly when the LLVMBuild
  601. # files change.
  602. include(${LLVMBUILDCMAKEFRAG})
  603. ######
  604. # Configure all of the various header file fragments LLVM uses which depend on
  605. # configuration variables.
  606. set(LLVM_ENUM_TARGETS "")
  607. set(LLVM_ENUM_ASM_PRINTERS "")
  608. set(LLVM_ENUM_ASM_PARSERS "")
  609. set(LLVM_ENUM_DISASSEMBLERS "")
  610. foreach(t ${LLVM_TARGETS_TO_BUILD})
  611. set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
  612. list(FIND LLVM_ALL_TARGETS ${t} idx)
  613. list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
  614. # At this point, LLVMBUILDTOOL already checked all the targets passed in
  615. # LLVM_TARGETS_TO_BUILD and LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, so
  616. # this test just makes sure that any experimental targets were passed via
  617. # LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, not LLVM_TARGETS_TO_BUILD.
  618. if( idx LESS 0 AND idy LESS 0 )
  619. message(FATAL_ERROR "The target `${t}' is experimental and must be passed "
  620. "via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.")
  621. else()
  622. set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
  623. endif()
  624. file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
  625. if( asmp_file )
  626. set(LLVM_ENUM_ASM_PRINTERS
  627. "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
  628. endif()
  629. if( EXISTS ${td}/AsmParser/CMakeLists.txt )
  630. set(LLVM_ENUM_ASM_PARSERS
  631. "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
  632. endif()
  633. if( EXISTS ${td}/Disassembler/CMakeLists.txt )
  634. set(LLVM_ENUM_DISASSEMBLERS
  635. "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
  636. endif()
  637. endforeach(t)
  638. # Produce the target definition files, which provide a way for clients to easily
  639. # include various classes of targets.
  640. configure_file(
  641. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
  642. ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
  643. )
  644. configure_file(
  645. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
  646. ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
  647. )
  648. configure_file(
  649. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
  650. ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
  651. )
  652. configure_file(
  653. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
  654. ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
  655. )
  656. # Configure the three LLVM configuration header files.
  657. configure_file(
  658. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
  659. ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
  660. configure_file(
  661. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
  662. ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
  663. configure_file(
  664. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake
  665. ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h)
  666. # Add target for generating source rpm package.
  667. set(LLVM_SRPM_USER_BINARY_SPECFILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm.spec.in
  668. CACHE FILEPATH ".spec file to use for srpm generation")
  669. set(LLVM_SRPM_BINARY_SPECFILE ${CMAKE_CURRENT_BINARY_DIR}/llvm.spec)
  670. set(LLVM_SRPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/srpm")
  671. get_source_info(${CMAKE_CURRENT_SOURCE_DIR} revision repository)
  672. string(LENGTH "${revision}" revision_length)
  673. if(revision MATCHES "^[0-9]+$" AND revision_length LESS 40)
  674. set(LLVM_RPM_SPEC_REVISION "r${revision}")
  675. else()
  676. set(LLVM_RPM_SPEC_REVISION "${revision}")
  677. endif()
  678. configure_file(
  679. ${LLVM_SRPM_USER_BINARY_SPECFILE}
  680. ${LLVM_SRPM_BINARY_SPECFILE} @ONLY)
  681. add_custom_target(srpm
  682. COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES
  683. COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE})
  684. set_target_properties(srpm PROPERTIES FOLDER "Misc")
  685. # They are not referenced. See set_output_directory().
  686. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
  687. set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
  688. set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
  689. if(APPLE AND DARWIN_LTO_LIBRARY)
  690. set(CMAKE_EXE_LINKER_FLAGS
  691. "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
  692. set(CMAKE_SHARED_LINKER_FLAGS
  693. "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
  694. set(CMAKE_MODULE_LINKER_FLAGS
  695. "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
  696. endif()
  697. # Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to
  698. # break things. In this case we need to enable the large-file API as well.
  699. if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
  700. add_definitions("-D_XOPEN_SOURCE=700")
  701. add_definitions("-D_LARGE_FILE_API")
  702. endif()
  703. # Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9.
  704. if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
  705. add_definitions("-D_FILE_OFFSET_BITS=64")
  706. endif()
  707. # Work around a broken bfd ld behavior. When linking a binary with a
  708. # foo.so library, it will try to find any library that foo.so uses and
  709. # check its symbols. This is wasteful (the check was done when foo.so
  710. # was created) and can fail since it is not the dynamic linker and
  711. # doesn't know how to handle search paths correctly.
  712. if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS|AIX")
  713. set(CMAKE_EXE_LINKER_FLAGS
  714. "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
  715. endif()
  716. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  717. include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
  718. # when crosscompiling import the executable targets from a file
  719. if(LLVM_USE_HOST_TOOLS)
  720. include(CrossCompile)
  721. llvm_create_cross_target(LLVM NATIVE "" Release)
  722. endif(LLVM_USE_HOST_TOOLS)
  723. if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
  724. # Dummy use to avoid CMake Warning: Manually-specified variables were not used
  725. # (this is a variable that CrossCompile sets on recursive invocations)
  726. endif()
  727. if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
  728. # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
  729. # with libxml2, iconv.h, etc., we must add /usr/local paths.
  730. include_directories(SYSTEM "/usr/local/include")
  731. link_directories("/usr/local/lib")
  732. endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
  733. if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
  734. # special hack for Solaris to handle crazy system sys/regset.h
  735. include_directories("${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/Solaris")
  736. endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
  737. # Make sure we don't get -rdynamic in every binary. For those that need it,
  738. # use export_executable_symbols(target).
  739. set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  740. include(AddLLVM)
  741. include(TableGen)
  742. if( MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
  743. # People report that -O3 is unreliable on MinGW. The traditional
  744. # build also uses -O2 for that reason:
  745. llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
  746. endif()
  747. # Put this before tblgen. Else we have a circular dependence.
  748. add_subdirectory(lib/Demangle)
  749. add_subdirectory(lib/Support)
  750. add_subdirectory(lib/TableGen)
  751. add_subdirectory(utils/TableGen)
  752. add_subdirectory(include/llvm)
  753. add_subdirectory(lib)
  754. if( LLVM_INCLUDE_UTILS )
  755. add_subdirectory(utils/FileCheck)
  756. add_subdirectory(utils/PerfectShuffle)
  757. add_subdirectory(utils/count)
  758. add_subdirectory(utils/not)
  759. add_subdirectory(utils/yaml-bench)
  760. else()
  761. if ( LLVM_INCLUDE_TESTS )
  762. message(FATAL_ERROR "Including tests when not building utils will not work.
  763. Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLUDE_TESTS to Off.")
  764. endif()
  765. endif()
  766. # Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util
  767. if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
  768. add_subdirectory(utils/LLVMVisualizers)
  769. endif()
  770. foreach( binding ${LLVM_BINDINGS_LIST} )
  771. if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
  772. add_subdirectory(bindings/${binding})
  773. endif()
  774. endforeach()
  775. add_subdirectory(projects)
  776. if( LLVM_INCLUDE_TOOLS )
  777. add_subdirectory(tools)
  778. endif()
  779. if( LLVM_INCLUDE_RUNTIMES )
  780. add_subdirectory(runtimes)
  781. endif()
  782. if( LLVM_INCLUDE_EXAMPLES )
  783. add_subdirectory(examples)
  784. endif()
  785. if( LLVM_INCLUDE_TESTS )
  786. if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
  787. include(LLVMExternalProjectUtils)
  788. llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
  789. USE_TOOLCHAIN
  790. EXCLUDE_FROM_ALL
  791. NO_INSTALL
  792. ALWAYS_CLEAN)
  793. endif()
  794. add_subdirectory(utils/lit)
  795. add_subdirectory(test)
  796. add_subdirectory(unittests)
  797. if( LLVM_INCLUDE_UTILS )
  798. add_subdirectory(utils/unittest)
  799. endif()
  800. if (WIN32)
  801. # This utility is used to prevent crashing tests from calling Dr. Watson on
  802. # Windows.
  803. add_subdirectory(utils/KillTheDoctor)
  804. endif()
  805. # Add a global check rule now that all subdirectories have been traversed
  806. # and we know the total set of lit testsuites.
  807. get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
  808. get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
  809. get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
  810. get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
  811. get_property(LLVM_ADDITIONAL_TEST_TARGETS
  812. GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_TARGETS)
  813. get_property(LLVM_ADDITIONAL_TEST_DEPENDS
  814. GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS)
  815. add_lit_target(check-all
  816. "Running all regression tests"
  817. ${LLVM_LIT_TESTSUITES}
  818. PARAMS ${LLVM_LIT_PARAMS}
  819. DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_TARGETS}
  820. ARGS ${LLVM_LIT_EXTRA_ARGS}
  821. )
  822. if(TARGET check-runtimes)
  823. add_dependencies(check-all check-runtimes)
  824. endif()
  825. add_custom_target(test-depends
  826. DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_DEPENDS})
  827. set_target_properties(test-depends PROPERTIES FOLDER "Tests")
  828. endif()
  829. if (LLVM_INCLUDE_DOCS)
  830. add_subdirectory(docs)
  831. endif()
  832. add_subdirectory(cmake/modules)
  833. # Do this last so that all lit targets have already been created.
  834. if (LLVM_INCLUDE_UTILS)
  835. add_subdirectory(utils/llvm-lit)
  836. endif()
  837. if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
  838. install(DIRECTORY include/llvm include/llvm-c
  839. DESTINATION include
  840. COMPONENT llvm-headers
  841. FILES_MATCHING
  842. PATTERN "*.def"
  843. PATTERN "*.h"
  844. PATTERN "*.td"
  845. PATTERN "*.inc"
  846. PATTERN "LICENSE.TXT"
  847. PATTERN ".svn" EXCLUDE
  848. )
  849. install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c
  850. DESTINATION include
  851. COMPONENT llvm-headers
  852. FILES_MATCHING
  853. PATTERN "*.def"
  854. PATTERN "*.h"
  855. PATTERN "*.gen"
  856. PATTERN "*.inc"
  857. # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
  858. PATTERN "CMakeFiles" EXCLUDE
  859. PATTERN "config.h" EXCLUDE
  860. PATTERN ".svn" EXCLUDE
  861. )
  862. if (LLVM_INSTALL_MODULEMAPS)
  863. install(DIRECTORY include/llvm include/llvm-c
  864. DESTINATION include
  865. COMPONENT llvm-headers
  866. FILES_MATCHING
  867. PATTERN "module.modulemap"
  868. )
  869. install(FILES include/llvm/module.install.modulemap
  870. DESTINATION include/llvm
  871. COMPONENT llvm-headers
  872. RENAME "module.extern.modulemap"
  873. )
  874. endif(LLVM_INSTALL_MODULEMAPS)
  875. # Installing the headers needs to depend on generating any public
  876. # tablegen'd headers.
  877. add_custom_target(llvm-headers DEPENDS intrinsics_gen)
  878. set_target_properties(llvm-headers PROPERTIES FOLDER "Misc")
  879. if (NOT LLVM_ENABLE_IDE)
  880. add_llvm_install_targets(install-llvm-headers
  881. DEPENDS llvm-headers
  882. COMPONENT llvm-headers)
  883. endif()
  884. # Custom target to install all libraries.
  885. add_custom_target(llvm-libraries)
  886. set_target_properties(llvm-libraries PROPERTIES FOLDER "Misc")
  887. if (NOT LLVM_ENABLE_IDE)
  888. add_llvm_install_targets(install-llvm-libraries
  889. DEPENDS llvm-libraries
  890. COMPONENT llvm-libraries)
  891. endif()
  892. get_property(LLVM_LIBS GLOBAL PROPERTY LLVM_LIBS)
  893. if(LLVM_LIBS)
  894. list(REMOVE_DUPLICATES LLVM_LIBS)
  895. foreach(lib ${LLVM_LIBS})
  896. add_dependencies(llvm-libraries ${lib})
  897. if (NOT LLVM_ENABLE_IDE)
  898. add_dependencies(install-llvm-libraries install-${lib})
  899. endif()
  900. endforeach()
  901. endif()
  902. endif()
  903. # This must be at the end of the LLVM root CMakeLists file because it must run
  904. # after all targets are created.
  905. include(LLVMDistributionSupport)
  906. llvm_distribution_add_targets()
  907. # This allows us to deploy the Universal CRT DLLs by passing -DCMAKE_INSTALL_UCRT_LIBRARIES=ON to CMake
  908. if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_INSTALL_UCRT_LIBRARIES)
  909. include(InstallRequiredSystemLibraries)
  910. endif()
  911. if (LLVM_INCLUDE_BENCHMARKS)
  912. # Override benchmark defaults so that when the library itself is updated these
  913. # modifications are not lost.
  914. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing" FORCE)
  915. set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Disable benchmark exceptions" FORCE)
  916. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install benchmark" FORCE)
  917. set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE BOOL "Don't download dependencies" FORCE)
  918. set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE)
  919. # Since LLVM requires C++11 it is safe to assume that std::regex is available.
  920. set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
  921. add_subdirectory(utils/benchmark)
  922. add_subdirectory(benchmarks)
  923. endif()
  924. if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
  925. add_subdirectory(utils/llvm-locstats)
  926. endif()