CMakeLists.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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.28 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. else()
  160. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  161. endif()
  162. endforeach()
  163. if(CMAKE_BOOTSTRAP)
  164. unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
  165. endif()
  166. # Optionally use system utility libraries.
  167. option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
  168. if(CMake_ENABLE_DEBUGGER)
  169. option(CMAKE_USE_SYSTEM_CPPDAP "Use system-installed cppdap" "${CMAKE_USE_SYSTEM_LIBRARY_CPPDAP}")
  170. endif()
  171. option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
  172. option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
  173. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
  174. "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
  175. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
  176. "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  177. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd"
  178. "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  179. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
  180. "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  181. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2"
  182. "${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON)
  183. option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
  184. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp"
  185. "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}" "NOT CMAKE_USE_SYSTEM_CPPDAP" ON)
  186. option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
  187. option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
  188. # For now use system KWIML only if explicitly requested rather
  189. # than activating via the general system libs options.
  190. option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
  191. mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
  192. # Mention to the user what system libraries are being used.
  193. foreach(util IN LISTS UTILITIES ITEMS KWIML)
  194. if(CMAKE_USE_SYSTEM_${util})
  195. message(STATUS "Using system-installed ${util}")
  196. endif()
  197. endforeach()
  198. # Inform utility library header wrappers whether to use system versions.
  199. configure_file(Utilities/cmThirdParty.h.in Utilities/cmThirdParty.h @ONLY)
  200. endmacro()
  201. #-----------------------------------------------------------------------
  202. # a macro to determine the generator and ctest executable to use
  203. # for testing. Simply to improve readability of the main script.
  204. #-----------------------------------------------------------------------
  205. macro(CMAKE_SETUP_TESTING)
  206. if(BUILD_TESTING)
  207. set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
  208. foreach(util IN ITEMS CURL EXPAT ZLIB)
  209. if(CMAKE_USE_SYSTEM_${util})
  210. set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
  211. endif()
  212. endforeach()
  213. # This variable is set by cmake, however to
  214. # test cmake we want to make sure that
  215. # the ctest from this cmake is used for testing
  216. # and not the ctest from the cmake building and testing
  217. # cmake.
  218. if(CMake_TEST_EXTERNAL_CMAKE)
  219. set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
  220. set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
  221. set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
  222. foreach(exe IN ITEMS cmake ctest cpack)
  223. add_executable(${exe} IMPORTED)
  224. set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
  225. endforeach()
  226. else()
  227. set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
  228. set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
  229. set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
  230. endif()
  231. endif()
  232. # configure some files for testing
  233. configure_file(Templates/CTestScript.cmake.in CTestScript.cmake @ONLY)
  234. configure_file(Tests/.NoDartCoverage Tests/.NoDartCoverage)
  235. configure_file(Tests/.NoDartCoverage Modules/.NoDartCoverage)
  236. configure_file(CTestCustom.cmake.in CTestCustom.cmake @ONLY)
  237. endmacro()
  238. # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
  239. # organization feature. Default to ON for non-Express users. Express users must
  240. # explicitly turn off this option to build CMake in the Express IDE...
  241. #
  242. option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
  243. mark_as_advanced(CMAKE_USE_FOLDERS)
  244. option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
  245. if(CMake_RUN_CLANG_TIDY)
  246. if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
  247. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
  248. endif()
  249. find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
  250. if(NOT CLANG_TIDY_COMMAND)
  251. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
  252. endif()
  253. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
  254. option(CMake_USE_CLANG_TIDY_MODULE "Use CMake's clang-tidy module." OFF)
  255. if(CMake_USE_CLANG_TIDY_MODULE)
  256. find_library(CMake_CLANG_TIDY_MODULE NAMES cmake-clang-tidy-module DOC "Location of the clang-tidy module")
  257. if(NOT CMake_CLANG_TIDY_MODULE)
  258. message(FATAL_ERROR "CMake_USE_CLANG_TIDY_MODULE is ON but cmake-clang-tidy-module is not found!")
  259. endif()
  260. list(APPEND CMAKE_CXX_CLANG_TIDY "--load=${CMake_CLANG_TIDY_MODULE}")
  261. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMake_CLANG_TIDY_MODULE}")
  262. endif()
  263. set(CMake_CLANG_TIDY_EXPORT_FIXES_DIR "" CACHE PATH "Directory to put clang-tidy fix files in.")
  264. mark_as_advanced(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
  265. if(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
  266. if(NOT IS_ABSOLUTE "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
  267. message(FATAL_ERROR "CMake_CLANG_TIDY_EXPORT_FIXES_DIR must be an absolute path!")
  268. endif()
  269. set(CMAKE_CXX_CLANG_TIDY_EXPORT_FIXES_DIR "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
  270. endif()
  271. # Create a preprocessor definition that depends on .clang-tidy content so
  272. # the compile command will change when .clang-tidy changes. This ensures
  273. # that a subsequent build re-runs clang-tidy on all sources even if they
  274. # do not otherwise need to be recompiled. Nothing actually uses this
  275. # definition. We add it to targets on which we run clang-tidy just to
  276. # get the build dependency on the .clang-tidy file.
  277. file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
  278. set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
  279. unset(clang_tidy_sha1)
  280. if(CMake_USE_CLANG_TIDY_MODULE)
  281. file(SHA1 "${CMake_CLANG_TIDY_MODULE}" clang_tidy_module_sha1)
  282. list(APPEND CLANG_TIDY_DEFINITIONS "CLANG_TIDY_MODULE_SHA1=${clang_tidy_module_sha1}")
  283. unset(clang_tidy_module_sha1)
  284. endif()
  285. endif()
  286. configure_file(.clang-tidy .clang-tidy COPYONLY)
  287. option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
  288. if(CMake_RUN_IWYU)
  289. if(CMake_BUILD_PCH)
  290. message(FATAL_ERROR "CMake_RUN_IWYU and CMake_BUILD_PCH are ON, but they are incompatible!")
  291. endif()
  292. find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
  293. if(NOT IWYU_COMMAND)
  294. message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
  295. endif()
  296. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  297. "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
  298. option(CMake_IWYU_VERBOSE "Run include-what-you-use in verbose mode" OFF)
  299. if (CMake_IWYU_VERBOSE)
  300. list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  301. -Xiwyu -v7)
  302. endif ()
  303. list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
  304. endif()
  305. #-----------------------------------------------------------------------
  306. # a macro that only sets the FOLDER target property if it's
  307. # "appropriate"
  308. #-----------------------------------------------------------------------
  309. macro(CMAKE_SET_TARGET_FOLDER tgt folder)
  310. if(CMAKE_USE_FOLDERS)
  311. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  312. if(MSVC AND TARGET ${tgt})
  313. set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
  314. endif()
  315. else()
  316. set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
  317. endif()
  318. endmacro()
  319. #-----------------------------------------------------------------------
  320. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  321. if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
  322. execute_process(COMMAND ${CMAKE_CXX_COMPILER}
  323. ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
  324. OUTPUT_VARIABLE _GXX_VERSION
  325. )
  326. string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
  327. _GXX_VERSION_SHORT ${_GXX_VERSION})
  328. if(_GXX_VERSION_SHORT EQUAL 33)
  329. message(FATAL_ERROR
  330. "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
  331. "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
  332. "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
  333. endif()
  334. endif()
  335. endif()
  336. #-----------------------------------------------------------------------
  337. # The main section of the CMakeLists file
  338. #
  339. #-----------------------------------------------------------------------
  340. include(Source/CMakeVersion.cmake)
  341. include(CTest)
  342. # Set up test-time configuration.
  343. set_directory_properties(PROPERTIES
  344. TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
  345. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  346. # where to write the resulting executables and libraries
  347. set(BUILD_SHARED_LIBS OFF)
  348. set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
  349. set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
  350. "Where to put the libraries for CMake")
  351. # Load install destinations.
  352. include(Source/CMakeInstallDestinations.cmake)
  353. if(BUILD_TESTING)
  354. include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
  355. endif()
  356. # Checks for cmSystemTools.
  357. if(WIN32)
  358. set(HAVE_UNSETENV 0)
  359. set(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE 1)
  360. else()
  361. include(CheckSymbolExists)
  362. CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
  363. CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
  364. endif()
  365. endif()
  366. # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
  367. #
  368. # If not defined or "", this variable defaults to the server at
  369. # "http://open.cdash.org".
  370. #
  371. # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
  372. # the network are skipped.
  373. #
  374. # If set to something starting with "http://localhost/", the CDash is
  375. # expected to be an instance of CDash used for CDash testing, pointing
  376. # to a cdash4simpletest database. In these cases, the CDash dashboards
  377. # should be run first.
  378. #
  379. if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x" AND NOT CMake_TEST_NO_NETWORK)
  380. set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
  381. endif()
  382. if(CMake_TEST_EXTERNAL_CMAKE)
  383. set(KWIML_TEST_ENABLE 1)
  384. add_subdirectory(Utilities/KWIML)
  385. endif()
  386. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  387. find_package(Threads)
  388. # build the utilities
  389. include(CMakeBuildUtilities)
  390. if(BUILD_QtDialog)
  391. if(APPLE)
  392. set(CMAKE_BUNDLE_VERSION
  393. "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  394. set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
  395. # make sure CMAKE_INSTALL_PREFIX ends in /
  396. if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
  397. string(APPEND CMAKE_INSTALL_PREFIX "/")
  398. endif()
  399. string(APPEND CMAKE_INSTALL_PREFIX "CMake.app/Contents")
  400. endif()
  401. endif()
  402. if(UNIX)
  403. # Install executables with the RPATH set for libraries outside the build tree.
  404. # This is also suitable for binaries in the build tree. Avoid re-link on install.
  405. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE BOOL "Install with RPATH set to find custom-built libraries.")
  406. set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Build with RPATH set to match install-tree RPATH.")
  407. mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_BUILD_WITH_INSTALL_RPATH)
  408. endif()
  409. # add the uninstall support
  410. configure_file(cmake_uninstall.cmake.in cmake_uninstall.cmake @ONLY)
  411. add_custom_target(uninstall
  412. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  413. include(CMakeCPack.cmake)
  414. endif()
  415. # setup some Testing support (a macro defined in this file)
  416. CMAKE_SETUP_TESTING()
  417. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  418. if(NOT CMake_VERSION_IS_RELEASE)
  419. if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
  420. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) OR
  421. (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
  422. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 3.0 AND
  423. NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") OR
  424. CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR
  425. CMAKE_C_COMPILER_ID STREQUAL "LCC")
  426. set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
  427. -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
  428. -Wmissing-format-attribute -fno-common -Wundef
  429. )
  430. set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
  431. -Wshadow -Wpointer-arith -Wformat-security -Wundef
  432. )
  433. foreach(FLAG_LANG IN ITEMS C CXX)
  434. foreach(FLAG IN LISTS ${FLAG_LANG}_FLAGS_LIST)
  435. if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
  436. string(APPEND CMAKE_${FLAG_LANG}_FLAGS " ${FLAG}")
  437. endif()
  438. endforeach()
  439. endforeach()
  440. unset(C_FLAGS_LIST)
  441. unset(CXX_FLAGS_LIST)
  442. endif()
  443. endif()
  444. # build the remaining subdirectories
  445. add_subdirectory(Source)
  446. add_subdirectory(Utilities)
  447. endif()
  448. add_subdirectory(Tests)
  449. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  450. if(BUILD_TESTING)
  451. CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
  452. endif()
  453. if(TARGET documentation)
  454. CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
  455. endif()
  456. endif()
  457. if(BUILD_TESTING)
  458. add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
  459. --system-information -G "${CMAKE_GENERATOR}"
  460. )
  461. endif()
  462. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  463. # Install license file as it requires.
  464. install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
  465. # Install script directories.
  466. install(
  467. DIRECTORY Help Modules Templates
  468. DESTINATION ${CMAKE_DATA_DIR}
  469. FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  470. DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  471. GROUP_READ GROUP_EXECUTE
  472. WORLD_READ WORLD_EXECUTE
  473. PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  474. GROUP_READ GROUP_EXECUTE
  475. WORLD_READ WORLD_EXECUTE
  476. REGEX "/(ExportImportList|cpp)$"
  477. PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  478. GROUP_READ GROUP_EXECUTE
  479. WORLD_READ WORLD_EXECUTE
  480. REGEX "Help/(dev|guide)($|/)" EXCLUDE
  481. )
  482. # Install auxiliary files integrating with other tools.
  483. add_subdirectory(Auxiliary)
  484. # Optionally sign installed binaries.
  485. if(CMake_INSTALL_SIGNTOOL)
  486. configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
  487. install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)
  488. endif()
  489. endif()