Merge branch 'release-3.29'
[kiteware-cmake.git] / CMakeLists.txt
blob5f661a9a71aa5626fefeb99e0fd31541ca616506
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 cmake_minimum_required(VERSION 3.13...3.28 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)
8 project(CMake)
9 unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
10 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 IN ITEMS C CXX)
17     foreach(c IN ITEMS 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()
23 # Make sure we can find internal find_package modules only used for
24 # building CMake and not for shipping externally
25 list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
27 if(CMAKE_BOOTSTRAP)
28   # Running from bootstrap script.  Set local variable and remove from cache.
29   set(CMAKE_BOOTSTRAP 1)
30   unset(CMAKE_BOOTSTRAP CACHE)
31 endif()
33 if(CMake_TEST_HOST_CMAKE)
34   get_filename_component(CMake_TEST_EXTERNAL_CMAKE "${CMAKE_COMMAND}" DIRECTORY)
35 endif()
37 if(NOT CMake_TEST_EXTERNAL_CMAKE)
38   if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
39     message(FATAL_ERROR
40       "CMake no longer compiles on HP-UX.  See\n"
41       "  https://gitlab.kitware.com/cmake/cmake/-/issues/17137\n"
42       "Use CMake 3.9 or lower instead."
43       )
44   endif()
46   set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
47 endif()
49 if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
50   if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
51     set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
52   else()
53     set(USE_LGPL "2.1")
54   endif()
55 else()
56   set(USE_LGPL "")
57 endif()
59 # Use most-recent available language dialects with GNU and Clang
60 if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
61   include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
62   if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
63     set(CMAKE_C_STANDARD 11)
64   else()
65     set(CMAKE_C_STANDARD 99)
66   endif()
67 endif()
68 if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
69   if(CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
70     set(CMAKE_CXX_STANDARD 98)
71   else()
72     include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
73     if(NOT CMake_CXX17_BROKEN)
74       set(CMAKE_CXX_STANDARD 17)
75     else()
76       include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
77       if(NOT CMake_CXX14_BROKEN)
78         set(CMAKE_CXX_STANDARD 14)
79       else()
80         set(CMAKE_CXX_STANDARD 11)
81       endif()
82     endif()
83   endif()
84 endif()
85 if(NOT CMake_TEST_EXTERNAL_CMAKE)
86   # include special compile flags for some compilers
87   include(CompileFlags.cmake)
89   # check for available C++ features
90   include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
92   if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
93     message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
94   endif()
95 endif()
97 # Inform STL library header wrappers whether to use system versions.
98 configure_file(Utilities/std/cmSTL.hxx.in Utilities/cmSTL.hxx @ONLY)
100 # set the internal encoding of CMake to UTF-8
101 set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
103 # option to use COMPONENT with install command
104 option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
105 mark_as_advanced(CMake_INSTALL_COMPONENTS)
106 macro(CMake_OPTIONAL_COMPONENT NAME)
107   if(CMake_INSTALL_COMPONENTS)
108     set(COMPONENT COMPONENT ${NAME})
109   else()
110     set(COMPONENT)
111   endif()
112 endmacro()
114 # option to disable installing 3rd-party dependencies
115 option(CMake_INSTALL_DEPENDENCIES
116   "Whether to install 3rd-party runtime dependencies" OFF)
117 mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
119 # option to build reference for CMake developers
120 option(CMake_BUILD_DEVELOPER_REFERENCE
121   "Build CMake Developer Reference" OFF)
122 mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
124 # option to build using interprocedural optimizations (IPO/LTO)
125 option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
126 if(CMake_BUILD_LTO)
127   include(CheckIPOSupported)
128   check_ipo_supported(RESULT HAVE_IPO)
129   if(HAVE_IPO)
130     set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
131   endif()
132 endif()
134 option(CMake_BUILD_PCH "Compile CMake with precompiled headers" OFF)
136 # Check whether to build support for the debugger mode.
137 if(NOT CMake_TEST_EXTERNAL_CMAKE)
138   if(NOT DEFINED CMake_ENABLE_DEBUGGER)
139     # The debugger uses cppdap, which does not compile everywhere.
140     if(CMAKE_SYSTEM_NAME MATCHES "Windows|Darwin|Linux|BSD|DragonFly|CYGWIN|MSYS"
141         AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.16)
142         AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "XLClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.1)
143         AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "LCC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.23)
144         )
145       set(CMake_ENABLE_DEBUGGER 1)
146     else()
147       set(CMake_ENABLE_DEBUGGER 0)
148     endif()
149   endif()
150 else()
151   set(CMake_ENABLE_DEBUGGER 0)
152 endif()
154 #-----------------------------------------------------------------------
155 # a macro to deal with system libraries, implemented as a macro
156 # simply to improve readability of the main script
157 #-----------------------------------------------------------------------
158 macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
159   include(CMakeDependentOption)
161   # Allow the user to enable/disable all system utility library options by
162   # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
163   set(UTILITIES BZIP2 CPPDAP CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD)
164   foreach(util IN LISTS UTILITIES)
165     if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
166         AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
167       set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
168     endif()
169     if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
170       if(CMAKE_USE_SYSTEM_LIBRARY_${util})
171         set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
172       else()
173         set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
174       endif()
175       if(CMAKE_BOOTSTRAP)
176         unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
177       endif()
178       string(TOLOWER "${util}" lutil)
179       set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
180         CACHE BOOL "Use system-installed ${lutil}" FORCE)
181     else()
182       set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
183     endif()
184   endforeach()
185   if(CMAKE_BOOTSTRAP)
186     unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
187   endif()
189   # Optionally use system utility libraries.
190   option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
191   if(CMake_ENABLE_DEBUGGER)
192     option(CMAKE_USE_SYSTEM_CPPDAP "Use system-installed cppdap" "${CMAKE_USE_SYSTEM_LIBRARY_CPPDAP}")
193   endif()
194   option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
195   option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
196   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
197     "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
198   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
199     "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
200   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd"
201     "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
202   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
203     "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
204   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2"
205     "${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON)
206   option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
207   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp"
208     "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}" "NOT CMAKE_USE_SYSTEM_CPPDAP" ON)
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}")
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)
217   # Mention to the user what system libraries are being used.
218   foreach(util IN LISTS UTILITIES ITEMS KWIML)
219     if(CMAKE_USE_SYSTEM_${util})
220       message(STATUS "Using system-installed ${util}")
221     endif()
222   endforeach()
224   # Inform utility library header wrappers whether to use system versions.
225   configure_file(Utilities/cmThirdParty.h.in Utilities/cmThirdParty.h @ONLY)
227 endmacro()
229 #-----------------------------------------------------------------------
230 # a macro to determine the generator and ctest executable to use
231 # for testing. Simply to improve readability of the main script.
232 #-----------------------------------------------------------------------
233 macro(CMAKE_SETUP_TESTING)
234   if(BUILD_TESTING)
235     set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
236     foreach(util IN ITEMS CURL EXPAT ZLIB)
237       if(CMAKE_USE_SYSTEM_${util})
238         set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
239       endif()
240     endforeach()
242     # This variable is set by cmake, however to
243     # test cmake we want to make sure that
244     # the ctest from this cmake is used for testing
245     # and not the ctest from the cmake building and testing
246     # cmake.
247     if(CMake_TEST_EXTERNAL_CMAKE)
248       set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
249       set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
250       set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
251       foreach(exe IN ITEMS cmake ctest cpack)
252         add_executable(${exe} IMPORTED)
253         set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
254       endforeach()
255     else()
256       set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
257       set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
258       set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
259     endif()
260   endif()
262   # configure some files for testing
263   configure_file(Templates/CTestScript.cmake.in CTestScript.cmake @ONLY)
264   configure_file(Tests/.NoDartCoverage Tests/.NoDartCoverage)
265   configure_file(Tests/.NoDartCoverage Modules/.NoDartCoverage)
266   configure_file(CTestCustom.cmake.in CTestCustom.cmake @ONLY)
267 endmacro()
270 # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
271 # organization feature. Default to ON for non-Express users. Express users must
272 # explicitly turn off this option to build CMake in the Express IDE...
274 option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
275 mark_as_advanced(CMAKE_USE_FOLDERS)
278 option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
279 if(CMake_RUN_CLANG_TIDY)
280   if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
281     message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
282   endif()
283   find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
284   if(NOT CLANG_TIDY_COMMAND)
285     message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
286   endif()
287   set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
289   option(CMake_USE_CLANG_TIDY_MODULE "Use CMake's clang-tidy module." OFF)
290   if(CMake_USE_CLANG_TIDY_MODULE)
291     find_library(CMake_CLANG_TIDY_MODULE NAMES cmake-clang-tidy-module DOC "Location of the clang-tidy module")
292     if(NOT CMake_CLANG_TIDY_MODULE)
293       message(FATAL_ERROR "CMake_USE_CLANG_TIDY_MODULE is ON but cmake-clang-tidy-module is not found!")
294     endif()
295     list(APPEND CMAKE_CXX_CLANG_TIDY "--load=${CMake_CLANG_TIDY_MODULE}")
296     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMake_CLANG_TIDY_MODULE}")
297   endif()
299   set(CMake_CLANG_TIDY_EXPORT_FIXES_DIR "" CACHE PATH "Directory to put clang-tidy fix files in.")
300   mark_as_advanced(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
301   if(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
302     if(NOT IS_ABSOLUTE "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
303       message(FATAL_ERROR "CMake_CLANG_TIDY_EXPORT_FIXES_DIR must be an absolute path!")
304     endif()
305     set(CMAKE_CXX_CLANG_TIDY_EXPORT_FIXES_DIR "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
306   endif()
308   # Create a preprocessor definition that depends on .clang-tidy content so
309   # the compile command will change when .clang-tidy changes.  This ensures
310   # that a subsequent build re-runs clang-tidy on all sources even if they
311   # do not otherwise need to be recompiled.  Nothing actually uses this
312   # definition.  We add it to targets on which we run clang-tidy just to
313   # get the build dependency on the .clang-tidy file.
314   file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
315   set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
316   unset(clang_tidy_sha1)
317   if(CMake_USE_CLANG_TIDY_MODULE)
318     file(SHA1 "${CMake_CLANG_TIDY_MODULE}" clang_tidy_module_sha1)
319     list(APPEND CLANG_TIDY_DEFINITIONS "CLANG_TIDY_MODULE_SHA1=${clang_tidy_module_sha1}")
320     unset(clang_tidy_module_sha1)
321   endif()
323 endif()
324 configure_file(.clang-tidy .clang-tidy COPYONLY)
327 option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
328 if(CMake_RUN_IWYU)
329   if(CMake_BUILD_PCH)
330     message(FATAL_ERROR "CMake_RUN_IWYU and CMake_BUILD_PCH are ON, but they are incompatible!")
331   endif()
332   find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
333   if(NOT IWYU_COMMAND)
334     message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
335   endif()
336   set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
337     "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
338   option(CMake_IWYU_VERBOSE "Run include-what-you-use in verbose mode" OFF)
339   if (CMake_IWYU_VERBOSE)
340     list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE
341       -Xiwyu -v7)
342   endif ()
343   list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
344 endif()
347 #-----------------------------------------------------------------------
348 # a macro that only sets the FOLDER target property if it's
349 # "appropriate"
350 #-----------------------------------------------------------------------
351 macro(CMAKE_SET_TARGET_FOLDER tgt folder)
352   if(CMAKE_USE_FOLDERS)
353     set_property(GLOBAL PROPERTY USE_FOLDERS ON)
354     if(MSVC AND TARGET ${tgt})
355       set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
356     endif()
357   else()
358     set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
359   endif()
360 endmacro()
362 #-----------------------------------------------------------------------
363 if(NOT CMake_TEST_EXTERNAL_CMAKE)
364   if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
365     execute_process(COMMAND ${CMAKE_CXX_COMPILER}
366       ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
367       OUTPUT_VARIABLE _GXX_VERSION
368     )
369     string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
370       _GXX_VERSION_SHORT ${_GXX_VERSION})
371     if(_GXX_VERSION_SHORT EQUAL 33)
372       message(FATAL_ERROR
373         "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
374         "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
375         "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
376     endif()
377   endif()
378 endif()
380 #-----------------------------------------------------------------------
381 # The main section of the CMakeLists file
383 #-----------------------------------------------------------------------
384 include(Source/CMakeVersion.cmake)
386 include(CTest)
388 # Set up test-time configuration.
389 set_directory_properties(PROPERTIES
390   TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
392 if(NOT CMake_TEST_EXTERNAL_CMAKE)
393   # where to write the resulting executables and libraries
394   set(BUILD_SHARED_LIBS OFF)
395   set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
396   set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
397     "Where to put the libraries for CMake")
399   # Load install destinations.
400   include(Source/CMakeInstallDestinations.cmake)
402   if(BUILD_TESTING)
403     include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
404   endif()
406   # Checks for cmSystemTools.
407   if(WIN32)
408     set(HAVE_UNSETENV 0)
409     set(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE 1)
410   else()
411     include(CheckSymbolExists)
412     CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
413     CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
414   endif()
415 endif()
417 # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
419 # If not defined or "", this variable defaults to the server at
420 # "http://open.cdash.org".
422 # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
423 # the network are skipped.
425 # If set to something starting with "http://localhost/", the CDash is
426 # expected to be an instance of CDash used for CDash testing, pointing
427 # to a cdash4simpletest database. In these cases, the CDash dashboards
428 # should be run first.
430 if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x" AND NOT CMake_TEST_NO_NETWORK)
431   set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
432 endif()
434 if(CMake_TEST_EXTERNAL_CMAKE)
435   set(KWIML_TEST_ENABLE 1)
436   add_subdirectory(Utilities/KWIML)
437 endif()
439 if(NOT CMake_TEST_EXTERNAL_CMAKE)
440   find_package(Threads)
441   # build the utilities
442   include(CMakeBuildUtilities)
444   if(BUILD_QtDialog)
445     if(APPLE)
446       set(CMAKE_BUNDLE_VERSION
447         "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
448       set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
449       # make sure CMAKE_INSTALL_PREFIX ends in /
450       if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
451         string(APPEND CMAKE_INSTALL_PREFIX "/")
452       endif()
453       string(APPEND CMAKE_INSTALL_PREFIX "CMake.app/Contents")
454     endif()
455   endif()
457   if(UNIX)
458     # Install executables with the RPATH set for libraries outside the build tree.
459     # This is also suitable for binaries in the build tree.  Avoid re-link on install.
460     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE BOOL "Install with RPATH set to find custom-built libraries.")
461     set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Build with RPATH set to match install-tree RPATH.")
462     mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_BUILD_WITH_INSTALL_RPATH)
463   endif()
465   # add the uninstall support
466   configure_file(cmake_uninstall.cmake.in cmake_uninstall.cmake @ONLY)
467   add_custom_target(uninstall
468     "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
470   include(CMakeCPack.cmake)
472 endif()
474 # setup some Testing support (a macro defined in this file)
475 CMAKE_SETUP_TESTING()
477 if(NOT CMake_TEST_EXTERNAL_CMAKE)
478   if(NOT CMake_VERSION_IS_RELEASE)
479     if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
480         NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) OR
481        (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
482         NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 3.0 AND
483         NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") OR
484        CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR
485        CMAKE_C_COMPILER_ID STREQUAL "LCC")
486       set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
487                        -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
488                        -Wmissing-format-attribute -fno-common -Wundef
489       )
490       set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
491                          -Wshadow -Wpointer-arith -Wformat-security -Wundef
492       )
494       foreach(FLAG_LANG IN ITEMS C CXX)
495         foreach(FLAG IN LISTS ${FLAG_LANG}_FLAGS_LIST)
496           if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
497             string(APPEND CMAKE_${FLAG_LANG}_FLAGS " ${FLAG}")
498           endif()
499         endforeach()
500       endforeach()
502       unset(C_FLAGS_LIST)
503       unset(CXX_FLAGS_LIST)
504     endif()
505   endif()
507   # build the remaining subdirectories
508   add_subdirectory(Source)
509   add_subdirectory(Utilities)
510 endif()
512 add_subdirectory(Tests)
514 if(NOT CMake_TEST_EXTERNAL_CMAKE)
515   if(BUILD_TESTING)
516     CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
517   endif()
518   if(TARGET documentation)
519     CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
520   endif()
521 endif()
523 if(BUILD_TESTING)
524   add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
525     --system-information  -G "${CMAKE_GENERATOR}"
526   )
527 endif()
529 if(NOT CMake_TEST_EXTERNAL_CMAKE)
530   # Install license file as it requires.
531   install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
533   # Install script directories.
534   install(
535     DIRECTORY Help Modules Templates
536     DESTINATION ${CMAKE_DATA_DIR}
537     FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
538     DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
539                           GROUP_READ GROUP_EXECUTE
540                           WORLD_READ WORLD_EXECUTE
541     PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
542                                 GROUP_READ GROUP_EXECUTE
543                                 WORLD_READ WORLD_EXECUTE
544     REGEX "/(ExportImportList|cpp)$"
545       PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
546                   GROUP_READ GROUP_EXECUTE
547                   WORLD_READ WORLD_EXECUTE
548     REGEX "Help/(dev|guide)($|/)" EXCLUDE
549     )
551   # Install auxiliary files integrating with other tools.
552   add_subdirectory(Auxiliary)
554   # Optionally sign installed binaries.
555   if(CMake_INSTALL_SIGNTOOL)
556     configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
557     install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)
558   endif()
559 endif()