CMakeLists.txt 34 KB

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