CMakeLists.txt 25 KB

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