CMakeLists.txt 23 KB

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