CMakeLists.txt 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. cmake_minimum_required(VERSION 3.1...3.12 FATAL_ERROR)
  4. set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideC.cmake)
  5. set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideCXX.cmake)
  6. project(CMake)
  7. unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
  8. unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
  9. # Make sure we can find internal find_package modules only used for
  10. # building CMake and not for shipping externally
  11. list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
  12. if(CMAKE_BOOTSTRAP)
  13. # Running from bootstrap script. Set local variable and remove from cache.
  14. set(CMAKE_BOOTSTRAP 1)
  15. unset(CMAKE_BOOTSTRAP CACHE)
  16. endif()
  17. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  18. if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  19. message(FATAL_ERROR
  20. "CMake no longer compiles on HP-UX. See\n"
  21. " https://gitlab.kitware.com/cmake/cmake/issues/17137\n"
  22. "Use CMake 3.9 or lower instead."
  23. )
  24. endif()
  25. set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
  26. endif()
  27. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  28. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
  29. set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
  30. else()
  31. set(USE_LGPL "2.1")
  32. endif()
  33. else()
  34. set(USE_LGPL "")
  35. endif()
  36. if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
  37. # Disallow architecture-specific try_run. It may not run on the host.
  38. macro(TRY_RUN)
  39. if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
  40. message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
  41. else()
  42. _TRY_RUN(${ARGV})
  43. endif()
  44. endmacro()
  45. endif()
  46. # Use most-recent available language dialects with GNU and Clang
  47. if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
  48. include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
  49. if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
  50. set(CMAKE_C_STANDARD 11)
  51. else()
  52. set(CMAKE_C_STANDARD 99)
  53. endif()
  54. endif()
  55. if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
  56. if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
  57. set(CMAKE_CXX_STANDARD 98)
  58. else()
  59. if(NOT CMAKE_VERSION VERSION_LESS 3.8)
  60. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
  61. else()
  62. set(CMake_CXX17_BROKEN 1)
  63. endif()
  64. if(NOT CMake_CXX17_BROKEN)
  65. set(CMAKE_CXX_STANDARD 17)
  66. else()
  67. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
  68. if(NOT CMake_CXX14_BROKEN)
  69. set(CMAKE_CXX_STANDARD 14)
  70. else()
  71. set(CMAKE_CXX_STANDARD 11)
  72. endif()
  73. endif()
  74. endif()
  75. endif()
  76. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  77. # include special compile flags for some compilers
  78. include(CompileFlags.cmake)
  79. # check for available C++ features
  80. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
  81. if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
  82. message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
  83. endif()
  84. endif()
  85. # set the internal encoding of CMake to UTF-8
  86. set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
  87. # option to use COMPONENT with install command
  88. option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
  89. mark_as_advanced(CMake_INSTALL_COMPONENTS)
  90. macro(CMake_OPTIONAL_COMPONENT NAME)
  91. if(CMake_INSTALL_COMPONENTS)
  92. set(COMPONENT COMPONENT ${NAME})
  93. else()
  94. set(COMPONENT)
  95. endif()
  96. endmacro()
  97. # option to disable installing 3rd-party dependencies
  98. option(CMake_INSTALL_DEPENDENCIES
  99. "Whether to install 3rd-party runtime dependencies" OFF)
  100. mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
  101. # option to build reference for CMake developers
  102. option(CMake_BUILD_DEVELOPER_REFERENCE
  103. "Build CMake Developer Reference" OFF)
  104. mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
  105. # option to build using interprocedural optimizations (IPO/LTO)
  106. if (NOT CMAKE_VERSION VERSION_LESS 3.12.2)
  107. option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
  108. if(CMake_BUILD_LTO)
  109. include(CheckIPOSupported)
  110. check_ipo_supported(RESULT HAVE_IPO)
  111. if(HAVE_IPO)
  112. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
  113. endif()
  114. endif()
  115. endif()
  116. #-----------------------------------------------------------------------
  117. # a macro to deal with system libraries, implemented as a macro
  118. # simply to improve readability of the main script
  119. #-----------------------------------------------------------------------
  120. macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
  121. # Options have dependencies.
  122. include(CMakeDependentOption)
  123. # Optionally use system xmlrpc. We no longer build or use it by default.
  124. option(CTEST_USE_XMLRPC "Enable xmlrpc submission method in CTest." OFF)
  125. mark_as_advanced(CTEST_USE_XMLRPC)
  126. # Allow the user to enable/disable all system utility library options by
  127. # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
  128. set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB)
  129. foreach(util ${UTILITIES})
  130. if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
  131. AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
  132. set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
  133. endif()
  134. if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
  135. if(CMAKE_USE_SYSTEM_LIBRARY_${util})
  136. set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
  137. else()
  138. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  139. endif()
  140. if(CMAKE_BOOTSTRAP)
  141. unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
  142. endif()
  143. string(TOLOWER "${util}" lutil)
  144. set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
  145. CACHE BOOL "Use system-installed ${lutil}" FORCE)
  146. else()
  147. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  148. endif()
  149. endforeach()
  150. if(CMAKE_BOOTSTRAP)
  151. unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
  152. endif()
  153. # Optionally use system utility libraries.
  154. option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
  155. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_CURL "Use system-installed curl"
  156. "${CMAKE_USE_SYSTEM_LIBRARY_CURL}" "NOT CTEST_USE_XMLRPC" ON)
  157. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat"
  158. "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}" "NOT CTEST_USE_XMLRPC" ON)
  159. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
  160. "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
  161. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
  162. "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  163. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
  164. "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  165. option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
  166. option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
  167. option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
  168. option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
  169. # For now use system KWIML only if explicitly requested rather
  170. # than activating via the general system libs options.
  171. option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
  172. mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
  173. # Mention to the user what system libraries are being used.
  174. foreach(util ${UTILITIES} KWIML)
  175. if(CMAKE_USE_SYSTEM_${util})
  176. message(STATUS "Using system-installed ${util}")
  177. endif()
  178. endforeach()
  179. # Inform utility library header wrappers whether to use system versions.
  180. configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
  181. ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
  182. @ONLY)
  183. endmacro()
  184. #-----------------------------------------------------------------------
  185. # a macro to determine the generator and ctest executable to use
  186. # for testing. Simply to improve readability of the main script.
  187. #-----------------------------------------------------------------------
  188. macro(CMAKE_SETUP_TESTING)
  189. if(BUILD_TESTING)
  190. set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
  191. foreach(util CURL EXPAT XMLRPC ZLIB)
  192. if(CMAKE_USE_SYSTEM_${util})
  193. set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
  194. endif()
  195. endforeach()
  196. # This variable is set by cmake, however to
  197. # test cmake we want to make sure that
  198. # the ctest from this cmake is used for testing
  199. # and not the ctest from the cmake building and testing
  200. # cmake.
  201. if(CMake_TEST_EXTERNAL_CMAKE)
  202. set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
  203. set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
  204. set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
  205. foreach(exe cmake ctest cpack)
  206. add_executable(${exe} IMPORTED)
  207. set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
  208. endforeach()
  209. else()
  210. set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
  211. set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
  212. set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
  213. endif()
  214. endif()
  215. # configure some files for testing
  216. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
  217. "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
  218. @ONLY)
  219. configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
  220. ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
  221. configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
  222. ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
  223. configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
  224. ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
  225. if(BUILD_TESTING AND DART_ROOT)
  226. configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
  227. ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
  228. endif()
  229. mark_as_advanced(DART_ROOT)
  230. mark_as_advanced(CURL_TESTING)
  231. endmacro()
  232. # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
  233. # organization feature. Default to ON for non-Express users. Express users must
  234. # explicitly turn off this option to build CMake in the Express IDE...
  235. #
  236. option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
  237. mark_as_advanced(CMAKE_USE_FOLDERS)
  238. option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
  239. if(CMake_RUN_CLANG_TIDY)
  240. if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
  241. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
  242. endif()
  243. find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
  244. if(NOT CLANG_TIDY_COMMAND)
  245. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
  246. endif()
  247. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
  248. # Create a preprocessor definition that depends on .clang-tidy content so
  249. # the compile command will change when .clang-tidy changes. This ensures
  250. # that a subsequent build re-runs clang-tidy on all sources even if they
  251. # do not otherwise need to be recompiled. Nothing actually uses this
  252. # definition. We add it to targets on which we run clang-tidy just to
  253. # get the build dependency on the .clang-tidy file.
  254. file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
  255. set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
  256. unset(clang_tidy_sha1)
  257. endif()
  258. configure_file(.clang-tidy .clang-tidy COPYONLY)
  259. option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
  260. if(CMake_RUN_IWYU)
  261. find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
  262. if(NOT IWYU_COMMAND)
  263. message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
  264. endif()
  265. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  266. "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
  267. list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
  268. endif()
  269. #-----------------------------------------------------------------------
  270. # a macro that only sets the FOLDER target property if it's
  271. # "appropriate"
  272. #-----------------------------------------------------------------------
  273. macro(CMAKE_SET_TARGET_FOLDER tgt folder)
  274. if(CMAKE_USE_FOLDERS)
  275. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  276. if(MSVC AND TARGET ${tgt})
  277. set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
  278. endif()
  279. else()
  280. set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
  281. endif()
  282. endmacro()
  283. #-----------------------------------------------------------------------
  284. # a macro to build the utilities used by CMake
  285. # Simply to improve readability of the main script.
  286. #-----------------------------------------------------------------------
  287. macro (CMAKE_BUILD_UTILITIES)
  288. find_package(Threads)
  289. #---------------------------------------------------------------------
  290. # Create the kwsys library for CMake.
  291. set(KWSYS_NAMESPACE cmsys)
  292. set(KWSYS_USE_SystemTools 1)
  293. set(KWSYS_USE_Directory 1)
  294. set(KWSYS_USE_RegularExpression 1)
  295. set(KWSYS_USE_Base64 1)
  296. set(KWSYS_USE_MD5 1)
  297. set(KWSYS_USE_Process 1)
  298. set(KWSYS_USE_CommandLineArguments 1)
  299. set(KWSYS_USE_ConsoleBuf 1)
  300. set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
  301. set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
  302. add_subdirectory(Source/kwsys)
  303. set(kwsys_folder "Utilities/KWSys")
  304. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
  305. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
  306. if(BUILD_TESTING)
  307. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
  308. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
  309. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
  310. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
  311. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
  312. endif()
  313. #---------------------------------------------------------------------
  314. # Setup third-party libraries.
  315. # Everything in the tree should be able to include files from the
  316. # Utilities directory.
  317. include_directories(
  318. ${CMake_BINARY_DIR}/Utilities
  319. ${CMake_SOURCE_DIR}/Utilities
  320. )
  321. # check for the use of system libraries versus builtin ones
  322. # (a macro defined in this file)
  323. CMAKE_HANDLE_SYSTEM_LIBRARIES()
  324. if(CMAKE_USE_SYSTEM_KWIML)
  325. find_package(KWIML 1.0)
  326. if(NOT KWIML_FOUND)
  327. message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
  328. endif()
  329. set(CMake_KWIML_LIBRARIES kwiml::kwiml)
  330. else()
  331. set(CMake_KWIML_LIBRARIES "")
  332. if(BUILD_TESTING)
  333. set(KWIML_TEST_ENABLE 1)
  334. endif()
  335. add_subdirectory(Utilities/KWIML)
  336. endif()
  337. if(CMAKE_USE_SYSTEM_LIBRHASH)
  338. find_package(LibRHash)
  339. if(NOT LibRHash_FOUND)
  340. message(FATAL_ERROR
  341. "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
  342. endif()
  343. set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
  344. else()
  345. set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
  346. add_subdirectory(Utilities/cmlibrhash)
  347. CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
  348. endif()
  349. #---------------------------------------------------------------------
  350. # Build zlib library for Curl, CMake, and CTest.
  351. set(CMAKE_ZLIB_HEADER "cm_zlib.h")
  352. if(CMAKE_USE_SYSTEM_ZLIB)
  353. find_package(ZLIB)
  354. if(NOT ZLIB_FOUND)
  355. message(FATAL_ERROR
  356. "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
  357. endif()
  358. set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
  359. set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
  360. else()
  361. set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
  362. set(CMAKE_ZLIB_LIBRARIES cmzlib)
  363. add_subdirectory(Utilities/cmzlib)
  364. CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
  365. endif()
  366. #---------------------------------------------------------------------
  367. # Build Curl library for CTest.
  368. if(CMAKE_USE_SYSTEM_CURL)
  369. find_package(CURL)
  370. if(NOT CURL_FOUND)
  371. message(FATAL_ERROR
  372. "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
  373. endif()
  374. set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
  375. set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
  376. else()
  377. set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
  378. set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
  379. set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
  380. set(CMAKE_CURL_INCLUDES)
  381. set(CMAKE_CURL_LIBRARIES cmcurl)
  382. if(CMAKE_TESTS_CDASH_SERVER)
  383. set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
  384. endif()
  385. set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
  386. if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
  387. AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
  388. find_package(OpenSSL QUIET)
  389. if(OPENSSL_FOUND)
  390. set(_CMAKE_USE_OPENSSL_DEFAULT ON)
  391. endif()
  392. endif()
  393. option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
  394. mark_as_advanced(CMAKE_USE_OPENSSL)
  395. if(CMAKE_USE_OPENSSL)
  396. set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
  397. set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
  398. mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
  399. endif()
  400. add_subdirectory(Utilities/cmcurl)
  401. CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
  402. CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
  403. endif()
  404. #---------------------------------------------------------------------
  405. # Build Compress library for CTest.
  406. set(CMAKE_COMPRESS_INCLUDES
  407. "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
  408. set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
  409. add_subdirectory(Utilities/cmcompress)
  410. CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
  411. #---------------------------------------------------------------------
  412. # Build expat library for CMake, CTest, and libarchive.
  413. if(CMAKE_USE_SYSTEM_EXPAT)
  414. find_package(EXPAT)
  415. if(NOT EXPAT_FOUND)
  416. message(FATAL_ERROR
  417. "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
  418. endif()
  419. set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
  420. set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
  421. else()
  422. set(CMAKE_EXPAT_INCLUDES)
  423. set(CMAKE_EXPAT_LIBRARIES cmexpat)
  424. add_subdirectory(Utilities/cmexpat)
  425. CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
  426. endif()
  427. #---------------------------------------------------------------------
  428. # Build or use system libbz2 for libarchive.
  429. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  430. if(CMAKE_USE_SYSTEM_BZIP2)
  431. find_package(BZip2)
  432. else()
  433. set(BZIP2_INCLUDE_DIR
  434. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
  435. set(BZIP2_LIBRARIES cmbzip2)
  436. add_subdirectory(Utilities/cmbzip2)
  437. CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
  438. endif()
  439. endif()
  440. #---------------------------------------------------------------------
  441. # Build or use system liblzma for libarchive.
  442. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  443. if(CMAKE_USE_SYSTEM_LIBLZMA)
  444. find_package(LibLZMA)
  445. if(NOT LIBLZMA_FOUND)
  446. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
  447. endif()
  448. else()
  449. add_subdirectory(Utilities/cmliblzma)
  450. CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
  451. set(LIBLZMA_HAS_AUTO_DECODER 1)
  452. set(LIBLZMA_HAS_EASY_ENCODER 1)
  453. set(LIBLZMA_HAS_LZMA_PRESET 1)
  454. set(LIBLZMA_INCLUDE_DIR
  455. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
  456. set(LIBLZMA_LIBRARY cmliblzma)
  457. endif()
  458. endif()
  459. #---------------------------------------------------------------------
  460. # Build or use system libarchive for CMake and CTest.
  461. if(CMAKE_USE_SYSTEM_LIBARCHIVE)
  462. find_package(LibArchive 3.1.0)
  463. if(NOT LibArchive_FOUND)
  464. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
  465. endif()
  466. set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
  467. set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
  468. else()
  469. set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
  470. set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
  471. set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
  472. set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
  473. add_definitions(-DLIBARCHIVE_STATIC)
  474. set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
  475. set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
  476. set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
  477. set(ENABLE_LZ4 OFF CACHE INTERNAL "Enable the use of the system LZ4 library if found")
  478. set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
  479. set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
  480. set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
  481. set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
  482. set(ENABLE_EXPAT ON CACHE INTERNAL "Enable the use of the system EXPAT library if found")
  483. set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
  484. set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
  485. set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
  486. set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
  487. set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
  488. set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
  489. add_subdirectory(Utilities/cmlibarchive)
  490. CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
  491. set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
  492. endif()
  493. #---------------------------------------------------------------------
  494. # Build jsoncpp library.
  495. if(CMAKE_USE_SYSTEM_JSONCPP)
  496. find_package(JsonCpp)
  497. if(NOT JsonCpp_FOUND)
  498. message(FATAL_ERROR
  499. "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
  500. endif()
  501. set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
  502. else()
  503. set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
  504. add_subdirectory(Utilities/cmjsoncpp)
  505. CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
  506. endif()
  507. #---------------------------------------------------------------------
  508. # Build libuv library.
  509. if(CMAKE_USE_SYSTEM_LIBUV)
  510. find_package(LibUV 1.10.0)
  511. if(NOT LIBUV_FOUND)
  512. message(FATAL_ERROR
  513. "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
  514. endif()
  515. set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
  516. else()
  517. set(CMAKE_LIBUV_LIBRARIES cmlibuv)
  518. add_subdirectory(Utilities/cmlibuv)
  519. CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
  520. endif()
  521. #---------------------------------------------------------------------
  522. # Build XMLRPC library for CMake and CTest.
  523. if(CTEST_USE_XMLRPC)
  524. find_package(XMLRPC QUIET REQUIRED libwww-client)
  525. if(NOT XMLRPC_FOUND)
  526. message(FATAL_ERROR
  527. "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
  528. endif()
  529. set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
  530. set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
  531. endif()
  532. #---------------------------------------------------------------------
  533. # Use curses?
  534. if (UNIX)
  535. if(NOT DEFINED BUILD_CursesDialog)
  536. include(${CMake_SOURCE_DIR}/Source/Checks/Curses.cmake)
  537. option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" "${CMakeCheckCurses_COMPILED}")
  538. endif()
  539. else ()
  540. set(BUILD_CursesDialog 0)
  541. endif ()
  542. if(BUILD_CursesDialog)
  543. set(CURSES_NEED_NCURSES TRUE)
  544. find_package(Curses)
  545. if(NOT CURSES_FOUND)
  546. message(WARNING
  547. "'ccmake' will not be built because Curses was not found.\n"
  548. "Turn off BUILD_CursesDialog to suppress this message."
  549. )
  550. set(BUILD_CursesDialog 0)
  551. endif()
  552. endif()
  553. if(BUILD_CursesDialog)
  554. if(NOT CMAKE_USE_SYSTEM_FORM)
  555. add_subdirectory(Source/CursesDialog/form)
  556. elseif(NOT CURSES_FORM_LIBRARY)
  557. message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
  558. endif()
  559. endif()
  560. endmacro ()
  561. #-----------------------------------------------------------------------
  562. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  563. if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
  564. execute_process(COMMAND ${CMAKE_CXX_COMPILER}
  565. ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
  566. OUTPUT_VARIABLE _GXX_VERSION
  567. )
  568. string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
  569. _GXX_VERSION_SHORT ${_GXX_VERSION})
  570. if(_GXX_VERSION_SHORT EQUAL 33)
  571. message(FATAL_ERROR
  572. "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
  573. "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
  574. "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
  575. endif()
  576. endif()
  577. endif()
  578. #-----------------------------------------------------------------------
  579. # The main section of the CMakeLists file
  580. #
  581. #-----------------------------------------------------------------------
  582. # Compute CMake_VERSION, etc.
  583. include(Source/CMakeVersionCompute.cmake)
  584. # Include the standard Dart testing module
  585. enable_testing()
  586. include (${CMAKE_ROOT}/Modules/Dart.cmake)
  587. # Set up test-time configuration.
  588. set_directory_properties(PROPERTIES
  589. TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
  590. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  591. # where to write the resulting executables and libraries
  592. set(BUILD_SHARED_LIBS OFF)
  593. set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
  594. set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
  595. "Where to put the libraries for CMake")
  596. # The CMake executables usually do not need any rpath to run in the build or
  597. # install tree.
  598. set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
  599. # Load install destinations.
  600. include(Source/CMakeInstallDestinations.cmake)
  601. if(BUILD_TESTING)
  602. include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
  603. endif()
  604. # no clue why we are testing for this here
  605. include(CheckSymbolExists)
  606. CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
  607. CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
  608. endif()
  609. # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
  610. #
  611. # If not defined or "", this variable defaults to the server at
  612. # "http://open.cdash.org".
  613. #
  614. # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
  615. # the network are skipped.
  616. #
  617. # If set to something starting with "http://localhost/", the CDash is
  618. # expected to be an instance of CDash used for CDash testing, pointing
  619. # to a cdash4simpletest database. In these cases, the CDash dashboards
  620. # should be run first.
  621. #
  622. if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
  623. set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
  624. endif()
  625. if(CMake_TEST_EXTERNAL_CMAKE)
  626. set(KWIML_TEST_ENABLE 1)
  627. add_subdirectory(Utilities/KWIML)
  628. endif()
  629. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  630. # build the utilities (a macro defined in this file)
  631. CMAKE_BUILD_UTILITIES()
  632. # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
  633. # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
  634. # which isn't in the default linker search path. So without RPATH ccmake
  635. # doesn't run and the build doesn't succeed since ccmake is executed for
  636. # generating the documentation.
  637. if(BUILD_CursesDialog)
  638. get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
  639. set(CURSES_NEED_RPATH FALSE)
  640. if(NOT "${_CURSES_DIR}" STREQUAL "/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/lib64" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib64")
  641. set(CURSES_NEED_RPATH TRUE)
  642. endif()
  643. endif()
  644. if(BUILD_QtDialog)
  645. if(APPLE)
  646. set(CMAKE_BUNDLE_VERSION
  647. "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  648. set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
  649. # make sure CMAKE_INSTALL_PREFIX ends in /
  650. if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
  651. set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
  652. endif()
  653. set(CMAKE_INSTALL_PREFIX
  654. "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
  655. endif()
  656. set(QT_NEED_RPATH FALSE)
  657. if(NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib64" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib64")
  658. set(QT_NEED_RPATH TRUE)
  659. endif()
  660. endif()
  661. # The same might be true on other systems for other libraries.
  662. # Then only enable RPATH if we have are building at least with cmake 2.4,
  663. # since this one has much better RPATH features than cmake 2.2.
  664. # The executables are then built with the RPATH for the libraries outside
  665. # the build tree, which is both the build and the install RPATH.
  666. if (UNIX)
  667. if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
  668. OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
  669. set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
  670. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  671. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  672. endif()
  673. endif ()
  674. # add the uninstall support
  675. configure_file(
  676. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  677. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  678. @ONLY)
  679. add_custom_target(uninstall
  680. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  681. include (CMakeCPack.cmake)
  682. endif()
  683. # setup some Testing support (a macro defined in this file)
  684. CMAKE_SETUP_TESTING()
  685. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  686. if(NOT CMake_VERSION_IS_RELEASE)
  687. if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
  688. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
  689. set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
  690. -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
  691. -Wmissing-format-attribute -fno-common -Wundef
  692. )
  693. set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
  694. -Wshadow -Wpointer-arith -Wformat-security -Wundef
  695. )
  696. foreach(FLAG_LANG C CXX)
  697. foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
  698. if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
  699. set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
  700. endif()
  701. endforeach()
  702. endforeach()
  703. unset(C_FLAGS_LIST)
  704. unset(CXX_FLAGS_LIST)
  705. endif()
  706. endif()
  707. # build the remaining subdirectories
  708. add_subdirectory(Source)
  709. add_subdirectory(Utilities)
  710. endif()
  711. add_subdirectory(Tests)
  712. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  713. if(BUILD_TESTING)
  714. CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
  715. IF(TARGET CMakeServerLibTests)
  716. CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
  717. ENDIF()
  718. endif()
  719. if(TARGET documentation)
  720. CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
  721. endif()
  722. endif()
  723. if(BUILD_TESTING)
  724. add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
  725. --system-information -G "${CMAKE_GENERATOR}" )
  726. endif()
  727. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  728. # Install license file as it requires.
  729. install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
  730. # Install script directories.
  731. install(
  732. DIRECTORY Help Modules Templates
  733. DESTINATION ${CMAKE_DATA_DIR}
  734. FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  735. DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  736. GROUP_READ GROUP_EXECUTE
  737. WORLD_READ WORLD_EXECUTE
  738. PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  739. GROUP_READ GROUP_EXECUTE
  740. WORLD_READ WORLD_EXECUTE
  741. REGEX "Help/dev($|/)" EXCLUDE
  742. )
  743. # Install auxiliary files integrating with other tools.
  744. add_subdirectory(Auxiliary)
  745. endif()