CMakeLists.txt 30 KB

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