CMakeLists.txt 31 KB

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