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