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