CMakeLists.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. cmake_minimum_required(VERSION 2.8.8)
  2. # FIXME: It may be removed when we use 2.8.12.
  3. if(CMAKE_VERSION VERSION_LESS 2.8.12)
  4. # Invalidate a couple of keywords.
  5. set(cmake_2_8_12_INTERFACE)
  6. set(cmake_2_8_12_PRIVATE)
  7. else()
  8. # Use ${cmake_2_8_12_KEYWORD} intead of KEYWORD in target_link_libraries().
  9. set(cmake_2_8_12_INTERFACE INTERFACE)
  10. set(cmake_2_8_12_PRIVATE PRIVATE)
  11. if(POLICY CMP0022)
  12. cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
  13. endif()
  14. endif()
  15. # If we are not building as a part of LLVM, build Clang as an
  16. # standalone project, using LLVM as an external library:
  17. if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
  18. project(Clang)
  19. # Rely on llvm-config.
  20. set(CONFIG_OUTPUT)
  21. find_program(LLVM_CONFIG "llvm-config")
  22. if(LLVM_CONFIG)
  23. message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
  24. set(CONFIG_COMMAND ${LLVM_CONFIG}
  25. "--assertion-mode"
  26. "--bindir"
  27. "--libdir"
  28. "--includedir"
  29. "--prefix"
  30. "--src-root")
  31. execute_process(
  32. COMMAND ${CONFIG_COMMAND}
  33. RESULT_VARIABLE HAD_ERROR
  34. OUTPUT_VARIABLE CONFIG_OUTPUT
  35. )
  36. if(NOT HAD_ERROR)
  37. string(REGEX REPLACE
  38. "[ \t]*[\r\n]+[ \t]*" ";"
  39. CONFIG_OUTPUT ${CONFIG_OUTPUT})
  40. else()
  41. string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
  42. message(STATUS "${CONFIG_COMMAND_STR}")
  43. message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
  44. endif()
  45. else()
  46. message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}")
  47. endif()
  48. list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS)
  49. list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
  50. list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
  51. list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
  52. list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
  53. list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
  54. if(NOT MSVC_IDE)
  55. set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
  56. CACHE BOOL "Enable assertions")
  57. # Assertions should follow llvm-config's.
  58. mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
  59. endif()
  60. set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
  61. set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
  62. set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
  63. set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
  64. set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
  65. find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
  66. NO_DEFAULT_PATH)
  67. set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake")
  68. set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
  69. if(EXISTS ${LLVMCONFIG_FILE})
  70. list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
  71. include(${LLVMCONFIG_FILE})
  72. else()
  73. message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}")
  74. endif()
  75. # They are used as destination of target generators.
  76. set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
  77. set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
  78. if(WIN32 OR CYGWIN)
  79. # DLL platform -- put DLLs into bin.
  80. set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
  81. else()
  82. set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
  83. endif()
  84. option(LLVM_INSTALL_TOOLCHAIN_ONLY
  85. "Only include toolchain files in the 'install' target." OFF)
  86. option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
  87. "Set to ON to force using an old, unsupported host toolchain." OFF)
  88. include(AddLLVM)
  89. include(TableGen)
  90. include(HandleLLVMOptions)
  91. set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
  92. if (NOT DEFINED LLVM_INCLUDE_TESTS)
  93. set(LLVM_INCLUDE_TESTS ON)
  94. endif()
  95. include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
  96. link_directories("${LLVM_LIBRARY_DIR}")
  97. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
  98. set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
  99. set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
  100. if(LLVM_INCLUDE_TESTS)
  101. # Check prebuilt llvm/utils.
  102. if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
  103. AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
  104. AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
  105. set(LLVM_UTILS_PROVIDED ON)
  106. endif()
  107. if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
  108. set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
  109. if(NOT LLVM_UTILS_PROVIDED)
  110. add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
  111. add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
  112. add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
  113. set(LLVM_UTILS_PROVIDED ON)
  114. set(CLANG_TEST_DEPS FileCheck count not)
  115. endif()
  116. set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
  117. if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
  118. AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
  119. AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
  120. add_subdirectory(${UNITTEST_DIR} utils/unittest)
  121. endif()
  122. else()
  123. # Seek installed Lit.
  124. find_program(LLVM_LIT "lit.py" ${LLVM_MAIN_SRC_DIR}/utils/lit
  125. DOC "Path to lit.py")
  126. endif()
  127. if(LLVM_LIT)
  128. # Define the default arguments to use with 'lit', and an option for the user
  129. # to override.
  130. set(LIT_ARGS_DEFAULT "-sv")
  131. if (MSVC OR XCODE)
  132. set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
  133. endif()
  134. set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
  135. # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
  136. if( WIN32 AND NOT CYGWIN )
  137. set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
  138. endif()
  139. else()
  140. set(LLVM_INCLUDE_TESTS OFF)
  141. endif()
  142. endif()
  143. set( CLANG_BUILT_STANDALONE 1 )
  144. set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
  145. else()
  146. set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
  147. endif()
  148. find_package(LibXml2)
  149. if (LIBXML2_FOUND)
  150. set(CLANG_HAVE_LIBXML 1)
  151. endif()
  152. set(CLANG_RESOURCE_DIR "" CACHE STRING
  153. "Relative directory from the Clang binary to its resource files.")
  154. set(C_INCLUDE_DIRS "" CACHE STRING
  155. "Colon separated list of directories clang will search for headers.")
  156. set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
  157. set(DEFAULT_SYSROOT "" CACHE PATH
  158. "Default <path> to all compiler invocations for --sysroot=<path>." )
  159. set(CLANG_DEFAULT_OPENMP_RUNTIME "libgomp" CACHE STRING
  160. "Default OpenMP runtime used by -fopenmp.")
  161. set(CLANG_VENDOR "" CACHE STRING
  162. "Vendor-specific text for showing with version information.")
  163. if( CLANG_VENDOR )
  164. add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " )
  165. endif()
  166. set(CLANG_REPOSITORY_STRING "" CACHE STRING
  167. "Vendor-specific text for showing the repository the source is taken from.")
  168. if(CLANG_REPOSITORY_STRING)
  169. add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}")
  170. endif()
  171. set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
  172. "Vendor-specific uti.")
  173. # The libdir suffix must exactly match whatever LLVM's configuration used.
  174. set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
  175. set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  176. set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
  177. if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
  178. message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
  179. "the makefiles distributed with LLVM. Please create a directory and run cmake "
  180. "from there, passing the path to this source directory as the last argument. "
  181. "This process created the file `CMakeCache.txt' and the directory "
  182. "`CMakeFiles'. Please delete them.")
  183. endif()
  184. if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
  185. file(GLOB_RECURSE
  186. tablegenned_files_on_include_dir
  187. "${CLANG_SOURCE_DIR}/include/clang/*.inc")
  188. if( tablegenned_files_on_include_dir )
  189. message(FATAL_ERROR "Apparently there is a previous in-source build, "
  190. "probably as the result of running `configure' and `make' on "
  191. "${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
  192. "${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
  193. endif()
  194. endif()
  195. # Compute the Clang version from the LLVM version.
  196. string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
  197. ${PACKAGE_VERSION})
  198. message(STATUS "Clang version: ${CLANG_VERSION}")
  199. string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
  200. ${CLANG_VERSION})
  201. string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
  202. ${CLANG_VERSION})
  203. if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
  204. set(CLANG_HAS_VERSION_PATCHLEVEL 1)
  205. string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL
  206. ${CLANG_VERSION})
  207. else()
  208. set(CLANG_HAS_VERSION_PATCHLEVEL 0)
  209. endif()
  210. # Configure the Version.inc file.
  211. configure_file(
  212. ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
  213. ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
  214. # Add appropriate flags for GCC
  215. if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
  216. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -fno-strict-aliasing")
  217. # Enable -pedantic for Clang even if it's not enabled for LLVM.
  218. if (NOT LLVM_ENABLE_PEDANTIC)
  219. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
  220. endif ()
  221. check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
  222. if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
  223. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
  224. endif()
  225. endif ()
  226. # Determine HOST_LINK_VERSION on Darwin.
  227. set(HOST_LINK_VERSION)
  228. if (APPLE)
  229. set(LD_V_OUTPUT)
  230. execute_process(
  231. COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
  232. RESULT_VARIABLE HAD_ERROR
  233. OUTPUT_VARIABLE LD_V_OUTPUT
  234. )
  235. if (NOT HAD_ERROR)
  236. if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
  237. string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
  238. elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
  239. string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
  240. endif()
  241. else()
  242. message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
  243. endif()
  244. endif()
  245. configure_file(
  246. ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
  247. ${CLANG_BINARY_DIR}/include/clang/Config/config.h)
  248. include(CMakeParseArguments)
  249. function(clang_tablegen)
  250. # Syntax:
  251. # clang_tablegen output-file [tablegen-arg ...] SOURCE source-file
  252. # [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]]
  253. #
  254. # Generates a custom command for invoking tblgen as
  255. #
  256. # tblgen source-file -o=output-file tablegen-arg ...
  257. #
  258. # and, if cmake-target-name is provided, creates a custom target for
  259. # executing the custom command depending on output-file. It is
  260. # possible to list more files to depend after DEPENDS.
  261. cmake_parse_arguments(CTG "" "SOURCE;TARGET" "" ${ARGN})
  262. if( NOT CTG_SOURCE )
  263. message(FATAL_ERROR "SOURCE source-file required by clang_tablegen")
  264. endif()
  265. set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} )
  266. tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS})
  267. if(CTG_TARGET)
  268. add_public_tablegen_target(${CTG_TARGET})
  269. set_target_properties( ${CTG_TARGET} PROPERTIES FOLDER "Clang tablegenning")
  270. set_property(GLOBAL APPEND PROPERTY CLANG_TABLEGEN_TARGETS ${CTG_TARGET})
  271. endif()
  272. endfunction(clang_tablegen)
  273. macro(set_clang_windows_version_resource_properties name)
  274. if(DEFINED windows_resource_file)
  275. set_windows_version_resource_properties(${name} ${windows_resource_file}
  276. VERSION_MAJOR ${CLANG_VERSION_MAJOR}
  277. VERSION_MINOR ${CLANG_VERSION_MINOR}
  278. VERSION_PATCHLEVEL ${CLANG_VERSION_PATCHLEVEL}
  279. VERSION_STRING "${CLANG_VERSION} (${BACKEND_PACKAGE_STRING})"
  280. PRODUCT_NAME "clang")
  281. endif()
  282. endmacro()
  283. macro(add_clang_library name)
  284. cmake_parse_arguments(ARG
  285. ""
  286. ""
  287. "ADDITIONAL_HEADERS"
  288. ${ARGN})
  289. set(srcs)
  290. if(MSVC_IDE OR XCODE)
  291. # Add public headers
  292. file(RELATIVE_PATH lib_path
  293. ${CLANG_SOURCE_DIR}/lib/
  294. ${CMAKE_CURRENT_SOURCE_DIR}
  295. )
  296. if(NOT lib_path MATCHES "^[.][.]")
  297. file( GLOB_RECURSE headers
  298. ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.h
  299. ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.def
  300. )
  301. set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON)
  302. file( GLOB_RECURSE tds
  303. ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.td
  304. )
  305. source_group("TableGen descriptions" FILES ${tds})
  306. set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON)
  307. if(headers OR tds)
  308. set(srcs ${headers} ${tds})
  309. endif()
  310. endif()
  311. endif(MSVC_IDE OR XCODE)
  312. if(srcs OR ARG_ADDITIONAL_HEADERS)
  313. set(srcs
  314. ADDITIONAL_HEADERS
  315. ${srcs}
  316. ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
  317. )
  318. endif()
  319. llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
  320. if(TARGET ${name})
  321. target_link_libraries(${name} ${cmake_2_8_12_INTERFACE} ${LLVM_COMMON_LIBS})
  322. if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libclang")
  323. install(TARGETS ${name}
  324. EXPORT ClangTargets
  325. LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
  326. ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
  327. RUNTIME DESTINATION bin)
  328. endif()
  329. set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
  330. else()
  331. # Add empty "phony" target
  332. add_custom_target(${name})
  333. endif()
  334. set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
  335. set_clang_windows_version_resource_properties(${name})
  336. endmacro(add_clang_library)
  337. macro(add_clang_executable name)
  338. add_llvm_executable( ${name} ${ARGN} )
  339. set_target_properties(${name} PROPERTIES FOLDER "Clang executables")
  340. set_clang_windows_version_resource_properties(${name})
  341. endmacro(add_clang_executable)
  342. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  343. include_directories(BEFORE
  344. ${CMAKE_CURRENT_BINARY_DIR}/include
  345. ${CMAKE_CURRENT_SOURCE_DIR}/include
  346. )
  347. if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
  348. install(DIRECTORY include/clang include/clang-c
  349. DESTINATION include
  350. FILES_MATCHING
  351. PATTERN "*.def"
  352. PATTERN "*.h"
  353. PATTERN "config.h" EXCLUDE
  354. PATTERN ".svn" EXCLUDE
  355. )
  356. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
  357. DESTINATION include
  358. FILES_MATCHING
  359. PATTERN "CMakeFiles" EXCLUDE
  360. PATTERN "*.inc"
  361. PATTERN "*.h"
  362. )
  363. endif()
  364. install(DIRECTORY include/clang-c
  365. DESTINATION include
  366. FILES_MATCHING
  367. PATTERN "*.h"
  368. PATTERN ".svn" EXCLUDE
  369. )
  370. add_definitions( -D_GNU_SOURCE )
  371. option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
  372. if (CLANG_ENABLE_ARCMT)
  373. set(ENABLE_CLANG_ARCMT "1")
  374. else()
  375. set(ENABLE_CLANG_ARCMT "0")
  376. endif()
  377. option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON)
  378. if (CLANG_ENABLE_STATIC_ANALYZER)
  379. set(ENABLE_CLANG_STATIC_ANALYZER "1")
  380. else()
  381. set(ENABLE_CLANG_STATIC_ANALYZER "0")
  382. endif()
  383. if (NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT)
  384. message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT")
  385. endif()
  386. if(CLANG_ENABLE_ARCMT)
  387. add_definitions(-DCLANG_ENABLE_ARCMT)
  388. add_definitions(-DCLANG_ENABLE_OBJC_REWRITER)
  389. endif()
  390. if(CLANG_ENABLE_STATIC_ANALYZER)
  391. add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER)
  392. endif()
  393. # Clang version information
  394. set(CLANG_EXECUTABLE_VERSION
  395. "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
  396. "Version number that will be placed into the clang executable, in the form XX.YY")
  397. set(LIBCLANG_LIBRARY_VERSION
  398. "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
  399. "Version number that will be placed into the libclang library , in the form XX.YY")
  400. mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
  401. add_subdirectory(utils/TableGen)
  402. add_subdirectory(include)
  403. # All targets below may depend on all tablegen'd files.
  404. get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
  405. list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS})
  406. add_subdirectory(lib)
  407. add_subdirectory(tools)
  408. add_subdirectory(runtime)
  409. option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF)
  410. if (CLANG_BUILD_EXAMPLES)
  411. set(ENABLE_CLANG_EXAMPLES "1")
  412. else()
  413. set(ENABLE_CLANG_EXAMPLES "0")
  414. endif()
  415. # add_subdirectory(examples) # HLSL Change
  416. option(CLANG_INCLUDE_TESTS
  417. "Generate build targets for the Clang unit tests."
  418. ${LLVM_INCLUDE_TESTS})
  419. if( CLANG_INCLUDE_TESTS OR HLSL_INCLUDE_TESTS ) # HLSL Change
  420. if(HLSL_INCLUDE_TESTS OR EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) # HLSL Change - no need for gtest
  421. add_subdirectory(unittests)
  422. list(APPEND CLANG_TEST_DEPS ClangUnitTests)
  423. list(APPEND CLANG_TEST_PARAMS
  424. clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
  425. )
  426. endif()
  427. # add_subdirectory(test) # HLSL Change - disable pure .lit tests
  428. if(CLANG_BUILT_STANDALONE)
  429. # Add a global check rule now that all subdirectories have been traversed
  430. # and we know the total set of lit testsuites.
  431. get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
  432. get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
  433. get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
  434. get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
  435. add_lit_target(check-all
  436. "Running all regression tests"
  437. ${LLVM_LIT_TESTSUITES}
  438. PARAMS ${LLVM_LIT_PARAMS}
  439. DEPENDS ${LLVM_LIT_DEPENDS}
  440. ARGS ${LLVM_LIT_EXTRA_ARGS}
  441. )
  442. endif()
  443. endif()
  444. option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs."
  445. ${LLVM_INCLUDE_DOCS})
  446. if( CLANG_INCLUDE_DOCS )
  447. add_subdirectory(docs)
  448. endif()
  449. set(CLANG_ORDER_FILE "" CACHE FILEPATH
  450. "Order file to use when compiling clang in order to improve startup time.")
  451. if (CLANG_BUILT_STANDALONE)
  452. # Generate a list of CMake library targets so that other CMake projects can
  453. # link against them. LLVM calls its version of this file LLVMExports.cmake, but
  454. # the usual CMake convention seems to be ${Project}Targets.cmake.
  455. set(CLANG_INSTALL_PACKAGE_DIR share/clang/cmake)
  456. set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}")
  457. get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
  458. export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
  459. # Install a <prefix>/share/clang/cmake/ClangConfig.cmake file so that
  460. # find_package(Clang) works. Install the target list with it.
  461. install(EXPORT ClangTargets DESTINATION ${CLANG_INSTALL_PACKAGE_DIR})
  462. install(FILES
  463. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake
  464. DESTINATION share/clang/cmake)
  465. # Also copy ClangConfig.cmake to the build directory so that dependent projects
  466. # can build against a build directory of Clang more easily.
  467. configure_file(
  468. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake
  469. ${CLANG_BINARY_DIR}/share/clang/cmake/ClangConfig.cmake
  470. COPYONLY)
  471. endif ()