CMakeLists.txt 27 KB

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