CMakeLists.txt 25 KB

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