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.1...3.19 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 unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
9 unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
11 # FIXME: This block should go away after a transition period.
12 if(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.
16 foreach(c DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
17 string(REGEX REPLACE "[-/]M[DT]d?( |$)" "" "CMAKE_${l}_FLAGS_${c}" "${CMAKE_${l}_FLAGS_${c}}")
22 # Make sure we can find internal find_package modules only used for
23 # building CMake and not for shipping externally
24 list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
27 # Running from bootstrap script. Set local variable and remove from cache.
28 set(CMAKE_BOOTSTRAP 1)
29 unset(CMAKE_BOOTSTRAP CACHE)
32 if(CMake_TEST_HOST_CMAKE)
33 get_filename_component(CMake_TEST_EXTERNAL_CMAKE "${CMAKE_COMMAND}" DIRECTORY)
36 if(NOT CMake_TEST_EXTERNAL_CMAKE)
37 if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
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."
45 set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
48 if(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}")
58 if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
59 # Disallow architecture-specific try_run. It may not run on the host.
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}]")
69 # Use most-recent available language dialects with GNU and Clang
70 if(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)
75 set(CMAKE_C_STANDARD 99)
78 if(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)
82 if(NOT CMAKE_VERSION VERSION_LESS 3.8)
83 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
85 set(CMake_CXX17_BROKEN 1)
87 if(NOT CMake_CXX17_BROKEN)
88 set(CMAKE_CXX_STANDARD 17)
90 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
91 if(NOT CMake_CXX14_BROKEN)
92 set(CMAKE_CXX_STANDARD 14)
94 set(CMAKE_CXX_STANDARD 11)
99 if(NOT CMake_TEST_EXTERNAL_CMAKE)
100 # include special compile flags for some compilers
101 include(CompileFlags.cmake)
103 # check for available C++ features
104 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
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).")
111 # Inform STL library header wrappers whether to use system versions.
112 configure_file(${CMake_SOURCE_DIR}/Utilities/std/cmSTL.hxx.in
113 ${CMake_BINARY_DIR}/Utilities/cmSTL.hxx
116 # set the internal encoding of CMake to UTF-8
117 set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
119 # option to use COMPONENT with install command
120 option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
121 mark_as_advanced(CMake_INSTALL_COMPONENTS)
122 macro(CMake_OPTIONAL_COMPONENT NAME)
123 if(CMake_INSTALL_COMPONENTS)
124 set(COMPONENT COMPONENT ${NAME})
130 # option to disable installing 3rd-party dependencies
131 option(CMake_INSTALL_DEPENDENCIES
132 "Whether to install 3rd-party runtime dependencies" OFF)
133 mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
135 # option to build reference for CMake developers
136 option(CMake_BUILD_DEVELOPER_REFERENCE
137 "Build CMake Developer Reference" OFF)
138 mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
140 # option to build using interprocedural optimizations (IPO/LTO)
141 if (NOT CMAKE_VERSION VERSION_LESS 3.12.2)
142 option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
144 include(CheckIPOSupported)
145 check_ipo_supported(RESULT HAVE_IPO)
147 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
152 #-----------------------------------------------------------------------
153 # a macro to deal with system libraries, implemented as a macro
154 # simply to improve readability of the main script
155 #-----------------------------------------------------------------------
156 macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
157 # Options have dependencies.
158 include(CMakeDependentOption)
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}")
168 if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
169 if(CMAKE_USE_SYSTEM_LIBRARY_${util})
170 set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
172 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
175 unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
177 string(TOLOWER "${util}" lutil)
178 set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
179 CACHE BOOL "Use system-installed ${lutil}" FORCE)
181 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
185 unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
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}")
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)
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}")
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
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 #-----------------------------------------------------------------------
230 macro(CMAKE_SETUP_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)
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
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})
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")
259 # configure some files for testing
260 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
261 "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
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)
273 mark_as_advanced(DART_ROOT)
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...
281 option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
282 mark_as_advanced(CMAKE_USE_FOLDERS)
285 option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
286 if(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!")
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!")
294 set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
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)
307 configure_file(.clang-tidy .clang-tidy COPYONLY)
310 option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
312 find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
314 message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
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})
322 #-----------------------------------------------------------------------
323 # a macro that only sets the FOLDER target property if it's
325 #-----------------------------------------------------------------------
326 macro(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}")
333 set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
338 #-----------------------------------------------------------------------
339 # a macro to build the utilities used by CMake
340 # Simply to improve readability of the main script.
341 #-----------------------------------------------------------------------
342 macro (CMAKE_BUILD_UTILITIES)
343 find_package(Threads)
345 # Suppress unnecessary checks in third-party code.
346 include(Utilities/cmThirdPartyChecks.cmake)
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)
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 "")
364 if(CMake_NO_SELF_BACKTRACE)
365 set(KWSYS_NO_EXECINFO 1)
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)
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}")
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}")
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")
402 include_directories(SYSTEM "${CMake_SOURCE_DIR}/Utilities/std")
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")
410 include_directories(SYSTEM "${CMake_SOURCE_DIR}/Utilities")
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")
419 # check for the use of system libraries versus builtin ones
420 # (a macro defined in this file)
421 CMAKE_HANDLE_SYSTEM_LIBRARIES()
423 if(CMAKE_USE_SYSTEM_KWIML)
424 find_package(KWIML 1.0)
426 message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
428 set(CMake_KWIML_LIBRARIES kwiml::kwiml)
430 set(CMake_KWIML_LIBRARIES "")
432 set(KWIML_TEST_ENABLE 1)
434 add_subdirectory(Utilities/KWIML)
437 if(CMAKE_USE_SYSTEM_LIBRHASH)
438 find_package(LibRHash)
439 if(NOT LibRHash_FOUND)
441 "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
443 set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
445 set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
446 add_subdirectory(Utilities/cmlibrhash)
447 CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
450 #---------------------------------------------------------------------
451 # Build zlib library for Curl, CMake, and CTest.
452 set(CMAKE_ZLIB_HEADER "cm_zlib.h")
453 if(CMAKE_USE_SYSTEM_ZLIB)
457 "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
459 set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
460 set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
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)
467 set(ZLIB_DLL_WITH_LIB cmzlib)
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")
475 #---------------------------------------------------------------------
476 # Build Curl library for CTest.
477 if(CMAKE_USE_SYSTEM_CURL)
481 "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
483 set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
484 set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
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")
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)
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)
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)
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")
521 #---------------------------------------------------------------------
522 # Build expat library for CMake, CTest, and libarchive.
523 if(CMAKE_USE_SYSTEM_EXPAT)
527 "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
529 set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
530 set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
532 set(CMAKE_EXPAT_INCLUDES)
533 set(CMAKE_EXPAT_LIBRARIES cmexpat)
534 add_subdirectory(Utilities/cmexpat)
535 CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
538 #---------------------------------------------------------------------
539 # Build or use system libbz2 for libarchive.
540 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
541 if(CMAKE_USE_SYSTEM_BZIP2)
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")
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")
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!")
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)
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!")
596 set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
597 set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
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})
628 #---------------------------------------------------------------------
629 # Build jsoncpp library.
630 if(CMAKE_USE_SYSTEM_JSONCPP)
631 find_package(JsonCpp 1.4.1)
632 if(NOT JsonCpp_FOUND)
634 "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
636 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
637 set_property(TARGET JsonCpp::JsonCpp APPEND PROPERTY
638 INTERFACE_COMPILE_OPTIONS -Wno-deprecated-declarations)
640 set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
642 set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
643 add_subdirectory(Utilities/cmjsoncpp)
644 CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
647 #---------------------------------------------------------------------
648 # Build libuv library.
649 if(CMAKE_USE_SYSTEM_LIBUV)
651 find_package(LibUV 1.38.0)
653 find_package(LibUV 1.10.0)
657 "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
659 set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
661 set(CMAKE_LIBUV_LIBRARIES cmlibuv)
662 add_subdirectory(Utilities/cmlibuv)
663 CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
666 #---------------------------------------------------------------------
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}")
674 set(BUILD_CursesDialog 0)
676 if(BUILD_CursesDialog)
677 set(CURSES_NEED_NCURSES TRUE)
681 "'ccmake' will not be built because Curses was not found.\n"
682 "Turn off BUILD_CursesDialog to suppress this message."
684 set(BUILD_CursesDialog 0)
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!" )
696 #-----------------------------------------------------------------------
697 if(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
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)
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}")
714 #-----------------------------------------------------------------------
715 # The main section of the CMakeLists file
717 #-----------------------------------------------------------------------
718 include(Source/CMakeVersion.cmake)
720 # Include the standard Dart testing module
722 include (${CMAKE_ROOT}/Modules/Dart.cmake)
724 # Set up test-time configuration.
725 set_directory_properties(PROPERTIES
726 TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
728 if(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")
735 # Load install destinations.
736 include(Source/CMakeInstallDestinations.cmake)
739 include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
742 # Checks for cmSystemTools.
745 set(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE 1)
747 include(CheckSymbolExists)
748 CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
749 CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
753 # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
755 # If not defined or "", this variable defaults to the server at
756 # "http://open.cdash.org".
758 # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
759 # the network are skipped.
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.
766 if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x" AND NOT CMake_TEST_NO_NETWORK)
767 set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
770 if(CMake_TEST_EXTERNAL_CMAKE)
771 set(KWIML_TEST_ENABLE 1)
772 add_subdirectory(Utilities/KWIML)
775 if(NOT CMake_TEST_EXTERNAL_CMAKE)
776 # build the utilities (a macro defined in this file)
777 CMAKE_BUILD_UTILITIES()
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}/")
788 set(CMAKE_INSTALL_PREFIX
789 "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
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)
801 # add the uninstall support
803 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
804 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
806 add_custom_target(uninstall
807 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
809 include (CMakeCPack.cmake)
813 # setup some Testing support (a macro defined in this file)
814 CMAKE_SETUP_TESTING()
816 if(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)
820 set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
821 -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
822 -Wmissing-format-attribute -fno-common -Wundef
824 set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
825 -Wshadow -Wpointer-arith -Wformat-security -Wundef
828 foreach(FLAG_LANG C CXX)
829 foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
830 if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
831 set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
837 unset(CXX_FLAGS_LIST)
841 # build the remaining subdirectories
842 add_subdirectory(Source)
843 add_subdirectory(Utilities)
846 add_subdirectory(Tests)
848 if(NOT CMake_TEST_EXTERNAL_CMAKE)
850 CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
851 IF(TARGET CMakeServerLibTests)
852 CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
855 if(TARGET documentation)
856 CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
861 add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
862 --system-information -G "${CMAKE_GENERATOR}" )
865 if(NOT CMake_TEST_EXTERNAL_CMAKE)
866 # Install license file as it requires.
867 install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
869 # Install script directories.
871 DIRECTORY Help Modules Templates
872 DESTINATION ${CMAKE_DATA_DIR}
873 FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
874 DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
875 GROUP_READ GROUP_EXECUTE
876 WORLD_READ WORLD_EXECUTE
877 PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
878 GROUP_READ GROUP_EXECUTE
879 WORLD_READ WORLD_EXECUTE
880 REGEX "/(ExportImportList|cpp)$"
881 PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
882 GROUP_READ GROUP_EXECUTE
883 WORLD_READ WORLD_EXECUTE
884 REGEX "Help/(dev|guide)($|/)" EXCLUDE
887 # Install auxiliary files integrating with other tools.
888 add_subdirectory(Auxiliary)
890 # Optionally sign installed binaries.
891 if(CMake_INSTALL_SIGNTOOL)
892 configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
893 install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)