CMakeLists.txt 29 KB

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