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.14 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 # Make sure we can find internal find_package modules only used for
12 # building CMake and not for shipping externally
13 list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
16 # Running from bootstrap script. Set local variable and remove from cache.
17 set(CMAKE_BOOTSTRAP 1)
18 unset(CMAKE_BOOTSTRAP CACHE)
21 if(NOT CMake_TEST_EXTERNAL_CMAKE)
22 if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
24 "CMake no longer compiles on HP-UX. See\n"
25 " https://gitlab.kitware.com/cmake/cmake/issues/17137\n"
26 "Use CMake 3.9 or lower instead."
30 set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
33 if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
34 if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
35 set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
43 if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
44 # Disallow architecture-specific try_run. It may not run on the host.
46 if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
47 message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
54 # Use most-recent available language dialects with GNU and Clang
55 if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
56 include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
57 if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
58 set(CMAKE_C_STANDARD 11)
60 set(CMAKE_C_STANDARD 99)
63 if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
64 if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
65 set(CMAKE_CXX_STANDARD 98)
67 if(NOT CMAKE_VERSION VERSION_LESS 3.8)
68 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
70 set(CMake_CXX17_BROKEN 1)
72 if(NOT CMake_CXX17_BROKEN)
73 set(CMAKE_CXX_STANDARD 17)
75 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
76 if(NOT CMake_CXX14_BROKEN)
77 set(CMAKE_CXX_STANDARD 14)
79 set(CMAKE_CXX_STANDARD 11)
84 if(NOT CMake_TEST_EXTERNAL_CMAKE)
85 # include special compile flags for some compilers
86 include(CompileFlags.cmake)
88 # check for available C++ features
89 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
91 if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
92 message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
96 # set the internal encoding of CMake to UTF-8
97 set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
99 # option to use COMPONENT with install command
100 option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
101 mark_as_advanced(CMake_INSTALL_COMPONENTS)
102 macro(CMake_OPTIONAL_COMPONENT NAME)
103 if(CMake_INSTALL_COMPONENTS)
104 set(COMPONENT COMPONENT ${NAME})
110 # option to disable installing 3rd-party dependencies
111 option(CMake_INSTALL_DEPENDENCIES
112 "Whether to install 3rd-party runtime dependencies" OFF)
113 mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
115 # option to build reference for CMake developers
116 option(CMake_BUILD_DEVELOPER_REFERENCE
117 "Build CMake Developer Reference" OFF)
118 mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
120 # option to build using interprocedural optimizations (IPO/LTO)
121 if (NOT CMAKE_VERSION VERSION_LESS 3.12.2)
122 option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
124 include(CheckIPOSupported)
125 check_ipo_supported(RESULT HAVE_IPO)
127 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
132 #-----------------------------------------------------------------------
133 # a macro to deal with system libraries, implemented as a macro
134 # simply to improve readability of the main script
135 #-----------------------------------------------------------------------
136 macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
137 # Options have dependencies.
138 include(CMakeDependentOption)
140 # Allow the user to enable/disable all system utility library options by
141 # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
142 set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB ZSTD)
143 foreach(util ${UTILITIES})
144 if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
145 AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
146 set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
148 if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
149 if(CMAKE_USE_SYSTEM_LIBRARY_${util})
150 set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
152 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
155 unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
157 string(TOLOWER "${util}" lutil)
158 set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
159 CACHE BOOL "Use system-installed ${lutil}" FORCE)
161 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
165 unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
168 # Optionally use system utility libraries.
169 option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
170 option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
171 option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
172 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
173 "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
174 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
175 "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
176 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd"
177 "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
178 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
179 "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
180 option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
181 option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
182 option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
183 option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
185 # For now use system KWIML only if explicitly requested rather
186 # than activating via the general system libs options.
187 option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
188 mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
190 # Mention to the user what system libraries are being used.
191 foreach(util ${UTILITIES} KWIML)
192 if(CMAKE_USE_SYSTEM_${util})
193 message(STATUS "Using system-installed ${util}")
197 # Inform utility library header wrappers whether to use system versions.
198 configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
199 ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
204 #-----------------------------------------------------------------------
205 # a macro to determine the generator and ctest executable to use
206 # for testing. Simply to improve readability of the main script.
207 #-----------------------------------------------------------------------
208 macro(CMAKE_SETUP_TESTING)
210 set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
211 foreach(util CURL EXPAT ZLIB)
212 if(CMAKE_USE_SYSTEM_${util})
213 set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
217 # This variable is set by cmake, however to
218 # test cmake we want to make sure that
219 # the ctest from this cmake is used for testing
220 # and not the ctest from the cmake building and testing
222 if(CMake_TEST_EXTERNAL_CMAKE)
223 set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
224 set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
225 set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
226 foreach(exe cmake ctest cpack)
227 add_executable(${exe} IMPORTED)
228 set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
231 set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
232 set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
233 set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
237 # configure some files for testing
238 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
239 "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
241 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
242 ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
243 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
244 ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
245 configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
246 ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
247 if(BUILD_TESTING AND DART_ROOT)
248 configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
249 ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
251 mark_as_advanced(DART_ROOT)
252 mark_as_advanced(CURL_TESTING)
256 # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
257 # organization feature. Default to ON for non-Express users. Express users must
258 # explicitly turn off this option to build CMake in the Express IDE...
260 option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
261 mark_as_advanced(CMAKE_USE_FOLDERS)
264 option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
265 if(CMake_RUN_CLANG_TIDY)
266 if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
267 message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
269 find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
270 if(NOT CLANG_TIDY_COMMAND)
271 message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
273 set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
275 # Create a preprocessor definition that depends on .clang-tidy content so
276 # the compile command will change when .clang-tidy changes. This ensures
277 # that a subsequent build re-runs clang-tidy on all sources even if they
278 # do not otherwise need to be recompiled. Nothing actually uses this
279 # definition. We add it to targets on which we run clang-tidy just to
280 # get the build dependency on the .clang-tidy file.
281 file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
282 set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
283 unset(clang_tidy_sha1)
286 configure_file(.clang-tidy .clang-tidy COPYONLY)
289 option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
291 find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
293 message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
295 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
296 "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
297 list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
301 #-----------------------------------------------------------------------
302 # a macro that only sets the FOLDER target property if it's
304 #-----------------------------------------------------------------------
305 macro(CMAKE_SET_TARGET_FOLDER tgt folder)
306 if(CMAKE_USE_FOLDERS)
307 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
308 if(MSVC AND TARGET ${tgt})
309 set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
312 set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
317 #-----------------------------------------------------------------------
318 # a macro to build the utilities used by CMake
319 # Simply to improve readability of the main script.
320 #-----------------------------------------------------------------------
321 macro (CMAKE_BUILD_UTILITIES)
322 find_package(Threads)
324 #---------------------------------------------------------------------
325 # Create the kwsys library for CMake.
326 set(KWSYS_NAMESPACE cmsys)
327 set(KWSYS_USE_SystemTools 1)
328 set(KWSYS_USE_Directory 1)
329 set(KWSYS_USE_RegularExpression 1)
330 set(KWSYS_USE_Base64 1)
332 set(KWSYS_USE_Process 1)
333 set(KWSYS_USE_CommandLineArguments 1)
334 set(KWSYS_USE_ConsoleBuf 1)
335 set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
336 set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
337 if(CMake_NO_CXX_STANDARD)
338 set(KWSYS_CXX_STANDARD "")
340 add_subdirectory(Source/kwsys)
341 set(kwsys_folder "Utilities/KWSys")
342 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
343 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
345 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
346 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
347 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
348 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
349 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
352 #---------------------------------------------------------------------
353 # Setup third-party libraries.
354 # Everything in the tree should be able to include files from the
355 # Utilities directory.
357 ${CMake_BINARY_DIR}/Utilities
358 ${CMake_SOURCE_DIR}/Utilities
361 # check for the use of system libraries versus builtin ones
362 # (a macro defined in this file)
363 CMAKE_HANDLE_SYSTEM_LIBRARIES()
365 if(CMAKE_USE_SYSTEM_KWIML)
366 find_package(KWIML 1.0)
368 message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
370 set(CMake_KWIML_LIBRARIES kwiml::kwiml)
372 set(CMake_KWIML_LIBRARIES "")
374 set(KWIML_TEST_ENABLE 1)
376 add_subdirectory(Utilities/KWIML)
379 if(CMAKE_USE_SYSTEM_LIBRHASH)
380 find_package(LibRHash)
381 if(NOT LibRHash_FOUND)
383 "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
385 set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
387 set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
388 add_subdirectory(Utilities/cmlibrhash)
389 CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
392 #---------------------------------------------------------------------
393 # Build zlib library for Curl, CMake, and CTest.
394 set(CMAKE_ZLIB_HEADER "cm_zlib.h")
395 if(CMAKE_USE_SYSTEM_ZLIB)
399 "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
401 set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
402 set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
404 set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
405 set(CMAKE_ZLIB_LIBRARIES cmzlib)
406 add_subdirectory(Utilities/cmzlib)
407 CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
410 #---------------------------------------------------------------------
411 # Build Curl library for CTest.
412 if(CMAKE_USE_SYSTEM_CURL)
416 "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
418 set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
419 set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
421 set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
422 set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
423 set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
424 set(CMAKE_CURL_INCLUDES)
425 set(CMAKE_CURL_LIBRARIES cmcurl)
426 if(CMAKE_TESTS_CDASH_SERVER)
427 set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
429 set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
430 if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
431 AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
432 find_package(OpenSSL QUIET)
434 set(_CMAKE_USE_OPENSSL_DEFAULT ON)
437 option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
438 mark_as_advanced(CMAKE_USE_OPENSSL)
439 if(CMAKE_USE_OPENSSL)
440 set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
441 set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
442 mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
444 add_subdirectory(Utilities/cmcurl)
445 CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
446 CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
449 #---------------------------------------------------------------------
450 # Build expat library for CMake, CTest, and libarchive.
451 if(CMAKE_USE_SYSTEM_EXPAT)
455 "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
457 set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
458 set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
460 set(CMAKE_EXPAT_INCLUDES)
461 set(CMAKE_EXPAT_LIBRARIES cmexpat)
462 add_subdirectory(Utilities/cmexpat)
463 CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
466 #---------------------------------------------------------------------
467 # Build or use system libbz2 for libarchive.
468 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
469 if(CMAKE_USE_SYSTEM_BZIP2)
472 set(BZIP2_INCLUDE_DIR
473 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
474 set(BZIP2_LIBRARIES cmbzip2)
475 add_subdirectory(Utilities/cmbzip2)
476 CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
480 #---------------------------------------------------------------------
481 # Build or use system zstd for libarchive.
482 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
483 if(NOT CMAKE_USE_SYSTEM_ZSTD)
484 set(ZSTD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmzstd")
485 set(ZSTD_LIBRARY cmzstd)
486 add_subdirectory(Utilities/cmzstd)
487 CMAKE_SET_TARGET_FOLDER(cmzstd "Utilities/3rdParty")
491 #---------------------------------------------------------------------
492 # Build or use system liblzma for libarchive.
493 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
494 if(CMAKE_USE_SYSTEM_LIBLZMA)
495 find_package(LibLZMA)
496 if(NOT LIBLZMA_FOUND)
497 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
500 add_subdirectory(Utilities/cmliblzma)
501 CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
502 set(LIBLZMA_HAS_AUTO_DECODER 1)
503 set(LIBLZMA_HAS_EASY_ENCODER 1)
504 set(LIBLZMA_HAS_LZMA_PRESET 1)
505 set(LIBLZMA_INCLUDE_DIR
506 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
507 set(LIBLZMA_LIBRARY cmliblzma)
511 #---------------------------------------------------------------------
512 # Build or use system libarchive for CMake and CTest.
513 if(CMAKE_USE_SYSTEM_LIBARCHIVE)
514 find_package(LibArchive 3.1.0)
515 if(NOT LibArchive_FOUND)
516 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
518 set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
519 set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
521 set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
522 set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
523 set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
524 set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
525 add_definitions(-DLIBARCHIVE_STATIC)
526 set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
527 set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
528 set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
529 set(ENABLE_LZ4 OFF CACHE INTERNAL "Enable the use of the system LZ4 library if found")
530 set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
531 set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
532 set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
533 set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
534 set(ENABLE_EXPAT ON CACHE INTERNAL "Enable the use of the system EXPAT library if found")
535 set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
536 set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
537 set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
538 set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
539 set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
540 set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
541 add_subdirectory(Utilities/cmlibarchive)
542 CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
543 set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
546 #---------------------------------------------------------------------
547 # Build jsoncpp library.
548 if(CMAKE_USE_SYSTEM_JSONCPP)
549 find_package(JsonCpp 1.4.1)
550 if(NOT JsonCpp_FOUND)
552 "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
554 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
555 set_property(TARGET JsonCpp::JsonCpp APPEND PROPERTY
556 INTERFACE_COMPILE_OPTIONS -Wno-deprecated-declarations)
558 set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
560 set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
561 add_subdirectory(Utilities/cmjsoncpp)
562 CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
565 #---------------------------------------------------------------------
566 # Build libuv library.
567 if(CMAKE_USE_SYSTEM_LIBUV)
568 find_package(LibUV 1.10.0)
571 "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
573 set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
575 set(CMAKE_LIBUV_LIBRARIES cmlibuv)
576 add_subdirectory(Utilities/cmlibuv)
577 CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
580 #---------------------------------------------------------------------
583 if(NOT DEFINED BUILD_CursesDialog)
584 include(${CMake_SOURCE_DIR}/Source/Checks/Curses.cmake)
585 option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" "${CMakeCheckCurses_COMPILED}")
588 set(BUILD_CursesDialog 0)
590 if(BUILD_CursesDialog)
591 set(CURSES_NEED_NCURSES TRUE)
595 "'ccmake' will not be built because Curses was not found.\n"
596 "Turn off BUILD_CursesDialog to suppress this message."
598 set(BUILD_CursesDialog 0)
601 if(BUILD_CursesDialog)
602 if(NOT CMAKE_USE_SYSTEM_FORM)
603 add_subdirectory(Source/CursesDialog/form)
604 elseif(NOT CURSES_FORM_LIBRARY)
605 message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
610 #-----------------------------------------------------------------------
611 if(NOT CMake_TEST_EXTERNAL_CMAKE)
612 if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
613 execute_process(COMMAND ${CMAKE_CXX_COMPILER}
614 ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
615 OUTPUT_VARIABLE _GXX_VERSION
617 string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
618 _GXX_VERSION_SHORT ${_GXX_VERSION})
619 if(_GXX_VERSION_SHORT EQUAL 33)
621 "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
622 "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
623 "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
628 #-----------------------------------------------------------------------
629 # The main section of the CMakeLists file
631 #-----------------------------------------------------------------------
632 # Compute CMake_VERSION, etc.
633 include(Source/CMakeVersionCompute.cmake)
635 # Include the standard Dart testing module
637 include (${CMAKE_ROOT}/Modules/Dart.cmake)
639 # Set up test-time configuration.
640 set_directory_properties(PROPERTIES
641 TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
643 if(NOT CMake_TEST_EXTERNAL_CMAKE)
644 # where to write the resulting executables and libraries
645 set(BUILD_SHARED_LIBS OFF)
646 set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
647 set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
648 "Where to put the libraries for CMake")
650 # The CMake executables usually do not need any rpath to run in the build or
652 set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
654 # Load install destinations.
655 include(Source/CMakeInstallDestinations.cmake)
658 include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
661 # no clue why we are testing for this here
662 include(CheckSymbolExists)
663 CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
664 CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
667 # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
669 # If not defined or "", this variable defaults to the server at
670 # "http://open.cdash.org".
672 # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
673 # the network are skipped.
675 # If set to something starting with "http://localhost/", the CDash is
676 # expected to be an instance of CDash used for CDash testing, pointing
677 # to a cdash4simpletest database. In these cases, the CDash dashboards
678 # should be run first.
680 if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
681 set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
684 if(CMake_TEST_EXTERNAL_CMAKE)
685 set(KWIML_TEST_ENABLE 1)
686 add_subdirectory(Utilities/KWIML)
689 if(NOT CMake_TEST_EXTERNAL_CMAKE)
690 # build the utilities (a macro defined in this file)
691 CMAKE_BUILD_UTILITIES()
693 # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
694 # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
695 # which isn't in the default linker search path. So without RPATH ccmake
696 # doesn't run and the build doesn't succeed since ccmake is executed for
697 # generating the documentation.
698 if(BUILD_CursesDialog)
699 get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
700 set(CURSES_NEED_RPATH FALSE)
701 if(NOT "${_CURSES_DIR}" STREQUAL "/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/lib64" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib64")
702 set(CURSES_NEED_RPATH TRUE)
708 set(CMAKE_BUNDLE_VERSION
709 "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
710 set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
711 # make sure CMAKE_INSTALL_PREFIX ends in /
712 if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
713 set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
715 set(CMAKE_INSTALL_PREFIX
716 "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
719 set(QT_NEED_RPATH FALSE)
720 if(NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib64" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib64")
721 set(QT_NEED_RPATH TRUE)
726 # The same might be true on other systems for other libraries.
727 # Then only enable RPATH if we have are building at least with cmake 2.4,
728 # since this one has much better RPATH features than cmake 2.2.
729 # The executables are then built with the RPATH for the libraries outside
730 # the build tree, which is both the build and the install RPATH.
732 if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
733 OR CMAKE_USE_SYSTEM_EXPAT OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
734 set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
735 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
736 set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
741 # add the uninstall support
743 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
744 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
746 add_custom_target(uninstall
747 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
749 include (CMakeCPack.cmake)
753 # setup some Testing support (a macro defined in this file)
754 CMAKE_SETUP_TESTING()
756 if(NOT CMake_TEST_EXTERNAL_CMAKE)
757 if(NOT CMake_VERSION_IS_RELEASE)
758 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
759 NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
760 set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
761 -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
762 -Wmissing-format-attribute -fno-common -Wundef
764 set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
765 -Wshadow -Wpointer-arith -Wformat-security -Wundef
768 foreach(FLAG_LANG C CXX)
769 foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
770 if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
771 set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
777 unset(CXX_FLAGS_LIST)
781 # build the remaining subdirectories
782 add_subdirectory(Source)
783 add_subdirectory(Utilities)
786 add_subdirectory(Tests)
788 if(NOT CMake_TEST_EXTERNAL_CMAKE)
790 CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
791 IF(TARGET CMakeServerLibTests)
792 CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
795 if(TARGET documentation)
796 CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
801 add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
802 --system-information -G "${CMAKE_GENERATOR}" )
805 if(NOT CMake_TEST_EXTERNAL_CMAKE)
806 # Install license file as it requires.
807 install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
809 # Install script directories.
811 DIRECTORY Help Modules Templates
812 DESTINATION ${CMAKE_DATA_DIR}
813 FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
814 DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
815 GROUP_READ GROUP_EXECUTE
816 WORLD_READ WORLD_EXECUTE
817 PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
818 GROUP_READ GROUP_EXECUTE
819 WORLD_READ WORLD_EXECUTE
820 REGEX "Help/dev($|/)" EXCLUDE
823 # Install auxiliary files integrating with other tools.
824 add_subdirectory(Auxiliary)
826 # Optionally sign installed binaries.
827 if(CMake_INSTALL_SIGNTOOL)
828 configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
829 install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)