CMakeLists.txt 25 KB

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