CMakeLists.txt 25 KB

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