CMakeLists.txt 29 KB

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