CMakeLists.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. # See docs/CMake.html for instructions about how to build LLVM with CMake.
  2. cmake_minimum_required(VERSION 2.8.12.2)
  3. if (NOT "${DXC_CMAKE_BEGINS_INCLUDE}" STREQUAL "")
  4. include(${DXC_CMAKE_BEGINS_INCLUDE})
  5. endif()
  6. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  7. message(STATUS "No build type selected, default to Debug")
  8. set(CMAKE_BUILD_TYPE "Debug")
  9. endif()
  10. if(POLICY CMP0022)
  11. cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
  12. endif()
  13. if (POLICY CMP0051)
  14. # CMake 3.1 and higher include generator expressions of the form
  15. # $<TARGETLIB:obj> in the SOURCES property. These need to be
  16. # stripped everywhere that access the SOURCES property, so we just
  17. # defer to the OLD behavior of not including generator expressions
  18. # in the output for now.
  19. cmake_policy(SET CMP0051 OLD)
  20. endif()
  21. if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
  22. set(cmake_3_2_USES_TERMINAL)
  23. else()
  24. set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
  25. endif()
  26. project(LLVM)
  27. # This requires a more recent version than CMake 3.4 but is a noop in prior versions. # HLSL Change
  28. set(VS_STARTUP_PROJECT "dndxc" CACHE STRING "VS startup project in solution") # HLSL Change
  29. # The following only works with the Ninja generator in CMake >= 3.0.
  30. set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
  31. "Define the maximum number of concurrent compilation jobs.")
  32. if(LLVM_PARALLEL_COMPILE_JOBS)
  33. if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja$")
  34. message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
  35. else()
  36. set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
  37. set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
  38. endif()
  39. endif()
  40. set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
  41. "Define the maximum number of concurrent link jobs.")
  42. if(LLVM_PARALLEL_LINK_JOBS)
  43. if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja$")
  44. message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
  45. else()
  46. set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
  47. set(CMAKE_JOB_POOL_LINK link_job_pool)
  48. endif()
  49. endif()
  50. # Add path for custom modules
  51. set(CMAKE_MODULE_PATH
  52. ${CMAKE_MODULE_PATH}
  53. "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
  54. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
  55. )
  56. set(LLVM_VERSION_MAJOR 3)
  57. set(LLVM_VERSION_MINOR 7)
  58. set(LLVM_VERSION_PATCH 0)
  59. set(LLVM_VERSION_SUFFIX "")
  60. if (NOT PACKAGE_VERSION)
  61. set(PACKAGE_VERSION
  62. "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
  63. endif()
  64. option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
  65. option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
  66. option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
  67. if ( LLVM_USE_FOLDERS )
  68. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  69. endif()
  70. option(HLSL_EMBED_VERSION "If set, embeds version information in the binaries." ON) # HLSL Change
  71. # HLSL Change - Directory with version.inc file used for the build (generated or copied from HLSL_FIXED_VERSION_LOCATION)
  72. set(HLSL_VERSION_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/utils/version)
  73. option(HLSL_OFFICIAL_BUILD "If set, embeds official version in the binaries (based on the latest release version)" OFF) # HLSL Change
  74. option(HLSL_ENABLE_FIXED_VER "Reads version information from a file." OFF) # HLSL Change
  75. option(HLSL_ENABLE_ANALYZE "Enables compiler analysis during compilation." OFF) # HLSL Change
  76. option(HLSL_OPTIONAL_PROJS_IN_DEFAULT "Include optional projects in default build target." OFF) # HLSL Change
  77. option(HLSL_BUILD_DXILCONV "Include DXBC to DXIL converter and tools." ON) # HLSL Change
  78. option(HLSL_ENABLE_DEBUG_ITERATORS "Disable debug iterators for faster debug and to remove some additional allocations with improper noexcept attribution" OFF) # HLSL Change
  79. # HLSL Change Starts - support commit querying
  80. option(HLSL_SUPPORT_QUERY_GIT_COMMIT_INFO "Supports querying Git commit info." ON)
  81. if ( HLSL_SUPPORT_QUERY_GIT_COMMIT_INFO )
  82. add_definitions(-DSUPPORT_QUERY_GIT_COMMIT_INFO)
  83. endif()
  84. # adjust link option to enable debugging from kernel mode; not compatible with incremental linking
  85. if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND WIN32)
  86. add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO)
  87. endif()
  88. # HLSL Change Ends
  89. # HLSL Change Starts - set flag for Appveyor CI
  90. if ( "$ENV{CI}" AND "$ENV{APPVEYOR}" )
  91. add_definitions(-DDXC_ON_APPVEYOR_CI)
  92. endif()
  93. # HLSL Change Ends
  94. # SPIRV change starts
  95. option(ENABLE_SPIRV_CODEGEN "Enables SPIR-V code generation." OFF)
  96. option(SPIRV_BUILD_TESTS "Build targets for the SPIR-V unit tests." OFF)
  97. # Enable SPIR-V CodeGen for Linux by default.
  98. if(NOT WIN32)
  99. set(ENABLE_SPIRV_CODEGEN ON)
  100. endif()
  101. if (${SPIRV_BUILD_TESTS})
  102. enable_testing()
  103. set(ENABLE_SPIRV_CODEGEN ON)
  104. endif()
  105. if (${ENABLE_SPIRV_CODEGEN})
  106. add_definitions(-DENABLE_SPIRV_CODEGEN)
  107. endif()
  108. # SPIRV change ends
  109. include(VersionFromVCS)
  110. option(LLVM_APPEND_VC_REV
  111. "Append the version control system revision id to LLVM version" OFF)
  112. if( LLVM_APPEND_VC_REV )
  113. add_version_info_from_vcs(PACKAGE_VERSION)
  114. endif()
  115. set(PACKAGE_NAME LLVM)
  116. set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
  117. set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
  118. set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
  119. "Default URL where bug reports are to be submitted.")
  120. # Configure CPack.
  121. if(0) # HLSL Change - disable CPack
  122. set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
  123. set(CPACK_PACKAGE_VENDOR "LLVM")
  124. set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
  125. set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
  126. set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
  127. set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
  128. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
  129. set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
  130. if(WIN32 AND NOT UNIX)
  131. set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
  132. set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
  133. set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
  134. set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
  135. set(CPACK_NSIS_MODIFY_PATH "ON")
  136. set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
  137. set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
  138. "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
  139. set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
  140. "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
  141. if( CMAKE_CL_64 )
  142. set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
  143. endif()
  144. endif()
  145. include(CPack)
  146. endif(0) # HLSL Change - disable CPack
  147. # Sanity check our source directory to make sure that we are not trying to
  148. # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
  149. # sure that we don't have any stray generated files lying around in the tree
  150. # (which would end up getting picked up by header search, instead of the correct
  151. # versions).
  152. if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
  153. message(FATAL_ERROR "In-source builds are not allowed.
  154. CMake would overwrite the makefiles distributed with LLVM.
  155. Please create a directory and run cmake from there, passing the path
  156. to this source directory as the last argument.
  157. This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
  158. Please delete them.")
  159. endif()
  160. if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
  161. file(GLOB_RECURSE
  162. tablegenned_files_on_include_dir
  163. "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
  164. file(GLOB_RECURSE
  165. tablegenned_files_on_lib_dir
  166. "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
  167. if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
  168. # HLSL Change - change FATAL_ERROR to WARNING to avoid problems with extraneous files
  169. message(WARNING "Apparently there is a previous in-source build,
  170. probably as the result of running `configure' and `make' on
  171. ${CMAKE_CURRENT_SOURCE_DIR}.
  172. This may cause problems. The suspicious files are:
  173. ${tablegenned_files_on_lib_dir}
  174. ${tablegenned_files_on_include_dir}
  175. Please clean the source directory.")
  176. endif()
  177. endif()
  178. string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
  179. set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
  180. # They are used as destination of target generators.
  181. set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
  182. set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
  183. if(WIN32 OR CYGWIN)
  184. # DLL platform -- put DLLs into bin.
  185. set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
  186. else()
  187. set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
  188. endif()
  189. # Each of them corresponds to llvm-config's.
  190. set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
  191. set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
  192. set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root
  193. set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
  194. set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix
  195. set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
  196. set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
  197. # HLSL removed targets AArch64, ARM, BPF, CppBackend, Hexagon, Mips, MSP430, PowerPC, Sparc, SystemZ, X86, XCore
  198. set(LLVM_ALL_TARGETS
  199. AMDGPU
  200. NVPTX
  201. )
  202. # List of targets with JIT support:
  203. set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
  204. set(LLVM_TARGETS_TO_BUILD "all"
  205. CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
  206. set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
  207. CACHE STRING "Semicolon-separated list of experimental targets to build.")
  208. option(BUILD_SHARED_LIBS
  209. "Build all libraries as shared libraries instead of static" OFF)
  210. option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
  211. if(LLVM_ENABLE_TIMESTAMPS)
  212. set(ENABLE_TIMESTAMPS 1)
  213. endif()
  214. option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
  215. if(LLVM_ENABLE_BACKTRACES)
  216. set(ENABLE_BACKTRACES 1)
  217. endif()
  218. option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
  219. if(LLVM_ENABLE_CRASH_OVERRIDES)
  220. set(ENABLE_CRASH_OVERRIDES 1)
  221. endif()
  222. option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
  223. set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
  224. set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
  225. set(LLVM_TARGET_ARCH "host"
  226. CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
  227. option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
  228. option(LLVM_ENABLE_THREADS "Use threads if available." ON)
  229. option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
  230. if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
  231. set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
  232. endif()
  233. set(LLVM_TARGETS_TO_BUILD
  234. ${LLVM_TARGETS_TO_BUILD}
  235. ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
  236. list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
  237. include(AddLLVMDefinitions)
  238. option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
  239. option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
  240. option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
  241. option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
  242. option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
  243. option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
  244. option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
  245. option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
  246. if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
  247. option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
  248. else()
  249. option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
  250. endif()
  251. set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
  252. "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
  253. option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
  254. "Set to ON to force using an old, unsupported host toolchain." OFF)
  255. option(LLVM_USE_INTEL_JITEVENTS
  256. "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
  257. OFF)
  258. if( LLVM_USE_INTEL_JITEVENTS )
  259. # Verify we are on a supported platform
  260. if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  261. message(FATAL_ERROR
  262. "Intel JIT API support is available on Linux and Windows only.")
  263. endif()
  264. endif( LLVM_USE_INTEL_JITEVENTS )
  265. option(LLVM_USE_OPROFILE
  266. "Use opagent JIT interface to inform OProfile about JIT code" OFF)
  267. # If enabled, verify we are on a platform that supports oprofile.
  268. if( LLVM_USE_OPROFILE )
  269. if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  270. message(FATAL_ERROR "OProfile support is available on Linux only.")
  271. endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
  272. endif( LLVM_USE_OPROFILE )
  273. set(LLVM_USE_SANITIZER "" CACHE STRING
  274. "Define the sanitizer used to build binaries and tests.")
  275. option(LLVM_USE_SPLIT_DWARF
  276. "Use -gsplit-dwarf when compiling llvm." OFF)
  277. option(WITH_POLLY "Build LLVM with Polly" ON)
  278. option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
  279. # Define an option controlling whether we should build for 32-bit on 64-bit
  280. # platforms, where supported.
  281. if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
  282. # TODO: support other platforms and toolchains.
  283. option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
  284. endif()
  285. # Define the default arguments to use with 'lit', and an option for the user to
  286. # override.
  287. set(LIT_ARGS_DEFAULT "-sv")
  288. if (MSVC OR XCODE)
  289. set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
  290. endif()
  291. set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
  292. # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
  293. if( WIN32 AND NOT CYGWIN )
  294. set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
  295. endif()
  296. # Define options to control the inclusion and default build behavior for
  297. # components which may not strictly be necessary (tools, examples, and tests).
  298. #
  299. # This is primarily to support building smaller or faster project files.
  300. option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
  301. option(LLVM_BUILD_TOOLS
  302. "Build the LLVM tools. If OFF, just generate build targets." ON)
  303. option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
  304. option(LLVM_BUILD_RUNTIME
  305. "Build the LLVM runtime libraries." ON)
  306. option(LLVM_BUILD_EXAMPLES
  307. "Build the LLVM example programs. If OFF, just generate build targets." OFF)
  308. option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
  309. option(LLVM_BUILD_TESTS
  310. "Build LLVM unit tests. If OFF, just generate build targets." OFF)
  311. option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
  312. option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
  313. option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
  314. option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
  315. option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
  316. option (LLVM_BUILD_EXTERNAL_COMPILER_RT
  317. "Build compiler-rt as an external project." OFF)
  318. option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" OFF)
  319. option(LLVM_DYLIB_EXPORT_ALL "Export all symbols from libLLVM.dylib (default is C API only" OFF)
  320. option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ON)
  321. if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT)
  322. set(DISABLE_LLVM_DYLIB_ATEXIT 1)
  323. endif()
  324. option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
  325. if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
  326. set(LLVM_USE_HOST_TOOLS ON)
  327. endif()
  328. # All options referred to from HandleLLVMOptions have to be specified
  329. # BEFORE this include, otherwise options will not be correctly set on
  330. # first cmake run
  331. include(config-ix)
  332. # By default, we target the host, but this can be overridden at CMake
  333. # invocation time.
  334. set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
  335. "Default target for which LLVM will generate code." )
  336. set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
  337. include(HandleLLVMOptions)
  338. # Verify that we can find a Python 3 interpreter and force cmake to use it.
  339. find_package(PythonInterp 3 REQUIRED)
  340. ######
  341. # LLVMBuild Integration
  342. #
  343. # We use llvm-build to generate all the data required by the CMake based
  344. # build system in one swoop:
  345. #
  346. # - We generate a file (a CMake fragment) in the object root which contains
  347. # all the definitions that are required by CMake.
  348. #
  349. # - We generate the library table used by llvm-config.
  350. #
  351. # - We generate the dependencies for the CMake fragment, so that we will
  352. # automatically reconfigure outselves.
  353. set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
  354. set(LLVMCONFIGLIBRARYDEPENDENCIESINC
  355. "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
  356. set(LLVMBUILDCMAKEFRAG
  357. "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
  358. # Create the list of optional components that are enabled
  359. if (LLVM_USE_INTEL_JITEVENTS)
  360. set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
  361. endif (LLVM_USE_INTEL_JITEVENTS)
  362. if (LLVM_USE_OPROFILE)
  363. set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
  364. endif (LLVM_USE_OPROFILE)
  365. # HLSL Change: use 'Unknown' in place of "${LLVM_NATIVE_ARCH}"
  366. message(STATUS "Constructing LLVMBuild project information")
  367. execute_process(
  368. COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
  369. --native-target Unknown
  370. --enable-targets "${LLVM_TARGETS_TO_BUILD}"
  371. --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
  372. --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
  373. --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
  374. OUTPUT_VARIABLE LLVMBUILDOUTPUT
  375. ERROR_VARIABLE LLVMBUILDERRORS
  376. OUTPUT_STRIP_TRAILING_WHITESPACE
  377. ERROR_STRIP_TRAILING_WHITESPACE
  378. RESULT_VARIABLE LLVMBUILDRESULT)
  379. # On Win32, CMake doesn't properly handle piping the default output/error
  380. # streams into the GUI console. So, we explicitly catch and report them.
  381. if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
  382. message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
  383. endif()
  384. if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
  385. message(FATAL_ERROR
  386. "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
  387. endif()
  388. # Include the generated CMake fragment. This will define properties from the
  389. # LLVMBuild files in a format which is easy to consume from CMake, and will add
  390. # the dependencies so that CMake will reconfigure properly when the LLVMBuild
  391. # files change.
  392. include(${LLVMBUILDCMAKEFRAG})
  393. ######
  394. # Configure all of the various header file fragments LLVM uses which depend on
  395. # configuration variables.
  396. set(LLVM_ENUM_TARGETS "")
  397. set(LLVM_ENUM_ASM_PRINTERS "")
  398. set(LLVM_ENUM_ASM_PARSERS "")
  399. set(LLVM_ENUM_DISASSEMBLERS "")
  400. foreach(t ${LLVM_TARGETS_TO_BUILD})
  401. if(NOT t STREQUAL "None") # HLSL Change - support for no target, but no continue() in CMake 2.8
  402. set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
  403. list(FIND LLVM_ALL_TARGETS ${t} idx)
  404. list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
  405. if( idx LESS 0 AND idy LESS 0 )
  406. message(FATAL_ERROR "The target `${t}' does not exist.
  407. It should be one of\n${LLVM_ALL_TARGETS}")
  408. else()
  409. set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
  410. endif()
  411. file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
  412. if( asmp_file )
  413. set(LLVM_ENUM_ASM_PRINTERS
  414. "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
  415. endif()
  416. if( EXISTS ${td}/AsmParser/CMakeLists.txt )
  417. set(LLVM_ENUM_ASM_PARSERS
  418. "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
  419. endif()
  420. if( EXISTS ${td}/Disassembler/CMakeLists.txt )
  421. set(LLVM_ENUM_DISASSEMBLERS
  422. "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
  423. endif()
  424. endif() # HLSL Change - support for no target
  425. endforeach(t)
  426. # Produce the target definition files, which provide a way for clients to easily
  427. # include various classes of targets.
  428. configure_file(
  429. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
  430. ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
  431. )
  432. configure_file(
  433. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
  434. ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
  435. )
  436. configure_file(
  437. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
  438. ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
  439. )
  440. configure_file(
  441. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
  442. ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
  443. )
  444. # Configure the three LLVM configuration header files.
  445. configure_file(
  446. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
  447. ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
  448. configure_file(
  449. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
  450. ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
  451. configure_file(
  452. ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
  453. ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
  454. # They are not referenced. See set_output_directory().
  455. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
  456. set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
  457. set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
  458. set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
  459. if (APPLE)
  460. set(CMAKE_INSTALL_NAME_DIR "@rpath")
  461. set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
  462. else(UNIX)
  463. if(NOT DEFINED CMAKE_INSTALL_RPATH)
  464. set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
  465. if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
  466. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
  467. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
  468. endif()
  469. endif(NOT DEFINED CMAKE_INSTALL_RPATH)
  470. endif()
  471. # Work around a broken bfd ld behavior. When linking a binary with a
  472. # foo.so library, it will try to find any library that foo.so uses and
  473. # check its symbols. This is wasteful (the check was done when foo.so
  474. # was created) and can fail since it is not the dynamic linker and
  475. # doesn't know how to handle search paths correctly.
  476. if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
  477. set(CMAKE_EXE_LINKER_FLAGS
  478. "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
  479. endif()
  480. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  481. # HLSL Change Starts - override assert to RaiseException instead of abort
  482. # for better test behavior
  483. if(WIN32 AND NOT UNIX)
  484. include_directories(BEFORE "${LLVM_MAIN_INCLUDE_DIR}/llvm/llvm_assert")
  485. endif()
  486. # HLSL Change Ends
  487. include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
  488. include_directories( ${LLVM_INCLUDE_DIR}/dxc/Tracing) # HLSL Change
  489. # when crosscompiling import the executable targets from a file
  490. if(LLVM_USE_HOST_TOOLS)
  491. include(CrossCompile)
  492. endif(LLVM_USE_HOST_TOOLS)
  493. if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
  494. # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
  495. # with libxml2, iconv.h, etc., we must add /usr/local paths.
  496. include_directories("/usr/local/include")
  497. link_directories("/usr/local/lib")
  498. endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
  499. if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
  500. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
  501. endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
  502. # Make sure we don't get -rdynamic in every binary. For those that need it,
  503. # use export_executable_symbols(target).
  504. set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  505. # enable warnings as errors for debug build
  506. if (WIN32)
  507. SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX")
  508. endif (WIN32)
  509. include(AddLLVM)
  510. include(TableGen)
  511. if( MINGW )
  512. # People report that -O3 is unreliable on MinGW. The traditional
  513. # build also uses -O2 for that reason:
  514. llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
  515. endif()
  516. # Put this before tblgen. Else we have a circular dependence.
  517. add_subdirectory(lib/Support)
  518. add_subdirectory(lib/MSSupport) # HLSL Change
  519. add_subdirectory(lib/TableGen)
  520. add_subdirectory(utils/TableGen)
  521. add_subdirectory(include/llvm)
  522. add_subdirectory(include/dxc/Support) # HLSL Change
  523. add_subdirectory(include/dxc/Tracing) # HLSL Change
  524. add_subdirectory(lib)
  525. if (HLSL_EMBED_VERSION)
  526. add_subdirectory(utils/version)
  527. endif()
  528. if( LLVM_INCLUDE_UTILS )
  529. # add_subdirectory(utils/FileCheck) # HLSL Change
  530. # add_subdirectory(utils/FileUpdate) # HLSL Change
  531. # add_subdirectory(utils/count) # HLSL Change
  532. # add_subdirectory(utils/not) # HLSL Change
  533. # add_subdirectory(utils/llvm-lit) # HLSL Change
  534. # add_subdirectory(utils/yaml-bench) # HLSL Change
  535. else()
  536. if ( LLVM_INCLUDE_TESTS )
  537. message(FATAL_ERROR "Including tests when not building utils will not work.
  538. Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
  539. endif()
  540. endif()
  541. if(LLVM_INCLUDE_TESTS)
  542. add_subdirectory(utils/unittest)
  543. endif()
  544. foreach( binding ${LLVM_BINDINGS_LIST} )
  545. if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
  546. add_subdirectory(bindings/${binding})
  547. endif()
  548. endforeach()
  549. add_subdirectory(projects)
  550. if(WITH_POLLY)
  551. if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
  552. set(WITH_POLLY OFF)
  553. endif()
  554. endif(WITH_POLLY)
  555. if(EXISTS "${LLVM_MAIN_SRC_DIR}/external")
  556. add_subdirectory(external) # SPIRV change
  557. endif()
  558. if( LLVM_INCLUDE_TOOLS )
  559. add_subdirectory(tools)
  560. endif()
  561. if( LLVM_INCLUDE_EXAMPLES AND 0 ) # HLSL Change - never build examples
  562. add_subdirectory(examples)
  563. endif()
  564. if( LLVM_INCLUDE_TESTS AND 0 ) # HLSL Change - never build tests/unittests
  565. add_subdirectory(test)
  566. add_subdirectory(unittests)
  567. if (MSVC)
  568. # This utility is used to prevent crashing tests from calling Dr. Watson on
  569. # Windows.
  570. add_subdirectory(utils/KillTheDoctor)
  571. endif()
  572. # Add a global check rule now that all subdirectories have been traversed
  573. # and we know the total set of lit testsuites.
  574. get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
  575. get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
  576. get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
  577. get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
  578. add_lit_target(check-all
  579. "Running all regression tests"
  580. ${LLVM_LIT_TESTSUITES}
  581. PARAMS ${LLVM_LIT_PARAMS}
  582. DEPENDS ${LLVM_LIT_DEPENDS}
  583. ARGS ${LLVM_LIT_EXTRA_ARGS}
  584. )
  585. endif()
  586. if (LLVM_INCLUDE_DOCS)
  587. add_subdirectory(docs)
  588. endif()
  589. add_subdirectory(cmake/modules)
  590. if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
  591. install(DIRECTORY include/llvm include/llvm-c
  592. DESTINATION include
  593. COMPONENT llvm-headers
  594. FILES_MATCHING
  595. PATTERN "*.def"
  596. PATTERN "*.h"
  597. PATTERN "*.td"
  598. PATTERN "*.inc"
  599. PATTERN "LICENSE.TXT"
  600. PATTERN ".svn" EXCLUDE
  601. )
  602. install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
  603. DESTINATION include
  604. COMPONENT llvm-headers
  605. FILES_MATCHING
  606. PATTERN "*.def"
  607. PATTERN "*.h"
  608. PATTERN "*.gen"
  609. PATTERN "*.inc"
  610. # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
  611. PATTERN "CMakeFiles" EXCLUDE
  612. PATTERN "config.h" EXCLUDE
  613. PATTERN ".svn" EXCLUDE
  614. )
  615. if (NOT CMAKE_CONFIGURATION_TYPES)
  616. add_custom_target(installhdrs
  617. DEPENDS ${name}
  618. COMMAND "${CMAKE_COMMAND}"
  619. -DCMAKE_INSTALL_COMPONENT=llvm-headers
  620. -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
  621. endif()
  622. endif()
  623. # Disable regeneration target for official builds as they always fun a full clean build.
  624. # This should eliminate the race-condition issue with "Cannot restore timestamp".
  625. if (HLSL_OFFICIAL_BUILD)
  626. set(CMAKE_SUPPRESS_REGENERATION ON)
  627. endif (HLSL_OFFICIAL_BUILD)
  628. if (NOT "${DXC_CMAKE_ENDS_INCLUDE}" STREQUAL "")
  629. include(${DXC_CMAKE_ENDS_INCLUDE})
  630. endif()