CMakeLists.txt 26 KB

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