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 2.8.12.2 FATAL_ERROR)
6 cmake_policy(SET CMP0025 NEW)
9 cmake_policy(SET CMP0053 NEW)
13 # Make sure we can find internal find_package modules only used for
14 # building CMake and not for shipping externally
15 list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
18 # Running from bootstrap script. Set local variable and remove from cache.
19 set(CMAKE_BOOTSTRAP 1)
20 unset(CMAKE_BOOTSTRAP CACHE)
23 if(NOT CMake_TEST_EXTERNAL_CMAKE)
24 set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
27 if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
28 if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
29 set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
37 if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
38 # Disallow architecture-specific try_run. It may not run on the host.
40 if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
41 message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
48 # Use most-recent available language dialects with GNU and Clang
49 if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
50 include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
51 if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
52 set(CMAKE_C_STANDARD 11)
54 set(CMAKE_C_STANDARD 99)
57 if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
58 if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
59 set(CMAKE_CXX_STANDARD 98)
61 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_cstdio.cmake)
62 if(NOT CMake_CXX14_CSTDIO_BROKEN)
63 set(CMAKE_CXX_STANDARD 14)
65 set(CMAKE_CXX_STANDARD 11)
69 if(NOT CMake_TEST_EXTERNAL_CMAKE)
70 # include special compile flags for some compilers
71 include(CompileFlags.cmake)
73 # check for available C++ features
74 include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
77 # set the internal encoding of CMake to UTF-8
78 set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
80 # option to use COMPONENT with install command
81 option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
82 mark_as_advanced(CMake_INSTALL_COMPONENTS)
83 macro(CMake_OPTIONAL_COMPONENT NAME)
84 if(CMake_INSTALL_COMPONENTS)
85 set(COMPONENT COMPONENT ${NAME})
91 # option to disable installing 3rd-party dependencies
92 option(CMake_INSTALL_DEPENDENCIES
93 "Whether to install 3rd-party runtime dependencies" OFF)
94 mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
96 # option to build reference for CMake developers
97 option(CMake_BUILD_DEVELOPER_REFERENCE
98 "Build CMake Developer Reference" OFF)
99 mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
101 #-----------------------------------------------------------------------
102 # a macro to deal with system libraries, implemented as a macro
103 # simply to improve readability of the main script
104 #-----------------------------------------------------------------------
105 macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
106 # Options have dependencies.
107 include(CMakeDependentOption)
109 # Optionally use system xmlrpc. We no longer build or use it by default.
110 option(CTEST_USE_XMLRPC "Enable xmlrpc submission method in CTest." OFF)
111 mark_as_advanced(CTEST_USE_XMLRPC)
113 # Allow the user to enable/disable all system utility library options by
114 # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
115 set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB)
116 foreach(util ${UTILITIES})
117 if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
118 AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
119 set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
121 if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
122 if(CMAKE_USE_SYSTEM_LIBRARY_${util})
123 set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
125 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
128 unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
130 string(TOLOWER "${util}" lutil)
131 set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
132 CACHE BOOL "Use system-installed ${lutil}" FORCE)
134 set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
138 unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
141 # Optionally use system utility libraries.
142 option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
143 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_CURL "Use system-installed curl"
144 "${CMAKE_USE_SYSTEM_LIBRARY_CURL}" "NOT CTEST_USE_XMLRPC" ON)
145 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat"
146 "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}" "NOT CTEST_USE_XMLRPC" ON)
147 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
148 "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
149 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
150 "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
151 CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
152 "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
153 option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
154 option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
155 option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
156 option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
158 # For now use system KWIML only if explicitly requested rather
159 # than activating via the general system libs options.
160 option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
161 mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
163 # Mention to the user what system libraries are being used.
164 foreach(util ${UTILITIES} KWIML)
165 if(CMAKE_USE_SYSTEM_${util})
166 message(STATUS "Using system-installed ${util}")
170 # Inform utility library header wrappers whether to use system versions.
171 configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
172 ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
177 #-----------------------------------------------------------------------
178 # a macro to determine the generator and ctest executable to use
179 # for testing. Simply to improve readability of the main script.
180 #-----------------------------------------------------------------------
181 macro(CMAKE_SETUP_TESTING)
183 set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
184 foreach(util CURL EXPAT XMLRPC ZLIB)
185 if(CMAKE_USE_SYSTEM_${util})
186 set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
190 # This variable is set by cmake, however to
191 # test cmake we want to make sure that
192 # the ctest from this cmake is used for testing
193 # and not the ctest from the cmake building and testing
195 if(CMake_TEST_EXTERNAL_CMAKE)
196 set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
197 set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
198 set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
199 foreach(exe cmake ctest cpack)
200 add_executable(${exe} IMPORTED)
201 set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
204 set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
205 set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
206 set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
210 # configure some files for testing
211 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
212 "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
214 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
215 ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
216 configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
217 ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
218 configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
219 ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
220 if(BUILD_TESTING AND DART_ROOT)
221 configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
222 ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
224 mark_as_advanced(DART_ROOT)
225 mark_as_advanced(CURL_TESTING)
229 # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
230 # organization feature. Default to ON for non-Express users. Express users must
231 # explicitly turn off this option to build CMake in the Express IDE...
233 option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
234 mark_as_advanced(CMAKE_USE_FOLDERS)
237 option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
238 if(CMake_RUN_CLANG_TIDY)
239 if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
240 message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
242 find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
243 if(NOT CLANG_TIDY_COMMAND)
244 message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
246 set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
248 configure_file(.clang-tidy .clang-tidy COPYONLY)
251 option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
253 find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
255 message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
257 set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
258 "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp")
262 #-----------------------------------------------------------------------
263 # a macro that only sets the FOLDER target property if it's
265 #-----------------------------------------------------------------------
266 macro(CMAKE_SET_TARGET_FOLDER tgt folder)
267 if(CMAKE_USE_FOLDERS)
268 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
269 if(MSVC AND TARGET ${tgt})
270 set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
273 set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
278 #-----------------------------------------------------------------------
279 # a macro to build the utilities used by CMake
280 # Simply to improve readability of the main script.
281 #-----------------------------------------------------------------------
282 macro (CMAKE_BUILD_UTILITIES)
283 #---------------------------------------------------------------------
284 # Create the kwsys library for CMake.
285 set(KWSYS_NAMESPACE cmsys)
286 set(KWSYS_USE_SystemTools 1)
287 set(KWSYS_USE_Directory 1)
288 set(KWSYS_USE_RegularExpression 1)
289 set(KWSYS_USE_Base64 1)
291 set(KWSYS_USE_Process 1)
292 set(KWSYS_USE_CommandLineArguments 1)
293 set(KWSYS_USE_ConsoleBuf 1)
294 set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
295 set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
296 add_subdirectory(Source/kwsys)
297 set(kwsys_folder "Utilities/KWSys")
298 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
299 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
301 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
302 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
303 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
304 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
305 CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
308 #---------------------------------------------------------------------
309 # Setup third-party libraries.
310 # Everything in the tree should be able to include files from the
311 # Utilities directory.
313 ${CMake_BINARY_DIR}/Utilities
314 ${CMake_SOURCE_DIR}/Utilities
317 # check for the use of system libraries versus builtin ones
318 # (a macro defined in this file)
319 CMAKE_HANDLE_SYSTEM_LIBRARIES()
321 if(CMAKE_USE_SYSTEM_KWIML)
322 find_package(KWIML 1.0)
324 message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
326 set(CMake_KWIML_LIBRARIES kwiml::kwiml)
328 set(CMake_KWIML_LIBRARIES "")
330 set(KWIML_TEST_ENABLE 1)
332 add_subdirectory(Utilities/KWIML)
335 if(CMAKE_USE_SYSTEM_LIBRHASH)
336 if(NOT CMAKE_VERSION VERSION_LESS 3.0)
337 find_package(LibRHash)
339 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBRHASH requires CMake >= 3.0")
341 if(NOT LibRHash_FOUND)
343 "CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
345 set(CMAKE_LIBRHASH_LIBRARIES LibRHash::LibRHash)
347 set(CMAKE_LIBRHASH_LIBRARIES cmlibrhash)
348 add_subdirectory(Utilities/cmlibrhash)
349 CMAKE_SET_TARGET_FOLDER(cmlibrhash "Utilities/3rdParty")
352 #---------------------------------------------------------------------
353 # Build zlib library for Curl, CMake, and CTest.
354 set(CMAKE_ZLIB_HEADER "cm_zlib.h")
355 if(CMAKE_USE_SYSTEM_ZLIB)
359 "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
361 set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
362 set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
364 set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
365 set(CMAKE_ZLIB_LIBRARIES cmzlib)
366 add_subdirectory(Utilities/cmzlib)
367 CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
370 #---------------------------------------------------------------------
371 # Build Curl library for CTest.
372 if(CMAKE_USE_SYSTEM_CURL)
376 "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
378 set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
379 set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
381 set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
382 set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
383 set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
384 add_definitions(-DCURL_STATICLIB)
385 set(CMAKE_CURL_INCLUDES)
386 set(CMAKE_CURL_LIBRARIES cmcurl)
387 if(CMAKE_TESTS_CDASH_SERVER)
388 set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
390 set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
391 if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
392 AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
393 find_package(OpenSSL QUIET)
395 set(_CMAKE_USE_OPENSSL_DEFAULT ON)
398 option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
399 mark_as_advanced(CMAKE_USE_OPENSSL)
400 if(CMAKE_USE_OPENSSL)
401 set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
402 set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
403 mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
405 add_subdirectory(Utilities/cmcurl)
406 CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
407 CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
410 #---------------------------------------------------------------------
411 # Build Compress library for CTest.
412 set(CMAKE_COMPRESS_INCLUDES
413 "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
414 set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
415 add_subdirectory(Utilities/cmcompress)
416 CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
418 #---------------------------------------------------------------------
419 # Build expat library for CMake, CTest, and libarchive.
420 if(CMAKE_USE_SYSTEM_EXPAT)
424 "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
426 set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
427 set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
429 set(CMAKE_EXPAT_INCLUDES)
430 set(CMAKE_EXPAT_LIBRARIES cmexpat)
431 add_subdirectory(Utilities/cmexpat)
432 CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
435 #---------------------------------------------------------------------
436 # Build or use system libbz2 for libarchive.
437 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
438 if(CMAKE_USE_SYSTEM_BZIP2)
441 set(BZIP2_INCLUDE_DIR
442 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
443 set(BZIP2_LIBRARIES cmbzip2)
444 add_subdirectory(Utilities/cmbzip2)
445 CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
449 #---------------------------------------------------------------------
450 # Build or use system liblzma for libarchive.
451 if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
452 if(CMAKE_USE_SYSTEM_LIBLZMA)
453 find_package(LibLZMA)
454 if(NOT LIBLZMA_FOUND)
455 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
458 add_subdirectory(Utilities/cmliblzma)
459 CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
460 set(LIBLZMA_HAS_AUTO_DECODER 1)
461 set(LIBLZMA_HAS_EASY_ENCODER 1)
462 set(LIBLZMA_HAS_LZMA_PRESET 1)
463 set(LIBLZMA_INCLUDE_DIR
464 "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
465 set(LIBLZMA_LIBRARY cmliblzma)
469 #---------------------------------------------------------------------
470 # Build or use system libarchive for CMake and CTest.
471 if(CMAKE_USE_SYSTEM_LIBARCHIVE)
472 find_package(LibArchive 3.0.0)
473 if(NOT LibArchive_FOUND)
474 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
476 set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
477 set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
479 set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES})
480 set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES})
481 set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
482 set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
483 add_definitions(-DLIBARCHIVE_STATIC)
484 set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
485 set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
486 set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system LZMA library if found")
487 set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
488 set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
489 set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
490 set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system libxml2 library if found")
491 set(ENABLE_EXPAT ON CACHE INTERNAL "Enable the use of the system EXPAT library if found")
492 set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system PCREPOSIX library if found")
493 set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system LibGCC library if found")
494 set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
495 set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
496 set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
497 set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
498 add_subdirectory(Utilities/cmlibarchive)
499 CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
500 set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
503 #---------------------------------------------------------------------
504 # Build jsoncpp library.
505 if(CMAKE_USE_SYSTEM_JSONCPP)
506 if(NOT CMAKE_VERSION VERSION_LESS 3.0)
507 find_package(JsonCpp)
509 message(FATAL_ERROR "CMAKE_USE_SYSTEM_JSONCPP requires CMake >= 3.0")
511 if(NOT JsonCpp_FOUND)
513 "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
515 set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
517 set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
518 add_subdirectory(Utilities/cmjsoncpp)
519 CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
522 #---------------------------------------------------------------------
523 # Build libuv library.
524 if(NOT DEFINED CMAKE_USE_LIBUV)
525 set(CMAKE_USE_LIBUV 1)
527 include(CheckCSourceCompiles)
528 check_c_source_compiles("
529 #include <CoreServices/CoreServices.h>
530 #include <AvailabilityMacros.h>
531 #ifndef MAC_OS_X_VERSION_10_5
532 #error \"MAC_OS_X_VERSION_10_5 is not defined\"
534 int main(void) { return 0; }
535 " HAVE_CoreServices_OS_X_10_5)
536 if(NOT HAVE_CoreServices_OS_X_10_5)
537 set(CMAKE_USE_LIBUV 0)
539 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
540 # Disable until it can be ported.
541 set(CMAKE_USE_LIBUV 0)
545 if(CMAKE_USE_SYSTEM_LIBUV)
546 if(NOT CMAKE_VERSION VERSION_LESS 3.0)
547 find_package(LibUV 1.0.0)
549 message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBUV requires CMake >= 3.0")
553 "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
555 set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
557 set(CMAKE_LIBUV_LIBRARIES cmlibuv)
558 add_subdirectory(Utilities/cmlibuv)
559 CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
562 set(CMAKE_LIBUV_LIBRARIES)
565 #---------------------------------------------------------------------
566 # Build XMLRPC library for CMake and CTest.
568 find_package(XMLRPC QUIET REQUIRED libwww-client)
571 "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
573 set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
574 set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
577 #---------------------------------------------------------------------
580 # there is a bug in the Syllable libraries which makes linking ccmake fail, Alex
581 if(NOT CMAKE_SYSTEM_NAME MATCHES syllable)
582 set(CURSES_NEED_NCURSES TRUE)
583 find_package(Curses QUIET)
585 option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" ON)
587 message("Curses libraries were not found. Curses GUI for CMake will not be built.")
588 set(BUILD_CursesDialog 0)
591 set(BUILD_CursesDialog 0)
594 set(BUILD_CursesDialog 0)
596 if(BUILD_CursesDialog)
597 if(NOT CMAKE_USE_SYSTEM_FORM)
598 add_subdirectory(Source/CursesDialog/form)
599 elseif(NOT CURSES_FORM_LIBRARY)
600 message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
605 #-----------------------------------------------------------------------
606 if(NOT CMake_TEST_EXTERNAL_CMAKE)
607 if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
608 execute_process(COMMAND ${CMAKE_CXX_COMPILER}
609 ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
610 OUTPUT_VARIABLE _GXX_VERSION
612 string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
613 _GXX_VERSION_SHORT ${_GXX_VERSION})
614 if(_GXX_VERSION_SHORT EQUAL 33)
616 "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
617 "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
618 "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
623 #-----------------------------------------------------------------------
624 # The main section of the CMakeLists file
626 #-----------------------------------------------------------------------
627 # Compute CMake_VERSION, etc.
628 include(Source/CMakeVersionCompute.cmake)
630 # Include the standard Dart testing module
632 include (${CMAKE_ROOT}/Modules/Dart.cmake)
634 # Set up test-time configuration.
635 set_directory_properties(PROPERTIES
636 TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
638 if(NOT CMake_TEST_EXTERNAL_CMAKE)
639 # where to write the resulting executables and libraries
640 set(BUILD_SHARED_LIBS OFF)
641 set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
642 set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
643 "Where to put the libraries for CMake")
645 # The CMake executables usually do not need any rpath to run in the build or
647 set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
649 # Load install destinations.
650 include(Source/CMakeInstallDestinations.cmake)
653 include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
656 # no clue why we are testing for this here
657 include(CheckSymbolExists)
658 CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
659 CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
662 # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
664 # If not defined or "", this variable defaults to the server at
665 # "http://open.cdash.org".
667 # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
668 # the network are skipped.
670 # If set to something starting with "http://localhost/", the CDash is
671 # expected to be an instance of CDash used for CDash testing, pointing
672 # to a cdash4simpletest database. In these cases, the CDash dashboards
673 # should be run first.
675 if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
676 set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
679 if(CMake_TEST_EXTERNAL_CMAKE)
680 set(KWIML_TEST_ENABLE 1)
681 add_subdirectory(Utilities/KWIML)
684 if(NOT CMake_TEST_EXTERNAL_CMAKE)
685 # build the utilities (a macro defined in this file)
686 CMAKE_BUILD_UTILITIES()
688 # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
689 # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
690 # which isn't in the default linker search path. So without RPATH ccmake
691 # doesn't run and the build doesn't succeed since ccmake is executed for
692 # generating the documentation.
693 if(BUILD_CursesDialog)
694 get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
695 set(CURSES_NEED_RPATH FALSE)
696 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")
697 set(CURSES_NEED_RPATH TRUE)
703 set(CMAKE_BUNDLE_VERSION
704 "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
705 set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
706 # make sure CMAKE_INSTALL_PREFIX ends in /
707 if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
708 set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
710 set(CMAKE_INSTALL_PREFIX
711 "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
714 set(QT_NEED_RPATH FALSE)
715 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")
716 set(QT_NEED_RPATH TRUE)
721 # The same might be true on other systems for other libraries.
722 # Then only enable RPATH if we have are building at least with cmake 2.4,
723 # since this one has much better RPATH features than cmake 2.2.
724 # The executables are then built with the RPATH for the libraries outside
725 # the build tree, which is both the build and the install RPATH.
727 if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB
728 OR CMAKE_USE_SYSTEM_EXPAT OR CTEST_USE_XMLRPC OR CURSES_NEED_RPATH OR QT_NEED_RPATH)
729 set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
730 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
731 set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
736 # add the uninstall support
738 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
739 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
741 add_custom_target(uninstall
742 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
744 include (CMakeCPack.cmake)
748 # setup some Testing support (a macro defined in this file)
749 CMAKE_SETUP_TESTING()
751 # Check whether to build server mode or not:
752 if(NOT CMake_TEST_EXTERNAL_CMAKE)
753 if(NOT DEFINED CMake_ENABLE_SERVER_MODE)
754 list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_auto_type CMake_HAVE_CXX_AUTO_TYPE)
755 list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_range_for CMake_HAVE_CXX_RANGE_FOR)
757 AND CMake_HAVE_CXX_AUTO_TYPE
758 AND CMake_HAVE_CXX_MAKE_UNIQUE
759 AND CMake_HAVE_CXX_RANGE_FOR
761 set(CMake_ENABLE_SERVER_MODE 1)
763 set(CMake_ENABLE_SERVER_MODE 0)
766 if(CMake_ENABLE_SERVER_MODE AND NOT CMAKE_USE_LIBUV)
767 message(FATAL_ERROR "The server mode requires libuv!")
770 set(CMake_ENABLE_SERVER_MODE 0)
772 if(NOT DEFINED CMake_TEST_SERVER_MODE)
773 set(CMake_TEST_SERVER_MODE ${CMake_ENABLE_SERVER_MODE})
776 if(NOT CMake_TEST_EXTERNAL_CMAKE)
777 if(NOT CMake_VERSION_IS_RELEASE)
778 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
779 NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
780 set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
781 -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
782 -Wmissing-format-attribute -fno-common -Wundef
784 set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
785 -Wshadow -Wpointer-arith -Wformat-security -Wundef
788 foreach(FLAG_LANG C CXX)
789 foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
790 if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
791 set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
797 unset(CXX_FLAGS_LIST)
801 # build the remaining subdirectories
802 add_subdirectory(Source)
803 add_subdirectory(Utilities)
806 add_subdirectory(Tests)
808 if(NOT CMake_TEST_EXTERNAL_CMAKE)
810 CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
812 if(TARGET documentation)
813 CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
818 add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
819 --system-information -G "${CMAKE_GENERATOR}" )
821 if(NOT CMake_TEST_EXTERNAL_CMAKE)
822 # Install license file as it requires.
823 install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
825 # Install script directories.
827 DIRECTORY Help Modules Templates
828 DESTINATION ${CMAKE_DATA_DIR}
829 FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
830 DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
831 GROUP_READ GROUP_EXECUTE
832 WORLD_READ WORLD_EXECUTE
833 PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
834 GROUP_READ GROUP_EXECUTE
835 WORLD_READ WORLD_EXECUTE
836 REGEX "Help/dev($|/)" EXCLUDE
839 # Install auxiliary files integrating with other tools.
840 add_subdirectory(Auxiliary)