CMakeLists.txt 30 KB

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