CMakeLists.txt 22 KB

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