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