CMakeLists.txt 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
  4. set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideC.cmake)
  5. set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideCXX.cmake)
  6. project(CMake)
  7. unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
  8. unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
  9. # Make sure we can find internal find_package modules only used for
  10. # building CMake and not for shipping externally
  11. list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
  12. if(CMAKE_BOOTSTRAP)
  13. # Running from bootstrap script. Set local variable and remove from cache.
  14. set(CMAKE_BOOTSTRAP 1)
  15. unset(CMAKE_BOOTSTRAP CACHE)
  16. endif()
  17. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  18. if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  19. message(FATAL_ERROR
  20. "CMake no longer compiles on HP-UX. See\n"
  21. " https://gitlab.kitware.com/cmake/cmake/issues/17137\n"
  22. "Use CMake 3.9 or lower instead."
  23. )
  24. endif()
  25. set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
  26. endif()
  27. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  28. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
  29. set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
  30. else()
  31. set(USE_LGPL "2.1")
  32. endif()
  33. else()
  34. set(USE_LGPL "")
  35. endif()
  36. if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
  37. # Disallow architecture-specific try_run. It may not run on the host.
  38. macro(TRY_RUN)
  39. if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
  40. message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
  41. else()
  42. _TRY_RUN(${ARGV})
  43. endif()
  44. endmacro()
  45. endif()
  46. # Use most-recent available language dialects with GNU and Clang
  47. if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
  48. include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
  49. if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
  50. set(CMAKE_C_STANDARD 11)
  51. else()
  52. set(CMAKE_C_STANDARD 99)
  53. endif()
  54. endif()
  55. if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
  56. if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
  57. set(CMAKE_CXX_STANDARD 98)
  58. else()
  59. if(NOT CMAKE_VERSION VERSION_LESS 3.8)
  60. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
  61. else()
  62. set(CMake_CXX17_BROKEN 1)
  63. endif()
  64. if(NOT CMake_CXX17_BROKEN)
  65. set(CMAKE_CXX_STANDARD 17)
  66. else()
  67. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
  68. if(NOT CMake_CXX14_BROKEN)
  69. set(CMAKE_CXX_STANDARD 14)
  70. else()
  71. set(CMAKE_CXX_STANDARD 11)
  72. endif()
  73. endif()
  74. endif()
  75. endif()
  76. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  77. # include special compile flags for some compilers
  78. include(CompileFlags.cmake)
  79. # check for available C++ features
  80. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
  81. if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
  82. message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
  83. endif()
  84. endif()
  85. # set the internal encoding of CMake to UTF-8
  86. set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
  87. # option to use COMPONENT with install command
  88. option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
  89. mark_as_advanced(CMake_INSTALL_COMPONENTS)
  90. macro(CMake_OPTIONAL_COMPONENT NAME)
  91. if(CMake_INSTALL_COMPONENTS)
  92. set(COMPONENT COMPONENT ${NAME})
  93. else()
  94. set(COMPONENT)
  95. endif()
  96. endmacro()
  97. # option to disable installing 3rd-party dependencies
  98. option(CMake_INSTALL_DEPENDENCIES
  99. "Whether to install 3rd-party runtime dependencies" OFF)
  100. mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
  101. # option to build reference for CMake developers
  102. option(CMake_BUILD_DEVELOPER_REFERENCE
  103. "Build CMake Developer Reference" OFF)
  104. mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
  105. #-----------------------------------------------------------------------
  106. # a macro to deal with system libraries, implemented as a macro
  107. # simply to improve readability of the main script
  108. #-----------------------------------------------------------------------
  109. macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
  110. # Options have dependencies.
  111. include(CMakeDependentOption)
  112. # Optionally use system xmlrpc. We no longer build or use it by default.
  113. option(CTEST_USE_XMLRPC "Enable xmlrpc submission method in CTest." OFF)
  114. mark_as_advanced(CTEST_USE_XMLRPC)
  115. # Allow the user to enable/disable all system utility library options by
  116. # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
  117. set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB)
  118. foreach(util ${UTILITIES})
  119. if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
  120. AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
  121. set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
  122. endif()
  123. if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
  124. if(CMAKE_USE_SYSTEM_LIBRARY_${util})
  125. set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
  126. else()
  127. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  128. endif()
  129. if(CMAKE_BOOTSTRAP)
  130. unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
  131. endif()
  132. string(TOLOWER "${util}" lutil)
  133. set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
  134. CACHE BOOL "Use system-installed ${lutil}" FORCE)
  135. else()
  136. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  137. endif()
  138. endforeach()
  139. if(CMAKE_BOOTSTRAP)
  140. unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
  141. endif()
  142. # Optionally use system utility libraries.
  143. option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
  144. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_CURL "Use system-installed curl"
  145. "${CMAKE_USE_SYSTEM_LIBRARY_CURL}" "NOT CTEST_USE_XMLRPC" ON)
  146. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat"
  147. "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}" "NOT CTEST_USE_XMLRPC" ON)
  148. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
  149. "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
  150. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
  151. "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  152. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
  153. "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  154. option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
  155. option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
  156. option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
  157. option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
  158. # For now use system KWIML only if explicitly requested rather
  159. # than activating via the general system libs options.
  160. option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
  161. mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
  162. # Mention to the user what system libraries are being used.
  163. foreach(util ${UTILITIES} KWIML)
  164. if(CMAKE_USE_SYSTEM_${util})
  165. message(STATUS "Using system-installed ${util}")
  166. endif()
  167. endforeach()
  168. # Inform utility library header wrappers whether to use system versions.
  169. configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
  170. ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
  171. @ONLY)
  172. endmacro()
  173. #-----------------------------------------------------------------------
  174. # a macro to determine the generator and ctest executable to use
  175. # for testing. Simply to improve readability of the main script.
  176. #-----------------------------------------------------------------------
  177. macro(CMAKE_SETUP_TESTING)
  178. if(BUILD_TESTING)
  179. set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
  180. foreach(util CURL EXPAT XMLRPC ZLIB)
  181. if(CMAKE_USE_SYSTEM_${util})
  182. set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
  183. endif()
  184. endforeach()
  185. # This variable is set by cmake, however to
  186. # test cmake we want to make sure that
  187. # the ctest from this cmake is used for testing
  188. # and not the ctest from the cmake building and testing
  189. # cmake.
  190. if(CMake_TEST_EXTERNAL_CMAKE)
  191. set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
  192. set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
  193. set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
  194. foreach(exe cmake ctest cpack)
  195. add_executable(${exe} IMPORTED)
  196. set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
  197. endforeach()
  198. else()
  199. set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
  200. set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
  201. set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
  202. endif()
  203. endif()
  204. # configure some files for testing
  205. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
  206. "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
  207. @ONLY)
  208. configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
  209. ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
  210. configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
  211. ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
  212. configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
  213. ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
  214. if(BUILD_TESTING AND DART_ROOT)
  215. configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
  216. ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
  217. endif()
  218. mark_as_advanced(DART_ROOT)
  219. mark_as_advanced(CURL_TESTING)
  220. endmacro()
  221. # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
  222. # organization feature. Default to ON for non-Express users. Express users must
  223. # explicitly turn off this option to build CMake in the Express IDE...
  224. #
  225. option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
  226. mark_as_advanced(CMAKE_USE_FOLDERS)
  227. option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
  228. if(CMake_RUN_CLANG_TIDY)
  229. if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
  230. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
  231. endif()
  232. find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
  233. if(NOT CLANG_TIDY_COMMAND)
  234. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
  235. endif()
  236. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
  237. # Create a preprocessor definition that depends on .clang-tidy content so
  238. # the compile command will change when .clang-tidy changes. This ensures
  239. # that a subsequent build re-runs clang-tidy on all sources even if they
  240. # do not otherwise need to be recompiled. Nothing actually uses this
  241. # definition. We add it to targets on which we run clang-tidy just to
  242. # get the build dependency on the .clang-tidy file.
  243. file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
  244. set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
  245. unset(clang_tidy_sha1)
  246. endif()
  247. configure_file(.clang-tidy .clang-tidy COPYONLY)
  248. option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
  249. if(CMake_RUN_IWYU)
  250. find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
  251. if(NOT IWYU_COMMAND)
  252. message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
  253. endif()
  254. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  255. "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
  256. endif()
  257. #-----------------------------------------------------------------------
  258. # a macro that only sets the FOLDER target property if it's
  259. # "appropriate"
  260. #-----------------------------------------------------------------------
  261. macro(CMAKE_SET_TARGET_FOLDER tgt folder)
  262. if(CMAKE_USE_FOLDERS)
  263. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  264. if(MSVC AND TARGET ${tgt})
  265. set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
  266. endif()
  267. else()
  268. set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
  269. endif()
  270. endmacro()
  271. #-----------------------------------------------------------------------
  272. # a macro to build the utilities used by CMake
  273. # Simply to improve readability of the main script.
  274. #-----------------------------------------------------------------------
  275. macro (CMAKE_BUILD_UTILITIES)
  276. find_package(Threads)
  277. #---------------------------------------------------------------------
  278. # Create the kwsys library for CMake.
  279. set(KWSYS_NAMESPACE cmsys)
  280. set(KWSYS_USE_SystemTools 1)
  281. set(KWSYS_USE_Directory 1)
  282. set(KWSYS_USE_RegularExpression 1)
  283. set(KWSYS_USE_Base64 1)
  284. set(KWSYS_USE_MD5 1)
  285. set(KWSYS_USE_Process 1)
  286. set(KWSYS_USE_CommandLineArguments 1)
  287. set(KWSYS_USE_ConsoleBuf 1)
  288. set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
  289. set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
  290. add_subdirectory(Source/kwsys)
  291. set(kwsys_folder "Utilities/KWSys")
  292. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
  293. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
  294. if(BUILD_TESTING)
  295. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
  296. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
  297. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
  298. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
  299. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
  300. endif()
  301. #---------------------------------------------------------------------
  302. # Setup third-party libraries.
  303. # Everything in the tree should be able to include files from the
  304. # Utilities directory.
  305. include_directories(
  306. ${CMake_BINARY_DIR}/Utilities
  307. ${CMake_SOURCE_DIR}/Utilities
  308. )
  309. # check for the use of system libraries versus builtin ones
  310. # (a macro defined in this file)
  311. CMAKE_HANDLE_SYSTEM_LIBRARIES()
  312. if(CMAKE_USE_SYSTEM_KWIML)
  313. find_package(KWIML 1.0)
  314. if(NOT KWIML_FOUND)
  315. message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
  316. endif()
  317. set(CMake_KWIML_LIBRARIES kwiml::kwiml)
  318. else()
  319. set(CMake_KWIML_LIBRARIES "")
  320. if(BUILD_TESTING)
  321. set(KWIML_TEST_ENABLE 1)
  322. endif()
  323. add_subdirectory(Utilities/KWIML)
  324. endif()
  325. if(CMAKE_USE_SYSTEM_LIBRHASH)
  326. find_package(LibRHash)
  327. if(NOT LibRHash_FOUND)
  328. message(FATAL_ERROR
  329. "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
  330. endif()
  331. set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
  332. else()
  333. set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
  334. add_subdirectory(Utilities/cmlibrhash)
  335. CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
  336. endif()
  337. #---------------------------------------------------------------------
  338. # Build zlib library for Curl, CMake, and CTest.
  339. set(CMAKE_ZLIB_HEADER "cm_zlib.h")
  340. if(CMAKE_USE_SYSTEM_ZLIB)
  341. find_package(ZLIB)
  342. if(NOT ZLIB_FOUND)
  343. message(FATAL_ERROR
  344. "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
  345. endif()
  346. set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
  347. set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
  348. else()
  349. set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
  350. set(CMAKE_ZLIB_LIBRARIES cmzlib)
  351. add_subdirectory(Utilities/cmzlib)
  352. CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
  353. endif()
  354. #---------------------------------------------------------------------
  355. # Build Curl library for CTest.
  356. if(CMAKE_USE_SYSTEM_CURL)
  357. find_package(CURL)
  358. if(NOT CURL_FOUND)
  359. message(FATAL_ERROR
  360. "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
  361. endif()
  362. set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
  363. set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
  364. else()
  365. set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
  366. set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
  367. set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
  368. add_definitions(-DCURL_STATICLIB)
  369. set(CMAKE_CURL_INCLUDES)
  370. set(CMAKE_CURL_LIBRARIES cmcurl)
  371. if(CMAKE_TESTS_CDASH_SERVER)
  372. set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
  373. endif()
  374. set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
  375. if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
  376. AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
  377. find_package(OpenSSL QUIET)
  378. if(OPENSSL_FOUND)
  379. set(_CMAKE_USE_OPENSSL_DEFAULT ON)
  380. endif()
  381. endif()
  382. option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
  383. mark_as_advanced(CMAKE_USE_OPENSSL)
  384. if(CMAKE_USE_OPENSSL)
  385. set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
  386. set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
  387. mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
  388. endif()
  389. add_subdirectory(Utilities/cmcurl)
  390. CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
  391. CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
  392. endif()
  393. #---------------------------------------------------------------------
  394. # Build Compress library for CTest.
  395. set(CMAKE_COMPRESS_INCLUDES
  396. "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
  397. set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
  398. add_subdirectory(Utilities/cmcompress)
  399. CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
  400. #---------------------------------------------------------------------
  401. # Build expat library for CMake, CTest, and libarchive.
  402. if(CMAKE_USE_SYSTEM_EXPAT)
  403. find_package(EXPAT)
  404. if(NOT EXPAT_FOUND)
  405. message(FATAL_ERROR
  406. "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
  407. endif()
  408. set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
  409. set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
  410. else()
  411. set(CMAKE_EXPAT_INCLUDES)
  412. set(CMAKE_EXPAT_LIBRARIES cmexpat)
  413. add_subdirectory(Utilities/cmexpat)
  414. CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
  415. endif()
  416. #---------------------------------------------------------------------
  417. # Build or use system libbz2 for libarchive.
  418. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  419. if(CMAKE_USE_SYSTEM_BZIP2)
  420. find_package(BZip2)
  421. else()
  422. set(BZIP2_INCLUDE_DIR
  423. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
  424. set(BZIP2_LIBRARIES cmbzip2)
  425. add_subdirectory(Utilities/cmbzip2)
  426. CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
  427. endif()
  428. endif()
  429. #---------------------------------------------------------------------
  430. # Build or use system liblzma for libarchive.
  431. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  432. if(CMAKE_USE_SYSTEM_LIBLZMA)
  433. find_package(LibLZMA)
  434. if(NOT LIBLZMA_FOUND)
  435. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
  436. endif()
  437. else()
  438. add_subdirectory(Utilities/cmliblzma)
  439. CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
  440. set(LIBLZMA_HAS_AUTO_DECODER 1)
  441. set(LIBLZMA_HAS_EASY_ENCODER 1)
  442. set(LIBLZMA_HAS_LZMA_PRESET 1)
  443. set(LIBLZMA_INCLUDE_DIR
  444. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
  445. set(LIBLZMA_LIBRARY cmliblzma)
  446. endif()
  447. endif()
  448. #---------------------------------------------------------------------
  449. # Build or use system libarchive for CMake and CTest.
  450. if(CMAKE_USE_SYSTEM_LIBARCHIVE)
  451. find_package(LibArchive 3.0.0)
  452. if(NOT LibArchive_FOUND)
  453. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
  454. endif()
  455. set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
  456. set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
  457. else()
  458. set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
  459. set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
  460. set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
  461. set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
  462. add_definitions(-DLIBARCHIVE_STATIC)
  463. set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
  464. set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
  465. set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
  466. set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
  467. set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
  468. set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
  469. set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
  470. set(ENABLE_EXPAT ON CACHE INTERNAL "Enable the use of the system EXPAT library if found")
  471. set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
  472. set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
  473. set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
  474. set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
  475. set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
  476. set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
  477. add_subdirectory(Utilities/cmlibarchive)
  478. CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
  479. set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
  480. endif()
  481. #---------------------------------------------------------------------
  482. # Build jsoncpp library.
  483. if(CMAKE_USE_SYSTEM_JSONCPP)
  484. find_package(JsonCpp)
  485. if(NOT JsonCpp_FOUND)
  486. message(FATAL_ERROR
  487. "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
  488. endif()
  489. set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
  490. else()
  491. set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
  492. add_subdirectory(Utilities/cmjsoncpp)
  493. CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
  494. endif()
  495. #---------------------------------------------------------------------
  496. # Build libuv library.
  497. if(CMAKE_USE_SYSTEM_LIBUV)
  498. find_package(LibUV 1.0.0)
  499. if(NOT LIBUV_FOUND)
  500. message(FATAL_ERROR
  501. "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
  502. endif()
  503. set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
  504. else()
  505. set(CMAKE_LIBUV_LIBRARIES cmlibuv)
  506. add_subdirectory(Utilities/cmlibuv)
  507. CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
  508. endif()
  509. #---------------------------------------------------------------------
  510. # Build XMLRPC library for CMake and CTest.
  511. if(CTEST_USE_XMLRPC)
  512. find_package(XMLRPC QUIET REQUIRED libwww-client)
  513. if(NOT XMLRPC_FOUND)
  514. message(FATAL_ERROR
  515. "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
  516. endif()
  517. set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
  518. set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
  519. endif()
  520. #---------------------------------------------------------------------
  521. # Use curses?
  522. if (UNIX)
  523. # there is a bug in the Syllable libraries which makes linking ccmake fail, Alex
  524. if(NOT CMAKE_SYSTEM_NAME MATCHES syllable)
  525. set(CURSES_NEED_NCURSES TRUE)
  526. find_package(Curses QUIET)
  527. if (CURSES_LIBRARY)
  528. option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" ON)
  529. else ()
  530. message("Curses libraries were not found. Curses GUI for CMake will not be built.")
  531. set(BUILD_CursesDialog 0)
  532. endif ()
  533. else()
  534. set(BUILD_CursesDialog 0)
  535. endif()
  536. else ()
  537. set(BUILD_CursesDialog 0)
  538. endif ()
  539. if(BUILD_CursesDialog)
  540. if(NOT CMAKE_USE_SYSTEM_FORM)
  541. add_subdirectory(Source/CursesDialog/form)
  542. elseif(NOT CURSES_FORM_LIBRARY)
  543. message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
  544. endif()
  545. endif()
  546. endmacro ()
  547. #-----------------------------------------------------------------------
  548. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  549. if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
  550. execute_process(COMMAND ${CMAKE_CXX_COMPILER}
  551. ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
  552. OUTPUT_VARIABLE _GXX_VERSION
  553. )
  554. string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
  555. _GXX_VERSION_SHORT ${_GXX_VERSION})
  556. if(_GXX_VERSION_SHORT EQUAL 33)
  557. message(FATAL_ERROR
  558. "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
  559. "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
  560. "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
  561. endif()
  562. endif()
  563. endif()
  564. #-----------------------------------------------------------------------
  565. # The main section of the CMakeLists file
  566. #
  567. #-----------------------------------------------------------------------
  568. # Compute CMake_VERSION, etc.
  569. include(Source/CMakeVersionCompute.cmake)
  570. # Include the standard Dart testing module
  571. enable_testing()
  572. include (${CMAKE_ROOT}/Modules/Dart.cmake)
  573. # Set up test-time configuration.
  574. set_directory_properties(PROPERTIES
  575. TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
  576. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  577. # where to write the resulting executables and libraries
  578. set(BUILD_SHARED_LIBS OFF)
  579. set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
  580. set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
  581. "Where to put the libraries for CMake")
  582. # The CMake executables usually do not need any rpath to run in the build or
  583. # install tree.
  584. set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
  585. # Load install destinations.
  586. include(Source/CMakeInstallDestinations.cmake)
  587. if(BUILD_TESTING)
  588. include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
  589. endif()
  590. # no clue why we are testing for this here
  591. include(CheckSymbolExists)
  592. CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
  593. CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
  594. endif()
  595. # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
  596. #
  597. # If not defined or "", this variable defaults to the server at
  598. # "http://open.cdash.org".
  599. #
  600. # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
  601. # the network are skipped.
  602. #
  603. # If set to something starting with "http://localhost/", the CDash is
  604. # expected to be an instance of CDash used for CDash testing, pointing
  605. # to a cdash4simpletest database. In these cases, the CDash dashboards
  606. # should be run first.
  607. #
  608. if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
  609. set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
  610. endif()
  611. if(CMake_TEST_EXTERNAL_CMAKE)
  612. set(KWIML_TEST_ENABLE 1)
  613. add_subdirectory(Utilities/KWIML)
  614. endif()
  615. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  616. # build the utilities (a macro defined in this file)
  617. CMAKE_BUILD_UTILITIES()
  618. # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
  619. # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
  620. # which isn't in the default linker search path. So without RPATH ccmake
  621. # doesn't run and the build doesn't succeed since ccmake is executed for
  622. # generating the documentation.
  623. if(BUILD_CursesDialog)
  624. get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
  625. set(CURSES_NEED_RPATH FALSE)
  626. 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")
  627. set(CURSES_NEED_RPATH TRUE)
  628. endif()
  629. endif()
  630. if(BUILD_QtDialog)
  631. if(APPLE)
  632. set(CMAKE_BUNDLE_VERSION
  633. "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  634. set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
  635. # make sure CMAKE_INSTALL_PREFIX ends in /
  636. if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
  637. set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
  638. endif()
  639. set(CMAKE_INSTALL_PREFIX
  640. "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
  641. endif()
  642. set(QT_NEED_RPATH FALSE)
  643. 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")
  644. set(QT_NEED_RPATH TRUE)
  645. endif()
  646. endif()
  647. # The same might be true on other systems for other libraries.
  648. # Then only enable RPATH if we have are building at least with cmake 2.4,
  649. # since this one has much better RPATH features than cmake 2.2.
  650. # The executables are then built with the RPATH for the libraries outside
  651. # the build tree, which is both the build and the install RPATH.
  652. if (UNIX)
  653. if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
  654. OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
  655. set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
  656. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  657. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  658. endif()
  659. endif ()
  660. # add the uninstall support
  661. configure_file(
  662. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  663. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  664. @ONLY)
  665. add_custom_target(uninstall
  666. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  667. include (CMakeCPack.cmake)
  668. endif()
  669. # setup some Testing support (a macro defined in this file)
  670. CMAKE_SETUP_TESTING()
  671. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  672. if(NOT CMake_VERSION_IS_RELEASE)
  673. if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
  674. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
  675. set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
  676. -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
  677. -Wmissing-format-attribute -fno-common -Wundef
  678. )
  679. set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
  680. -Wshadow -Wpointer-arith -Wformat-security -Wundef
  681. )
  682. foreach(FLAG_LANG C CXX)
  683. foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
  684. if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
  685. set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
  686. endif()
  687. endforeach()
  688. endforeach()
  689. unset(C_FLAGS_LIST)
  690. unset(CXX_FLAGS_LIST)
  691. endif()
  692. endif()
  693. # build the remaining subdirectories
  694. add_subdirectory(Source)
  695. add_subdirectory(Utilities)
  696. endif()
  697. add_subdirectory(Tests)
  698. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  699. if(BUILD_TESTING)
  700. CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
  701. IF(TARGET CMakeServerLibTests)
  702. CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
  703. ENDIF()
  704. endif()
  705. if(TARGET documentation)
  706. CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
  707. endif()
  708. endif()
  709. # add a test
  710. add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
  711. --system-information -G "${CMAKE_GENERATOR}" )
  712. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  713. # Install license file as it requires.
  714. install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
  715. # Install script directories.
  716. install(
  717. DIRECTORY Help Modules Templates
  718. DESTINATION ${CMAKE_DATA_DIR}
  719. FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  720. DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  721. GROUP_READ GROUP_EXECUTE
  722. WORLD_READ WORLD_EXECUTE
  723. PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  724. GROUP_READ GROUP_EXECUTE
  725. WORLD_READ WORLD_EXECUTE
  726. REGEX "Help/dev($|/)" EXCLUDE
  727. )
  728. # Install auxiliary files integrating with other tools.
  729. add_subdirectory(Auxiliary)
  730. endif()