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 FATAL_ERROR)
7 # Make sure we can find internal find_package modules only used for
8 # building CMake and not for shipping externally
9 list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
12 # Running from bootstrap script. Set local variable and remove from cache.
13 set(CMAKE_BOOTSTRAP 1)
14 unset(CMAKE_BOOTSTRAP CACHE)
17 if(NOT CMake_TEST_EXTERNAL_CMAKE)
18 if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
20 "CMake no longer compiles on HP-UX. See\n"
21 " https://gitlab.kitware.com/cmake/cmake/issues/17137\n"
22 "Use CMake 3.9 or lower instead."
26 set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
29 if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
30 if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
31 set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
39 if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
40 # Disallow architecture-specific try_run. It may not run on the host.
42 if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
43 message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
50 # Use most-recent available language dialects with GNU and Clang
51 if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
52 include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
53 if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
54 set(CMAKE_C_STANDARD 11)
56 set(CMAKE_C_STANDARD 99)
59 if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
60 if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
61 set(CMAKE_CXX_STANDARD 98)
63 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_cstdio.cmake)
64 if(NOT CMake_CXX14_CSTDIO_BROKEN)
65 set(CMAKE_CXX_STANDARD 14)
67 set(CMAKE_CXX_STANDARD 11)
71 if(NOT CMake_TEST_EXTERNAL_CMAKE)
72 # include special compile flags for some compilers
73 include(CompileFlags.cmake)
75 # check for available C++ features
76 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
78 if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
79 message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
83 # set the internal encoding of CMake to UTF-8
84 set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
86 # option to use COMPONENT with install command
87 option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
88 mark_as_advanced(CMake_INSTALL_COMPONENTS)
89 macro(CMake_OPTIONAL_COMPONENT NAME)
90 if(CMake_INSTALL_COMPONENTS)
91 set(COMPONENT COMPONENT ${NAME})
97 # option to disable installing 3rd-party dependencies
98 option(CMake_INSTALL_DEPENDENCIES
99 "Whether to install 3rd-party runtime dependencies" OFF)
100 mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
102 # option to build reference for CMake developers
103 option(CMake_BUILD_DEVELOPER_REFERENCE
104 "Build CMake Developer Reference" OFF)
105 mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
107 #-----------------------------------------------------------------------
108 # a macro to deal with system libraries, implemented as a macro
109 # simply to improve readability of the main script
110 #-----------------------------------------------------------------------
111 macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
112 # Options have dependencies.
113 include(CMakeDependentOption)
115 # Optionally use system xmlrpc. We no longer build or use it by default.
116 option(CTEST_USE_XMLRPC "Enable xmlrpc submission method in CTest." OFF)
117 mark_as_advanced(CTEST_USE_XMLRPC)
119 # Allow the user to enable/disable all system utility library options by
120 # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
121 set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB)
122 foreach(util ${UTILITIES})
123 if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
124 AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
125 set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
127 if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
128 if(CMAKE_USE_SYSTEM_LIBRARY_${util})
129 set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
131 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
134 unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
136 string(TOLOWER "${util}" lutil)
137 set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
138 CACHE BOOL "Use system-installed ${lutil}" FORCE)
140 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
144 unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
147 # Optionally use system utility libraries.
148 option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
149 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_CURL "Use system-installed curl"
150 "${CMAKE_USE_SYSTEM_LIBRARY_CURL}" "NOT CTEST_USE_XMLRPC" ON)
151 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat"
152 "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}" "NOT CTEST_USE_XMLRPC" ON)
153 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
154 "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
155 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
156 "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
157 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
158 "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
159 option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
160 option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
161 option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
162 option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
164 # For now use system KWIML only if explicitly requested rather
165 # than activating via the general system libs options.
166 option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
167 mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
169 # Mention to the user what system libraries are being used.
170 foreach(util ${UTILITIES} KWIML)
171 if(CMAKE_USE_SYSTEM_${util})
172 message(STATUS "Using system-installed ${util}")
176 # Inform utility library header wrappers whether to use system versions.
177 configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
178 ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
183 #-----------------------------------------------------------------------
184 # a macro to determine the generator and ctest executable to use
185 # for testing. Simply to improve readability of the main script.
186 #-----------------------------------------------------------------------
187 macro(CMAKE_SETUP_TESTING)
189 set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
190 foreach(util CURL EXPAT XMLRPC ZLIB)
191 if(CMAKE_USE_SYSTEM_${util})
192 set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
196 # This variable is set by cmake, however to
197 # test cmake we want to make sure that
198 # the ctest from this cmake is used for testing
199 # and not the ctest from the cmake building and testing
201 if(CMake_TEST_EXTERNAL_CMAKE)
202 set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
203 set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
204 set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
205 foreach(exe cmake ctest cpack)
206 add_executable(${exe} IMPORTED)
207 set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
210 set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
211 set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
212 set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
216 # configure some files for testing
217 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
218 "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
220 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
221 ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
222 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
223 ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
224 configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
225 ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
226 if(BUILD_TESTING AND DART_ROOT)
227 configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
228 ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
230 mark_as_advanced(DART_ROOT)
231 mark_as_advanced(CURL_TESTING)
235 # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
236 # organization feature. Default to ON for non-Express users. Express users must
237 # explicitly turn off this option to build CMake in the Express IDE...
239 option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
240 mark_as_advanced(CMAKE_USE_FOLDERS)
243 option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
244 if(CMake_RUN_CLANG_TIDY)
245 if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
246 message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
248 find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
249 if(NOT CLANG_TIDY_COMMAND)
250 message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
252 set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
254 # provide definitions for targets that require a rebuild once .clang-tidy changes
255 file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
256 set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
257 unset(clang_tidy_sha1)
260 configure_file(.clang-tidy .clang-tidy COPYONLY)
263 option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
265 find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
267 message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
269 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
270 "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp")
274 #-----------------------------------------------------------------------
275 # a macro that only sets the FOLDER target property if it's
277 #-----------------------------------------------------------------------
278 macro(CMAKE_SET_TARGET_FOLDER tgt folder)
279 if(CMAKE_USE_FOLDERS)
280 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
281 if(MSVC AND TARGET ${tgt})
282 set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
285 set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
290 #-----------------------------------------------------------------------
291 # a macro to build the utilities used by CMake
292 # Simply to improve readability of the main script.
293 #-----------------------------------------------------------------------
294 macro (CMAKE_BUILD_UTILITIES)
295 #---------------------------------------------------------------------
296 # Create the kwsys library for CMake.
297 set(KWSYS_NAMESPACE cmsys)
298 set(KWSYS_USE_SystemTools 1)
299 set(KWSYS_USE_Directory 1)
300 set(KWSYS_USE_RegularExpression 1)
301 set(KWSYS_USE_Base64 1)
303 set(KWSYS_USE_Process 1)
304 set(KWSYS_USE_CommandLineArguments 1)
305 set(KWSYS_USE_ConsoleBuf 1)
306 set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
307 set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
308 add_subdirectory(Source/kwsys)
309 set(kwsys_folder "Utilities/KWSys")
310 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
311 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
313 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
314 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
315 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
316 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
317 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
320 #---------------------------------------------------------------------
321 # Setup third-party libraries.
322 # Everything in the tree should be able to include files from the
323 # Utilities directory.
325 ${CMake_BINARY_DIR}/Utilities
326 ${CMake_SOURCE_DIR}/Utilities
329 # check for the use of system libraries versus builtin ones
330 # (a macro defined in this file)
331 CMAKE_HANDLE_SYSTEM_LIBRARIES()
333 if(CMAKE_USE_SYSTEM_KWIML)
334 find_package(KWIML 1.0)
336 message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
338 set(CMake_KWIML_LIBRARIES kwiml::kwiml)
340 set(CMake_KWIML_LIBRARIES "")
342 set(KWIML_TEST_ENABLE 1)
344 add_subdirectory(Utilities/KWIML)
347 if(CMAKE_USE_SYSTEM_LIBRHASH)
348 find_package(LibRHash)
349 if(NOT LibRHash_FOUND)
351 "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
353 set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
355 set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
356 add_subdirectory(Utilities/cmlibrhash)
357 CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
360 #---------------------------------------------------------------------
361 # Build zlib library for Curl, CMake, and CTest.
362 set(CMAKE_ZLIB_HEADER "cm_zlib.h")
363 if(CMAKE_USE_SYSTEM_ZLIB)
367 "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
369 set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
370 set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
372 set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
373 set(CMAKE_ZLIB_LIBRARIES cmzlib)
374 add_subdirectory(Utilities/cmzlib)
375 CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
378 #---------------------------------------------------------------------
379 # Build Curl library for CTest.
380 if(CMAKE_USE_SYSTEM_CURL)
384 "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
386 set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
387 set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
389 set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
390 set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
391 set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
392 add_definitions(-DCURL_STATICLIB)
393 set(CMAKE_CURL_INCLUDES)
394 set(CMAKE_CURL_LIBRARIES cmcurl)
395 if(CMAKE_TESTS_CDASH_SERVER)
396 set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
398 set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
399 if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
400 AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
401 find_package(OpenSSL QUIET)
403 set(_CMAKE_USE_OPENSSL_DEFAULT ON)
406 option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
407 mark_as_advanced(CMAKE_USE_OPENSSL)
408 if(CMAKE_USE_OPENSSL)
409 set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
410 set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
411 mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
413 add_subdirectory(Utilities/cmcurl)
414 CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
415 CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
418 #---------------------------------------------------------------------
419 # Build Compress library for CTest.
420 set(CMAKE_COMPRESS_INCLUDES
421 "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
422 set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
423 add_subdirectory(Utilities/cmcompress)
424 CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
426 #---------------------------------------------------------------------
427 # Build expat library for CMake, CTest, and libarchive.
428 if(CMAKE_USE_SYSTEM_EXPAT)
432 "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
434 set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
435 set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
437 set(CMAKE_EXPAT_INCLUDES)
438 set(CMAKE_EXPAT_LIBRARIES cmexpat)
439 add_subdirectory(Utilities/cmexpat)
440 CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
443 #---------------------------------------------------------------------
444 # Build or use system libbz2 for libarchive.
445 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
446 if(CMAKE_USE_SYSTEM_BZIP2)
449 set(BZIP2_INCLUDE_DIR
450 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
451 set(BZIP2_LIBRARIES cmbzip2)
452 add_subdirectory(Utilities/cmbzip2)
453 CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
457 #---------------------------------------------------------------------
458 # Build or use system liblzma for libarchive.
459 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
460 if(CMAKE_USE_SYSTEM_LIBLZMA)
461 find_package(LibLZMA)
462 if(NOT LIBLZMA_FOUND)
463 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
466 add_subdirectory(Utilities/cmliblzma)
467 CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
468 set(LIBLZMA_HAS_AUTO_DECODER 1)
469 set(LIBLZMA_HAS_EASY_ENCODER 1)
470 set(LIBLZMA_HAS_LZMA_PRESET 1)
471 set(LIBLZMA_INCLUDE_DIR
472 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
473 set(LIBLZMA_LIBRARY cmliblzma)
477 #---------------------------------------------------------------------
478 # Build or use system libarchive for CMake and CTest.
479 if(CMAKE_USE_SYSTEM_LIBARCHIVE)
480 find_package(LibArchive 3.0.0)
481 if(NOT LibArchive_FOUND)
482 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
484 set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
485 set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
487 set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
488 set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
489 set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
490 set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
491 add_definitions(-DLIBARCHIVE_STATIC)
492 set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
493 set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
494 set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
495 set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
496 set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
497 set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
498 set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
499 set(ENABLE_EXPAT ON CACHE INTERNAL "Enable the use of the system EXPAT library if found")
500 set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
501 set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
502 set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
503 set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
504 set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
505 set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
506 add_subdirectory(Utilities/cmlibarchive)
507 CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
508 set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
511 #---------------------------------------------------------------------
512 # Build jsoncpp library.
513 if(CMAKE_USE_SYSTEM_JSONCPP)
514 find_package(JsonCpp)
515 if(NOT JsonCpp_FOUND)
517 "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
519 set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
521 set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
522 add_subdirectory(Utilities/cmjsoncpp)
523 CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
526 #---------------------------------------------------------------------
527 # Build libuv library.
528 if(CMAKE_USE_SYSTEM_LIBUV)
529 find_package(LibUV 1.0.0)
532 "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
534 set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
536 set(CMAKE_LIBUV_LIBRARIES cmlibuv)
537 add_subdirectory(Utilities/cmlibuv)
538 CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
541 #---------------------------------------------------------------------
542 # Build XMLRPC library for CMake and CTest.
544 find_package(XMLRPC QUIET REQUIRED libwww-client)
547 "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
549 set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
550 set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
553 #---------------------------------------------------------------------
556 # there is a bug in the Syllable libraries which makes linking ccmake fail, Alex
557 if(NOT CMAKE_SYSTEM_NAME MATCHES syllable)
558 set(CURSES_NEED_NCURSES TRUE)
559 find_package(Curses QUIET)
561 option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" ON)
563 message("Curses libraries were not found. Curses GUI for CMake will not be built.")
564 set(BUILD_CursesDialog 0)
567 set(BUILD_CursesDialog 0)
570 set(BUILD_CursesDialog 0)
572 if(BUILD_CursesDialog)
573 if(NOT CMAKE_USE_SYSTEM_FORM)
574 add_subdirectory(Source/CursesDialog/form)
575 elseif(NOT CURSES_FORM_LIBRARY)
576 message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
581 #-----------------------------------------------------------------------
582 if(NOT CMake_TEST_EXTERNAL_CMAKE)
583 if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
584 execute_process(COMMAND ${CMAKE_CXX_COMPILER}
585 ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
586 OUTPUT_VARIABLE _GXX_VERSION
588 string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
589 _GXX_VERSION_SHORT ${_GXX_VERSION})
590 if(_GXX_VERSION_SHORT EQUAL 33)
592 "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
593 "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
594 "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
599 #-----------------------------------------------------------------------
600 # The main section of the CMakeLists file
602 #-----------------------------------------------------------------------
603 # Compute CMake_VERSION, etc.
604 include(Source/CMakeVersionCompute.cmake)
606 # Include the standard Dart testing module
608 include (${CMAKE_ROOT}/Modules/Dart.cmake)
610 # Set up test-time configuration.
611 set_directory_properties(PROPERTIES
612 TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
614 if(NOT CMake_TEST_EXTERNAL_CMAKE)
615 # where to write the resulting executables and libraries
616 set(BUILD_SHARED_LIBS OFF)
617 set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
618 set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
619 "Where to put the libraries for CMake")
621 # The CMake executables usually do not need any rpath to run in the build or
623 set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
625 # Load install destinations.
626 include(Source/CMakeInstallDestinations.cmake)
629 include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
632 # no clue why we are testing for this here
633 include(CheckSymbolExists)
634 CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
635 CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
638 # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
640 # If not defined or "", this variable defaults to the server at
641 # "http://open.cdash.org".
643 # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
644 # the network are skipped.
646 # If set to something starting with "http://localhost/", the CDash is
647 # expected to be an instance of CDash used for CDash testing, pointing
648 # to a cdash4simpletest database. In these cases, the CDash dashboards
649 # should be run first.
651 if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
652 set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
655 if(CMake_TEST_EXTERNAL_CMAKE)
656 set(KWIML_TEST_ENABLE 1)
657 add_subdirectory(Utilities/KWIML)
660 if(NOT CMake_TEST_EXTERNAL_CMAKE)
661 # build the utilities (a macro defined in this file)
662 CMAKE_BUILD_UTILITIES()
664 # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
665 # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
666 # which isn't in the default linker search path. So without RPATH ccmake
667 # doesn't run and the build doesn't succeed since ccmake is executed for
668 # generating the documentation.
669 if(BUILD_CursesDialog)
670 get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
671 set(CURSES_NEED_RPATH FALSE)
672 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")
673 set(CURSES_NEED_RPATH TRUE)
679 set(CMAKE_BUNDLE_VERSION
680 "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
681 set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
682 # make sure CMAKE_INSTALL_PREFIX ends in /
683 if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
684 set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
686 set(CMAKE_INSTALL_PREFIX
687 "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
690 set(QT_NEED_RPATH FALSE)
691 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")
692 set(QT_NEED_RPATH TRUE)
697 # The same might be true on other systems for other libraries.
698 # Then only enable RPATH if we have are building at least with cmake 2.4,
699 # since this one has much better RPATH features than cmake 2.2.
700 # The executables are then built with the RPATH for the libraries outside
701 # the build tree, which is both the build and the install RPATH.
703 if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
704 OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
705 set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
706 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
707 set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
712 # add the uninstall support
714 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
715 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
717 add_custom_target(uninstall
718 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
720 include (CMakeCPack.cmake)
724 # setup some Testing support (a macro defined in this file)
725 CMAKE_SETUP_TESTING()
727 if(NOT CMake_TEST_EXTERNAL_CMAKE)
728 if(NOT CMake_VERSION_IS_RELEASE)
729 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
730 NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
731 set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
732 -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
733 -Wmissing-format-attribute -fno-common -Wundef
735 set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
736 -Wshadow -Wpointer-arith -Wformat-security -Wundef
739 foreach(FLAG_LANG C CXX)
740 foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
741 if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
742 set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
748 unset(CXX_FLAGS_LIST)
752 # build the remaining subdirectories
753 add_subdirectory(Source)
754 add_subdirectory(Utilities)
757 add_subdirectory(Tests)
759 if(NOT CMake_TEST_EXTERNAL_CMAKE)
761 CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
762 IF(TARGET CMakeServerLibTests)
763 CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
766 if(TARGET documentation)
767 CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
772 add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
773 --system-information -G "${CMAKE_GENERATOR}" )
775 if(NOT CMake_TEST_EXTERNAL_CMAKE)
776 # Install license file as it requires.
777 install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
779 # Install script directories.
781 DIRECTORY Help Modules Templates
782 DESTINATION ${CMAKE_DATA_DIR}
783 FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
784 DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
785 GROUP_READ GROUP_EXECUTE
786 WORLD_READ WORLD_EXECUTE
787 PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
788 GROUP_READ GROUP_EXECUTE
789 WORLD_READ WORLD_EXECUTE
790 REGEX "Help/dev($|/)" EXCLUDE
793 # Install auxiliary files integrating with other tools.
794 add_subdirectory(Auxiliary)