CMakeLists.txt 26 KB

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