bootstrap 47 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
cmake_bootstrap_server=""
76 77
cmake_sphinx_man=""
cmake_sphinx_html=""
78
cmake_sphinx_qthelp=""
79
cmake_sphinx_build=""
80
cmake_sphinx_flags=""
81

82
# Determine whether this is a Cygwin environment.
83
if echo "${cmake_system}" | grep -q CYGWIN; then
84
  cmake_system_cygwin=true
85 86
  cmake_doc_dir_keyword="CYGWIN"
  cmake_man_dir_keyword="CYGWIN"
87 88 89 90
else
  cmake_system_cygwin=false
fi

91
# Determine whether this is a MinGW environment.
92
if echo "${cmake_system}" | grep -q 'MINGW\|MSYS'; then
93 94 95 96 97
  cmake_system_mingw=true
else
  cmake_system_mingw=false
fi

98
# Determine whether this is OS X
99
if echo "${cmake_system}" | grep -q Darwin; then
100 101 102 103 104
  cmake_system_darwin=true
else
  cmake_system_darwin=false
fi

105
# Determine whether this is BeOS
106
if echo "${cmake_system}" | grep -q BeOS; then
107
  cmake_system_beos=true
108 109
  cmake_doc_dir_keyword="HAIKU"
  cmake_man_dir_keyword="HAIKU"
110 111 112 113
else
  cmake_system_beos=false
fi

114
# Determine whether this is Haiku
115
if echo "${cmake_system}" | grep -q Haiku; then
116
  cmake_system_haiku=true
117 118
  cmake_doc_dir_keyword="HAIKU"
  cmake_man_dir_keyword="HAIKU"
119 120 121 122
else
  cmake_system_haiku=false
fi

123
# Determine whether this is OpenVMS
124
if echo "${cmake_system}" | grep -q OpenVMS; then
125 126 127 128 129
  cmake_system_openvms=true
else
  cmake_system_openvms=false
fi

130
# Determine whether this is HP-UX
131
if echo "${cmake_system}" | grep -q HP-UX; then
132 133 134 135 136
  cmake_system_hpux=true
else
  cmake_system_hpux=false
fi

137
# Determine whether this is Linux
138
if echo "${cmake_system}" | grep -q Linux; then
139
  cmake_system_linux=true
140 141 142 143 144 145 146 147 148
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
149
  if uname -m | grep -q parisc; then
150 151
    cmake_machine_parisc=true
  fi
152
elif ${cmake_system_hpux}; then
153
  if uname -m | grep -q ia64; then : ; else
154 155
    cmake_machine_parisc=true
  fi
156 157
fi

158 159 160 161 162 163 164 165 166
# 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

167 168 169 170 171 172 173 174 175 176 177 178 179 180
# 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}"

181
# Helper function to fix windows paths.
182 183 184 185 186 187 188 189 190 191 192 193 194 195
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
196 197 198 199 200 201 202 203 204 205 206 207 208 209

# 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
210
elif ${cmake_system_haiku}; then
211
  cmake_default_prefix=`finddir B_COMMON_DIRECTORY`
212 213 214 215
else
  cmake_default_prefix="/usr/local"
fi

216
# Lookup default install destinations.
217
cmake_bin_dir_default="`cmake_install_dest_default BIN ${cmake_bin_dir_keyword}`"
218 219 220
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}`"
221
cmake_xdgdata_dir_default="`cmake_install_dest_default XDGDATA ${cmake_xdgdata_dir_keyword}`"
222

223
CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
224
CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
225
CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
226

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

241 242 243 244 245 246 247 248
CMAKE_UNUSED_SOURCES="\
  cmGlobalXCodeGenerator \
  cmLocalXCodeGenerator \
  cmXCodeObject \
  cmXCode21Object \
  cmSourceGroup \
"

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

418 419 420
if ${cmake_system_mingw}; then
  CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES}\
    cmGlobalMSYSMakefileGenerator \
421
    cmGlobalMinGWMakefileGenerator"
422 423
fi

424 425 426 427 428 429 430 431 432 433
LexerParser_CXX_SOURCES="\
  cmCommandArgumentLexer \
  cmCommandArgumentParser \
  cmExprLexer \
  cmExprParser \
"

LexerParser_C_SOURCES="\
  cmListFileLexer \
"
434

435 436
if ${cmake_system_mingw}; then
  KWSYS_C_SOURCES="\
437
    EncodingC \
438
    ProcessWin32 \
439
    String \
440 441
    System \
    Terminal"
442 443
else
  KWSYS_C_SOURCES="\
444
    EncodingC \
445
    ProcessUNIX \
446
    String \
447 448
    System \
    Terminal"
449
fi
450 451

KWSYS_CXX_SOURCES="\
452
  Directory \
453
  EncodingCXX \
454
  FStream \
Andy Cedilnik's avatar
Andy Cedilnik committed
455
  Glob \
456 457 458 459 460
  RegularExpression \
  SystemTools"

KWSYS_FILES="\
  Directory.hxx \
461 462 463
  Encoding.h \
  Encoding.hxx \
  FStream.hxx \
Andy Cedilnik's avatar
Andy Cedilnik committed
464
  Glob.hxx \
465 466
  Process.h \
  RegularExpression.hxx \
467
  String.h \
468
  String.hxx \
469
  System.h \
470 471
  SystemTools.hxx \
  Terminal.h"
472

473
# Display CMake bootstrap usage
474 475
cmake_usage()
{
476
echo '
477
Usage: '"$0"' [<options>...] [-- <cmake-options>...]
478 479 480
Options: [defaults in brackets after descriptions]
Configuration:
  --help                  print this message
481
  --version               only print version information
482
  --verbose               display more information
483 484
  --parallel=n            bootstrap cmake in parallel, where n is
                          number of nodes [1]
485
  --enable-ccache         Enable ccache when building cmake
486
  --init=FILE             load FILE as script to populate cache
487
  --system-libs           use all system-installed third-party libraries
488
                          (for use only by package maintainers)
489
  --no-system-libs        use all cmake-provided third-party libraries
490
                          (default)
491 492 493 494
  --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)
495 496
  --system-jsoncpp        use system-installed jsoncpp library
  --no-system-jsoncpp     use cmake-provided jsoncpp library (default)
497 498 499 500
  --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)
501 502
  --system-liblzma        use system-installed liblzma library
  --no-system-liblzma     use cmake-provided liblzma library (default)
503 504
  --system-libarchive     use system-installed libarchive library
  --no-system-libarchive  use cmake-provided libarchive library (default)
505 506
  --system-librhash       use system-installed librhash library
  --no-system-librhash    use cmake-provided librhash library (default)
507

508 509 510
  --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
511

512 513 514
  --server                enable the server mode (default if supported)
  --no-server             disable the server mode

515 516
  --sphinx-man            build man pages with Sphinx
  --sphinx-html           build html help with Sphinx
517
  --sphinx-qthelp         build qch help with Sphinx
518
  --sphinx-build=<sb>     use <sb> as the sphinx-build executable
519
  --sphinx-flags=<flags>  pass <flags> to sphinx-build executable
520

521
Directory and file names:
522
  --prefix=PREFIX         install files in tree rooted at PREFIX
523
                          ['"${cmake_default_prefix}"']
524 525
  --bindir=DIR            install binaries in PREFIX/DIR
                          ['"${cmake_bin_dir_default}"']
526
  --datadir=DIR           install data files in PREFIX/DIR
527
                          ['"${cmake_data_dir_default}"']
528
  --docdir=DIR            install documentation files in PREFIX/DIR
529
                          ['"${cmake_doc_dir_default}"']
530
  --mandir=DIR            install man pages files in PREFIX/DIR/manN
531
                          ['"${cmake_man_dir_default}"']
532 533
  --xdgdatadir=DIR        install XDG specific files in PREFIX/DIR
                          ['"${cmake_xdgdata_dir_default}"']
534
'
535 536 537
  exit 10
}

538
# Display CMake bootstrap usage
539
cmake_version_display()
540
{
541
  echo "CMake ${cmake_version}, ${cmake_copyright}"
542 543 544
}

# Display CMake bootstrap error, display the log file and exit
545 546
cmake_error()
{
547 548
  res=$1
  shift 1
549
  echo "---------------------------------------------"
550
  echo "Error when bootstrapping CMake:"
551 552 553
  echo "$*"
  echo "---------------------------------------------"
  if [ -f cmake_bootstrap.log ]; then
554 555
    echo "Log of errors: `pwd`/cmake_bootstrap.log"
    #cat cmake_bootstrap.log
556 557
    echo "---------------------------------------------"
  fi
558
  exit ${res}
559
}
560

561 562 563 564 565 566 567 568 569 570 571 572
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
}

573 574 575 576 577 578 579
# Replace KWSYS_NAMESPACE with cmsys
cmake_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  SEARCHFOR="$3"
  REPLACEWITH="$4"
580
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
581
    sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" "${INFILE}" > "${OUTFILE}${_tmp}"
582 583
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
584
        #echo "Files are the same"
585
        rm -f "${OUTFILE}${_tmp}"
586
      else
587
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
588 589
      fi
    fi
590
  else
591
    cmake_error 1 "Cannot find file ${INFILE}"
592 593 594
  fi
}

595 596 597 598 599 600
cmake_kwsys_config_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  shift 2
  APPEND="$*"
601 602
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
    echo "${APPEND}" > "${OUTFILE}${_tmp}"
603 604 605 606 607 608 609 610
    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}"
611 612
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
613
        #echo "Files are the same"
614
        rm -f "${OUTFILE}${_tmp}"
615
      else
616
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
617 618 619 620 621 622
      fi
    fi
  else
    cmake_error 2 "Cannot find file ${INFILE}"
  fi
}
623
# Write string into a file
624 625 626 627 628 629 630
cmake_report ()
{
  FILE=$1
  shift
  echo "$*" >> ${FILE}
}

631
# Escape spaces in strings
632 633 634 635 636
cmake_escape ()
{
  echo $1 | sed "s/ /\\\\ /g"
}

637 638 639 640 641 642
# Strip prefix from argument
cmake_arg ()
{
  echo "$1" | sed "s/^${2-[^=]*=}//"
}

643
# Write message to the log
644 645 646 647 648
cmake_log ()
{
  echo "$*" >> cmake_bootstrap.log
}

649
# Return temp file
650 651
cmake_tmp_file ()
{
652
  echo "cmake_bootstrap_$$_test"
653 654
}

655 656
# Run a compiler test. First argument is compiler, second one are compiler
# flags, third one is test source file to be compiled
657 658 659 660 661 662 663 664 665 666 667
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}"
668 669
  echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
  echo "----------  file   -----------------------"
670
  cat "${TESTFILE}"
671
  echo "------------------------------------------"
672 673 674
  "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  RES=$?
  if [ "${RES}" -ne "0" ]; then
675 676
    echo "Test failed to compile"
    return 1
677 678
  fi
  if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
679
    echo "Test failed to produce executable"
680 681 682 683 684 685
    return 2
  fi
  ./${TMPFILE}
  RES=$?
  rm -f "${TMPFILE}"
  if [ "${RES}" -ne "0" ]; then
686
    echo "Test produced non-zero return code"
687 688
    return 3
  fi
689
  echo "Test succeeded"
690 691 692
  return 0
}

693
# Run a make test. First argument is the make interpreter.
694 695
cmake_try_make ()
{
696 697
  MAKE_PROC="$1"
  MAKE_FLAGS="$2"
698
  echo "Try: ${MAKE_PROC}"
699
  "${MAKE_PROC}" ${MAKE_FLAGS}
700 701
  RES=$?
  if [ "${RES}" -ne "0" ]; then
702 703
    echo "${MAKE_PROC} does not work"
    return 1
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
  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
}

720
# Parse arguments
721
cmake_verbose=
722
cmake_parallel_make=
723
cmake_ccache_enabled=
724
cmake_prefix_dir="${cmake_default_prefix}"
725 726
while test $# != 0; do
  case "$1" in
727 728 729
  --prefix=*) dir=`cmake_arg "$1"`
              cmake_prefix_dir=`cmake_fix_slashes "$dir"` ;;
  --parallel=*) cmake_parallel_make=`cmake_arg "$1"` ;;
730
  --bindir=*) cmake_bin_dir=`cmake_arg "$1"` ;;
731 732 733
  --datadir=*) cmake_data_dir=`cmake_arg "$1"` ;;
  --docdir=*) cmake_doc_dir=`cmake_arg "$1"` ;;
  --mandir=*) cmake_man_dir=`cmake_arg "$1"` ;;
734
  --xdgdatadir=*) cmake_xdgdata_dir=`cmake_arg "$1"` ;;
735
  --init=*) cmake_init_file=`cmake_arg "$1"` ;;
736 737
  --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" ;;
738
  --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-librhash|--system-zlib|--system-liblzma)
739 740
    lib=`cmake_arg "$1" "--system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
741
  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-librhash|--no-system-zlib|--no-system-liblzma)
742 743
    lib=`cmake_arg "$1" "--no-system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=0" ;;
744 745
  --qt-gui) cmake_bootstrap_qt_gui="1" ;;
  --no-qt-gui) cmake_bootstrap_qt_gui="0" ;;
746
  --qt-qmake=*) cmake_bootstrap_qt_qmake=`cmake_arg "$1"` ;;
747 748
  --server) cmake_bootstrap_server="1" ;;
  --no-server) cmake_bootstrap_server="0" ;;
749 750
  --sphinx-man) cmake_sphinx_man="1" ;;
  --sphinx-html) cmake_sphinx_html="1" ;;
751
  --sphinx-qthelp) cmake_sphinx_qthelp="1" ;;
752
  --sphinx-build=*) cmake_sphinx_build=`cmake_arg "$1"` ;;
753
  --sphinx-flags=*) cmake_sphinx_flags=`cmake_arg "$1"` ;;
754 755 756 757
  --help) cmake_usage ;;
  --version) cmake_version_display ; exit 2 ;;
  --verbose) cmake_verbose=TRUE ;;
  --enable-ccache) cmake_ccache_enabled=TRUE ;;
758
  --) shift; break ;;
759 760 761
  *) die "Unknown option: $1" ;;
  esac
  shift
762 763
done

764
# If verbose, display some information about bootstrap
765 766 767 768 769 770
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}"
771 772 773 774
  if [ "x${cmake_parallel_make}" != "x" ]; then
    echo "Doing parallel make: ${cmake_parallel_make}"
  fi
  echo ""
775 776 777
fi

echo "---------------------------------------------"
778
# Get CMake version
779
echo "`cmake_version_display`"
780

781 782 783 784 785 786 787 788 789 790 791 792 793
# 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?
794 795
  if [ -d "${cmake_source_dir}/Bootstrap${_cmk}" ]; then
    cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap${_cmk}\".
796
Looks like somebody did bootstrap CMake in the source tree, but now you are
797
trying to do bootstrap in the binary tree. Please remove Bootstrap${_cmk}
798 799 800 801
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
802
    if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
803 804 805 806 807 808 809 810
      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

811
# Make bootstrap directory
812 813
[ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
if [ ! -d "${cmake_bootstrap_dir}" ]; then
814
  cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
815 816 817
fi
cd "${cmake_bootstrap_dir}"

818 819
[ -d "cmsys" ] || mkdir "cmsys"
if [ ! -d "cmsys" ]; then
820
  cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
821 822
fi

823
# Delete all the bootstrap files
824
rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
825 826
rm -f "${cmake_bootstrap_dir}/cmConfigure.h${_tmp}"
rm -f "${cmake_bootstrap_dir}/cmVersionConfig.h${_tmp}"
827

828
# If exist compiler flags, set them
829 830
cmake_c_flags=${CFLAGS}
cmake_cxx_flags=${CXXFLAGS}
Bill Hoffman's avatar
Bill Hoffman committed
831
cmake_ld_flags=${LDFLAGS}
832

833 834 835 836 837
# Add Cygwin-specific flags
if ${cmake_system_cygwin}; then
  cmake_ld_flags="${LDFLAGS} -Wl,--enable-auto-import"
fi

838
# Add CoreFoundation framework on Darwin
839
if ${cmake_system_darwin}; then
840
  cmake_ld_flags="${LDFLAGS} -framework CoreFoundation"
841 842
fi

843 844 845 846 847
# Add BeOS toolkits...
if ${cmake_system_beos}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

848 849 850 851 852
# Add Haiku toolkits...
if ${cmake_system_haiku}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

853 854 855 856 857 858 859
# Workaround for short jump tables on PA-RISC
if ${cmake_machine_parisc}; then
  if ${cmake_c_compiler_is_gnu}; then
    cmake_c_flags="${CFLAGS} -mlong-calls"
  fi
  if ${cmake_cxx_compiler_is_gnu}; then
    cmake_cxx_flags="${CXXFLAGS} -mlong-calls"
860 861 862
  fi
fi

863 864 865 866 867 868
#-----------------------------------------------------------------------------
# Detect known toolchains on some platforms.
cmake_toolchains=''
case "${cmake_system}" in
  *AIX*)   cmake_toolchains='XL GNU' ;;
  *CYGWIN*) cmake_toolchains='GNU' ;;
869
  *Darwin*) cmake_toolchains='Clang GNU' ;;
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
  *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

#-----------------------------------------------------------------------------
924 925 926
# Test C compiler
cmake_c_compiler=

927
# If CC is set, use that for compiler, otherwise use list of known compilers
928 929 930
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_c_compilers="\${cmake_toolchain_${cmake_toolchain}_CC}"
elif [ -n "${CC}" ]; then
931 932 933 934 935
  cmake_c_compilers="${CC}"
else
  cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
fi

936
# Check if C compiler works
937
TMPFILE=`cmake_tmp_file`
938
echo '
939 940
#ifdef __cplusplus
# error "The CMAKE_C_COMPILER is set to a C++ compiler"
941 942
#endif

943 944 945
#include<stdio.h>

#if defined(__CLASSIC_C__)
946 947 948 949
int main(argc, argv)
  int argc;
  char* argv[];
#else
Andy Cedilnik's avatar
Andy Cedilnik committed
950
int main(int argc, char* argv[])
951
#endif
952
{
953
  printf("%d%c", (argv != 0), (char)0x0a);
Andy Cedilnik's avatar
Andy Cedilnik committed
954
  return argc-1;
955
}
956
' > "${TMPFILE}.c"
957
for a in ${cmake_c_compilers}; do
958 959
  if [ -z "${cmake_c_compiler}" ] && \
    cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
960 961 962
    cmake_c_compiler="${a}"
  fi
done
963 964 965 966 967 968 969 970 971 972 973
for std in 11 99 90; do
  try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" C \"${std}\"`"
  for flag in $try_flags; do
    echo "Checking whether ${cmake_c_compiler} supports ${flag}" >> cmake_bootstrap.log 2>&1
    if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags} ${flag}" \
      "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
      cmake_c_flags="${cmake_c_flags} ${flag}"
      break 2
    fi
  done
done
974 975 976
rm -f "${TMPFILE}.c"

if [ -z "${cmake_c_compiler}" ]; then
977
  cmake_error 6 "Cannot find appropriate C compiler on this system.
Bill Hoffman's avatar
Bill Hoffman committed
978 979 980
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.
"
981 982 983
fi
echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"

984
#-----------------------------------------------------------------------------
985 986
# Test CXX compiler
cmake_cxx_compiler=
987

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

990
# If CC is set, use that for compiler, otherwise use list of known compilers
991 992 993
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_cxx_compilers="\${cmake_toolchain_${cmake_toolchain}_CXX}"
elif [ -n "${CXX}" ]; then
994 995 996 997 998
  cmake_cxx_compilers="${CXX}"
else
  cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
fi

999
# Check if C++ compiler works
1000
TMPFILE=`cmake_tmp_file`
1001
echo '
1002 1003 1004 1005 1006 1007
#if defined(TEST1)
# include <iostream>
#else
# include <iostream.h>
#endif

1008 1009 1010 1011
#if __cplusplus >= 201103L && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140
#error "SunPro <= 5.13 C++ 11 mode not supported due to bug in move semantics."
#endif

1012
class NeedCXX
1013 1014 1015 1016 1017 1018 1019
{
public:
  NeedCXX() { this->Foo = 1; }
  int GetFoo() { return this->Foo; }
private:
  int Foo;
};
1020 1021
int main()
{
1022
  NeedCXX c;
1023 1024 1025 1026 1027
#ifdef TEST3
  cout << c.GetFoo() << endl;
#else
  std::cout << c.GetFoo() << std::endl;
#endif
1028 1029
  return 0;
}
1030
' > "${TMPFILE}.cxx"
1031
for a in ${cmake_cxx_compilers}; do
1032 1033 1034 1035 1036 1037
  for b in 1 2 3; do
    if [ -z "${cmake_cxx_compiler}" ] && \
      cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      cmake_cxx_compiler="${a}"
    fi
  done
1038
done
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
for std in 14 11 98; do
  try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" CXX \"${std}\"`"
  for flag in $try_flags; do
    echo "Checking for wheter ${cmake_cxx_flags} supports ${flag}" >> cmake_bootstrap.log 2>&1
    if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags} ${flag} -DTEST1" \
      "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      cmake_cxx_flags="${cmake_cxx_flags} ${flag} "
      break 2
    fi
  done
done
1050 1051 1052
rm -f "${TMPFILE}.cxx"

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

1059
#-----------------------------------------------------------------------------
1060 1061 1062
# Test Make

cmake_make_processor=
1063
cmake_make_flags=
1064 1065

# If MAKE is set, use that for make processor, otherwise use list of known make
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
if [ -n "${MAKE}" ]; then
  cmake_make_processors="${MAKE}"
else
  cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
fi

TMPFILE="`cmake_tmp_file`_dir"
rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
cd "${cmake_bootstrap_dir}/${TMPFILE}"
1076
echo '
1077
test: test.c
1078
	"'"${cmake_c_compiler}"'" '"${cmake_ld_flags} ${cmake_c_flags}"' -o test test.c
1079 1080
'>"Makefile"
echo '
1081
#include <stdio.h>
1082
int main(){ printf("1%c", (char)0x0a); return 0; }
1083
' > "test.c"
1084
cmake_original_make_flags="${cmake_make_flags}"
1085 1086 1087
if [ "x${cmake_parallel_make}" != "x" ]; then
  cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
fi
1088
for a in ${cmake_make_processors}; do
1089
  if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
1090 1091 1092
    cmake_make_processor="${a}"
  fi
done
1093 1094 1095 1096 1097
cmake_full_make_flags="${cmake_make_flags}"
if [ "x${cmake_original_make_flags}" != "x${cmake_make_flags}" ]; then
  if [ -z "${cmake_make_processor}" ]; then
    cmake_make_flags="${cmake_original_make_flags}"
    for a in ${cmake_make_processors}; do
1098
      if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
1099 1100 1101 1102 1103
        cmake_make_processor="${a}"
      fi
    done
  fi
fi
1104 1105
cd "${cmake_bootstrap_dir}"

1106
if [ -z "${cmake_make_processor}" ]; then
1107
  cmake_error 8 "Cannot find appropriate Makefile processor on this system.
1108 1109
Please specify one using environment variable MAKE."
fi
1110
rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
1111 1112 1113 1114 1115 1116
echo "Makefile processor on this system is: ${cmake_make_processor}"
if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
  echo "---------------------------------------------"
  echo "Makefile processor ${cmake_make_processor} does not support parallel build"
  echo "---------------------------------------------"
fi
1117

1118 1119
# Ok, we have CC, CXX, and MAKE.

1120
# Test C++ compiler features
1121

1122 1123 1124
# Are we GCC?

TMPFILE=`cmake_tmp_file`
1125
echo '
Andy Cedilnik's avatar