CMakeLists.txt 25 KB

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