CMakeLists.txt 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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_IWYU "Run include-what-you-use with the compiler." OFF)
  204. if(CMake_RUN_IWYU)
  205. find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
  206. if(NOT IWYU_COMMAND)
  207. message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
  208. endif()
  209. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  210. "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp")
  211. endif()
  212. #-----------------------------------------------------------------------
  213. # a macro that only sets the FOLDER target property if it's
  214. # "appropriate"
  215. #-----------------------------------------------------------------------
  216. macro(CMAKE_SET_TARGET_FOLDER tgt folder)
  217. if(CMAKE_USE_FOLDERS)
  218. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  219. if(MSVC AND TARGET ${tgt})
  220. set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
  221. endif()
  222. else()
  223. set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
  224. endif()
  225. endmacro()
  226. #-----------------------------------------------------------------------
  227. # a macro to build the utilities used by CMake
  228. # Simply to improve readability of the main script.
  229. #-----------------------------------------------------------------------
  230. macro (CMAKE_BUILD_UTILITIES)
  231. #---------------------------------------------------------------------
  232. # Create the kwsys library for CMake.
  233. set(KWSYS_NAMESPACE cmsys)
  234. set(KWSYS_USE_SystemTools 1)
  235. set(KWSYS_USE_Directory 1)
  236. set(KWSYS_USE_RegularExpression 1)
  237. set(KWSYS_USE_Base64 1)
  238. set(KWSYS_USE_MD5 1)
  239. set(KWSYS_USE_Process 1)
  240. set(KWSYS_USE_CommandLineArguments 1)
  241. set(KWSYS_USE_ConsoleBuf 1)
  242. set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
  243. set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
  244. add_subdirectory(Source/kwsys)
  245. set(kwsys_folder "Utilities/KWSys")
  246. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
  247. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
  248. if(BUILD_TESTING)
  249. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
  250. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
  251. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
  252. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
  253. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
  254. endif()
  255. #---------------------------------------------------------------------
  256. # Setup third-party libraries.
  257. # Everything in the tree should be able to include files from the
  258. # Utilities directory.
  259. include_directories(
  260. ${CMake_BINARY_DIR}/Utilities
  261. ${CMake_SOURCE_DIR}/Utilities
  262. )
  263. # check for the use of system libraries versus builtin ones
  264. # (a macro defined in this file)
  265. CMAKE_HANDLE_SYSTEM_LIBRARIES()
  266. if(CMAKE_USE_SYSTEM_KWIML)
  267. find_package(KWIML 1.0)
  268. if(NOT KWIML_FOUND)
  269. message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
  270. endif()
  271. set(CMake_KWIML_LIBRARIES kwiml::kwiml)
  272. else()
  273. set(CMake_KWIML_LIBRARIES "")
  274. if(BUILD_TESTING)
  275. set(KWIML_TEST_ENABLE 1)
  276. endif()
  277. add_subdirectory(Utilities/KWIML)
  278. endif()
  279. if(CMAKE_USE_SYSTEM_LIBRHASH)
  280. if(NOT CMAKE_VERSION VERSION_LESS 3.0)
  281. find_package(LibRHash)
  282. else()
  283. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBRHASH requires CMake >= 3.0")
  284. endif()
  285. if(NOT LibRHash_FOUND)
  286. message(FATAL_ERROR
  287. "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
  288. endif()
  289. set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
  290. else()
  291. set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
  292. add_subdirectory(Utilities/cmlibrhash)
  293. CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
  294. endif()
  295. #---------------------------------------------------------------------
  296. # Build zlib library for Curl, CMake, and CTest.
  297. set(CMAKE_ZLIB_HEADER "cm_zlib.h")
  298. if(CMAKE_USE_SYSTEM_ZLIB)
  299. find_package(ZLIB)
  300. if(NOT ZLIB_FOUND)
  301. message(FATAL_ERROR
  302. "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
  303. endif()
  304. set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
  305. set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
  306. else()
  307. set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
  308. set(CMAKE_ZLIB_LIBRARIES cmzlib)
  309. add_subdirectory(Utilities/cmzlib)
  310. CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
  311. endif()
  312. #---------------------------------------------------------------------
  313. # Build Curl library for CTest.
  314. if(CMAKE_USE_SYSTEM_CURL)
  315. find_package(CURL)
  316. if(NOT CURL_FOUND)
  317. message(FATAL_ERROR
  318. "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
  319. endif()
  320. set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
  321. set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
  322. else()
  323. set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
  324. set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
  325. set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
  326. add_definitions(-DCURL_STATICLIB)
  327. set(CMAKE_CURL_INCLUDES)
  328. set(CMAKE_CURL_LIBRARIES cmcurl)
  329. if(CMAKE_TESTS_CDASH_SERVER)
  330. set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
  331. endif()
  332. set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
  333. if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
  334. AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
  335. find_package(OpenSSL QUIET)
  336. if(OPENSSL_FOUND)
  337. set(_CMAKE_USE_OPENSSL_DEFAULT ON)
  338. endif()
  339. endif()
  340. option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
  341. mark_as_advanced(CMAKE_USE_OPENSSL)
  342. if(CMAKE_USE_OPENSSL)
  343. set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
  344. set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
  345. mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
  346. endif()
  347. add_subdirectory(Utilities/cmcurl)
  348. CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
  349. CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
  350. endif()
  351. #---------------------------------------------------------------------
  352. # Build Compress library for CTest.
  353. set(CMAKE_COMPRESS_INCLUDES
  354. "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
  355. set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
  356. add_subdirectory(Utilities/cmcompress)
  357. CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
  358. #---------------------------------------------------------------------
  359. # Build expat library for CMake, CTest, and libarchive.
  360. if(CMAKE_USE_SYSTEM_EXPAT)
  361. find_package(EXPAT)
  362. if(NOT EXPAT_FOUND)
  363. message(FATAL_ERROR
  364. "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
  365. endif()
  366. set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
  367. set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
  368. else()
  369. set(CMAKE_EXPAT_INCLUDES)
  370. set(CMAKE_EXPAT_LIBRARIES cmexpat)
  371. add_subdirectory(Utilities/cmexpat)
  372. CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
  373. endif()
  374. #---------------------------------------------------------------------
  375. # Build or use system libbz2 for libarchive.
  376. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  377. if(CMAKE_USE_SYSTEM_BZIP2)
  378. find_package(BZip2)
  379. else()
  380. set(BZIP2_INCLUDE_DIR
  381. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
  382. set(BZIP2_LIBRARIES cmbzip2)
  383. add_subdirectory(Utilities/cmbzip2)
  384. CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
  385. endif()
  386. endif()
  387. #---------------------------------------------------------------------
  388. # Build or use system liblzma for libarchive.
  389. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  390. if(CMAKE_USE_SYSTEM_LIBLZMA)
  391. find_package(LibLZMA)
  392. if(NOT LIBLZMA_FOUND)
  393. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
  394. endif()
  395. else()
  396. add_subdirectory(Utilities/cmliblzma)
  397. CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
  398. set(LIBLZMA_HAS_AUTO_DECODER 1)
  399. set(LIBLZMA_HAS_EASY_ENCODER 1)
  400. set(LIBLZMA_HAS_LZMA_PRESET 1)
  401. set(LIBLZMA_INCLUDE_DIR
  402. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
  403. set(LIBLZMA_LIBRARY cmliblzma)
  404. endif()
  405. endif()
  406. #---------------------------------------------------------------------
  407. # Build or use system libarchive for CMake and CTest.
  408. if(CMAKE_USE_SYSTEM_LIBARCHIVE)
  409. find_package(LibArchive 3.0.0)
  410. if(NOT LibArchive_FOUND)
  411. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
  412. endif()
  413. set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
  414. set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
  415. else()
  416. set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
  417. set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
  418. set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
  419. set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
  420. add_definitions(-DLIBARCHIVE_STATIC)
  421. set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
  422. set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
  423. set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
  424. set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
  425. set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
  426. set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
  427. set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
  428. set(ENABLE_EXPAT ON CACHE INTERNAL "Enable the use of the system EXPAT library if found")
  429. set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
  430. set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
  431. set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
  432. set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
  433. set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
  434. set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
  435. add_subdirectory(Utilities/cmlibarchive)
  436. CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
  437. set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
  438. endif()
  439. #---------------------------------------------------------------------
  440. # Build jsoncpp library.
  441. if(CMAKE_USE_SYSTEM_JSONCPP)
  442. if(NOT CMAKE_VERSION VERSION_LESS 3.0)
  443. find_package(JsonCpp)
  444. else()
  445. message(FATAL_ERROR "CMAKE_USE_SYSTEM_JSONCPP requires CMake >= 3.0")
  446. endif()
  447. if(NOT JsonCpp_FOUND)
  448. message(FATAL_ERROR
  449. "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
  450. endif()
  451. set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
  452. else()
  453. set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
  454. add_subdirectory(Utilities/cmjsoncpp)
  455. CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
  456. endif()
  457. #---------------------------------------------------------------------
  458. # Build libuv library.
  459. if(NOT DEFINED CMAKE_USE_LIBUV)
  460. set(CMAKE_USE_LIBUV 1)
  461. if(APPLE)
  462. include(CheckCSourceCompiles)
  463. check_c_source_compiles("
  464. #include <CoreServices/CoreServices.h>
  465. #include <AvailabilityMacros.h>
  466. #ifndef MAC_OS_X_VERSION_10_5
  467. #error \"MAC_OS_X_VERSION_10_5 is not defined\"
  468. #endif
  469. int main(void) { return 0; }
  470. " HAVE_CoreServices_OS_X_10_5)
  471. if(NOT HAVE_CoreServices_OS_X_10_5)
  472. set(CMAKE_USE_LIBUV 0)
  473. endif()
  474. elseif(CYGWIN)
  475. # libuv does not support Cygwin
  476. set(CMAKE_USE_LIBUV 0)
  477. elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  478. # Disable until it can be ported.
  479. set(CMAKE_USE_LIBUV 0)
  480. endif()
  481. endif()
  482. if(CMAKE_USE_LIBUV)
  483. if(CMAKE_USE_SYSTEM_LIBUV)
  484. if(NOT CMAKE_VERSION VERSION_LESS 3.0)
  485. find_package(LibUV 1.0.0)
  486. else()
  487. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBUV requires CMake >= 3.0")
  488. endif()
  489. if(NOT LIBUV_FOUND)
  490. message(FATAL_ERROR
  491. "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
  492. endif()
  493. set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
  494. else()
  495. set(CMAKE_LIBUV_LIBRARIES cmlibuv)
  496. add_subdirectory(Utilities/cmlibuv)
  497. CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
  498. endif()
  499. else()
  500. set(CMAKE_LIBUV_LIBRARIES)
  501. endif()
  502. #---------------------------------------------------------------------
  503. # Build XMLRPC library for CMake and CTest.
  504. if(CTEST_USE_XMLRPC)
  505. find_package(XMLRPC QUIET REQUIRED libwww-client)
  506. if(NOT XMLRPC_FOUND)
  507. message(FATAL_ERROR
  508. "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
  509. endif()
  510. set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
  511. set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
  512. endif()
  513. #---------------------------------------------------------------------
  514. # Use curses?
  515. if (UNIX)
  516. # there is a bug in the Syllable libraries which makes linking ccmake fail, Alex
  517. if(NOT CMAKE_SYSTEM_NAME MATCHES syllable)
  518. set(CURSES_NEED_NCURSES TRUE)
  519. find_package(Curses QUIET)
  520. if (CURSES_LIBRARY)
  521. option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" ON)
  522. else ()
  523. message("Curses libraries were not found. Curses GUI for CMake will not be built.")
  524. set(BUILD_CursesDialog 0)
  525. endif ()
  526. else()
  527. set(BUILD_CursesDialog 0)
  528. endif()
  529. else ()
  530. set(BUILD_CursesDialog 0)
  531. endif ()
  532. if(BUILD_CursesDialog)
  533. if(NOT CMAKE_USE_SYSTEM_FORM)
  534. add_subdirectory(Source/CursesDialog/form)
  535. elseif(NOT CURSES_FORM_LIBRARY)
  536. message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
  537. endif()
  538. endif()
  539. endmacro ()
  540. #-----------------------------------------------------------------------
  541. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  542. if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
  543. execute_process(COMMAND ${CMAKE_CXX_COMPILER}
  544. ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
  545. OUTPUT_VARIABLE _GXX_VERSION
  546. )
  547. string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
  548. _GXX_VERSION_SHORT ${_GXX_VERSION})
  549. if(_GXX_VERSION_SHORT EQUAL 33)
  550. message(FATAL_ERROR
  551. "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
  552. "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
  553. "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
  554. endif()
  555. endif()
  556. endif()
  557. #-----------------------------------------------------------------------
  558. # The main section of the CMakeLists file
  559. #
  560. #-----------------------------------------------------------------------
  561. # Compute CMake_VERSION, etc.
  562. include(Source/CMakeVersionCompute.cmake)
  563. # Include the standard Dart testing module
  564. enable_testing()
  565. include (${CMAKE_ROOT}/Modules/Dart.cmake)
  566. # Set up test-time configuration.
  567. set_directory_properties(PROPERTIES
  568. TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
  569. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  570. # where to write the resulting executables and libraries
  571. set(BUILD_SHARED_LIBS OFF)
  572. set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
  573. set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
  574. "Where to put the libraries for CMake")
  575. # The CMake executables usually do not need any rpath to run in the build or
  576. # install tree.
  577. set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
  578. # Load install destinations.
  579. include(Source/CMakeInstallDestinations.cmake)
  580. if(BUILD_TESTING)
  581. include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
  582. endif()
  583. # include special compile flags for some compilers
  584. include(CompileFlags.cmake)
  585. # no clue why we are testing for this here
  586. include(CheckSymbolExists)
  587. CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
  588. CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
  589. endif()
  590. # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
  591. #
  592. # If not defined or "", this variable defaults to the server at
  593. # "http://open.cdash.org".
  594. #
  595. # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
  596. # the network are skipped.
  597. #
  598. # If set to something starting with "http://localhost/", the CDash is
  599. # expected to be an instance of CDash used for CDash testing, pointing
  600. # to a cdash4simpletest database. In these cases, the CDash dashboards
  601. # should be run first.
  602. #
  603. if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
  604. set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
  605. endif()
  606. if(CMake_TEST_EXTERNAL_CMAKE)
  607. set(KWIML_TEST_ENABLE 1)
  608. add_subdirectory(Utilities/KWIML)
  609. endif()
  610. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  611. # build the utilities (a macro defined in this file)
  612. CMAKE_BUILD_UTILITIES()
  613. # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
  614. # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
  615. # which isn't in the default linker search path. So without RPATH ccmake
  616. # doesn't run and the build doesn't succeed since ccmake is executed for
  617. # generating the documentation.
  618. if(BUILD_CursesDialog)
  619. get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
  620. set(CURSES_NEED_RPATH FALSE)
  621. 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")
  622. set(CURSES_NEED_RPATH TRUE)
  623. endif()
  624. endif()
  625. if(BUILD_QtDialog)
  626. if(APPLE)
  627. set(CMAKE_BUNDLE_VERSION
  628. "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  629. set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
  630. # make sure CMAKE_INSTALL_PREFIX ends in /
  631. if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
  632. set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
  633. endif()
  634. set(CMAKE_INSTALL_PREFIX
  635. "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
  636. endif()
  637. set(QT_NEED_RPATH FALSE)
  638. 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")
  639. set(QT_NEED_RPATH TRUE)
  640. endif()
  641. endif()
  642. # The same might be true on other systems for other libraries.
  643. # Then only enable RPATH if we have are building at least with cmake 2.4,
  644. # since this one has much better RPATH features than cmake 2.2.
  645. # The executables are then built with the RPATH for the libraries outside
  646. # the build tree, which is both the build and the install RPATH.
  647. if (UNIX)
  648. if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
  649. OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
  650. set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
  651. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  652. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  653. endif()
  654. endif ()
  655. # add the uninstall support
  656. configure_file(
  657. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  658. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  659. @ONLY)
  660. add_custom_target(uninstall
  661. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  662. include (CMakeCPack.cmake)
  663. endif()
  664. # setup some Testing support (a macro defined in this file)
  665. CMAKE_SETUP_TESTING()
  666. # Check whether to build server mode or not:
  667. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  668. if(NOT DEFINED CMake_ENABLE_SERVER_MODE)
  669. list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_auto_type CMake_HAVE_CXX_AUTO_TYPE)
  670. list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_range_for CMake_HAVE_CXX_RANGE_FOR)
  671. if(CMAKE_USE_LIBUV
  672. AND CMake_HAVE_CXX_AUTO_TYPE
  673. AND CMake_HAVE_CXX_MAKE_UNIQUE
  674. AND CMake_HAVE_CXX_RANGE_FOR
  675. )
  676. set(CMake_ENABLE_SERVER_MODE 1)
  677. else()
  678. set(CMake_ENABLE_SERVER_MODE 0)
  679. endif()
  680. endif()
  681. if(CMake_ENABLE_SERVER_MODE AND NOT CMAKE_USE_LIBUV)
  682. message(FATAL_ERROR "The server mode requires libuv!")
  683. endif()
  684. else()
  685. set(CMake_ENABLE_SERVER_MODE 0)
  686. endif()
  687. if(NOT DEFINED CMake_TEST_SERVER_MODE)
  688. set(CMake_TEST_SERVER_MODE ${CMake_ENABLE_SERVER_MODE})
  689. endif()
  690. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  691. if(NOT CMake_VERSION_IS_RELEASE)
  692. if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
  693. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
  694. set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
  695. -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
  696. -Wmissing-format-attribute -fno-common -Wundef
  697. )
  698. set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
  699. -Wshadow -Wpointer-arith -Wformat-security -Wundef
  700. )
  701. foreach(FLAG_LANG C CXX)
  702. foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
  703. if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
  704. set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
  705. endif()
  706. endforeach()
  707. endforeach()
  708. unset(C_FLAGS_LIST)
  709. unset(CXX_FLAGS_LIST)
  710. endif()
  711. endif()
  712. # build the remaining subdirectories
  713. add_subdirectory(Source)
  714. add_subdirectory(Utilities)
  715. endif()
  716. add_subdirectory(Tests)
  717. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  718. if(BUILD_TESTING)
  719. CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
  720. endif()
  721. if(TARGET documentation)
  722. CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
  723. endif()
  724. endif()
  725. # add a test
  726. add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
  727. --system-information -G "${CMAKE_GENERATOR}" )
  728. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  729. # Install license file as it requires.
  730. install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
  731. # Install script directories.
  732. install(
  733. DIRECTORY Help Modules Templates
  734. DESTINATION ${CMAKE_DATA_DIR}
  735. FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  736. DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  737. GROUP_READ GROUP_EXECUTE
  738. WORLD_READ WORLD_EXECUTE
  739. PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  740. GROUP_READ GROUP_EXECUTE
  741. WORLD_READ WORLD_EXECUTE
  742. REGEX "Help/dev($|/)" EXCLUDE
  743. )
  744. # Install auxiliary files integrating with other tools.
  745. add_subdirectory(Auxiliary)
  746. endif()