CMakeLists.txt 22 KB

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