Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/CMakeLists.txt
3132 views
1
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
# file LICENSE.rst or https://cmake.org/licensing for details.
3
4
cmake_minimum_required(VERSION 3.13...4.0 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)
7
8
project(CMake)
9
unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
10
unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
11
12
# FIXME: This block should go away after a transition period.
13
if(MSVC AND NOT CMAKE_VERSION VERSION_LESS 3.15)
14
# Filter out MSVC runtime library flags that may have come from
15
# the cache of an existing build tree or from scripts.
16
foreach(l IN ITEMS C CXX)
17
foreach(c IN ITEMS DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
18
string(REGEX REPLACE "[-/]M[DT]d?( |$)" "" "CMAKE_${l}_FLAGS_${c}" "${CMAKE_${l}_FLAGS_${c}}")
19
endforeach()
20
endforeach()
21
endif()
22
23
# Make sure we can find internal find_package modules only used for
24
# building CMake and not for shipping externally
25
list(INSERT CMAKE_MODULE_PATH 0 ${CMake_SOURCE_DIR}/Source/Modules)
26
27
if(CMAKE_BOOTSTRAP)
28
# Running from bootstrap script. Set local variable and remove from cache.
29
set(CMAKE_BOOTSTRAP 1)
30
unset(CMAKE_BOOTSTRAP CACHE)
31
endif()
32
33
if(CMake_TEST_HOST_CMAKE)
34
get_filename_component(CMake_TEST_EXTERNAL_CMAKE "${CMAKE_COMMAND}" DIRECTORY)
35
endif()
36
37
if(NOT CMake_TEST_EXTERNAL_CMAKE)
38
if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
39
message(FATAL_ERROR
40
"CMake no longer compiles on HP-UX. See\n"
41
" https://gitlab.kitware.com/cmake/cmake/-/issues/17137\n"
42
"Use CMake 3.9 or lower instead."
43
)
44
endif()
45
46
set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
47
endif()
48
49
if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
50
if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL MATCHES "^3|2\\.1$")
51
set(USE_LGPL "${CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL}")
52
else()
53
set(USE_LGPL "2.1")
54
endif()
55
else()
56
set(USE_LGPL "")
57
endif()
58
59
# Use most-recent available language dialects with GNU and Clang
60
if(NOT DEFINED CMAKE_C_STANDARD AND NOT CMake_NO_C_STANDARD)
61
include(${CMake_SOURCE_DIR}/Source/Checks/cm_c11_thread_local.cmake)
62
if(NOT CMake_C11_THREAD_LOCAL_BROKEN)
63
set(CMAKE_C_STANDARD 11)
64
else()
65
set(CMAKE_C_STANDARD 99)
66
endif()
67
endif()
68
if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
69
if(CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
70
set(CMAKE_CXX_STANDARD 98)
71
else()
72
include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
73
if(NOT CMake_CXX17_BROKEN)
74
set(CMAKE_CXX_STANDARD 17)
75
else()
76
include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
77
if(NOT CMake_CXX14_BROKEN)
78
set(CMAKE_CXX_STANDARD 14)
79
else()
80
set(CMAKE_CXX_STANDARD 11)
81
endif()
82
endif()
83
endif()
84
endif()
85
if(NOT CMake_TEST_EXTERNAL_CMAKE)
86
# include special compile flags for some compilers
87
include(CompileFlags.cmake)
88
89
# check for available C++ features
90
include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
91
92
if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
93
message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
94
endif()
95
endif()
96
97
# Inform STL library header wrappers whether to use system versions.
98
configure_file(Utilities/std/cmSTL.hxx.in Utilities/cmSTL.hxx @ONLY)
99
100
# set the internal encoding of CMake to UTF-8
101
set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
102
103
# enable parallel install
104
set_property(GLOBAL PROPERTY INSTALL_PARALLEL ON)
105
106
# option to use COMPONENT with install command
107
option(CMake_INSTALL_COMPONENTS "Using components when installing" OFF)
108
mark_as_advanced(CMake_INSTALL_COMPONENTS)
109
macro(CMake_OPTIONAL_COMPONENT NAME)
110
if(CMake_INSTALL_COMPONENTS)
111
set(COMPONENT COMPONENT ${NAME})
112
else()
113
set(COMPONENT)
114
endif()
115
endmacro()
116
117
# option to disable installing 3rd-party dependencies
118
option(CMake_INSTALL_DEPENDENCIES
119
"Whether to install 3rd-party runtime dependencies" OFF)
120
mark_as_advanced(CMake_INSTALL_DEPENDENCIES)
121
122
# option to build reference for CMake developers
123
option(CMake_BUILD_DEVELOPER_REFERENCE
124
"Build CMake Developer Reference" OFF)
125
mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
126
127
# option to build using interprocedural optimizations (IPO/LTO)
128
option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
129
if(CMake_BUILD_LTO)
130
include(CheckIPOSupported)
131
check_ipo_supported(RESULT HAVE_IPO)
132
if(HAVE_IPO)
133
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
134
endif()
135
endif()
136
137
option(CMake_BUILD_PCH "Compile CMake with precompiled headers" OFF)
138
139
# Check whether to build support for the debugger mode.
140
if(NOT CMake_TEST_EXTERNAL_CMAKE)
141
if(NOT DEFINED CMake_ENABLE_DEBUGGER)
142
# The debugger uses cppdap, which does not compile everywhere.
143
if(CMAKE_SYSTEM_NAME MATCHES "Windows|Darwin|Linux|BSD|DragonFly|CYGWIN|MSYS"
144
AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.16)
145
AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "XLClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.1)
146
AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "LCC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.23)
147
)
148
set(CMake_ENABLE_DEBUGGER 1)
149
else()
150
set(CMake_ENABLE_DEBUGGER 0)
151
endif()
152
endif()
153
else()
154
set(CMake_ENABLE_DEBUGGER 0)
155
endif()
156
157
#-----------------------------------------------------------------------
158
# a macro to deal with system libraries, implemented as a macro
159
# simply to improve readability of the main script
160
#-----------------------------------------------------------------------
161
macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
162
include(CMakeDependentOption)
163
164
# Allow the user to enable/disable all system utility library options by
165
# defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
166
set(UTILITIES BZIP2 CPPDAP CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD)
167
foreach(util IN LISTS UTILITIES)
168
if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
169
AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
170
set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
171
endif()
172
if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
173
if(CMAKE_USE_SYSTEM_LIBRARY_${util})
174
set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
175
else()
176
set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
177
endif()
178
if(CMAKE_BOOTSTRAP)
179
unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
180
endif()
181
string(TOLOWER "${util}" lutil)
182
set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
183
CACHE BOOL "Use system-installed ${lutil}" FORCE)
184
elseif(util STREQUAL "CURL" AND APPLE)
185
# macOS provides a curl with backends configured by Apple.
186
set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
187
else()
188
set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
189
endif()
190
endforeach()
191
if(CMAKE_BOOTSTRAP)
192
unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
193
endif()
194
195
# Optionally use system utility libraries.
196
option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
197
if(CMake_ENABLE_DEBUGGER)
198
option(CMAKE_USE_SYSTEM_CPPDAP "Use system-installed cppdap" "${CMAKE_USE_SYSTEM_LIBRARY_CPPDAP}")
199
endif()
200
option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
201
option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
202
cmake_dependent_option(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
203
"${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
204
cmake_dependent_option(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
205
"${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
206
cmake_dependent_option(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd"
207
"${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
208
cmake_dependent_option(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
209
"${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
210
cmake_dependent_option(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2"
211
"${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON)
212
option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
213
cmake_dependent_option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp"
214
"${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}" "NOT CMAKE_USE_SYSTEM_CPPDAP" ON)
215
option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
216
option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
217
218
# For now use system KWIML only if explicitly requested rather
219
# than activating via the general system libs options.
220
option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF)
221
mark_as_advanced(CMAKE_USE_SYSTEM_KWIML)
222
223
# Mention to the user what system libraries are being used.
224
if(CMAKE_USE_SYSTEM_CURL)
225
# Avoid messaging about curl-only dependencies.
226
list(REMOVE_ITEM UTILITIES NGHTTP2)
227
endif()
228
foreach(util IN LISTS UTILITIES ITEMS KWIML)
229
if(CMAKE_USE_SYSTEM_${util})
230
message(STATUS "Using system-installed ${util}")
231
endif()
232
endforeach()
233
234
# Inform utility library header wrappers whether to use system versions.
235
configure_file(Utilities/cmThirdParty.h.in Utilities/cmThirdParty.h @ONLY)
236
237
endmacro()
238
239
#-----------------------------------------------------------------------
240
# a macro to determine the generator and ctest executable to use
241
# for testing. Simply to improve readability of the main script.
242
#-----------------------------------------------------------------------
243
macro(CMAKE_SETUP_TESTING)
244
if(BUILD_TESTING)
245
set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
246
foreach(util IN ITEMS CURL EXPAT ZLIB)
247
if(CMAKE_USE_SYSTEM_${util})
248
set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
249
endif()
250
endforeach()
251
252
# This variable is set by cmake, however to
253
# test cmake we want to make sure that
254
# the ctest from this cmake is used for testing
255
# and not the ctest from the cmake building and testing
256
# cmake.
257
if(CMake_TEST_EXTERNAL_CMAKE)
258
set(CMAKE_CTEST_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/ctest")
259
set(CMAKE_CMAKE_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cmake")
260
set(CMAKE_CPACK_COMMAND "${CMake_TEST_EXTERNAL_CMAKE}/cpack")
261
foreach(exe IN ITEMS cmake ctest cpack)
262
add_executable(${exe} IMPORTED)
263
set_property(TARGET ${exe} PROPERTY IMPORTED_LOCATION ${CMake_TEST_EXTERNAL_CMAKE}/${exe})
264
endforeach()
265
else()
266
set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
267
set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
268
set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
269
endif()
270
endif()
271
272
# configure some files for testing
273
configure_file(Tests/.NoDartCoverage Tests/.NoDartCoverage)
274
configure_file(CTestCustom.cmake.in CTestCustom.cmake @ONLY)
275
endmacro()
276
277
278
# Provide a way for Visual Studio Express users to turn OFF the new FOLDER
279
# organization feature. Default to ON for non-Express users. Express users must
280
# explicitly turn off this option to build CMake in the Express IDE...
281
#
282
option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
283
mark_as_advanced(CMAKE_USE_FOLDERS)
284
285
286
option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
287
if(CMake_RUN_CLANG_TIDY)
288
if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
289
message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
290
endif()
291
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
292
if(NOT CLANG_TIDY_COMMAND)
293
message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
294
endif()
295
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
296
297
option(CMake_USE_CLANG_TIDY_MODULE "Use CMake's clang-tidy module." OFF)
298
if(CMake_USE_CLANG_TIDY_MODULE)
299
find_library(CMake_CLANG_TIDY_MODULE NAMES cmake-clang-tidy-module DOC "Location of the clang-tidy module")
300
if(NOT CMake_CLANG_TIDY_MODULE)
301
message(FATAL_ERROR "CMake_USE_CLANG_TIDY_MODULE is ON but cmake-clang-tidy-module is not found!")
302
endif()
303
list(APPEND CMAKE_CXX_CLANG_TIDY "--load=${CMake_CLANG_TIDY_MODULE}")
304
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMake_CLANG_TIDY_MODULE}")
305
endif()
306
307
set(CMake_CLANG_TIDY_EXPORT_FIXES_DIR "" CACHE PATH "Directory to put clang-tidy fix files in.")
308
mark_as_advanced(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
309
if(CMake_CLANG_TIDY_EXPORT_FIXES_DIR)
310
if(NOT IS_ABSOLUTE "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
311
message(FATAL_ERROR "CMake_CLANG_TIDY_EXPORT_FIXES_DIR must be an absolute path!")
312
endif()
313
set(CMAKE_CXX_CLANG_TIDY_EXPORT_FIXES_DIR "${CMake_CLANG_TIDY_EXPORT_FIXES_DIR}")
314
endif()
315
316
# Create a preprocessor definition that depends on .clang-tidy content so
317
# the compile command will change when .clang-tidy changes. This ensures
318
# that a subsequent build re-runs clang-tidy on all sources even if they
319
# do not otherwise need to be recompiled. Nothing actually uses this
320
# definition. We add it to targets on which we run clang-tidy just to
321
# get the build dependency on the .clang-tidy file.
322
file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
323
set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
324
unset(clang_tidy_sha1)
325
if(CMake_USE_CLANG_TIDY_MODULE)
326
file(SHA1 "${CMake_CLANG_TIDY_MODULE}" clang_tidy_module_sha1)
327
list(APPEND CLANG_TIDY_DEFINITIONS "CLANG_TIDY_MODULE_SHA1=${clang_tidy_module_sha1}")
328
unset(clang_tidy_module_sha1)
329
endif()
330
331
configure_file(.clang-tidy .clang-tidy COPYONLY)
332
endif()
333
334
335
option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
336
if(CMake_RUN_IWYU)
337
if(CMake_BUILD_PCH)
338
message(FATAL_ERROR "CMake_RUN_IWYU and CMake_BUILD_PCH are ON, but they are incompatible!")
339
endif()
340
find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
341
if(NOT IWYU_COMMAND)
342
message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
343
endif()
344
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
345
"${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
346
option(CMake_IWYU_VERBOSE "Run include-what-you-use in verbose mode" OFF)
347
if (CMake_IWYU_VERBOSE)
348
list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE
349
-Xiwyu -v7)
350
endif ()
351
list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
352
endif()
353
354
355
#-----------------------------------------------------------------------
356
# a macro that only sets the FOLDER target property if it's
357
# "appropriate"
358
#-----------------------------------------------------------------------
359
macro(CMAKE_SET_TARGET_FOLDER tgt folder)
360
if(CMAKE_USE_FOLDERS)
361
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
362
if(MSVC AND TARGET ${tgt})
363
set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
364
endif()
365
else()
366
set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
367
endif()
368
endmacro()
369
370
#-----------------------------------------------------------------------
371
if(NOT CMake_TEST_EXTERNAL_CMAKE)
372
if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
373
execute_process(COMMAND ${CMAKE_CXX_COMPILER}
374
${CMAKE_CXX_COMPILER_ARG1} -dumpversion
375
OUTPUT_VARIABLE _GXX_VERSION
376
)
377
string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
378
_GXX_VERSION_SHORT ${_GXX_VERSION})
379
if(_GXX_VERSION_SHORT EQUAL 33)
380
message(FATAL_ERROR
381
"GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
382
"Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
383
"${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
384
endif()
385
endif()
386
endif()
387
388
#-----------------------------------------------------------------------
389
# The main section of the CMakeLists file
390
#
391
#-----------------------------------------------------------------------
392
include(Source/CMakeCopyright.cmake)
393
include(Source/CMakeVersion.cmake)
394
395
include(CTest)
396
397
# Set up test-time configuration.
398
set_property(DIRECTORY APPEND PROPERTY
399
TEST_INCLUDE_FILES "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
400
401
if(NOT CMake_TEST_EXTERNAL_CMAKE)
402
# where to write the resulting executables and libraries
403
set(BUILD_SHARED_LIBS OFF)
404
set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
405
set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
406
"Where to put the libraries for CMake")
407
408
# Load install destinations.
409
include(Source/CMakeInstallDestinations.cmake)
410
411
if(BUILD_TESTING)
412
include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
413
endif()
414
415
# Checks for cmSystemTools.
416
if(WIN32)
417
set(HAVE_UNSETENV 0)
418
set(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE 1)
419
else()
420
include(CheckSymbolExists)
421
check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV)
422
check_symbol_exists(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
423
endif()
424
endif()
425
426
# CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
427
#
428
# If not defined or "", this variable defaults to the server at
429
# "http://open.cdash.org".
430
#
431
# If set explicitly to "NOTFOUND", curl tests and ctest tests that use
432
# the network are skipped.
433
#
434
# If set to something starting with "http://localhost/", the CDash is
435
# expected to be an instance of CDash used for CDash testing, pointing
436
# to a cdash4simpletest database. In these cases, the CDash dashboards
437
# should be run first.
438
#
439
if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x" AND NOT CMake_TEST_NO_NETWORK)
440
set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org")
441
endif()
442
443
if(CMake_TEST_EXTERNAL_CMAKE)
444
set(KWIML_TEST_ENABLE 1)
445
add_subdirectory(Utilities/KWIML)
446
endif()
447
448
if(NOT CMake_TEST_EXTERNAL_CMAKE)
449
find_package(Threads)
450
# build the utilities
451
include(CMakeBuildUtilities)
452
453
if(BUILD_QtDialog)
454
if(APPLE)
455
set(CMAKE_BUNDLE_VERSION
456
"${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
457
set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
458
# make sure CMAKE_INSTALL_PREFIX ends in /
459
if(NOT CMAKE_INSTALL_PREFIX MATCHES "/$")
460
string(APPEND CMAKE_INSTALL_PREFIX "/")
461
endif()
462
string(APPEND CMAKE_INSTALL_PREFIX "CMake.app/Contents")
463
endif()
464
endif()
465
466
if(UNIX)
467
# Install executables with the RPATH set for libraries outside the build tree.
468
# This is also suitable for binaries in the build tree. Avoid re-link on install.
469
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE BOOL "Install with RPATH set to find custom-built libraries.")
470
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Build with RPATH set to match install-tree RPATH.")
471
mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_BUILD_WITH_INSTALL_RPATH)
472
endif()
473
474
# add the uninstall support
475
configure_file(cmake_uninstall.cmake.in cmake_uninstall.cmake @ONLY)
476
add_custom_target(uninstall
477
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
478
479
include(CMakeCPack.cmake)
480
481
endif()
482
483
# setup some Testing support (a macro defined in this file)
484
CMAKE_SETUP_TESTING()
485
486
if(NOT CMake_TEST_EXTERNAL_CMAKE)
487
if(NOT CMake_VERSION_IS_RELEASE)
488
if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
489
NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2) OR
490
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
491
NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 3.0 AND
492
NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") OR
493
CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR
494
CMAKE_C_COMPILER_ID STREQUAL "LCC")
495
set(C_FLAGS_LIST -Wcast-align -Wchar-subscripts
496
-Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
497
-Wmissing-format-attribute -fno-common -Wundef
498
-Werror=implicit-function-declaration
499
-Wstrict-prototypes
500
)
501
set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
502
-Wshadow -Wpointer-arith -Wformat-security -Wundef
503
)
504
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
505
NOT (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11))
506
list(APPEND CXX_FLAGS_LIST
507
-Wundefined-func-template
508
)
509
endif()
510
511
foreach(FLAG_LANG IN ITEMS C CXX)
512
foreach(FLAG IN LISTS ${FLAG_LANG}_FLAGS_LIST)
513
if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
514
string(APPEND CMAKE_${FLAG_LANG}_FLAGS " ${FLAG}")
515
endif()
516
endforeach()
517
endforeach()
518
519
unset(C_FLAGS_LIST)
520
unset(CXX_FLAGS_LIST)
521
endif()
522
endif()
523
524
# build the remaining subdirectories
525
add_subdirectory(Source)
526
add_subdirectory(Utilities)
527
endif()
528
529
add_subdirectory(Tests)
530
531
if(NOT CMake_TEST_EXTERNAL_CMAKE)
532
if(BUILD_TESTING)
533
CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
534
endif()
535
if(TARGET documentation)
536
CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
537
endif()
538
endif()
539
540
if(BUILD_TESTING)
541
add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
542
--system-information -G "${CMAKE_GENERATOR}"
543
)
544
endif()
545
546
if(NOT CMake_TEST_EXTERNAL_CMAKE)
547
# Install license file as it requires.
548
install(FILES
549
"${CMake_LICENSE_FILE}"
550
"${CMake_SOURCE_DIR}/CONTRIBUTORS.rst"
551
DESTINATION ${CMAKE_DOC_DIR})
552
553
# Install script directories.
554
install(
555
DIRECTORY Help Modules Templates
556
DESTINATION ${CMAKE_DATA_DIR}
557
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
558
DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
559
GROUP_READ GROUP_EXECUTE
560
WORLD_READ WORLD_EXECUTE
561
PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
562
GROUP_READ GROUP_EXECUTE
563
WORLD_READ WORLD_EXECUTE
564
REGEX "/(ExportImportList|cpp)$"
565
PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
566
GROUP_READ GROUP_EXECUTE
567
WORLD_READ WORLD_EXECUTE
568
REGEX "Help/(dev|guide)($|/)" EXCLUDE
569
)
570
571
# Install auxiliary files integrating with other tools.
572
add_subdirectory(Auxiliary)
573
574
# Optionally sign installed binaries.
575
if(CMake_INSTALL_SIGNTOOL)
576
configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
577
install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)
578
endif()
579
endif()
580
581