CMakeLists.txt 30 KB

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