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.

564 lines
21 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
  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.13...3.29 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. # FIXME: This block should go away after a transition period.
  10. if(MSVC AND NOT CMAKE_VERSION VERSION_LESS 3.15)
  11. # Filter out MSVC runtime library flags that may have come from
  12. # the cache of an existing build tree or from scripts.
  13. foreach(l IN ITEMS C CXX)
  14. foreach(c IN ITEMS DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
  15. string(REGEX REPLACE "[-/]M[DT]d?( |$)" "" "CMAKE_${l}_FLAGS_${c}" "${CMAKE_${l}_FLAGS_${c}}")
  16. endforeach()
  17. endforeach()
  18. endif()
  19. # Make sure we can find internal find_package modules only used for
  20. # building CMake and not for shipping externally
  21. list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
  22. if(CMAKE_BOOTSTRAP)
  23. # Running from bootstrap script. Set local variable and remove from cache.
  24. set(CMAKE_BOOTSTRAP 1)
  25. unset(CMAKE_BOOTSTRAP CACHE)
  26. endif()
  27. if(CMake_TEST_HOST_CMAKE)
  28. get_filename_component(CMake_TEST_EXTERNAL_CMAKE "${CMAKE_COMMAND}" DIRECTORY)
  29. endif()
  30. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  31. if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  32. message(FATAL_ERROR
  33. "CMake no longer compiles on HP-UX. See\n"
  34. " https://gitlab.kitware.com/cmake/cmake/-/issues/17137\n"
  35. "Use CMake 3.9 or lower instead."
  36. )
  37. endif()
  38. set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
  39. endif()
  40. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  41. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
  42. set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
  43. else()
  44. set(USE_LGPL "2.1")
  45. endif()
  46. else()
  47. set(USE_LGPL "")
  48. endif()
  49. # Use most-recent available language dialects with GNU and Clang
  50. if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
  51. include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
  52. if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
  53. set(CMAKE_C_STANDARD 11)
  54. else()
  55. set(CMAKE_C_STANDARD 99)
  56. endif()
  57. endif()
  58. if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
  59. if(CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
  60. set(CMAKE_CXX_STANDARD 98)
  61. else()
  62. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
  63. if(NOT CMake_CXX17_BROKEN)
  64. set(CMAKE_CXX_STANDARD 17)
  65. else()
  66. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
  67. if(NOT CMake_CXX14_BROKEN)
  68. set(CMAKE_CXX_STANDARD 14)
  69. else()
  70. set(CMAKE_CXX_STANDARD 11)
  71. endif()
  72. endif()
  73. endif()
  74. endif()
  75. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  76. # include special compile flags for some compilers
  77. include(CompileFlags.cmake)
  78. # check for available C++ features
  79. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
  80. if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
  81. message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
  82. endif()
  83. endif()
  84. # Inform STL library header wrappers whether to use system versions.
  85. configure_file(Utilities/std/cmSTL.hxx.in Utilities/cmSTL.hxx @ONLY)
  86. # set the internal encoding of CMake to UTF-8
  87. set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
  88. # option to use COMPONENT with install command
  89. option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
  90. mark_as_advanced(CMake_INSTALL_COMPONENTS)
  91. macro(CMake_OPTIONAL_COMPONENT NAME)
  92. if(CMake_INSTALL_COMPONENTS)
  93. set(COMPONENT COMPONENT ${NAME})
  94. else()
  95. set(COMPONENT)
  96. endif()
  97. endmacro()
  98. # option to disable installing 3rd-party dependencies
  99. option(CMake_INSTALL_DEPENDENCIES
  100. "Whether to install 3rd-party runtime dependencies" OFF)
  101. mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
  102. # option to build reference for CMake developers
  103. option(CMake_BUILD_DEVELOPER_REFERENCE
  104. "Build CMake Developer Reference" OFF)
  105. mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
  106. # option to build using interprocedural optimizations (IPO/LTO)
  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. option(CMake_BUILD_PCH "Compile CMake with precompiled headers" OFF)
  116. # Check whether to build support for the debugger mode.
  117. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  118. if(NOT DEFINED CMake_ENABLE_DEBUGGER)
  119. # The debugger uses cppdap, which does not compile everywhere.
  120. if(CMAKE_SYSTEM_NAME MATCHES "Windows|Darwin|Linux|BSD|DragonFly|CYGWIN|MSYS"
  121. AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.16)
  122. AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "XLClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.1)
  123. AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "LCC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.23)
  124. )
  125. set(CMake_ENABLE_DEBUGGER 1)
  126. else()
  127. set(CMake_ENABLE_DEBUGGER 0)
  128. endif()
  129. endif()
  130. else()
  131. set(CMake_ENABLE_DEBUGGER 0)
  132. endif()
  133. #-----------------------------------------------------------------------
  134. # a macro to deal with system libraries, implemented as a macro
  135. # simply to improve readability of the main script
  136. #-----------------------------------------------------------------------
  137. macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
  138. include(CMakeDependentOption)
  139. # Allow the user to enable/disable all system utility library options by
  140. # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
  141. set(UTILITIES BZIP2 CPPDAP CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD)
  142. foreach(util IN LISTS UTILITIES)
  143. if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
  144. AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
  145. set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
  146. endif()
  147. if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
  148. if(CMAKE_USE_SYSTEM_LIBRARY_${util})
  149. set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
  150. else()
  151. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  152. endif()
  153. if(CMAKE_BOOTSTRAP)
  154. unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
  155. endif()
  156. string(TOLOWER "${util}" lutil)
  157. set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
  158. CACHE BOOL "Use system-installed ${lutil}" FORCE)
  159. elseif(util STREQUAL "CURL" AND APPLE)
  160. # macOS provides a curl with backends configured by Apple.
  161. set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
  162. else()
  163. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  164. endif()
  165. endforeach()
  166. if(CMAKE_BOOTSTRAP)
  167. unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
  168. endif()
  169. # Optionally use system utility libraries.
  170. option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
  171. if(CMake_ENABLE_DEBUGGER)
  172. option(CMAKE_USE_SYSTEM_CPPDAP "Use system-installed cppdap" "${CMAKE_USE_SYSTEM_LIBRARY_CPPDAP}")
  173. endif()
  174. option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
  175. option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
  176. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
  177. "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
  178. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
  179. "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  180. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd"
  181. "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  182. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
  183. "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  184. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2"
  185. "${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON)
  186. option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
  187. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp"
  188. "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}" "NOT CMAKE_USE_SYSTEM_CPPDAP" ON)
  189. option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
  190. option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
  191. # For now use system KWIML only if explicitly requested rather
  192. # than activating via the general system libs options.
  193. option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
  194. mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
  195. # Mention to the user what system libraries are being used.
  196. if(CMAKE_USE_SYSTEM_CURL)
  197. # Avoid messaging about curl-only dependencies.
  198. list(REMOVE_ITEM UTILITIES NGHTTP2)
  199. endif()
  200. foreach(util IN LISTS UTILITIES ITEMS KWIML)
  201. if(CMAKE_USE_SYSTEM_${util})
  202. message(STATUS "Using system-installed ${util}")
  203. endif()
  204. endforeach()
  205. # Inform utility library header wrappers whether to use system versions.
  206. configure_file(Utilities/cmThirdParty.h.in Utilities/cmThirdParty.h @ONLY)
  207. endmacro()
  208. #-----------------------------------------------------------------------
  209. # a macro to determine the generator and ctest executable to use
  210. # for testing. Simply to improve readability of the main script.
  211. #-----------------------------------------------------------------------
  212. macro(CMAKE_SETUP_TESTING)
  213. if(BUILD_TESTING)
  214. set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
  215. foreach(util IN ITEMS CURL EXPAT ZLIB)
  216. if(CMAKE_USE_SYSTEM_${util})
  217. set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
  218. endif()
  219. endforeach()
  220. # This variable is set by cmake, however to
  221. # test cmake we want to make sure that
  222. # the ctest from this cmake is used for testing
  223. # and not the ctest from the cmake building and testing
  224. # cmake.
  225. if(CMake_TEST_EXTERNAL_CMAKE)
  226. set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
  227. set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
  228. set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
  229. foreach(exe IN ITEMS cmake ctest cpack)
  230. add_executable(${exe} IMPORTED)
  231. set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
  232. endforeach()
  233. else()
  234. set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
  235. set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
  236. set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
  237. endif()
  238. endif()
  239. # configure some files for testing
  240. configure_file(Tests/.NoDartCoverage Tests/.NoDartCoverage)
  241. configure_file(CTestCustom.cmake.in CTestCustom.cmake @ONLY)
  242. endmacro()
  243. # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
  244. # organization feature. Default to ON for non-Express users. Express users must
  245. # explicitly turn off this option to build CMake in the Express IDE...
  246. #
  247. option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
  248. mark_as_advanced(CMAKE_USE_FOLDERS)
  249. option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
  250. if(CMake_RUN_CLANG_TIDY)
  251. if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
  252. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
  253. endif()
  254. find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
  255. if(NOT CLANG_TIDY_COMMAND)
  256. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
  257. endif()
  258. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
  259. option(CMake_USE_CLANG_TIDY_MODULE "Use CMake's clang-tidy module." OFF)
  260. if(CMake_USE_CLANG_TIDY_MODULE)
  261. find_library(CMake_CLANG_TIDY_MODULE NAMES cmake-clang-tidy-module DOC "Location of the clang-tidy module")
  262. if(NOT CMake_CLANG_TIDY_MODULE)
  263. message(FATAL_ERROR "CMake_USE_CLANG_TIDY_MODULE is ON but cmake-clang-tidy-module is not found!")
  264. endif()
  265. list(APPEND CMAKE_CXX_CLANG_TIDY "--load=${CMake_CLANG_TIDY_MODULE}")
  266. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMake_CLANG_TIDY_MODULE}")
  267. endif()
  268. set(CMake_CLANG_TIDY_EXPORT_FIXES_DIR "" CACHE PATH "Directory to put clang-tidy fix files in.")
  269. mark_as_advanced(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
  270. if(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
  271. if(NOT IS_ABSOLUTE "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
  272. message(FATAL_ERROR "CMake_CLANG_TIDY_EXPORT_FIXES_DIR must be an absolute path!")
  273. endif()
  274. set(CMAKE_CXX_CLANG_TIDY_EXPORT_FIXES_DIR "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
  275. endif()
  276. # Create a preprocessor definition that depends on .clang-tidy content so
  277. # the compile command will change when .clang-tidy changes. This ensures
  278. # that a subsequent build re-runs clang-tidy on all sources even if they
  279. # do not otherwise need to be recompiled. Nothing actually uses this
  280. # definition. We add it to targets on which we run clang-tidy just to
  281. # get the build dependency on the .clang-tidy file.
  282. file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
  283. set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
  284. unset(clang_tidy_sha1)
  285. if(CMake_USE_CLANG_TIDY_MODULE)
  286. file(SHA1 "${CMake_CLANG_TIDY_MODULE}" clang_tidy_module_sha1)
  287. list(APPEND CLANG_TIDY_DEFINITIONS "CLANG_TIDY_MODULE_SHA1=${clang_tidy_module_sha1}")
  288. unset(clang_tidy_module_sha1)
  289. endif()
  290. endif()
  291. configure_file(.clang-tidy .clang-tidy COPYONLY)
  292. option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
  293. if(CMake_RUN_IWYU)
  294. if(CMake_BUILD_PCH)
  295. message(FATAL_ERROR "CMake_RUN_IWYU and CMake_BUILD_PCH are ON, but they are incompatible!")
  296. endif()
  297. find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
  298. if(NOT IWYU_COMMAND)
  299. message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
  300. endif()
  301. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  302. "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
  303. option(CMake_IWYU_VERBOSE "Run include-what-you-use in verbose mode" OFF)
  304. if (CMake_IWYU_VERBOSE)
  305. list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  306. -Xiwyu -v7)
  307. endif ()
  308. list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
  309. endif()
  310. #-----------------------------------------------------------------------
  311. # a macro that only sets the FOLDER target property if it's
  312. # "appropriate"
  313. #-----------------------------------------------------------------------
  314. macro(CMAKE_SET_TARGET_FOLDER tgt folder)
  315. if(CMAKE_USE_FOLDERS)
  316. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  317. if(MSVC AND TARGET ${tgt})
  318. set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
  319. endif()
  320. else()
  321. set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
  322. endif()
  323. endmacro()
  324. #-----------------------------------------------------------------------
  325. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  326. if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
  327. execute_process(COMMAND ${CMAKE_CXX_COMPILER}
  328. ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
  329. OUTPUT_VARIABLE _GXX_VERSION
  330. )
  331. string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
  332. _GXX_VERSION_SHORT ${_GXX_VERSION})
  333. if(_GXX_VERSION_SHORT EQUAL 33)
  334. message(FATAL_ERROR
  335. "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
  336. "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
  337. "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
  338. endif()
  339. endif()
  340. endif()
  341. #-----------------------------------------------------------------------
  342. # The main section of the CMakeLists file
  343. #
  344. #-----------------------------------------------------------------------
  345. include(Source/CMakeVersion.cmake)
  346. include(CTest)
  347. # Set up test-time configuration.
  348. set_directory_properties(PROPERTIES
  349. TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
  350. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  351. # where to write the resulting executables and libraries
  352. set(BUILD_SHARED_LIBS OFF)
  353. set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
  354. set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
  355. "Where to put the libraries for CMake")
  356. # Load install destinations.
  357. include(Source/CMakeInstallDestinations.cmake)
  358. if(BUILD_TESTING)
  359. include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
  360. endif()
  361. # Checks for cmSystemTools.
  362. if(WIN32)
  363. set(HAVE_UNSETENV 0)
  364. set(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE 1)
  365. else()
  366. include(CheckSymbolExists)
  367. CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
  368. CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
  369. endif()
  370. endif()
  371. # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
  372. #
  373. # If not defined or "", this variable defaults to the server at
  374. # "http://open.cdash.org".
  375. #
  376. # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
  377. # the network are skipped.
  378. #
  379. # If set to something starting with "http://localhost/", the CDash is
  380. # expected to be an instance of CDash used for CDash testing, pointing
  381. # to a cdash4simpletest database. In these cases, the CDash dashboards
  382. # should be run first.
  383. #
  384. if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x" AND NOT CMake_TEST_NO_NETWORK)
  385. set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
  386. endif()
  387. if(CMake_TEST_EXTERNAL_CMAKE)
  388. set(KWIML_TEST_ENABLE 1)
  389. add_subdirectory(Utilities/KWIML)
  390. endif()
  391. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  392. find_package(Threads)
  393. # build the utilities
  394. include(CMakeBuildUtilities)
  395. if(BUILD_QtDialog)
  396. if(APPLE)
  397. set(CMAKE_BUNDLE_VERSION
  398. "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  399. set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
  400. # make sure CMAKE_INSTALL_PREFIX ends in /
  401. if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
  402. string(APPEND CMAKE_INSTALL_PREFIX "/")
  403. endif()
  404. string(APPEND CMAKE_INSTALL_PREFIX "CMake.app/Contents")
  405. endif()
  406. endif()
  407. if(UNIX)
  408. # Install executables with the RPATH set for libraries outside the build tree.
  409. # This is also suitable for binaries in the build tree. Avoid re-link on install.
  410. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE BOOL "Install with RPATH set to find custom-built libraries.")
  411. set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Build with RPATH set to match install-tree RPATH.")
  412. mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_BUILD_WITH_INSTALL_RPATH)
  413. endif()
  414. # add the uninstall support
  415. configure_file(cmake_uninstall.cmake.in cmake_uninstall.cmake @ONLY)
  416. add_custom_target(uninstall
  417. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  418. include(CMakeCPack.cmake)
  419. endif()
  420. # setup some Testing support (a macro defined in this file)
  421. CMAKE_SETUP_TESTING()
  422. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  423. if(NOT CMake_VERSION_IS_RELEASE)
  424. if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
  425. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) OR
  426. (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
  427. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 3.0 AND
  428. NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") OR
  429. CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR
  430. CMAKE_C_COMPILER_ID STREQUAL "LCC")
  431. set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
  432. -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
  433. -Wmissing-format-attribute -fno-common -Wundef
  434. )
  435. set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
  436. -Wshadow -Wpointer-arith -Wformat-security -Wundef
  437. )
  438. foreach(FLAG_LANG IN ITEMS C CXX)
  439. foreach(FLAG IN LISTS ${FLAG_LANG}_FLAGS_LIST)
  440. if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
  441. string(APPEND CMAKE_${FLAG_LANG}_FLAGS " ${FLAG}")
  442. endif()
  443. endforeach()
  444. endforeach()
  445. unset(C_FLAGS_LIST)
  446. unset(CXX_FLAGS_LIST)
  447. endif()
  448. endif()
  449. # build the remaining subdirectories
  450. add_subdirectory(Source)
  451. add_subdirectory(Utilities)
  452. endif()
  453. add_subdirectory(Tests)
  454. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  455. if(BUILD_TESTING)
  456. CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
  457. endif()
  458. if(TARGET documentation)
  459. CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
  460. endif()
  461. endif()
  462. if(BUILD_TESTING)
  463. add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
  464. --system-information -G "${CMAKE_GENERATOR}"
  465. )
  466. endif()
  467. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  468. # Install license file as it requires.
  469. install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
  470. # Install script directories.
  471. install(
  472. DIRECTORY Help Modules Templates
  473. DESTINATION ${CMAKE_DATA_DIR}
  474. FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  475. DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  476. GROUP_READ GROUP_EXECUTE
  477. WORLD_READ WORLD_EXECUTE
  478. PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  479. GROUP_READ GROUP_EXECUTE
  480. WORLD_READ WORLD_EXECUTE
  481. REGEX "/(ExportImportList|cpp)$"
  482. PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  483. GROUP_READ GROUP_EXECUTE
  484. WORLD_READ WORLD_EXECUTE
  485. REGEX "Help/(dev|guide)($|/)" EXCLUDE
  486. )
  487. # Install auxiliary files integrating with other tools.
  488. add_subdirectory(Auxiliary)
  489. # Optionally sign installed binaries.
  490. if(CMake_INSTALL_SIGNTOOL)
  491. configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
  492. install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)
  493. endif()
  494. endif()