CMakeLists.txt 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  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.20 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 C CXX)
  14. foreach(c 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. if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
  50. # Disallow architecture-specific try_run. It may not run on the host.
  51. macro(TRY_RUN)
  52. if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
  53. message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
  54. else()
  55. _TRY_RUN(${ARGV})
  56. endif()
  57. endmacro()
  58. endif()
  59. # Use most-recent available language dialects with GNU and Clang
  60. if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
  61. include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
  62. if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
  63. set(CMAKE_C_STANDARD 11)
  64. else()
  65. set(CMAKE_C_STANDARD 99)
  66. endif()
  67. endif()
  68. if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
  69. if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
  70. set(CMAKE_CXX_STANDARD 98)
  71. else()
  72. if(NOT CMAKE_VERSION VERSION_LESS 3.8)
  73. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
  74. else()
  75. set(CMake_CXX17_BROKEN 1)
  76. endif()
  77. if(NOT CMake_CXX17_BROKEN)
  78. set(CMAKE_CXX_STANDARD 17)
  79. else()
  80. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
  81. if(NOT CMake_CXX14_BROKEN)
  82. set(CMAKE_CXX_STANDARD 14)
  83. else()
  84. set(CMAKE_CXX_STANDARD 11)
  85. endif()
  86. endif()
  87. endif()
  88. endif()
  89. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  90. # include special compile flags for some compilers
  91. include(CompileFlags.cmake)
  92. # check for available C++ features
  93. include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
  94. if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
  95. message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
  96. endif()
  97. endif()
  98. # Inform STL library header wrappers whether to use system versions.
  99. configure_file(${CMake_SOURCE_DIR}/Utilities/std/cmSTL.hxx.in
  100. ${CMake_BINARY_DIR}/Utilities/cmSTL.hxx
  101. @ONLY)
  102. # set the internal encoding of CMake to UTF-8
  103. set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
  104. # option to use COMPONENT with install command
  105. option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
  106. mark_as_advanced(CMake_INSTALL_COMPONENTS)
  107. macro(CMake_OPTIONAL_COMPONENT NAME)
  108. if(CMake_INSTALL_COMPONENTS)
  109. set(COMPONENT COMPONENT ${NAME})
  110. else()
  111. set(COMPONENT)
  112. endif()
  113. endmacro()
  114. # option to disable installing 3rd-party dependencies
  115. option(CMake_INSTALL_DEPENDENCIES
  116. "Whether to install 3rd-party runtime dependencies" OFF)
  117. mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
  118. # option to build reference for CMake developers
  119. option(CMake_BUILD_DEVELOPER_REFERENCE
  120. "Build CMake Developer Reference" OFF)
  121. mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
  122. # option to build using interprocedural optimizations (IPO/LTO)
  123. if (NOT CMAKE_VERSION VERSION_LESS 3.12.2)
  124. option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
  125. if(CMake_BUILD_LTO)
  126. include(CheckIPOSupported)
  127. check_ipo_supported(RESULT HAVE_IPO)
  128. if(HAVE_IPO)
  129. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
  130. endif()
  131. endif()
  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. # Options have dependencies.
  139. include(CMakeDependentOption)
  140. # Allow the user to enable/disable all system utility library options by
  141. # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
  142. set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD)
  143. foreach(util ${UTILITIES})
  144. if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
  145. AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
  146. set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
  147. endif()
  148. if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
  149. if(CMAKE_USE_SYSTEM_LIBRARY_${util})
  150. set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
  151. else()
  152. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  153. endif()
  154. if(CMAKE_BOOTSTRAP)
  155. unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
  156. endif()
  157. string(TOLOWER "${util}" lutil)
  158. set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
  159. CACHE BOOL "Use system-installed ${lutil}" FORCE)
  160. else()
  161. set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
  162. endif()
  163. endforeach()
  164. if(CMAKE_BOOTSTRAP)
  165. unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
  166. endif()
  167. # Optionally use system utility libraries.
  168. option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
  169. option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
  170. option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
  171. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
  172. "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
  173. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
  174. "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  175. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd"
  176. "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  177. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
  178. "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
  179. CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2"
  180. "${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON)
  181. option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
  182. option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
  183. option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
  184. option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
  185. # For now use system KWIML only if explicitly requested rather
  186. # than activating via the general system libs options.
  187. option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
  188. mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
  189. # Mention to the user what system libraries are being used.
  190. foreach(util ${UTILITIES} KWIML)
  191. if(CMAKE_USE_SYSTEM_${util})
  192. message(STATUS "Using system-installed ${util}")
  193. endif()
  194. endforeach()
  195. # Inform utility library header wrappers whether to use system versions.
  196. configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
  197. ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
  198. @ONLY)
  199. endmacro()
  200. #-----------------------------------------------------------------------
  201. # a macro to determine the generator and ctest executable to use
  202. # for testing. Simply to improve readability of the main script.
  203. #-----------------------------------------------------------------------
  204. macro(CMAKE_SETUP_TESTING)
  205. if(BUILD_TESTING)
  206. set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
  207. foreach(util CURL EXPAT ZLIB)
  208. if(CMAKE_USE_SYSTEM_${util})
  209. set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
  210. endif()
  211. endforeach()
  212. # This variable is set by cmake, however to
  213. # test cmake we want to make sure that
  214. # the ctest from this cmake is used for testing
  215. # and not the ctest from the cmake building and testing
  216. # cmake.
  217. if(CMake_TEST_EXTERNAL_CMAKE)
  218. set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
  219. set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
  220. set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
  221. foreach(exe cmake ctest cpack)
  222. add_executable(${exe} IMPORTED)
  223. set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
  224. endforeach()
  225. else()
  226. set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
  227. set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
  228. set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
  229. endif()
  230. endif()
  231. # configure some files for testing
  232. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
  233. "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
  234. @ONLY)
  235. configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
  236. ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
  237. configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
  238. ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
  239. configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
  240. ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
  241. if(BUILD_TESTING AND DART_ROOT)
  242. configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
  243. ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
  244. endif()
  245. mark_as_advanced(DART_ROOT)
  246. endmacro()
  247. # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
  248. # organization feature. Default to ON for non-Express users. Express users must
  249. # explicitly turn off this option to build CMake in the Express IDE...
  250. #
  251. option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
  252. mark_as_advanced(CMAKE_USE_FOLDERS)
  253. option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
  254. if(CMake_RUN_CLANG_TIDY)
  255. if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
  256. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
  257. endif()
  258. find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
  259. if(NOT CLANG_TIDY_COMMAND)
  260. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
  261. endif()
  262. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
  263. # Create a preprocessor definition that depends on .clang-tidy content so
  264. # the compile command will change when .clang-tidy changes. This ensures
  265. # that a subsequent build re-runs clang-tidy on all sources even if they
  266. # do not otherwise need to be recompiled. Nothing actually uses this
  267. # definition. We add it to targets on which we run clang-tidy just to
  268. # get the build dependency on the .clang-tidy file.
  269. file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
  270. set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
  271. unset(clang_tidy_sha1)
  272. endif()
  273. configure_file(.clang-tidy .clang-tidy COPYONLY)
  274. option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
  275. if(CMake_RUN_IWYU)
  276. find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
  277. if(NOT IWYU_COMMAND)
  278. message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
  279. endif()
  280. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  281. "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
  282. list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
  283. endif()
  284. #-----------------------------------------------------------------------
  285. # a macro that only sets the FOLDER target property if it's
  286. # "appropriate"
  287. #-----------------------------------------------------------------------
  288. macro(CMAKE_SET_TARGET_FOLDER tgt folder)
  289. if(CMAKE_USE_FOLDERS)
  290. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  291. if(MSVC AND TARGET ${tgt})
  292. set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
  293. endif()
  294. else()
  295. set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
  296. endif()
  297. endmacro()
  298. #-----------------------------------------------------------------------
  299. # a macro to build the utilities used by CMake
  300. # Simply to improve readability of the main script.
  301. #-----------------------------------------------------------------------
  302. macro (CMAKE_BUILD_UTILITIES)
  303. find_package(Threads)
  304. # Suppress unnecessary checks in third-party code.
  305. include(Utilities/cmThirdPartyChecks.cmake)
  306. #---------------------------------------------------------------------
  307. # Create the kwsys library for CMake.
  308. set(KWSYS_NAMESPACE cmsys)
  309. set(KWSYS_USE_SystemTools 1)
  310. set(KWSYS_USE_Directory 1)
  311. set(KWSYS_USE_RegularExpression 1)
  312. set(KWSYS_USE_Base64 1)
  313. set(KWSYS_USE_MD5 1)
  314. set(KWSYS_USE_Process 1)
  315. set(KWSYS_USE_CommandLineArguments 1)
  316. set(KWSYS_USE_ConsoleBuf 1)
  317. set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
  318. set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
  319. if(CMake_NO_CXX_STANDARD)
  320. set(KWSYS_CXX_STANDARD "")
  321. endif()
  322. if(CMake_NO_SELF_BACKTRACE)
  323. set(KWSYS_NO_EXECINFO 1)
  324. endif()
  325. if(WIN32)
  326. # FIXME: Teach KWSys to hard-code these checks on Windows.
  327. set(KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC_COMPILED 0)
  328. set(KWSYS_C_HAS_PTRDIFF_T_COMPILED 1)
  329. set(KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H_COMPILED 1)
  330. set(KWSYS_CXX_HAS_RLIMIT64_COMPILED 0)
  331. set(KWSYS_CXX_HAS_SETENV_COMPILED 0)
  332. set(KWSYS_CXX_HAS_UNSETENV_COMPILED 0)
  333. set(KWSYS_CXX_HAS_UTIMENSAT_COMPILED 0)
  334. set(KWSYS_CXX_HAS_UTIMES_COMPILED 0)
  335. set(KWSYS_CXX_STAT_HAS_ST_MTIM_COMPILED 0)
  336. set(KWSYS_CXX_STAT_HAS_ST_MTIMESPEC_COMPILED 0)
  337. set(KWSYS_STL_HAS_WSTRING_COMPILED 1)
  338. set(KWSYS_SYS_HAS_IFADDRS_H 0)
  339. endif()
  340. add_subdirectory(Source/kwsys)
  341. set(kwsys_folder "Utilities/KWSys")
  342. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
  343. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
  344. if(BUILD_TESTING)
  345. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
  346. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
  347. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
  348. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
  349. CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
  350. endif()
  351. #---------------------------------------------------------------------
  352. # Setup third-party libraries.
  353. # Everything in the tree should be able to include files from the
  354. # Utilities directory.
  355. if ((CMAKE_SYSTEM_NAME STREQUAL "AIX" OR CMAKE_SYSTEM_NAME STREQUAL "OS400") AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  356. # using -isystem option generate error "template with C linkage"
  357. include_directories("${CMake_SOURCE_DIR}/Utilities/std")
  358. else()
  359. include_directories(SYSTEM "${CMake_SOURCE_DIR}/Utilities/std")
  360. endif()
  361. include_directories("${CMake_BINARY_DIR}/Utilities")
  362. if ((CMAKE_SYSTEM_NAME STREQUAL "AIX" OR CMAKE_SYSTEM_NAME STREQUAL "OS400") AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  363. # using -isystem option generate error "template with C linkage"
  364. include_directories("${CMake_SOURCE_DIR}/Utilities")
  365. else()
  366. include_directories(SYSTEM "${CMake_SOURCE_DIR}/Utilities")
  367. endif()
  368. #---------------------------------------------------------------------
  369. # Build CMake std library for CMake and CTest.
  370. set(CMAKE_STD_LIBRARY cmstd)
  371. add_subdirectory(Utilities/std)
  372. CMAKE_SET_TARGET_FOLDER(cmstd "Utilities/std")
  373. # check for the use of system libraries versus builtin ones
  374. # (a macro defined in this file)
  375. CMAKE_HANDLE_SYSTEM_LIBRARIES()
  376. if(CMAKE_USE_SYSTEM_KWIML)
  377. find_package(KWIML 1.0)
  378. if(NOT KWIML_FOUND)
  379. message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
  380. endif()
  381. set(CMake_KWIML_LIBRARIES kwiml::kwiml)
  382. else()
  383. set(CMake_KWIML_LIBRARIES "")
  384. if(BUILD_TESTING)
  385. set(KWIML_TEST_ENABLE 1)
  386. endif()
  387. add_subdirectory(Utilities/KWIML)
  388. endif()
  389. if(CMAKE_USE_SYSTEM_LIBRHASH)
  390. find_package(LibRHash)
  391. if(NOT LibRHash_FOUND)
  392. message(FATAL_ERROR
  393. "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
  394. endif()
  395. set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
  396. else()
  397. set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
  398. add_subdirectory(Utilities/cmlibrhash)
  399. CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
  400. endif()
  401. #---------------------------------------------------------------------
  402. # Build zlib library for Curl, CMake, and CTest.
  403. set(CMAKE_ZLIB_HEADER "cm_zlib.h")
  404. if(CMAKE_USE_SYSTEM_ZLIB)
  405. find_package(ZLIB)
  406. if(NOT ZLIB_FOUND)
  407. message(FATAL_ERROR
  408. "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
  409. endif()
  410. set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
  411. set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
  412. else()
  413. set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
  414. set(CMAKE_ZLIB_LIBRARIES cmzlib)
  415. set(WITHOUT_ZLIB_DLL "")
  416. set(WITHOUT_ZLIB_DLL_WITH_LIB cmzlib)
  417. set(ZLIB_DLL "")
  418. set(ZLIB_DLL_WITH_LIB cmzlib)
  419. set(ZLIB_WINAPI "")
  420. set(ZLIB_WINAPI_COMPILED 0)
  421. set(ZLIB_WINAPI_WITH_LIB cmzlib)
  422. add_subdirectory(Utilities/cmzlib)
  423. CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
  424. endif()
  425. #---------------------------------------------------------------------
  426. # Build Curl library for CTest.
  427. if(CMAKE_USE_SYSTEM_CURL)
  428. find_package(CURL)
  429. if(NOT CURL_FOUND)
  430. message(FATAL_ERROR
  431. "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
  432. endif()
  433. set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
  434. set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
  435. else()
  436. set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
  437. set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
  438. set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
  439. set(CMAKE_CURL_INCLUDES)
  440. set(CMAKE_CURL_LIBRARIES cmcurl)
  441. if(CMAKE_TESTS_CDASH_SERVER)
  442. set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
  443. endif()
  444. set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
  445. if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
  446. AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
  447. set(_CMAKE_USE_OPENSSL_DEFAULT ON)
  448. endif()
  449. option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
  450. mark_as_advanced(CMAKE_USE_OPENSSL)
  451. if(CMAKE_USE_OPENSSL)
  452. set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
  453. set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
  454. mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
  455. endif()
  456. if(NOT CMAKE_USE_SYSTEM_NGHTTP2)
  457. # Tell curl's FindNGHTTP2 module to use our library.
  458. set(NGHTTP2_LIBRARY cmnghttp2)
  459. set(NGHTTP2_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmnghttp2/lib/includes)
  460. endif()
  461. add_subdirectory(Utilities/cmcurl)
  462. CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
  463. CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
  464. if(NOT CMAKE_USE_SYSTEM_NGHTTP2)
  465. # Configure after curl to re-use some check results.
  466. add_subdirectory(Utilities/cmnghttp2)
  467. CMAKE_SET_TARGET_FOLDER(cmnghttp2 "Utilities/3rdParty")
  468. endif()
  469. endif()
  470. #---------------------------------------------------------------------
  471. # Build expat library for CMake, CTest, and libarchive.
  472. if(CMAKE_USE_SYSTEM_EXPAT)
  473. find_package(EXPAT)
  474. if(NOT EXPAT_FOUND)
  475. message(FATAL_ERROR
  476. "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
  477. endif()
  478. set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
  479. set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
  480. else()
  481. set(CMAKE_EXPAT_INCLUDES)
  482. set(CMAKE_EXPAT_LIBRARIES cmexpat)
  483. add_subdirectory(Utilities/cmexpat)
  484. CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
  485. endif()
  486. #---------------------------------------------------------------------
  487. # Build or use system libbz2 for libarchive.
  488. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  489. if(CMAKE_USE_SYSTEM_BZIP2)
  490. find_package(BZip2)
  491. else()
  492. set(BZIP2_INCLUDE_DIR
  493. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
  494. set(BZIP2_LIBRARIES cmbzip2)
  495. set(BZIP2_NEED_PREFIX "")
  496. set(USE_BZIP2_DLL "")
  497. set(USE_BZIP2_DLL_WITH_LIB cmbzip2)
  498. set(USE_BZIP2_STATIC "")
  499. set(USE_BZIP2_STATIC_WITH_LIB cmbzip2)
  500. add_subdirectory(Utilities/cmbzip2)
  501. CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
  502. endif()
  503. endif()
  504. #---------------------------------------------------------------------
  505. # Build or use system zstd for libarchive.
  506. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  507. if(NOT CMAKE_USE_SYSTEM_ZSTD)
  508. set(ZSTD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmzstd")
  509. set(ZSTD_LIBRARY cmzstd)
  510. add_subdirectory(Utilities/cmzstd)
  511. CMAKE_SET_TARGET_FOLDER(cmzstd "Utilities/3rdParty")
  512. endif()
  513. endif()
  514. #---------------------------------------------------------------------
  515. # Build or use system liblzma for libarchive.
  516. if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
  517. if(CMAKE_USE_SYSTEM_LIBLZMA)
  518. find_package(LibLZMA)
  519. if(NOT LIBLZMA_FOUND)
  520. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
  521. endif()
  522. else()
  523. add_subdirectory(Utilities/cmliblzma)
  524. CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
  525. set(LIBLZMA_HAS_AUTO_DECODER 1)
  526. set(LIBLZMA_HAS_EASY_ENCODER 1)
  527. set(LIBLZMA_HAS_LZMA_PRESET 1)
  528. set(LIBLZMA_INCLUDE_DIR
  529. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
  530. set(LIBLZMA_LIBRARY cmliblzma)
  531. set(HAVE_LZMA_STREAM_ENCODER_MT 1)
  532. endif()
  533. endif()
  534. #---------------------------------------------------------------------
  535. # Build or use system libarchive for CMake and CTest.
  536. if(CMAKE_USE_SYSTEM_LIBARCHIVE)
  537. find_package(LibArchive 3.3.3)
  538. if(NOT LibArchive_FOUND)
  539. message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
  540. endif()
  541. set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
  542. set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
  543. else()
  544. set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
  545. set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
  546. set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
  547. set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
  548. add_definitions(-DLIBARCHIVE_STATIC)
  549. set(ENABLE_MBEDTLS OFF CACHE INTERNAL "Enable use of mbed TLS")
  550. set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
  551. set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
  552. set(ENABLE_LIBB2 OFF CACHE INTERNAL "Enable the use of the system LIBB2 library if found")
  553. set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
  554. set(ENABLE_LZ4 OFF CACHE INTERNAL "Enable the use of the system LZ4 library if found")
  555. set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
  556. set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
  557. set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
  558. set(ENABLE_ZSTD ON CACHE INTERNAL "Enable the use of the system zstd library if found")
  559. set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
  560. set(ENABLE_EXPAT OFF CACHE INTERNAL "Enable the use of the system EXPAT library if found")
  561. set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
  562. set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
  563. set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
  564. set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
  565. set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
  566. set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
  567. SET(POSIX_REGEX_LIB "" CACHE INTERNAL "Choose what library should provide POSIX regular expression support")
  568. add_subdirectory(Utilities/cmlibarchive)
  569. CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
  570. set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
  571. endif()
  572. #---------------------------------------------------------------------
  573. # Build jsoncpp library.
  574. if(CMAKE_USE_SYSTEM_JSONCPP)
  575. find_package(JsonCpp 1.4.1)
  576. if(NOT JsonCpp_FOUND)
  577. message(FATAL_ERROR
  578. "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
  579. endif()
  580. if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
  581. set_property(TARGET JsonCpp::JsonCpp APPEND PROPERTY
  582. INTERFACE_COMPILE_OPTIONS -Wno-deprecated-declarations)
  583. endif()
  584. set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
  585. else()
  586. set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
  587. add_subdirectory(Utilities/cmjsoncpp)
  588. CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
  589. endif()
  590. #---------------------------------------------------------------------
  591. # Build libuv library.
  592. if(CMAKE_USE_SYSTEM_LIBUV)
  593. if(WIN32)
  594. find_package(LibUV 1.38.0)
  595. else()
  596. find_package(LibUV 1.10.0)
  597. endif()
  598. if(NOT LIBUV_FOUND)
  599. message(FATAL_ERROR
  600. "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
  601. endif()
  602. set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
  603. else()
  604. set(CMAKE_LIBUV_LIBRARIES cmlibuv)
  605. add_subdirectory(Utilities/cmlibuv)
  606. CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
  607. endif()
  608. #---------------------------------------------------------------------
  609. # Use curses?
  610. if (UNIX)
  611. if(NOT DEFINED BUILD_CursesDialog)
  612. include(${CMake_SOURCE_DIR}/Source/Checks/Curses.cmake)
  613. option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" "${CMakeCheckCurses_COMPILED}")
  614. endif()
  615. else ()
  616. set(BUILD_CursesDialog 0)
  617. endif ()
  618. if(BUILD_CursesDialog)
  619. set(CURSES_NEED_NCURSES TRUE)
  620. find_package(Curses)
  621. if(NOT CURSES_FOUND)
  622. message(WARNING
  623. "'ccmake' will not be built because Curses was not found.\n"
  624. "Turn off BUILD_CursesDialog to suppress this message."
  625. )
  626. set(BUILD_CursesDialog 0)
  627. endif()
  628. endif()
  629. if(BUILD_CursesDialog)
  630. if(NOT CMAKE_USE_SYSTEM_FORM)
  631. add_subdirectory(Source/CursesDialog/form)
  632. elseif(NOT CURSES_FORM_LIBRARY)
  633. message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
  634. endif()
  635. endif()
  636. endmacro ()
  637. #-----------------------------------------------------------------------
  638. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  639. if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
  640. execute_process(COMMAND ${CMAKE_CXX_COMPILER}
  641. ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
  642. OUTPUT_VARIABLE _GXX_VERSION
  643. )
  644. string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
  645. _GXX_VERSION_SHORT ${_GXX_VERSION})
  646. if(_GXX_VERSION_SHORT EQUAL 33)
  647. message(FATAL_ERROR
  648. "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
  649. "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
  650. "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
  651. endif()
  652. endif()
  653. endif()
  654. #-----------------------------------------------------------------------
  655. # The main section of the CMakeLists file
  656. #
  657. #-----------------------------------------------------------------------
  658. include(Source/CMakeVersion.cmake)
  659. # Include the standard Dart testing module
  660. enable_testing()
  661. include (${CMAKE_ROOT}/Modules/Dart.cmake)
  662. # Set up test-time configuration.
  663. set_directory_properties(PROPERTIES
  664. TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
  665. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  666. # where to write the resulting executables and libraries
  667. set(BUILD_SHARED_LIBS OFF)
  668. set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
  669. set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
  670. "Where to put the libraries for CMake")
  671. # Load install destinations.
  672. include(Source/CMakeInstallDestinations.cmake)
  673. if(BUILD_TESTING)
  674. include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
  675. endif()
  676. # Checks for cmSystemTools.
  677. if(WIN32)
  678. set(HAVE_UNSETENV 0)
  679. set(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE 1)
  680. else()
  681. include(CheckSymbolExists)
  682. CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
  683. CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
  684. endif()
  685. endif()
  686. # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
  687. #
  688. # If not defined or "", this variable defaults to the server at
  689. # "http://open.cdash.org".
  690. #
  691. # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
  692. # the network are skipped.
  693. #
  694. # If set to something starting with "http://localhost/", the CDash is
  695. # expected to be an instance of CDash used for CDash testing, pointing
  696. # to a cdash4simpletest database. In these cases, the CDash dashboards
  697. # should be run first.
  698. #
  699. if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x" AND NOT CMake_TEST_NO_NETWORK)
  700. set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
  701. endif()
  702. if(CMake_TEST_EXTERNAL_CMAKE)
  703. set(KWIML_TEST_ENABLE 1)
  704. add_subdirectory(Utilities/KWIML)
  705. endif()
  706. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  707. # build the utilities (a macro defined in this file)
  708. CMAKE_BUILD_UTILITIES()
  709. if(BUILD_QtDialog)
  710. if(APPLE)
  711. set(CMAKE_BUNDLE_VERSION
  712. "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
  713. set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
  714. # make sure CMAKE_INSTALL_PREFIX ends in /
  715. if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
  716. set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
  717. endif()
  718. set(CMAKE_INSTALL_PREFIX
  719. "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
  720. endif()
  721. endif()
  722. if(UNIX)
  723. # Install executables with the RPATH set for libraries outside the build tree.
  724. # This is also suitable for binaries in the build tree. Avoid re-link on install.
  725. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE BOOL "Install with RPATH set to find custom-built libraries.")
  726. set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Build with RPATH set to match install-tree RPATH.")
  727. mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_BUILD_WITH_INSTALL_RPATH)
  728. endif()
  729. # add the uninstall support
  730. configure_file(
  731. "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  732. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  733. @ONLY)
  734. add_custom_target(uninstall
  735. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  736. include (CMakeCPack.cmake)
  737. endif()
  738. # setup some Testing support (a macro defined in this file)
  739. CMAKE_SETUP_TESTING()
  740. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  741. if(NOT CMake_VERSION_IS_RELEASE)
  742. if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
  743. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) OR
  744. (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
  745. NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 3.0 AND
  746. NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") OR
  747. CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
  748. set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
  749. -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
  750. -Wmissing-format-attribute -fno-common -Wundef
  751. )
  752. set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
  753. -Wshadow -Wpointer-arith -Wformat-security -Wundef
  754. )
  755. foreach(FLAG_LANG C CXX)
  756. foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
  757. if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
  758. set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
  759. endif()
  760. endforeach()
  761. endforeach()
  762. unset(C_FLAGS_LIST)
  763. unset(CXX_FLAGS_LIST)
  764. endif()
  765. endif()
  766. # build the remaining subdirectories
  767. add_subdirectory(Source)
  768. add_subdirectory(Utilities)
  769. endif()
  770. add_subdirectory(Tests)
  771. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  772. if(BUILD_TESTING)
  773. CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
  774. IF(TARGET CMakeServerLibTests)
  775. CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
  776. ENDIF()
  777. endif()
  778. if(TARGET documentation)
  779. CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
  780. endif()
  781. endif()
  782. if(BUILD_TESTING)
  783. add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
  784. --system-information -G "${CMAKE_GENERATOR}" )
  785. endif()
  786. if(NOT CMake_TEST_EXTERNAL_CMAKE)
  787. # Install license file as it requires.
  788. install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
  789. # Install script directories.
  790. install(
  791. DIRECTORY Help Modules Templates
  792. DESTINATION ${CMAKE_DATA_DIR}
  793. FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  794. DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  795. GROUP_READ GROUP_EXECUTE
  796. WORLD_READ WORLD_EXECUTE
  797. PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  798. GROUP_READ GROUP_EXECUTE
  799. WORLD_READ WORLD_EXECUTE
  800. REGEX "/(ExportImportList|cpp)$"
  801. PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
  802. GROUP_READ GROUP_EXECUTE
  803. WORLD_READ WORLD_EXECUTE
  804. REGEX "Help/(dev|guide)($|/)" EXCLUDE
  805. )
  806. # Install auxiliary files integrating with other tools.
  807. add_subdirectory(Auxiliary)
  808. # Optionally sign installed binaries.
  809. if(CMake_INSTALL_SIGNTOOL)
  810. configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
  811. install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)
  812. endif()
  813. endif()