You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

831 lines
31 KiB

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