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.15 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 # set the internal encoding of CMake to UTF-8
112 set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
114 # option to use COMPONENT with install command
115 option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
116 mark_as_advanced(CMake_INSTALL_COMPONENTS)
117 macro(CMake_OPTIONAL_COMPONENT NAME)
118 if(CMake_INSTALL_COMPONENTS)
119 set(COMPONENT COMPONENT ${NAME})
125 # option to disable installing 3rd-party dependencies
126 option(CMake_INSTALL_DEPENDENCIES
127 "Whether to install 3rd-party runtime dependencies" OFF)
128 mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
130 # option to build reference for CMake developers
131 option(CMake_BUILD_DEVELOPER_REFERENCE
132 "Build CMake Developer Reference" OFF)
133 mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
135 # option to build using interprocedural optimizations (IPO/LTO)
136 if (NOT CMAKE_VERSION VERSION_LESS 3.12.2)
137 option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
139 include(CheckIPOSupported)
140 check_ipo_supported(RESULT HAVE_IPO)
142 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
147 #-----------------------------------------------------------------------
148 # a macro to deal with system libraries, implemented as a macro
149 # simply to improve readability of the main script
150 #-----------------------------------------------------------------------
151 macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
152 # Options have dependencies.
153 include(CMakeDependentOption)
155 # Allow the user to enable/disable all system utility library options by
156 # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
157 set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB ZSTD)
158 foreach(util ${UTILITIES})
159 if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
160 AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
161 set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
163 if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
164 if(CMAKE_USE_SYSTEM_LIBRARY_${util})
165 set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
167 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
170 unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
172 string(TOLOWER "${util}" lutil)
173 set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
174 CACHE BOOL "Use system-installed ${lutil}" FORCE)
176 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
180 unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
183 # Optionally use system utility libraries.
184 option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
185 option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
186 option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
187 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
188 "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
189 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
190 "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
191 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd"
192 "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
193 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
194 "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
195 option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
196 option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
197 option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
198 option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
200 # For now use system KWIML only if explicitly requested rather
201 # than activating via the general system libs options.
202 option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
203 mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
205 # Mention to the user what system libraries are being used.
206 foreach(util ${UTILITIES} KWIML)
207 if(CMAKE_USE_SYSTEM_${util})
208 message(STATUS "Using system-installed ${util}")
212 # Inform utility library header wrappers whether to use system versions.
213 configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
214 ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
219 #-----------------------------------------------------------------------
220 # a macro to determine the generator and ctest executable to use
221 # for testing. Simply to improve readability of the main script.
222 #-----------------------------------------------------------------------
223 macro(CMAKE_SETUP_TESTING)
225 set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
226 foreach(util CURL EXPAT ZLIB)
227 if(CMAKE_USE_SYSTEM_${util})
228 set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
232 # This variable is set by cmake, however to
233 # test cmake we want to make sure that
234 # the ctest from this cmake is used for testing
235 # and not the ctest from the cmake building and testing
237 if(CMake_TEST_EXTERNAL_CMAKE)
238 set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
239 set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
240 set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
241 foreach(exe cmake ctest cpack)
242 add_executable(${exe} IMPORTED)
243 set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
246 set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
247 set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
248 set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
252 # configure some files for testing
253 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
254 "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
256 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
257 ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
258 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
259 ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
260 configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
261 ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
262 if(BUILD_TESTING AND DART_ROOT)
263 configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
264 ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
266 mark_as_advanced(DART_ROOT)
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!")
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!")
287 set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
289 # Create a preprocessor definition that depends on .clang-tidy content so
290 # the compile command will change when .clang-tidy changes. This ensures
291 # that a subsequent build re-runs clang-tidy on all sources even if they
292 # do not otherwise need to be recompiled. Nothing actually uses this
293 # definition. We add it to targets on which we run clang-tidy just to
294 # get the build dependency on the .clang-tidy file.
295 file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
296 set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
297 unset(clang_tidy_sha1)
300 configure_file(.clang-tidy .clang-tidy COPYONLY)
303 option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
305 find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
307 message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
309 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
310 "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
311 list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
315 #-----------------------------------------------------------------------
316 # a macro that only sets the FOLDER target property if it's
318 #-----------------------------------------------------------------------
319 macro(CMAKE_SET_TARGET_FOLDER tgt folder)
320 if(CMAKE_USE_FOLDERS)
321 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
322 if(MSVC AND TARGET ${tgt})
323 set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
326 set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
331 #-----------------------------------------------------------------------
332 # a macro to build the utilities used by CMake
333 # Simply to improve readability of the main script.
334 #-----------------------------------------------------------------------
335 macro (CMAKE_BUILD_UTILITIES)
336 find_package(Threads)
338 #---------------------------------------------------------------------
339 # Create the kwsys library for CMake.
340 set(KWSYS_NAMESPACE cmsys)
341 set(KWSYS_USE_SystemTools 1)
342 set(KWSYS_USE_Directory 1)
343 set(KWSYS_USE_RegularExpression 1)
344 set(KWSYS_USE_Base64 1)
346 set(KWSYS_USE_Process 1)
347 set(KWSYS_USE_CommandLineArguments 1)
348 set(KWSYS_USE_ConsoleBuf 1)
349 set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
350 set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
351 if(CMake_NO_CXX_STANDARD)
352 set(KWSYS_CXX_STANDARD "")
354 add_subdirectory(Source/kwsys)
355 set(kwsys_folder "Utilities/KWSys")
356 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
357 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
359 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
360 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
361 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
362 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
363 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
366 #---------------------------------------------------------------------
367 # Setup third-party libraries.
368 # Everything in the tree should be able to include files from the
369 # Utilities directory.
370 if ((CMAKE_SYSTEM_NAME STREQUAL "AIX" OR CMAKE_SYSTEM_NAME STREQUAL "OS400") AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
371 # using -isystem option generate error "template with C linkage"
372 include_directories("${CMake_SOURCE_DIR}/Utilities/std")
374 include_directories(SYSTEM "${CMake_SOURCE_DIR}/Utilities/std")
378 ${CMake_BINARY_DIR}/Utilities
379 ${CMake_SOURCE_DIR}/Utilities
382 #---------------------------------------------------------------------
383 # Build CMake std library for CMake and CTest.
384 set(CMAKE_STD_LIBRARY cmstd)
385 add_subdirectory(Utilities/std)
386 CMAKE_SET_TARGET_FOLDER(cmstd "Utilities/std")
388 # check for the use of system libraries versus builtin ones
389 # (a macro defined in this file)
390 CMAKE_HANDLE_SYSTEM_LIBRARIES()
392 if(CMAKE_USE_SYSTEM_KWIML)
393 find_package(KWIML 1.0)
395 message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
397 set(CMake_KWIML_LIBRARIES kwiml::kwiml)
399 set(CMake_KWIML_LIBRARIES "")
401 set(KWIML_TEST_ENABLE 1)
403 add_subdirectory(Utilities/KWIML)
406 if(CMAKE_USE_SYSTEM_LIBRHASH)
407 find_package(LibRHash)
408 if(NOT LibRHash_FOUND)
410 "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
412 set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
414 set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
415 add_subdirectory(Utilities/cmlibrhash)
416 CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
419 #---------------------------------------------------------------------
420 # Build zlib library for Curl, CMake, and CTest.
421 set(CMAKE_ZLIB_HEADER "cm_zlib.h")
422 if(CMAKE_USE_SYSTEM_ZLIB)
426 "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
428 set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
429 set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
431 set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
432 set(CMAKE_ZLIB_LIBRARIES cmzlib)
433 add_subdirectory(Utilities/cmzlib)
434 CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
437 #---------------------------------------------------------------------
438 # Build Curl library for CTest.
439 if(CMAKE_USE_SYSTEM_CURL)
443 "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
445 set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
446 set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
448 set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
449 set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
450 set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
451 set(CMAKE_CURL_INCLUDES)
452 set(CMAKE_CURL_LIBRARIES cmcurl)
453 if(CMAKE_TESTS_CDASH_SERVER)
454 set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
456 set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
457 if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
458 AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
459 set(_CMAKE_USE_OPENSSL_DEFAULT ON)
461 option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
462 mark_as_advanced(CMAKE_USE_OPENSSL)
463 if(CMAKE_USE_OPENSSL)
464 set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
465 set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
466 mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
468 add_subdirectory(Utilities/cmcurl)
469 CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
470 CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
473 #---------------------------------------------------------------------
474 # Build expat library for CMake, CTest, and libarchive.
475 if(CMAKE_USE_SYSTEM_EXPAT)
479 "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
481 set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
482 set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
484 set(CMAKE_EXPAT_INCLUDES)
485 set(CMAKE_EXPAT_LIBRARIES cmexpat)
486 add_subdirectory(Utilities/cmexpat)
487 CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
490 #---------------------------------------------------------------------
491 # Build or use system libbz2 for libarchive.
492 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
493 if(CMAKE_USE_SYSTEM_BZIP2)
496 set(BZIP2_INCLUDE_DIR
497 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
498 set(BZIP2_LIBRARIES cmbzip2)
499 add_subdirectory(Utilities/cmbzip2)
500 CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
504 #---------------------------------------------------------------------
505 # Build or use system zstd for libarchive.
506 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
507 if(NOT CMAKE_USE_SYSTEM_ZSTD)
508 set(ZSTD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmzstd")
509 set(ZSTD_LIBRARY cmzstd)
510 add_subdirectory(Utilities/cmzstd)
511 CMAKE_SET_TARGET_FOLDER(cmzstd "Utilities/3rdParty")
515 #---------------------------------------------------------------------
516 # Build or use system liblzma for libarchive.
517 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
518 if(CMAKE_USE_SYSTEM_LIBLZMA)
519 find_package(LibLZMA)
520 if(NOT LIBLZMA_FOUND)
521 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
524 add_subdirectory(Utilities/cmliblzma)
525 CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
526 set(LIBLZMA_HAS_AUTO_DECODER 1)
527 set(LIBLZMA_HAS_EASY_ENCODER 1)
528 set(LIBLZMA_HAS_LZMA_PRESET 1)
529 set(LIBLZMA_INCLUDE_DIR
530 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
531 set(LIBLZMA_LIBRARY cmliblzma)
535 #---------------------------------------------------------------------
536 # Build or use system libarchive for CMake and CTest.
537 if(CMAKE_USE_SYSTEM_LIBARCHIVE)
538 find_package(LibArchive 3.3.3)
539 if(NOT LibArchive_FOUND)
540 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
542 set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
543 set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
545 set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
546 set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
547 set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
548 set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
549 add_definitions(-DLIBARCHIVE_STATIC)
550 set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
551 set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
552 set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
553 set(ENABLE_LZ4 OFF CACHE INTERNAL "Enable the use of the system LZ4 library if found")
554 set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
555 set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
556 set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
557 set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
558 set(ENABLE_EXPAT ON CACHE INTERNAL "Enable the use of the system EXPAT library if found")
559 set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
560 set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
561 set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
562 set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
563 set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
564 set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
565 add_subdirectory(Utilities/cmlibarchive)
566 CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
567 set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
570 #---------------------------------------------------------------------
571 # Build jsoncpp library.
572 if(CMAKE_USE_SYSTEM_JSONCPP)
573 find_package(JsonCpp 1.4.1)
574 if(NOT JsonCpp_FOUND)
576 "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
578 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
579 set_property(TARGET JsonCpp::JsonCpp APPEND PROPERTY
580 INTERFACE_COMPILE_OPTIONS -Wno-deprecated-declarations)
582 set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
584 set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
585 add_subdirectory(Utilities/cmjsoncpp)
586 CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
589 #---------------------------------------------------------------------
590 # Build libuv library.
591 if(CMAKE_USE_SYSTEM_LIBUV)
592 find_package(LibUV 1.10.0)
595 "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
597 set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
599 set(CMAKE_LIBUV_LIBRARIES cmlibuv)
600 add_subdirectory(Utilities/cmlibuv)
601 CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
604 #---------------------------------------------------------------------
607 if(NOT DEFINED BUILD_CursesDialog)
608 include(${CMake_SOURCE_DIR}/Source/Checks/Curses.cmake)
609 option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" "${CMakeCheckCurses_COMPILED}")
612 set(BUILD_CursesDialog 0)
614 if(BUILD_CursesDialog)
615 set(CURSES_NEED_NCURSES TRUE)
619 "'ccmake' will not be built because Curses was not found.\n"
620 "Turn off BUILD_CursesDialog to suppress this message."
622 set(BUILD_CursesDialog 0)
625 if(BUILD_CursesDialog)
626 if(NOT CMAKE_USE_SYSTEM_FORM)
627 add_subdirectory(Source/CursesDialog/form)
628 elseif(NOT CURSES_FORM_LIBRARY)
629 message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
634 #-----------------------------------------------------------------------
635 if(NOT CMake_TEST_EXTERNAL_CMAKE)
636 if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
637 execute_process(COMMAND ${CMAKE_CXX_COMPILER}
638 ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
639 OUTPUT_VARIABLE _GXX_VERSION
641 string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
642 _GXX_VERSION_SHORT ${_GXX_VERSION})
643 if(_GXX_VERSION_SHORT EQUAL 33)
645 "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
646 "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
647 "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
652 #-----------------------------------------------------------------------
653 # The main section of the CMakeLists file
655 #-----------------------------------------------------------------------
656 include(Source/CMakeVersion.cmake)
658 # Include the standard Dart testing module
660 include (${CMAKE_ROOT}/Modules/Dart.cmake)
662 # Set up test-time configuration.
663 set_directory_properties(PROPERTIES
664 TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
666 if(NOT CMake_TEST_EXTERNAL_CMAKE)
667 # where to write the resulting executables and libraries
668 set(BUILD_SHARED_LIBS OFF)
669 set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
670 set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
671 "Where to put the libraries for CMake")
673 # Load install destinations.
674 include(Source/CMakeInstallDestinations.cmake)
677 include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
680 # no clue why we are testing for this here
681 include(CheckSymbolExists)
682 CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
683 CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
686 # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
688 # If not defined or "", this variable defaults to the server at
689 # "http://open.cdash.org".
691 # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
692 # the network are skipped.
694 # If set to something starting with "http://localhost/", the CDash is
695 # expected to be an instance of CDash used for CDash testing, pointing
696 # to a cdash4simpletest database. In these cases, the CDash dashboards
697 # should be run first.
699 if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x" AND NOT CMake_TEST_NO_NETWORK)
700 set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
703 if(CMake_TEST_EXTERNAL_CMAKE)
704 set(KWIML_TEST_ENABLE 1)
705 add_subdirectory(Utilities/KWIML)
708 if(NOT CMake_TEST_EXTERNAL_CMAKE)
709 # build the utilities (a macro defined in this file)
710 CMAKE_BUILD_UTILITIES()
714 set(CMAKE_BUNDLE_VERSION
715 "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
716 set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
717 # make sure CMAKE_INSTALL_PREFIX ends in /
718 if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
719 set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
721 set(CMAKE_INSTALL_PREFIX
722 "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
727 # Install executables with the RPATH set for libraries outside the build tree.
728 # This is also suitable for binaries in the build tree. Avoid re-link on install.
729 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE BOOL "Install with RPATH set to find custom-built libraries.")
730 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Build with RPATH set to match install-tree RPATH.")
731 mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_BUILD_WITH_INSTALL_RPATH)
734 # add the uninstall support
736 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
737 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
739 add_custom_target(uninstall
740 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
742 include (CMakeCPack.cmake)
746 # setup some Testing support (a macro defined in this file)
747 CMAKE_SETUP_TESTING()
749 if(NOT CMake_TEST_EXTERNAL_CMAKE)
750 if(NOT CMake_VERSION_IS_RELEASE)
751 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
752 NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
753 set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
754 -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
755 -Wmissing-format-attribute -fno-common -Wundef
757 set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
758 -Wshadow -Wpointer-arith -Wformat-security -Wundef
761 foreach(FLAG_LANG C CXX)
762 foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
763 if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
764 set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
770 unset(CXX_FLAGS_LIST)
774 # build the remaining subdirectories
775 add_subdirectory(Source)
776 add_subdirectory(Utilities)
779 add_subdirectory(Tests)
781 if(NOT CMake_TEST_EXTERNAL_CMAKE)
783 CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
784 IF(TARGET CMakeServerLibTests)
785 CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
788 if(TARGET documentation)
789 CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
794 add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
795 --system-information -G "${CMAKE_GENERATOR}" )
798 if(NOT CMake_TEST_EXTERNAL_CMAKE)
799 # Install license file as it requires.
800 install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
802 # Install script directories.
804 DIRECTORY Help Modules Templates
805 DESTINATION ${CMAKE_DATA_DIR}
806 FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
807 DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
808 GROUP_READ GROUP_EXECUTE
809 WORLD_READ WORLD_EXECUTE
810 PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
811 GROUP_READ GROUP_EXECUTE
812 WORLD_READ WORLD_EXECUTE
813 PATTERN "ExportImportList"
814 PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
815 GROUP_READ GROUP_EXECUTE
816 WORLD_READ WORLD_EXECUTE
817 REGEX "Help/(dev|guide)($|/)" EXCLUDE
820 # Install auxiliary files integrating with other tools.
821 add_subdirectory(Auxiliary)
823 # Optionally sign installed binaries.
824 if(CMake_INSTALL_SIGNTOOL)
825 configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
826 install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)