CMakeLists.txt 27 KB

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