bootstrap 48.4 KB
Newer Older
1
#!/bin/sh
2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
4

5 6 7 8
die() {
  echo "$@" 1>&2 ; exit 1
}

9 10 11
# Compile flag extraction function.
cmake_extract_standard_flags()
{
12
  sed -n "s/ *set *( *CMAKE_${2}${3}_EXTENSION_COMPILE_OPTION *\"\{0,1\}\([^\")]*\).*/\1/p" \
13
    "${cmake_source_dir}/Modules/Compiler/"${1:-*}-${2}.cmake 2>/dev/null | tr ';' ' '
14 15
}

16 17 18
# Version number extraction function.
cmake_version_component()
{
19
  sed -n "
20
/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
21
" "${cmake_source_dir}/Source/CMakeVersion.cmake"
22 23
}

24 25 26
# Install destination extraction function.
cmake_install_dest_default()
{
27
  sed -n '
28
/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT.*) # '"${2}"'$/ {
29 30 31 32 33 34 35
  s/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT *"\([^"]*\)").*$/\1/
  s/${CMake_VERSION_MAJOR}/'"${cmake_version_major}"'/
  s/${CMake_VERSION_MINOR}/'"${cmake_version_minor}"'/
  s/${CMake_VERSION_PATCH}/'"${cmake_version_patch}"'/
  p
  q
}
36
' "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake"
37 38
}

39 40
cmake_toupper()
{
41
    echo "$1" | tr '[:lower:]' '[:upper:]'
42 43
}

44 45
# Detect system and directory information.
cmake_system=`uname`
46
cmake_source_dir=`cd "\`dirname \"$0\"\`";pwd`
47
cmake_binary_dir=`pwd`
48 49

# Load version information.
50 51
cmake_version_major="`cmake_version_component MAJOR`"
cmake_version_minor="`cmake_version_component MINOR`"
52 53
cmake_version_patch="`cmake_version_component PATCH`"
cmake_version="${cmake_version_major}.${cmake_version_minor}.${cmake_version_patch}"
54 55 56 57
cmake_version_rc="`cmake_version_component RC`"
if [ "$cmake_version_rc" != "" ]; then
  cmake_version="${cmake_version}-rc${cmake_version_rc}"
fi
58

59 60
cmake_copyright="`grep '^Copyright .* Kitware' "${cmake_source_dir}/Copyright.txt"`"

61
cmake_bin_dir_keyword="OTHER"
62 63 64
cmake_data_dir_keyword="OTHER"
cmake_doc_dir_keyword="OTHER"
cmake_man_dir_keyword="OTHER"
65
cmake_xdgdata_dir_keyword="OTHER"
66
cmake_bin_dir=""
67 68 69
cmake_data_dir=""
cmake_doc_dir=""
cmake_man_dir=""
70
cmake_xdgdata_dir=""
71
cmake_init_file=""
72
cmake_bootstrap_system_libs=""
73 74
cmake_bootstrap_qt_gui=""
cmake_bootstrap_qt_qmake=""
75 76
cmake_sphinx_man=""
cmake_sphinx_html=""
77
cmake_sphinx_qthelp=""
78
cmake_sphinx_build=""
79
cmake_sphinx_flags=""
80

81
# Determine whether this is a Cygwin environment.
82
if echo "${cmake_system}" | grep CYGWIN >/dev/null 2>&1; then
83
  cmake_system_cygwin=true
84 85
  cmake_doc_dir_keyword="CYGWIN"
  cmake_man_dir_keyword="CYGWIN"
86 87 88 89
else
  cmake_system_cygwin=false
fi

90
# Determine whether this is a MinGW environment.
91
if echo "${cmake_system}" | grep 'MINGW\|MSYS' >/dev/null 2>&1; then
92 93 94 95 96
  cmake_system_mingw=true
else
  cmake_system_mingw=false
fi

97
# Determine whether this is OS X
98
if echo "${cmake_system}" | grep Darwin >/dev/null 2>&1; then
99 100 101 102 103
  cmake_system_darwin=true
else
  cmake_system_darwin=false
fi

104
# Determine whether this is BeOS
105
if echo "${cmake_system}" | grep BeOS >/dev/null 2>&1; then
106
  cmake_system_beos=true
107 108
  cmake_doc_dir_keyword="HAIKU"
  cmake_man_dir_keyword="HAIKU"
109 110 111 112
else
  cmake_system_beos=false
fi

113
# Determine whether this is Haiku
114
if echo "${cmake_system}" | grep Haiku >/dev/null 2>&1; then
115
  cmake_system_haiku=true
116 117
  cmake_doc_dir_keyword="HAIKU"
  cmake_man_dir_keyword="HAIKU"
118 119 120 121
else
  cmake_system_haiku=false
fi

122
# Determine whether this is OpenVMS
123
if echo "${cmake_system}" | grep OpenVMS >/dev/null 2>&1; then
124 125 126 127 128
  cmake_system_openvms=true
else
  cmake_system_openvms=false
fi

129
# Determine whether this is HP-UX
130
if echo "${cmake_system}" | grep HP-UX >/dev/null 2>&1; then
131 132 133 134 135
  die 'CMake no longer compiles on HP-UX.  See

  https://gitlab.kitware.com/cmake/cmake/issues/17137

Use CMake 3.9 or lower instead.'
136 137 138 139 140
  cmake_system_hpux=true
else
  cmake_system_hpux=false
fi

141
# Determine whether this is Linux
142
if echo "${cmake_system}" | grep Linux >/dev/null 2>&1; then
143
  cmake_system_linux=true
144 145 146 147 148 149 150 151 152
else
  cmake_system_linux=false
 fi

# Determine whether this is a PA-RISC machine
# This only works for Linux or HP-UX, not other PA-RISC OSs (BSD maybe?). Also
# may falsely detect parisc on HP-UX m68k
cmake_machine_parisc=false
if ${cmake_system_linux}; then
153
  if uname -m | grep parisc >/dev/null 2>&1; then
154 155
    cmake_machine_parisc=true
  fi
156
elif ${cmake_system_hpux}; then
157
  if uname -m | grep ia64 >/dev/null 2>&1; then : ; else
158 159
    cmake_machine_parisc=true
  fi
160 161
fi

162 163 164 165 166 167 168 169 170
# Choose the generator to use for bootstrapping.
if ${cmake_system_mingw}; then
  # Bootstrapping from an MSYS prompt.
  cmake_bootstrap_generator="MSYS Makefiles"
else
  # Bootstrapping from a standard UNIX prompt.
  cmake_bootstrap_generator="Unix Makefiles"
fi

171 172 173 174 175 176 177 178 179 180 181 182 183 184
# Choose tools and extensions for this platform.
if ${cmake_system_openvms}; then
  _tmp="_tmp"
  _cmk="_cmk"
  _diff=`which diff`
else
  _tmp=".tmp"
  _cmk=".cmk"
  _diff="diff"
fi

# Construct bootstrap directory name.
cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap${_cmk}"

185
# Helper function to fix windows paths.
186 187 188 189 190 191 192 193 194 195 196 197 198 199
case "${cmake_system}" in
*MINGW*)
  cmake_fix_slashes()
  {
    cmd //c echo "$(echo "$1" | sed 's/\\/\//g')" | sed 's/^"//;s/" *$//'
  }
  ;;
*)
  cmake_fix_slashes()
  {
    echo "$1" | sed 's/\\/\//g'
  }
  ;;
esac
200 201 202 203 204 205 206 207 208 209 210 211 212 213

# Choose the default install prefix.
if ${cmake_system_mingw}; then
  if [ "x${PROGRAMFILES}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${PROGRAMFILES}/CMake"`
  elif [ "x${ProgramFiles}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${ProgramFiles}/CMake"`
  elif [ "x${SYSTEMDRIVE}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${SYSTEMDRIVE}/Program Files/CMake"`
  elif [ "x${SystemDrive}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${SystemDrive}/Program Files/CMake"`
  else
    cmake_default_prefix="c:/Program Files/CMake"
  fi
214
elif ${cmake_system_haiku}; then
215
  cmake_default_prefix=`finddir B_COMMON_DIRECTORY`
216 217 218 219
else
  cmake_default_prefix="/usr/local"
fi

220
# Lookup default install destinations.
221
cmake_bin_dir_default="`cmake_install_dest_default BIN ${cmake_bin_dir_keyword}`"
222 223 224
cmake_data_dir_default="`cmake_install_dest_default DATA ${cmake_data_dir_keyword}`"
cmake_doc_dir_default="`cmake_install_dest_default DOC ${cmake_doc_dir_keyword}`"
cmake_man_dir_default="`cmake_install_dest_default MAN ${cmake_man_dir_keyword}`"
225
cmake_xdgdata_dir_default="`cmake_install_dest_default XDGDATA ${cmake_xdgdata_dir_keyword}`"
226

227 228
CMAKE_KNOWN_C_COMPILERS="cc gcc clang xlc icc tcc"
CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ clang++ c++ icc como "
229
CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
230

231 232 233 234 235
CMAKE_PROBLEMATIC_FILES="\
  CMakeCache.txt \
  CMakeSystem.cmake \
  CMakeCCompiler.cmake \
  CMakeCXXCompiler.cmake \
236 237 238
  */CMakeSystem.cmake \
  */CMakeCCompiler.cmake \
  */CMakeCXXCompiler.cmake \
239 240 241 242 243 244
  Source/cmConfigure.h \
  Source/CTest/Curl/config.h \
  Utilities/cmexpat/expatConfig.h \
  Utilities/cmexpat/expatDllConfig.h \
  "

245 246 247 248 249 250 251 252
CMAKE_UNUSED_SOURCES="\
  cmGlobalXCodeGenerator \
  cmLocalXCodeGenerator \
  cmXCodeObject \
  cmXCode21Object \
  cmSourceGroup \
"

253
CMAKE_CXX_SOURCES="\
254 255 256 257 258 259 260 261 262 263 264 265
  cmAddCustomCommandCommand \
  cmAddCustomTargetCommand \
  cmAddDefinitionsCommand \
  cmAddDependenciesCommand \
  cmAddExecutableCommand \
  cmAddLibraryCommand \
  cmAddSubDirectoryCommand \
  cmAddTestCommand \
  cmBreakCommand \
  cmBuildCommand \
  cmCMakeMinimumRequired \
  cmCMakePolicyCommand \
266 267
  cmCPackPropertiesGenerator \
  cmCacheManager \
268
  cmCommand \
269
  cmCommandArgumentParserHelper \
270
  cmCommandArgumentsHelper \
271 272 273 274 275 276 277
  cmCommands \
  cmCommonTargetGenerator \
  cmComputeComponentGraph \
  cmComputeLinkDepends \
  cmComputeLinkInformation \
  cmComputeTargetDepends \
  cmConditionEvaluator \
278 279 280 281
  cmConfigureFileCommand \
  cmContinueCommand \
  cmCoreTryCompile \
  cmCreateTestSourceList \
282 283
  cmCustomCommand \
  cmCustomCommandGenerator \
284
  cmDefinePropertyCommand \
285 286 287
  cmDefinitions \
  cmDepends \
  cmDependsC \
288
  cmDisallowedCommand \
289
  cmDocumentationFormatter \
290 291 292 293
  cmEnableLanguageCommand \
  cmEnableTestingCommand \
  cmExecProgramCommand \
  cmExecuteProcessCommand \
294 295 296 297 298 299 300 301 302
  cmExpandedCommandArgument \
  cmExportBuildFileGenerator \
  cmExportFileGenerator \
  cmExportInstallFileGenerator \
  cmExportSet \
  cmExportSetMap \
  cmExportTryCompileFileGenerator \
  cmExprParserHelper \
  cmExternalMakefileProjectGenerator \
303
  cmFileCommand \
304
  cmFileTimeComparison \
305 306 307 308 309 310 311 312 313
  cmFindBase \
  cmFindCommon \
  cmFindFileCommand \
  cmFindLibraryCommand \
  cmFindPackageCommand \
  cmFindPathCommand \
  cmFindProgramCommand \
  cmForEachCommand \
  cmFunctionCommand \
314
  cmFSPermissions \
315 316 317 318 319 320 321 322 323 324
  cmGeneratedFileStream \
  cmGeneratorExpression \
  cmGeneratorExpressionContext \
  cmGeneratorExpressionDAGChecker \
  cmGeneratorExpressionEvaluationFile \
  cmGeneratorExpressionEvaluator \
  cmGeneratorExpressionLexer \
  cmGeneratorExpressionNode \
  cmGeneratorExpressionParser \
  cmGeneratorTarget \
325 326 327 328 329 330 331
  cmGetCMakePropertyCommand \
  cmGetDirectoryPropertyCommand \
  cmGetFilenameComponentCommand \
  cmGetPropertyCommand \
  cmGetSourceFilePropertyCommand \
  cmGetTargetPropertyCommand \
  cmGetTestPropertyCommand \
332 333 334
  cmGlobalCommonGenerator \
  cmGlobalGenerator \
  cmGlobalUnixMakefileGenerator3 \
335
  cmGlobVerificationManager \
336 337 338
  cmHexFileConverter \
  cmIfCommand \
  cmIncludeCommand \
339
  cmIncludeGuardCommand \
340 341 342 343
  cmIncludeDirectoryCommand \
  cmIncludeRegularExpressionCommand \
  cmInstallCommand \
  cmInstallCommandArguments \
344 345
  cmInstallDirectoryGenerator \
  cmInstallExportGenerator \
346
  cmInstallFilesCommand \
347 348 349 350
  cmInstallFilesGenerator \
  cmInstallGenerator \
  cmInstallScriptGenerator \
  cmInstallTargetGenerator \
351
  cmInstallTargetsCommand \
352
  cmInstalledFile \
353
  cmLinkDirectoriesCommand \
354
  cmLinkLineComputer \
355
  cmListCommand \
356 357 358 359 360
  cmListFileCache \
  cmLocalCommonGenerator \
  cmLocalGenerator \
  cmLocalUnixMakefileGenerator3 \
  cmMSVC60LinkLineComputer \
361 362
  cmMacroCommand \
  cmMakeDirectoryCommand \
363 364 365 366 367
  cmMakefile \
  cmMakefileExecutableTargetGenerator \
  cmMakefileLibraryTargetGenerator \
  cmMakefileTargetGenerator \
  cmMakefileUtilityTargetGenerator \
368 369 370
  cmMarkAsAdvancedCommand \
  cmMathCommand \
  cmMessageCommand \
371 372 373
  cmMessenger \
  cmNewLineStyle \
  cmOSXBundleGenerator \
374
  cmOptionCommand \
375 376 377 378 379
  cmOrderDirectories \
  cmOutputConverter \
  cmParseArgumentsCommand \
  cmPathLabel \
  cmPolicies \
380
  cmProcessOutput \
381
  cmProjectCommand \
382 383 384 385
  cmProperty \
  cmPropertyDefinition \
  cmPropertyDefinitionMap \
  cmPropertyMap \
386
  cmReturnCommand \
387 388 389
  cmRulePlaceholderExpander \
  cmScriptGenerator \
  cmSearchPath \
390 391 392 393 394 395 396 397
  cmSeparateArgumentsCommand \
  cmSetCommand \
  cmSetDirectoryPropertiesCommand \
  cmSetPropertyCommand \
  cmSetSourceFilesPropertiesCommand \
  cmSetTargetPropertiesCommand \
  cmSetTestsPropertiesCommand \
  cmSiteNameCommand \
398 399 400 401 402
  cmSourceFile \
  cmSourceFileLocation \
  cmState \
  cmStateDirectory \
  cmStateSnapshot \
403
  cmStringReplaceHelper \
404 405
  cmStringCommand \
  cmSubdirCommand \
406 407
  cmSystemTools \
  cmTarget \
408 409 410 411
  cmTargetCompileDefinitionsCommand \
  cmTargetCompileFeaturesCommand \
  cmTargetCompileOptionsCommand \
  cmTargetIncludeDirectoriesCommand \
412
  cmTargetLinkLibrariesCommand \
413
  cmTargetPropCommandBase \
414
  cmTargetPropertyComputer \
415
  cmTargetSourcesCommand \
416 417
  cmTest \
  cmTestGenerator \
418 419 420
  cmTimestamp \
  cmTryCompileCommand \
  cmTryRunCommand \
421
  cmUnexpectedCommand \
422
  cmUnsetCommand \
423
  cmUVHandlePtr \
424
  cmVersion \
425
  cmWhileCommand \
426
  cmWorkingDirectory \
427 428 429
  cmake  \
  cmakemain \
  cmcmd  \
430
"
431

432 433 434
if ${cmake_system_mingw}; then
  CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES}\
    cmGlobalMSYSMakefileGenerator \
435
    cmGlobalMinGWMakefileGenerator"
436 437
fi

438 439 440 441 442 443 444 445 446 447
LexerParser_CXX_SOURCES="\
  cmCommandArgumentLexer \
  cmCommandArgumentParser \
  cmExprLexer \
  cmExprParser \
"

LexerParser_C_SOURCES="\
  cmListFileLexer \
"
448

449 450
if ${cmake_system_mingw}; then
  KWSYS_C_SOURCES="\
451
    EncodingC \
452
    ProcessWin32 \
453
    String \
454 455
    System \
    Terminal"
456 457
else
  KWSYS_C_SOURCES="\
458
    EncodingC \
459
    ProcessUNIX \
460
    String \
461 462
    System \
    Terminal"
463
fi
464 465

KWSYS_CXX_SOURCES="\
466
  Directory \
467
  EncodingCXX \
468
  FStream \
Andy Cedilnik's avatar
Andy Cedilnik committed
469
  Glob \
470 471 472 473 474
  RegularExpression \
  SystemTools"

KWSYS_FILES="\
  Directory.hxx \
475 476 477
  Encoding.h \
  Encoding.hxx \
  FStream.hxx \
Andy Cedilnik's avatar
Andy Cedilnik committed
478
  Glob.hxx \
479 480
  Process.h \
  RegularExpression.hxx \
481
  String.h \
482
  String.hxx \
483
  System.h \
484 485
  SystemTools.hxx \
  Terminal.h"
486

487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
if ${cmake_system_mingw}; then
  LIBUV_C_SOURCES="\
    src/fs-poll.c \
    src/inet.c \
    src/threadpool.c \
    src/uv-common.c \
    src/win/async.c \
    src/win/core.c \
    src/win/detect-wakeup.c \
    src/win/dl.c \
    src/win/error.c \
    src/win/fs-event.c \
    src/win/fs.c \
    src/win/getaddrinfo.c \
    src/win/getnameinfo.c \
    src/win/handle.c \
    src/win/loop-watcher.c \
    src/win/pipe.c \
    src/win/poll.c \
    src/win/process-stdio.c \
    src/win/process.c \
    src/win/req.c \
    src/win/signal.c \
    src/win/stream.c \
    src/win/tcp.c \
    src/win/thread.c \
    src/win/timer.c \
    src/win/tty.c \
    src/win/udp.c \
    src/win/util.c \
    src/win/winapi.c \
    src/win/winsock.c \
    "
else
  LIBUV_C_SOURCES="\
    src/uv-common.c \
    src/unix/cmake-bootstrap.c \
    src/unix/core.c \
    src/unix/fs.c \
    src/unix/loop.c \
    src/unix/loop-watcher.c \
    src/unix/no-fsevents.c \
    src/unix/pipe.c \
    src/unix/poll.c \
    src/unix/posix-hrtime.c \
    src/unix/posix-poll.c \
    src/unix/process.c \
    src/unix/signal.c \
    src/unix/stream.c \
    src/unix/timer.c \
    "
fi

540
# Display CMake bootstrap usage
541 542
cmake_usage()
{
543
echo '
544
Usage: '"$0"' [<options>...] [-- <cmake-options>...]
545 546 547
Options: [defaults in brackets after descriptions]
Configuration:
  --help                  print this message
548
  --version               only print version information
549
  --verbose               display more information
550 551
  --parallel=n            bootstrap cmake in parallel, where n is
                          number of nodes [1]
552
  --enable-ccache         Enable ccache when building cmake
553
  --init=FILE             load FILE as script to populate cache
554
  --system-libs           use all system-installed third-party libraries
555
                          (for use only by package maintainers)
556
  --no-system-libs        use all cmake-provided third-party libraries
557
                          (default)
558 559 560 561
  --system-curl           use system-installed curl library
  --no-system-curl        use cmake-provided curl library (default)
  --system-expat          use system-installed expat library
  --no-system-expat       use cmake-provided expat library (default)
562 563
  --system-jsoncpp        use system-installed jsoncpp library
  --no-system-jsoncpp     use cmake-provided jsoncpp library (default)
564 565 566 567
  --system-zlib           use system-installed zlib library
  --no-system-zlib        use cmake-provided zlib library (default)
  --system-bzip2          use system-installed bzip2 library
  --no-system-bzip2       use cmake-provided bzip2 library (default)
568 569
  --system-liblzma        use system-installed liblzma library
  --no-system-liblzma     use cmake-provided liblzma library (default)
570 571
  --system-libarchive     use system-installed libarchive library
  --no-system-libarchive  use cmake-provided libarchive library (default)
572 573
  --system-librhash       use system-installed librhash library
  --no-system-librhash    use cmake-provided librhash library (default)
574 575
  --system-libuv          use system-installed libuv library
  --no-system-libuv       use cmake-provided libuv library (default)
576

577 578 579
  --qt-gui                build the Qt-based GUI (requires Qt >= 4.2)
  --no-qt-gui             do not build the Qt-based GUI (default)
  --qt-qmake=<qmake>      use <qmake> as the qmake executable to find Qt
580

581 582
  --sphinx-man            build man pages with Sphinx
  --sphinx-html           build html help with Sphinx
583
  --sphinx-qthelp         build qch help with Sphinx
584
  --sphinx-build=<sb>     use <sb> as the sphinx-build executable
585
  --sphinx-flags=<flags>  pass <flags> to sphinx-build executable
586

587
Directory and file names:
588
  --prefix=PREFIX         install files in tree rooted at PREFIX
589
                          ['"${cmake_default_prefix}"']
590 591
  --bindir=DIR            install binaries in PREFIX/DIR
                          ['"${cmake_bin_dir_default}"']
592
  --datadir=DIR           install data files in PREFIX/DIR
593
                          ['"${cmake_data_dir_default}"']
594
  --docdir=DIR            install documentation files in PREFIX/DIR
595
                          ['"${cmake_doc_dir_default}"']
596
  --mandir=DIR            install man pages files in PREFIX/DIR/manN
597
                          ['"${cmake_man_dir_default}"']
598 599
  --xdgdatadir=DIR        install XDG specific files in PREFIX/DIR
                          ['"${cmake_xdgdata_dir_default}"']
600
'
601 602 603
  exit 10
}

604
# Display CMake bootstrap usage
605
cmake_version_display()
606
{
607
  echo "CMake ${cmake_version}, ${cmake_copyright}"
608 609 610
}

# Display CMake bootstrap error, display the log file and exit
611 612
cmake_error()
{
613 614
  res=$1
  shift 1
615
  echo "---------------------------------------------"
616
  echo "Error when bootstrapping CMake:"
617 618 619
  echo "$*"
  echo "---------------------------------------------"
  if [ -f cmake_bootstrap.log ]; then
620 621
    echo "Log of errors: `pwd`/cmake_bootstrap.log"
    #cat cmake_bootstrap.log
622 623
    echo "---------------------------------------------"
  fi
624
  exit ${res}
625
}
626

627 628 629 630 631 632 633 634 635 636 637 638
cmake_generate_file ()
{
  OUTFILE="$1"
  CONTENT="$2"
  echo "$CONTENT" > "$OUTFILE.tmp"
  if "${_diff}" "$OUTFILE.tmp" "$OUTFILE" > /dev/null 2> /dev/null ; then
    rm -f "$OUTFILE.tmp"
  else
    mv -f "$OUTFILE.tmp" "$OUTFILE"
  fi
}

639 640 641 642 643 644 645
# Replace KWSYS_NAMESPACE with cmsys
cmake_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  SEARCHFOR="$3"
  REPLACEWITH="$4"
646
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
647
    sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" "${INFILE}" > "${OUTFILE}${_tmp}"
648 649
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
650
        #echo "Files are the same"
651
        rm -f "${OUTFILE}${_tmp}"
652
      else
653
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
654 655
      fi
    fi
656
  else
657
    cmake_error 1 "Cannot find file ${INFILE}"
658 659 660
  fi
}

661 662 663 664 665 666
cmake_kwsys_config_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  shift 2
  APPEND="$*"
667 668
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
    echo "${APPEND}" > "${OUTFILE}${_tmp}"
669 670 671 672 673 674 675 676
    sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
              s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
              s/@KWSYS_LFS_AVAILABLE@/${KWSYS_LFS_AVAILABLE}/g;
              s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g;
              s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
              s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g;
              s/@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@/${KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H}/g;
             }" "${INFILE}" >> "${OUTFILE}${_tmp}"
677 678
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
679
        #echo "Files are the same"
680
        rm -f "${OUTFILE}${_tmp}"
681
      else
682
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
683 684 685 686 687 688
      fi
    fi
  else
    cmake_error 2 "Cannot find file ${INFILE}"
  fi
}
689
# Write string into a file
690 691 692 693 694 695 696
cmake_report ()
{
  FILE=$1
  shift
  echo "$*" >> ${FILE}
}

697
# Escape spaces in strings
698 699 700 701 702
cmake_escape ()
{
  echo $1 | sed "s/ /\\\\ /g"
}

703 704 705 706 707 708
# Encode object file names.
cmake_obj ()
{
  echo $1 | sed 's/\//-/g' | sed 's/$/\.o/'
}

709 710 711 712 713 714
# Strip prefix from argument
cmake_arg ()
{
  echo "$1" | sed "s/^${2-[^=]*=}//"
}

715
# Write message to the log
716 717 718 719 720
cmake_log ()
{
  echo "$*" >> cmake_bootstrap.log
}

721
# Return temp file
722 723
cmake_tmp_file ()
{
724
  echo "cmake_bootstrap_$$_test"
725 726
}

727 728
# Run a compiler test. First argument is compiler, second one are compiler
# flags, third one is test source file to be compiled
729 730 731 732 733 734 735 736 737 738 739
cmake_try_run ()
{
  COMPILER=$1
  FLAGS=$2
  TESTFILE=$3
  if [ ! -f "${TESTFILE}" ]; then
    echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
    exit 4
  fi
  TMPFILE=`cmake_tmp_file`
  echo "Try: ${COMPILER}"
740 741
  echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
  echo "----------  file   -----------------------"
742
  cat "${TESTFILE}"
743
  echo "------------------------------------------"
744 745 746
  "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  RES=$?
  if [ "${RES}" -ne "0" ]; then
747 748
    echo "Test failed to compile"
    return 1
749 750
  fi
  if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
751
    echo "Test failed to produce executable"
752 753 754 755 756 757
    return 2
  fi
  ./${TMPFILE}
  RES=$?
  rm -f "${TMPFILE}"
  if [ "${RES}" -ne "0" ]; then
758
    echo "Test produced non-zero return code"
759 760
    return 3
  fi
761
  echo "Test succeeded"
762 763 764
  return 0
}

765
# Run a make test. First argument is the make interpreter.
766 767
cmake_try_make ()
{
768 769
  MAKE_PROC="$1"
  MAKE_FLAGS="$2"
770
  echo "Try: ${MAKE_PROC}"
771
  "${MAKE_PROC}" ${MAKE_FLAGS}
772 773
  RES=$?
  if [ "${RES}" -ne "0" ]; then
774 775
    echo "${MAKE_PROC} does not work"
    return 1
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
  fi
  if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
    echo "${COMPILER} does not produce output"
    return 2
  fi
  ./test
  RES=$?
  rm -f "test"
  if [ "${RES}" -ne "0" ]; then
    echo "${MAKE_PROC} produces strange executable"
    return 3
  fi
  echo "${MAKE_PROC} works"
  return 0
}

792
# Parse arguments
793
cmake_verbose=
794
cmake_parallel_make=
795
cmake_ccache_enabled=
796
cmake_prefix_dir="${cmake_default_prefix}"
797 798
while test $# != 0; do
  case "$1" in
799 800 801
  --prefix=*) dir=`cmake_arg "$1"`
              cmake_prefix_dir=`cmake_fix_slashes "$dir"` ;;
  --parallel=*) cmake_parallel_make=`cmake_arg "$1"` ;;
802
  --bindir=*) cmake_bin_dir=`cmake_arg "$1"` ;;
803 804 805
  --datadir=*) cmake_data_dir=`cmake_arg "$1"` ;;
  --docdir=*) cmake_doc_dir=`cmake_arg "$1"` ;;
  --mandir=*) cmake_man_dir=`cmake_arg "$1"` ;;
806
  --xdgdatadir=*) cmake_xdgdata_dir=`cmake_arg "$1"` ;;
807
  --init=*) cmake_init_file=`cmake_arg "$1"` ;;
808 809
  --system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" ;;
  --no-system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" ;;
810
  --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-librhash|--system-zlib|--system-liblzma|--system-libuv)
811 812
    lib=`cmake_arg "$1" "--system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
813
  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-librhash|--no-system-zlib|--no-system-liblzma|--no-system-libuv)
814 815
    lib=`cmake_arg "$1" "--no-system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=0" ;;
816 817
  --qt-gui) cmake_bootstrap_qt_gui="1" ;;
  --no-qt-gui) cmake_bootstrap_qt_gui="0" ;;
818
  --qt-qmake=*) cmake_bootstrap_qt_qmake=`cmake_arg "$1"` ;;
819 820
  --sphinx-man) cmake_sphinx_man="1" ;;
  --sphinx-html) cmake_sphinx_html="1" ;;
821
  --sphinx-qthelp) cmake_sphinx_qthelp="1" ;;
822
  --sphinx-build=*) cmake_sphinx_build=`cmake_arg "$1"` ;;
823
  --sphinx-flags=*) cmake_sphinx_flags=`cmake_arg "$1"` ;;
824 825 826 827
  --help) cmake_usage ;;
  --version) cmake_version_display ; exit 2 ;;
  --verbose) cmake_verbose=TRUE ;;
  --enable-ccache) cmake_ccache_enabled=TRUE ;;
828 829 830 831 832
  CC=*) CC=`cmake_arg "$1"` ;;
  CXX=*) CXX=`cmake_arg "$1"` ;;
  CFLAGS=*) CFLAGS=`cmake_arg "$1"` ;;
  CXXFLAGS=*) CXXFLAGS=`cmake_arg "$1"` ;;
  LDFLAGS=*) LDFLAGS=`cmake_arg "$1"` ;;
833
  --) shift; break ;;
834 835 836
  *) die "Unknown option: $1" ;;
  esac
  shift
837 838
done

839
# If verbose, display some information about bootstrap
840 841 842 843 844 845
if [ -n "${cmake_verbose}" ]; then
  echo "---------------------------------------------"
  echo "Source directory: ${cmake_source_dir}"
  echo "Binary directory: ${cmake_binary_dir}"
  echo "Prefix directory: ${cmake_prefix_dir}"
  echo "System:           ${cmake_system}"
846 847 848 849
  if [ "x${cmake_parallel_make}" != "x" ]; then
    echo "Doing parallel make: ${cmake_parallel_make}"
  fi
  echo ""
850 851 852
fi

echo "---------------------------------------------"
853
# Get CMake version
854
echo "`cmake_version_display`"
855

856 857 858 859 860 861 862 863 864 865 866 867 868
# Check for in-source build
cmake_in_source_build=
if [ -f "${cmake_binary_dir}/Source/cmake.cxx" -a \
     -f "${cmake_binary_dir}/Source/cmake.h" ]; then
  if [ -n "${cmake_verbose}" ]; then
    echo "Warning: This is an in-source build"
  fi
  cmake_in_source_build=TRUE
fi

# If this is not an in-source build, then Bootstrap stuff should not exist.
if [ -z "${cmake_in_source_build}" ]; then
  # Did somebody bootstrap in the source tree?
869 870
  if [ -d "${cmake_source_dir}/Bootstrap${_cmk}" ]; then
    cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap${_cmk}\".
871
Looks like somebody did bootstrap CMake in the source tree, but now you are
872
trying to do bootstrap in the binary tree. Please remove Bootstrap${_cmk}
873 874 875 876
directory from the source tree."
  fi
  # Is there a cache in the source tree?
  for cmake_problematic_file in ${CMAKE_PROBLEMATIC_FILES}; do
Will Schroeder's avatar
Will Schroeder committed
877
    if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
878 879 880 881 882 883 884 885
      cmake_error 10 "Found \"${cmake_source_dir}/${cmake_problematic_file}\".
Looks like somebody tried to build CMake in the source tree, but now you are
trying to do bootstrap in the binary tree. Please remove \"${cmake_problematic_file}\"
from the source tree."
    fi
  done
fi

886
# Make bootstrap directory
887 888
[ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
if [ ! -d "${cmake_bootstrap_dir}" ]; then
889
  cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
890 891 892
fi
cd "${cmake_bootstrap_dir}"

893 894
[ -d "cmsys" ] || mkdir "cmsys"
if [ ! -d "cmsys" ]; then
895
  cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
896 897
fi

898
# Delete all the bootstrap files
899
rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
900 901
rm -f "${cmake_bootstrap_dir}/cmConfigure.h${_tmp}"
rm -f "${cmake_bootstrap_dir}/cmVersionConfig.h${_tmp}"
902

903 904 905 906 907 908
# If building in-source, remove any cmConfigure.h that may
# have been created by a previous run of the bootstrap cmake.
if [ -n "${cmake_in_source_build}" ]; then
  rm -f "${cmake_source_dir}/Source/cmConfigure.h"
fi

909
# If exist compiler flags, set them
910 911
cmake_c_flags=${CFLAGS}
cmake_cxx_flags=${CXXFLAGS}
Bill Hoffman's avatar
Bill Hoffman committed
912
cmake_ld_flags=${LDFLAGS}
913

914 915 916 917 918
# Add Cygwin-specific flags
if ${cmake_system_cygwin}; then
  cmake_ld_flags="${LDFLAGS} -Wl,--enable-auto-import"
fi

919
# Add CoreFoundation framework on Darwin
920
if ${cmake_system_darwin}; then
921
  cmake_ld_flags="${LDFLAGS} -framework CoreFoundation"
922 923
fi

924 925 926 927 928
# Add BeOS toolkits...
if ${cmake_system_beos}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

929 930 931 932 933
# Add Haiku toolkits...
if ${cmake_system_haiku}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

934 935 936 937 938 939
#-----------------------------------------------------------------------------
# Detect known toolchains on some platforms.
cmake_toolchains=''
case "${cmake_system}" in
  *AIX*)   cmake_toolchains='XL GNU' ;;
  *CYGWIN*) cmake_toolchains='GNU' ;;
940
  *Darwin*) cmake_toolchains='Clang GNU' ;;
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
  *Linux*) cmake_toolchains='GNU Clang XL PGI PathScale' ;;
  *MINGW*) cmake_toolchains='GNU' ;;
esac

# Toolchain compiler name table.
cmake_toolchain_Clang_CC='clang'
cmake_toolchain_Clang_CXX='clang++'
cmake_toolchain_GNU_CC='gcc'
cmake_toolchain_GNU_CXX='g++'
cmake_toolchain_PGI_CC='pgcc'
cmake_toolchain_PGI_CXX='pgCC'
cmake_toolchain_PathScale_CC='pathcc'
cmake_toolchain_PathScale_CXX='pathCC'
cmake_toolchain_XL_CC='xlc'
cmake_toolchain_XL_CXX='xlC'

cmake_toolchain_try()
{
  tc="$1"
  TMPFILE=`cmake_tmp_file`

  eval "tc_CC=\${cmake_toolchain_${tc}_CC}"
  echo 'int main() { return 0; }' > "${TMPFILE}.c"
  cmake_try_run "$tc_CC" "" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1
  tc_result_CC="$?"
  rm -f "${TMPFILE}.c"
  test "${tc_result_CC}" = "0" || return 1

  eval "tc_CXX=\${cmake_toolchain_${tc}_CXX}"
  echo 'int main() { return 0; }' > "${TMPFILE}.cpp"
  cmake_try_run "$tc_CXX" "" "${TMPFILE}.cpp" >> cmake_bootstrap.log 2>&1
  tc_result_CXX="$?"
  rm -f "${TMPFILE}.cpp"
  test "${tc_result_CXX}" = "0" || return 1

  cmake_toolchain="$tc"
}

cmake_toolchain_detect()
{
  cmake_toolchain=
  for tc in ${cmake_toolchains}; do
    echo "Checking for $tc toolchain" >> cmake_bootstrap.log 2>&1
    cmake_toolchain_try "$tc" &&
    echo "Found $tc toolchain" &&
    break
  done
}

if [ -z "${CC}" -a -z "${CXX}" ]; then
  cmake_toolchain_detect
fi

994
thread_flags=''
995 996 997
case "${cmake_system}" in
  *AIX*)   thread_flags='-pthread' ;;
esac
998

999
#-----------------------------------------------------------------------------
1000 1001 1002
# Test C compiler
cmake_c_compiler=

1003
# If CC is set, use that for compiler, otherwise use list of known compilers
1004 1005 1006
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_c_compilers="\${cmake_toolchain_${cmake_toolchain}_CC}"
elif [ -n "${CC}" ]; then
1007 1008 1009 1010 1011
  cmake_c_compilers="${CC}"
else
  cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
fi

1012
# Check if C compiler works
1013
TMPFILE=`cmake_tmp_file`
1014
echo '
1015 1016
#ifdef __cplusplus
# error "The CMAKE_C_COMPILER is set to a C++ compiler"
1017 1018
#endif

1019 1020 1021 1022
#if defined(_AIX) && defined(__GNUC__) && !defined(_THREAD_SAFE)
#error "On AIX with GNU we need the -pthread flag."
#endif

1023 1024 1025 1026
#if defined(__sun) && __STDC_VERSION__ < 199901L
#error "On Solaris we need C99."
#endif

1027
#include <stdio.h>
1028

Andy Cedilnik's avatar
Andy Cedilnik committed
1029
int main(int argc, char* argv[])
1030
{
1031
  printf("%d%c", (argv != 0), (char)0x0a);
1032
  return argc - 1;
1033
}
1034
' > "${TMPFILE}.c"
1035
for std in 11 99 90; do
1036
  std_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" C \"${std}\"`"
1037
  for compiler in ${cmake_c_compilers}; do
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
    for std_flag in '' $std_flags; do
      for thread_flag in '' $thread_flags; do
        echo "Checking whether '${compiler} ${cmake_c_flags} ${std_flag} ${thread_flag}' works." >> cmake_bootstrap.log 2>&1
        if cmake_try_run "${compiler}" "${cmake_c_flags} ${std_flag} ${thread_flag}" \
          "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
          cmake_c_compiler="${compiler}"
          cmake_c_flags="${cmake_c_flags} ${std_flag} ${thread_flag}"
          break 3
        fi
      done
1048
    done
1049 1050
  done
done
1051 1052 1053
rm -f "${TMPFILE}.c"

if [ -z "${cmake_c_compiler}" ]; then
1054
  cmake_error 6 "Cannot find appropriate C compiler on this system.
Bill Hoffman's avatar
Bill Hoffman committed
1055 1056 1057
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.
"
1058 1059 1060
fi
echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"

1061
#-----------------------------------------------------------------------------
1062 1063
# Test CXX compiler
cmake_cxx_compiler=
1064

1065 1066
# On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.

1067
# If CC is set, use that for compiler, otherwise use list of known compilers
1068 1069 1070
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_cxx_compilers="\${cmake_toolchain_${cmake_toolchain}_CXX}"
elif [ -n "${CXX}" ]; then
1071 1072 1073 1074 1075
  cmake_cxx_compilers="${CXX}"
else
  cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
fi

1076
# Check if C++ compiler works
1077
TMPFILE=`cmake_tmp_file`
1078
echo '
1079 1080
#include <iostream>
#include <memory>
1081
#include <unordered_map>
1082

1083 1084 1085 1086
#if __cplusplus < 201103L
#error "Compiler is not in a mode aware of C++11."
#endif

1087 1088 1089 1090
#if defined(_AIX) && defined(__GNUC__) && !defined(_THREAD_SAFE)
#error "On AIX with GNU we need the -pthread flag."
#endif

1091 1092
#if defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140
#error "SunPro <= 5.13 mode not supported due to bug in move semantics."
1093 1094
#endif

1095
class Class
1096 1097
{
public:
1098
  int Get() const { return this->Member; }
1099
private:
1100
  int Member = 1;
1101
};
1102 1103
int main()
{
1104 1105
  auto const c = std::unique_ptr<Class>(new Class);
  std::cout << c->Get() << std::endl;
1106 1107
  return 0;
}
1108
' > "${TMPFILE}.cxx"
1109
for std in 17 14 11; do
1110
  std_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" CXX \"${std}\"`"
1111
  for compiler in ${cmake_cxx_compilers}; do
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
    for std_flag in '' $std_flags; do
      for thread_flag in '' $thread_flags; do
        echo "Checking whether '${compiler} ${cmake_cxx_flags} ${std_flag} ${thread_flag}' works." >> cmake_bootstrap.log 2>&1
        if cmake_try_run "${compiler}" "${cmake_cxx_flags} ${std_flag} ${thread_flag}" \
          "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
          cmake_cxx_compiler="${compiler}"
          cmake_cxx_flags="${cmake_cxx_flags} ${std_flag} ${thread_flag} "
          break 3
        fi
      done
1122
    done
1123 1124
  done
done
1125 1126 1127
rm -f "${TMPFILE}.cxx"

if [ -z "${cmake_cxx_compiler}" ]; then
1128
cmake_error 7 "Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.
Bill Hoffman's avatar
Bill Hoffman committed
1129
Please specify one using environment variable CXX.
1130 1131
The C++ flags are \"$cmake_cxx_flags\".
They can be changed using the environment variable CXXFLAGS.
Bill Hoffman's avatar
Bill Hoffman committed
1132
See cmake_bootstrap.log for compilers attempted."
1133 1134 1135
fi
echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"

1136
#-----------------------------------------------------------------------------
1137 1138 1139
# Test Make

cmake_make_processor=
1140
cmake_make_flags=
1141 1142

# If MAKE is set, use that for make processor, otherwise use list of known make
1143 1144 1145