CMakeLists.txt 29 KB

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