CMakeLists.txt 30 KB

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