CMakeLists.txt 29 KB
Newer Older
1 2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

4
cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR)
5 6 7
if(POLICY CMP0025)
  cmake_policy(SET CMP0025 NEW)
endif()
Stephen Kelly's avatar
Stephen Kelly committed
8 9 10
if(POLICY CMP0053)
  cmake_policy(SET CMP0053 NEW)
endif()
11
project(CMake)
12

13
if(CMAKE_BOOTSTRAP)
14
  # Running from bootstrap script.  Set local variable and remove from cache.
15 16 17
  set(CMAKE_BOOTSTRAP 1)
  unset(CMAKE_BOOTSTRAP CACHE)
endif()
18

19 20 21
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
endif()
22

23 24 25 26 27 28 29 30 31 32
if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
    set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
  else()
    set(USE_LGPL "2.1")
  endif()
else()
  set(USE_LGPL "")
endif()

33
if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
34
  # Disallow architecture-specific try_run.  It may not run on the host.
35 36 37 38
  macro(TRY_RUN)
    if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
      message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
    else()
39
      _TRY_RUN(${ARGV})
40 41 42
    endif()
  endmacro()
endif()
43

44
# Use most-recent available language dialects with GNU and Clang
45
if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
46 47 48 49 50 51
  include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
  if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
    set(CMAKE_C_STANDARD 11)
  else()
    set(CMAKE_C_STANDARD 99)
  endif()
52
endif()
53
if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
54 55 56 57 58 59
  include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_cstdio.cmake)
  if(NOT CMake_CXX14_CSTDIO_BROKEN)
    set(CMAKE_CXX_STANDARD 14)
  else()
    set(CMAKE_CXX_STANDARD 11)
  endif()
60
endif()
61
if(NOT CMake_TEST_EXTERNAL_CMAKE)
62
  include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
63
endif()
64

65
# option to set the internal encoding of CMake to UTF-8
66
option(CMAKE_ENCODING_UTF8 "Use UTF-8 encoding internally." ON)
67 68 69 70 71
mark_as_advanced(CMAKE_ENCODING_UTF8)
if(CMAKE_ENCODING_UTF8)
  set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
endif()

72 73 74 75 76 77 78 79 80 81 82
# option to use COMPONENT with install command
option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
mark_as_advanced(CMake_INSTALL_COMPONENTS)
macro(CMake_OPTIONAL_COMPONENT NAME)
  if(CMake_INSTALL_COMPONENTS)
    set(COMPONENT COMPONENT ${NAME})
  else()
    set(COMPONENT)
  endif()
endmacro()

83 84
# option to disable installing 3rd-party dependencies
option(CMake_INSTALL_DEPENDENCIES
85
  "Whether to install 3rd-party runtime dependencies" OFF)
86 87
mark_as_advanced(CMake_INSTALL_DEPENDENCIES)

88 89 90 91 92
# option to build reference for CMake developers
option(CMake_BUILD_DEVELOPER_REFERENCE
  "Build CMake Developer Reference" OFF)
mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)

93 94 95 96
#-----------------------------------------------------------------------
# a macro to deal with system libraries, implemented as a macro
# simply to improve readability of the main script
#-----------------------------------------------------------------------
97
macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
98
  # Options have dependencies.
99
  include(CMakeDependentOption)
100

101
  # Optionally use system xmlrpc.  We no longer build or use it by default.
102 103
  option(CTEST_USE_XMLRPC "Enable xmlrpc submission method in CTest." OFF)
  mark_as_advanced(CTEST_USE_XMLRPC)
104

105 106
  # Allow the user to enable/disable all system utility library options by
  # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
107
  set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBUV ZLIB)
108 109
  foreach(util ${UTILITIES})
    if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
110
        AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
111 112 113 114 115 116 117 118 119 120 121 122 123
      set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
    endif()
    if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
      if(CMAKE_USE_SYSTEM_LIBRARY_${util})
        set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
      else()
        set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
      endif()
      if(CMAKE_BOOTSTRAP)
        unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
      endif()
      string(TOLOWER "${util}" lutil)
      set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
124
        CACHE BOOL "Use system-installed ${lutil}" FORCE)
125 126 127
    else()
      set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
    endif()
128
  endforeach()
129 130 131
  if(CMAKE_BOOTSTRAP)
    unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
  endif()
132 133

  # Optionally use system utility libraries.
134
  option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
135
  CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_CURL "Use system-installed curl"
136
    "${CMAKE_USE_SYSTEM_LIBRARY_CURL}" "NOT CTEST_USE_XMLRPC" ON)
137
  CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat"
138
    "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}" "NOT CTEST_USE_XMLRPC" ON)
139
  CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
140
    "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
141
  CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
142
    "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
143 144
  CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
    "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
145
  option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
146
  option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
147
  option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
148

149 150 151 152 153
  # For now use system KWIML only if explicitly requested rather
  # than activating via the general system libs options.
  option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
  mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)

154
  # Mention to the user what system libraries are being used.
155
  foreach(util ${UTILITIES} KWIML)
156 157
    if(CMAKE_USE_SYSTEM_${util})
      message(STATUS "Using system-installed ${util}")
158 159
    endif()
  endforeach()
160 161

  # Inform utility library header wrappers whether to use system versions.
162
  configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
163 164 165
    ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
    @ONLY)

166
endmacro()
167 168 169 170 171

#-----------------------------------------------------------------------
# a macro to determine the generator and ctest executable to use
# for testing. Simply to improve readability of the main script.
#-----------------------------------------------------------------------
172 173 174 175 176 177
macro(CMAKE_SETUP_TESTING)
  if(BUILD_TESTING)
    set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
    foreach(util CURL EXPAT XMLRPC ZLIB)
      if(CMAKE_USE_SYSTEM_${util})
        set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
178 179
      endif()
    endforeach()
180

181 182 183 184 185
    # This variable is set by cmake, however to
    # test cmake we want to make sure that
    # the ctest from this cmake is used for testing
    # and not the ctest from the cmake building and testing
    # cmake.
186 187 188 189 190 191 192 193 194 195 196 197 198
    if(CMake_TEST_EXTERNAL_CMAKE)
      set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
      set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
      set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
      foreach(exe cmake ctest cpack)
        add_executable(${exe} IMPORTED)
        set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
      endforeach()
    else()
      set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
      set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
      set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
    endif()
199
  endif()
200 201

  # configure some files for testing
202
  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
203
    "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
204
    @ONLY)
205
  configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
206
    ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
207
  configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
208
    ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
209
  configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
210
    ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
211 212
  if(BUILD_TESTING AND DART_ROOT)
    configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
Ken Martin's avatar
Ken Martin committed
213
      ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
214
  endif()
215 216
  mark_as_advanced(DART_ROOT)
  mark_as_advanced(CURL_TESTING)
217
endmacro()
218 219


220 221 222 223
# Provide a way for Visual Studio Express users to turn OFF the new FOLDER
# organization feature. Default to ON for non-Express users. Express users must
# explicitly turn off this option to build CMake in the Express IDE...
#
224 225
option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
mark_as_advanced(CMAKE_USE_FOLDERS)
226 227 228 229 230 231


#-----------------------------------------------------------------------
# a macro that only sets the FOLDER target property if it's
# "appropriate"
#-----------------------------------------------------------------------
232 233 234
macro(CMAKE_SET_TARGET_FOLDER tgt folder)
  if(CMAKE_USE_FOLDERS)
    set_property(GLOBAL PROPERTY USE_FOLDERS ON)
235 236
    if(MSVC AND TARGET ${tgt})
      set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
237 238 239 240
    endif()
  else()
    set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
  endif()
241
endmacro()
242

243 244 245 246 247

#-----------------------------------------------------------------------
# a macro to build the utilities used by CMake
# Simply to improve readability of the main script.
#-----------------------------------------------------------------------
248
macro (CMAKE_BUILD_UTILITIES)
249 250
  #---------------------------------------------------------------------
  # Create the kwsys library for CMake.
251 252 253 254 255 256 257 258 259
  set(KWSYS_NAMESPACE cmsys)
  set(KWSYS_USE_SystemTools 1)
  set(KWSYS_USE_Directory 1)
  set(KWSYS_USE_RegularExpression 1)
  set(KWSYS_USE_Base64 1)
  set(KWSYS_USE_MD5 1)
  set(KWSYS_USE_Process 1)
  set(KWSYS_USE_CommandLineArguments 1)
  set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
260
  set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
261 262
  add_subdirectory(Source/kwsys)
  set(kwsys_folder "Utilities/KWSys")
263 264
  CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
  CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
265 266 267 268 269 270 271
  if(BUILD_TESTING)
    CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
    CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
    CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
    CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
    CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
  endif()
272

273 274 275 276
  #---------------------------------------------------------------------
  # Setup third-party libraries.
  # Everything in the tree should be able to include files from the
  # Utilities directory.
277
  include_directories(
278
    ${CMake_BINARY_DIR}/Utilities
279
    ${CMake_SOURCE_DIR}/Utilities
280
    )
281

282
  # check for the use of system libraries versus builtin ones
Ken Martin's avatar
Ken Martin committed
283
  # (a macro defined in this file)
284
  CMAKE_HANDLE_SYSTEM_LIBRARIES()
285

286 287 288 289 290 291 292 293 294 295 296 297 298 299
  if(CMAKE_USE_SYSTEM_KWIML)
    find_package(KWIML 1.0)
    if(NOT KWIML_FOUND)
      message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!")
    endif()
    set(CMake_KWIML_LIBRARIES kwiml::kwiml)
  else()
    set(CMake_KWIML_LIBRARIES "")
    if(BUILD_TESTING)
      set(KWIML_TEST_ENABLE 1)
    endif()
    add_subdirectory(Utilities/KWIML)
  endif()

300 301
  #---------------------------------------------------------------------
  # Build zlib library for Curl, CMake, and CTest.
302 303 304 305 306
  set(CMAKE_ZLIB_HEADER "cm_zlib.h")
  if(CMAKE_USE_SYSTEM_ZLIB)
    find_package(ZLIB)
    if(NOT ZLIB_FOUND)
      message(FATAL_ERROR
307
        "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
308
    endif()
309 310
    set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
    set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
311
  else()
312 313 314
    set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
    set(CMAKE_ZLIB_LIBRARIES cmzlib)
    add_subdirectory(Utilities/cmzlib)
315
    CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
316
  endif()
317

318 319
  #---------------------------------------------------------------------
  # Build Curl library for CTest.
320 321 322 323
  if(CMAKE_USE_SYSTEM_CURL)
    find_package(CURL)
    if(NOT CURL_FOUND)
      message(FATAL_ERROR
324
        "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
325
    endif()
326 327
    set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
    set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
328
  else()
329 330 331
    set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
    set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
    set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
332
    add_definitions(-DCURL_STATICLIB)
333 334 335 336
    set(CMAKE_CURL_INCLUDES)
    set(CMAKE_CURL_LIBRARIES cmcurl)
    if(CMAKE_TESTS_CDASH_SERVER)
      set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
337
    endif()
338 339 340 341 342 343 344 345 346
    set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
    if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
        AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
      find_package(OpenSSL QUIET)
      if(OPENSSL_FOUND)
        set(_CMAKE_USE_OPENSSL_DEFAULT ON)
      endif()
    endif()
    option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
347 348 349 350 351 352
    mark_as_advanced(CMAKE_USE_OPENSSL)
    if(CMAKE_USE_OPENSSL)
      set(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle")
      set(CURL_CA_PATH "" CACHE PATH "Path to SSL CA Certificate Directory")
      mark_as_advanced(CURL_CA_BUNDLE CURL_CA_PATH)
    endif()
353
    add_subdirectory(Utilities/cmcurl)
354 355
    CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
    CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
356
  endif()
357 358 359

  #---------------------------------------------------------------------
  # Build Compress library for CTest.
360
  set(CMAKE_COMPRESS_INCLUDES
361
    "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
362 363
  set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
  add_subdirectory(Utilities/cmcompress)
364
  CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
365 366 367 368
  if(CMAKE_USE_SYSTEM_BZIP2)
    find_package(BZip2)
  else()
    set(BZIP2_INCLUDE_DIR
369
      "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
370 371
    set(BZIP2_LIBRARIES cmbzip2)
    add_subdirectory(Utilities/cmbzip2)
372
    CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
373
  endif()
374

375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
  #---------------------------------------------------------------------
  # Build or use system liblzma for libarchive.
  if(CMAKE_USE_SYSTEM_LIBLZMA)
    find_package(LibLZMA)
    if(NOT LIBLZMA_FOUND)
      message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBLZMA is ON but LibLZMA is not found!")
    endif()
    set(LZMA_INCLUDE_DIR ${LIBLZMA_INCLUDE_DIRS})
    set(LZMA_LIBRARY ${LIBLZMA_LIBRARIES})
  else()
    add_subdirectory(Utilities/cmliblzma)
    CMAKE_SET_TARGET_FOLDER(cmliblzma "Utilities/3rdParty")
    set(LZMA_INCLUDE_DIR
      "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmliblzma/liblzma/api")
    set(LZMA_LIBRARY cmliblzma)
  endif()

392 393
  #---------------------------------------------------------------------
  # Build or use system libarchive for CMake and CTest.
394
  if(CMAKE_USE_SYSTEM_LIBARCHIVE)
395
    find_package(LibArchive 3.0.0)
396 397 398 399 400
    if(NOT LibArchive_FOUND)
      message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
    endif()
    set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
    set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
401
  else()
402 403 404 405 406
    set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
    set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
    add_definitions(-DLIBARCHIVE_STATIC)
    set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
    set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
407
    set(ENABLE_LZMA ON CACHE INTERNAL "Enable the use of the system found LZMA library if found")
408 409
    set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system found ZLIB library if found")
    set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system found BZip2 library if found")
410
    set(ENABLE_LIBXML2 OFF CACHE INTERNAL "Enable the use of the system found libxml2 library if found")
411 412 413
    set(ENABLE_EXPAT OFF CACHE INTERNAL "Enable the use of the system found EXPAT library if found")
    set(ENABLE_PCREPOSIX OFF CACHE INTERNAL "Enable the use of the system found PCREPOSIX library if found")
    set(ENABLE_LibGCC OFF CACHE INTERNAL "Enable the use of the system found LibGCC library if found")
414 415 416
    set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
    set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
    set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
417
    set(ENABLE_CNG OFF CACHE INTERNAL "Enable the use of CNG(Crypto Next Generation)")
418
    add_subdirectory(Utilities/cmlibarchive)
419
    CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
420
    set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
421
  endif()
422

423 424
  #---------------------------------------------------------------------
  # Build expat library for CMake and CTest.
425 426 427 428
  if(CMAKE_USE_SYSTEM_EXPAT)
    find_package(EXPAT)
    if(NOT EXPAT_FOUND)
      message(FATAL_ERROR
429
        "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
430
    endif()
431 432
    set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
    set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
433
  else()
434 435 436
    set(CMAKE_EXPAT_INCLUDES)
    set(CMAKE_EXPAT_LIBRARIES cmexpat)
    add_subdirectory(Utilities/cmexpat)
437
    CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
438
  endif()
439

440 441
  #---------------------------------------------------------------------
  # Build jsoncpp library.
442
  if(CMAKE_USE_SYSTEM_JSONCPP)
443 444
    if(NOT CMAKE_VERSION VERSION_LESS 3.0)
      include(${CMake_SOURCE_DIR}/Source/Modules/FindJsonCpp.cmake)
445 446 447 448 449 450 451 452 453 454 455 456 457
    else()
      message(FATAL_ERROR "CMAKE_USE_SYSTEM_JSONCPP requires CMake >= 3.0")
    endif()
    if(NOT JsonCpp_FOUND)
      message(FATAL_ERROR
        "CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
    endif()
    set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
  else()
    set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
    add_subdirectory(Utilities/cmjsoncpp)
    CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
  endif()
458

459 460 461 462
  #---------------------------------------------------------------------
  # Build libuv library.
  if(NOT DEFINED CMAKE_USE_LIBUV)
    set(CMAKE_USE_LIBUV 1)
463 464 465 466 467 468 469 470 471 472 473 474 475
    if(APPLE)
      include(CheckCSourceCompiles)
      check_c_source_compiles("
#include <CoreServices/CoreServices.h>
#include <AvailabilityMacros.h>
#ifndef MAC_OS_X_VERSION_10_5
#error \"MAC_OS_X_VERSION_10_5 is not defined\"
#endif
int main(void) { return 0; }
" HAVE_CoreServices_OS_X_10_5)
      if(NOT HAVE_CoreServices_OS_X_10_5)
        set(CMAKE_USE_LIBUV 0)
      endif()
Brad King's avatar
Brad King committed
476 477 478
    elseif(CYGWIN)
      # libuv does not support Cygwin
      set(CMAKE_USE_LIBUV 0)
Brad King's avatar
Brad King committed
479 480 481
    elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
      # Disable until it can be ported.
      set(CMAKE_USE_LIBUV 0)
Brad King's avatar
Brad King committed
482 483 484
    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
      # Disable until it can be ported.
      set(CMAKE_USE_LIBUV 0)
485
    endif()
486 487
  endif()
  if(CMAKE_USE_LIBUV)
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    if(CMAKE_USE_SYSTEM_LIBUV)
      if(NOT CMAKE_VERSION VERSION_LESS 3.0)
        include(${CMake_SOURCE_DIR}/Source/Modules/FindLibUV.cmake)
      else()
        message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBUV requires CMake >= 3.0")
      endif()
      if(NOT LIBUV_FOUND)
        message(FATAL_ERROR
          "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
      endif()
      set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
    else()
      set(CMAKE_LIBUV_LIBRARIES cmlibuv)
      add_subdirectory(Utilities/cmlibuv)
      CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
    endif()
504 505 506 507
  else()
    set(CMAKE_LIBUV_LIBRARIES)
  endif()

508 509
  #---------------------------------------------------------------------
  # Build XMLRPC library for CMake and CTest.
510 511 512 513
  if(CTEST_USE_XMLRPC)
    find_package(XMLRPC QUIET REQUIRED libwww-client)
    if(NOT XMLRPC_FOUND)
      message(FATAL_ERROR
514
        "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
515
    endif()
516 517
    set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
    set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
518
  endif()
519

520 521
  #---------------------------------------------------------------------
  # Use curses?
522
  if (UNIX)
523
    # there is a bug in the Syllable libraries which makes linking ccmake fail, Alex
524
    if(NOT CMAKE_SYSTEM_NAME MATCHES syllable)
525 526 527 528
      set(CURSES_NEED_NCURSES TRUE)
      find_package(Curses QUIET)
      if (CURSES_LIBRARY)
        option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" ON)
529
      else ()
530 531
        message("Curses libraries were not found. Curses GUI for CMake will not be built.")
        set(BUILD_CursesDialog 0)
532 533
      endif ()
    else()
534
      set(BUILD_CursesDialog 0)
535 536
    endif()
  else ()
537
    set(BUILD_CursesDialog 0)
538
  endif ()
539
  if(BUILD_CursesDialog)
540 541 542 543 544
    if(NOT CMAKE_USE_SYSTEM_FORM)
      add_subdirectory(Source/CursesDialog/form)
    elseif(NOT CURSES_FORM_LIBRARY)
      message( FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!" )
    endif()
545 546
  endif()
endmacro ()
547

548
#-----------------------------------------------------------------------
549 550 551 552 553 554 555 556 557 558 559 560 561 562
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
    execute_process(COMMAND ${CMAKE_CXX_COMPILER}
      ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
      OUTPUT_VARIABLE _GXX_VERSION
    )
    string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
      _GXX_VERSION_SHORT ${_GXX_VERSION})
    if(_GXX_VERSION_SHORT EQUAL 33)
      message(FATAL_ERROR
        "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
        "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
        "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
    endif()
563 564
  endif()
endif()
565 566 567 568 569

#-----------------------------------------------------------------------
# The main section of the CMakeLists file
#
#-----------------------------------------------------------------------
570 571
# Compute CMake_VERSION, etc.
include(Source/CMakeVersionCompute.cmake)
572

573
# Include the standard Dart testing module
574 575
enable_testing()
include (${CMAKE_ROOT}/Modules/Dart.cmake)
576

577
# Set up test-time configuration.
578
set_directory_properties(PROPERTIES
579 580
  TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")

581 582 583 584 585 586
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  # where to write the resulting executables and libraries
  set(BUILD_SHARED_LIBS OFF)
  set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
  set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
    "Where to put the libraries for CMake")
587

588 589 590
  # The CMake executables usually do not need any rpath to run in the build or
  # install tree.
  set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
591

592 593
  # Load install destinations.
  include(Source/CMakeInstallDestinations.cmake)
594

595 596 597
  if(BUILD_TESTING)
    include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
  endif()
598

599 600
  # include special compile flags for some compilers
  include(CompileFlags.cmake)
601

602 603 604 605 606
  # no clue why we are testing for this here
  include(CheckSymbolExists)
  CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
  CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
607

608 609 610
# CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
#
# If not defined or "", this variable defaults to the server at
Brad King's avatar
Brad King committed
611
# "http://open.cdash.org".
612 613 614 615 616 617 618 619 620
#
# If set explicitly to "NOTFOUND", curl tests and ctest tests that use
# the network are skipped.
#
# If set to something starting with "http://localhost/", the CDash is
# expected to be an instance of CDash used for CDash testing, pointing
# to a cdash4simpletest database. In these cases, the CDash dashboards
# should be run first.
#
621
if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
Brad King's avatar
Brad King committed
622
  set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
623
endif()
624

625
if(CMake_TEST_EXTERNAL_CMAKE)
Brad King's avatar
Brad King committed
626
  set(KWIML_TEST_ENABLE 1)
627
  add_subdirectory(Utilities/KWIML)
Brad King's avatar
Brad King committed
628
endif()
629

630 631 632
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  # build the utilities (a macro defined in this file)
  CMAKE_BUILD_UTILITIES()
633

634 635 636 637 638 639 640 641 642 643
  # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
  # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
  # which isn't in the default linker search path. So without RPATH ccmake
  # doesn't run and the build doesn't succeed since ccmake is executed for
  # generating the documentation.
  if(BUILD_CursesDialog)
    get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
    set(CURSES_NEED_RPATH FALSE)
    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")
      set(CURSES_NEED_RPATH TRUE)
644 645
    endif()
  endif()
646

647 648 649 650 651 652
  if(BUILD_QtDialog)
    if(APPLE)
      set(CMAKE_BUNDLE_VERSION
        "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
      set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
      # make sure CMAKE_INSTALL_PREFIX ends in /
653
      if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
654 655 656 657 658 659 660 661 662 663
        set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
      endif()
      set(CMAKE_INSTALL_PREFIX
        "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
    endif()

    set(QT_NEED_RPATH FALSE)
    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")
      set(QT_NEED_RPATH TRUE)
    endif()
664
  endif()
665 666


667 668 669 670 671 672 673 674 675 676 677 678 679
  # The same might be true on other systems for other libraries.
  # Then only enable RPATH if we have are building at least with cmake 2.4,
  # since this one has much better RPATH features than cmake 2.2.
  # The executables are then built with the RPATH for the libraries outside
  # the build tree, which is both the build and the install RPATH.
  if (UNIX)
    if(   CMAKE_USE_SYSTEM_CURL   OR  CMAKE_USE_SYSTEM_ZLIB
          OR  CMAKE_USE_SYSTEM_EXPAT  OR  CTEST_USE_XMLRPC  OR  CURSES_NEED_RPATH  OR  QT_NEED_RPATH)
      set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
      set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
      set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
    endif()
  endif ()
Alexander Neundorf's avatar
 
Alexander Neundorf committed
680 681


682 683 684 685 686 687 688
  # add the uninstall support
  configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    @ONLY)
  add_custom_target(uninstall
    "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
Ken Martin's avatar
Ken Martin committed
689

690 691 692
  include (CMakeCPack.cmake)

endif()
693

694 695
# setup some Testing support (a macro defined in this file)
CMAKE_SETUP_TESTING()
696

697
# Check whether to build server mode or not:
698 699 700 701 702 703 704 705 706
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  if(NOT DEFINED CMake_ENABLE_SERVER_MODE)
    list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_auto_type CMake_HAVE_CXX_AUTO_TYPE)
    list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_range_for CMake_HAVE_CXX_RANGE_FOR)
    if(CMAKE_USE_LIBUV
        AND CMake_HAVE_CXX_AUTO_TYPE
        AND CMake_HAVE_CXX_MAKE_UNIQUE
        AND CMake_HAVE_CXX_RANGE_FOR
        )
707
      set(CMake_ENABLE_SERVER_MODE 1)
708 709
    else()
      set(CMake_ENABLE_SERVER_MODE 0)
710 711
    endif()
  endif()
712 713 714 715 716
  if(CMake_ENABLE_SERVER_MODE AND NOT CMAKE_USE_LIBUV)
    message(FATAL_ERROR "The server mode requires libuv!")
  endif()
else()
  set(CMake_ENABLE_SERVER_MODE 0)
717
endif()
718 719 720
if(NOT DEFINED CMake_TEST_SERVER_MODE)
  set(CMake_TEST_SERVER_MODE ${CMake_ENABLE_SERVER_MODE})
endif()
721

722 723
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  if(NOT CMake_VERSION_IS_RELEASE)
724
    if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
        NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
      set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
                       -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
                       -Wmissing-format-attribute -fno-common -Wundef
      )
      set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
                         -Wshadow -Wpointer-arith -Wformat-security -Wundef
      )

      foreach(FLAG_LANG  C CXX)
        foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
          if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
            set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
          endif()
        endforeach()
740 741
      endforeach()

742 743 744
      unset(C_FLAGS_LIST)
      unset(CXX_FLAGS_LIST)
    endif()
745
  endif()
746 747 748 749

  # build the remaining subdirectories
  add_subdirectory(Source)
  add_subdirectory(Utilities)
750
endif()
751

752
add_subdirectory(Tests)
753

754 755 756 757 758 759 760
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  if(BUILD_TESTING)
    CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
  endif()
  if(TARGET documentation)
    CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
  endif()
761
endif()
762

763
# add a test
764
add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
765
  --system-information  -G "${CMAKE_GENERATOR}" )
766

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
if(NOT CMake_TEST_EXTERNAL_CMAKE)
  # Install license file as it requires.
  install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})

  # Install script directories.
  install(
    DIRECTORY Help Modules Templates
    DESTINATION ${CMAKE_DATA_DIR}
    FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
    DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
                          GROUP_READ GROUP_EXECUTE
                          WORLD_READ WORLD_EXECUTE
    PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
                                GROUP_READ GROUP_EXECUTE
                                WORLD_READ WORLD_EXECUTE
    )

  # Install auxiliary files integrating with other tools.
  add_subdirectory(Auxiliary)
endif()