bootstrap 52.1 KB
Newer Older
1
#!/bin/sh
2 3
#=============================================================================
# CMake - Cross Platform Makefile Generator
4
# Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
5
#
6 7
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
8
#
9 10 11 12
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
13

14 15 16 17
die() {
  echo "$@" 1>&2 ; exit 1
}

18 19 20
# Version number extraction function.
cmake_version_component()
{
Brad King's avatar
Brad King committed
21
  cat "${cmake_source_dir}/Source/CMakeVersion.cmake" | sed -n "
22 23 24 25
/^SET(CMake_VERSION_${1}/ {s/SET(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
"
}

26 27 28 29 30
cmake_toupper()
{
    echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
}

31 32
# Detect system and directory information.
cmake_system=`uname`
33
cmake_source_dir=`cd "\`dirname \"$0\"\`";pwd`
34
cmake_binary_dir=`pwd`
35 36

# Load version information.
37 38
cmake_version_major="`cmake_version_component MAJOR`"
cmake_version_minor="`cmake_version_component MINOR`"
39 40 41 42 43 44 45 46 47
cmake_version_patch="`cmake_version_component PATCH`"
cmake_version="${cmake_version_major}.${cmake_version_minor}.${cmake_version_patch}"
cmake_version_tweak="`cmake_version_component TWEAK`"
if [ "$cmake_version_tweak" != "0" ]; then
  cmake_version="${cmake_version}.${cmake_version_tweak}"
fi

cmake_data_dir="/share/cmake-${cmake_version_major}.${cmake_version_minor}"
cmake_doc_dir="/doc/cmake-${cmake_version_major}.${cmake_version_minor}"
48 49
cmake_man_dir="/man"
cmake_init_file=""
50
cmake_bootstrap_system_libs=""
51 52
cmake_bootstrap_qt_gui=""
cmake_bootstrap_qt_qmake=""
53

54 55 56 57 58 59 60
# Determine whether this is a Cygwin environment.
if echo "${cmake_system}" | grep CYGWIN >/dev/null 2>&1; then
  cmake_system_cygwin=true
else
  cmake_system_cygwin=false
fi

61 62 63 64 65 66 67
# Determine whether this is a MinGW environment.
if echo "${cmake_system}" | grep MINGW >/dev/null 2>&1; then
  cmake_system_mingw=true
else
  cmake_system_mingw=false
fi

68 69 70 71 72 73 74
# Determine whether this is OS X
if echo "${cmake_system}" | grep Darwin >/dev/null 2>&1; then
  cmake_system_darwin=true
else
  cmake_system_darwin=false
fi

75 76 77 78 79 80 81
# Determine whether this is BeOS 
if echo "${cmake_system}" | grep BeOS >/dev/null 2>&1; then
  cmake_system_beos=true
else
  cmake_system_beos=false
fi

82 83 84 85 86 87 88
# Determine whether this is Haiku 
if echo "${cmake_system}" | grep Haiku >/dev/null 2>&1; then
  cmake_system_haiku=true
else
  cmake_system_haiku=false
fi

89 90 91 92 93 94 95
# Determine whether this is OpenVMS
if echo "${cmake_system}" | grep OpenVMS >/dev/null 2>&1; then
  cmake_system_openvms=true
else
  cmake_system_openvms=false
fi

96 97 98 99 100 101 102 103 104
# 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

105 106 107 108 109 110 111 112 113 114 115 116 117 118
# 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}"

119
# Helper function to fix windows paths.
120 121 122 123 124 125 126 127 128 129 130 131 132 133
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
134 135 136 137 138 139 140 141 142 143 144 145 146 147

# 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
148 149
elif ${cmake_system_haiku}; then
  cmake_default_prefix=`/bin/finddir B_COMMON_DIRECTORY`
150 151 152 153
else
  cmake_default_prefix="/usr/local"
fi

154
CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
155
CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
Bill Hoffman's avatar
Bill Hoffman committed
156
CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
157

158 159 160 161 162 163 164 165 166 167 168
CMAKE_PROBLEMATIC_FILES="\
  CMakeCache.txt \
  CMakeSystem.cmake \
  CMakeCCompiler.cmake \
  CMakeCXXCompiler.cmake \
  Source/cmConfigure.h \
  Source/CTest/Curl/config.h \
  Utilities/cmexpat/expatConfig.h \
  Utilities/cmexpat/expatDllConfig.h \
  "

169 170 171 172 173 174 175 176
CMAKE_UNUSED_SOURCES="\
  cmGlobalXCodeGenerator \
  cmLocalXCodeGenerator \
  cmXCodeObject \
  cmXCode21Object \
  cmSourceGroup \
"

177
CMAKE_CXX_SOURCES="\
178
  cmStandardIncludes \
179 180
  cmake  \
  cmakemain \
181
  cmakewizard  \
182 183 184
  cmCommandArgumentLexer \
  cmCommandArgumentParser \
  cmCommandArgumentParserHelper \
185
  cmDefinitions \
186 187
  cmDepends \
  cmDependsC \
188 189
  cmDocumentationFormatter \
  cmDocumentationFormatterText \
190
  cmPolicies \
Ken Martin's avatar
Ken Martin committed
191 192 193 194
  cmProperty \
  cmPropertyMap \
  cmPropertyDefinition \
  cmPropertyDefinitionMap \
195 196
  cmMakeDepend \
  cmMakefile \
197 198 199
  cmExportFileGenerator \
  cmExportInstallFileGenerator \
  cmInstallDirectoryGenerator \
200
  cmGeneratedFileStream \
201
  cmGeneratorTarget \
202
  cmGeneratorExpression \
203 204
  cmGlobalGenerator \
  cmLocalGenerator \
205
  cmInstallGenerator \
206
  cmInstallExportGenerator \
207
  cmInstallFilesGenerator \
208 209
  cmInstallScriptGenerator \
  cmInstallTargetGenerator \
210
  cmScriptGenerator \
211
  cmSourceFile \
212
  cmSourceFileLocation \
213
  cmSystemTools \
214
  cmTestGenerator \
Bill Hoffman's avatar
Bill Hoffman committed
215
  cmVersion \
216
  cmFileTimeComparison \
217 218
  cmGlobalUnixMakefileGenerator3 \
  cmLocalUnixMakefileGenerator3 \
219 220 221 222
  cmMakefileExecutableTargetGenerator \
  cmMakefileLibraryTargetGenerator \
  cmMakefileTargetGenerator \
  cmMakefileUtilityTargetGenerator \
223
  cmNewLineStyle \
224
  cmBootstrapCommands \
225 226
  cmCommands \
  cmTarget \
227
  cmTest \
228
  cmCustomCommand \
229
  cmCustomCommandGenerator \
Bill Hoffman's avatar
Bill Hoffman committed
230
  cmDocumentVariables \
231 232
  cmCacheManager \
  cmListFileCache \
233
  cmComputeLinkDepends \
234
  cmComputeLinkInformation \
235
  cmOrderDirectories \
236
  cmComputeTargetDepends \
237
  cmComputeComponentGraph \
238 239 240
  cmExprLexer \
  cmExprParser \
  cmExprParserHelper \
241
"
242

243 244 245 246 247 248 249
if ${cmake_system_mingw}; then
  CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES}\
    cmGlobalMSYSMakefileGenerator \
    cmGlobalMinGWMakefileGenerator \
    cmWin32ProcessExecution"
fi

250 251 252 253
CMAKE_C_SOURCES="\
  cmListFileLexer \
  "

254 255
if ${cmake_system_mingw}; then
  KWSYS_C_SOURCES="\
256
    ProcessWin32 \
257
    String \
258
    System"
259 260 261 262 263 264 265
  KWSYS_C_MINGW_SOURCES="\
    ProcessFwd9x \
    EncodeExecutable"
  KWSYS_C_GENERATED_SOURCES="\
    cmsysProcessFwd9xEnc"
else
  KWSYS_C_SOURCES="\
266
    ProcessUNIX \
267
    String \
268
    System"
269 270 271
  KWSYS_C_MINGW_SOURCES=""
  KWSYS_C_GENERATED_SOURCES=""
fi
272 273

KWSYS_CXX_SOURCES="\
Brad King's avatar
Brad King committed
274
  Directory \
Andy Cedilnik's avatar
Andy Cedilnik committed
275
  Glob \
Brad King's avatar
Brad King committed
276 277 278 279
  RegularExpression \
  SystemTools"

KWSYS_FILES="\
280
  auto_ptr.hxx \
Brad King's avatar
Brad King committed
281
  Directory.hxx \
Andy Cedilnik's avatar
Andy Cedilnik committed
282
  Glob.hxx \
Brad King's avatar
Brad King committed
283 284
  Process.h \
  RegularExpression.hxx \
285
  String.h \
286
  String.hxx \
287
  System.h \
Brad King's avatar
Brad King committed
288 289
  SystemTools.hxx"

290
KWSYS_IOS_FILES="
Brad King's avatar
Brad King committed
291 292 293 294 295
  fstream \
  iosfwd \
  iostream \
  sstream"

296
# Display CMake bootstrap usage
297 298
cmake_usage()
{
299
echo '
300
Usage: '"$0"' [<options>...] [-- <cmake-options>...]
301 302 303
Options: [defaults in brackets after descriptions]
Configuration:
  --help                  print this message
304
  --version               only print version information
305
  --verbose               display more information
306 307
  --parallel=n            bootstrap cmake in parallel, where n is
                          number of nodes [1]
308
  --enable-ccache         Enable ccache when building cmake
309
  --init=FILE             load FILE as script to populate cache
310
  --system-libs           use all system-installed third-party libraries
311
                          (for use only by package maintainers)
312
  --no-system-libs        use all cmake-provided third-party libraries
313
                          (default)
314 315 316 317 318 319 320 321 322 323 324
  --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)
  --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)
  --system-libarchive     use system-installed libarchive library
  --no-system-libarchive  use cmake-provided libarchive library (default)

325 326 327
  --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
328

329
Directory and file names:
330
  --prefix=PREFIX         install files in tree rooted at PREFIX
331
                          [${cmake_default_prefix}]
332 333 334 335 336 337
  --datadir=DIR           install data files in PREFIX/DIR
                          [/share/CMake]
  --docdir=DIR            install documentation files in PREFIX/DIR
                          [/doc/CMake]
  --mandir=DIR            install man pages files in PREFIX/DIR/manN
                          [/man]
338
'
339 340 341
  exit 10
}

342
# Display CMake bootstrap usage
343
cmake_version_display()
344
{
345
  echo "CMake ${cmake_version}, Copyright 2000-2011 Kitware, Inc."
346 347 348
}

# Display CMake bootstrap error, display the log file and exit
349 350
cmake_error()
{
351 352
  res=$1
  shift 1
353
  echo "---------------------------------------------"
354 355 356 357
  echo "Error when bootstrapping CMake:" 
  echo "$*"
  echo "---------------------------------------------"
  if [ -f cmake_bootstrap.log ]; then
358 359
    echo "Log of errors: `pwd`/cmake_bootstrap.log"
    #cat cmake_bootstrap.log
360 361
    echo "---------------------------------------------"
  fi
362
  exit ${res}
363
}
364

365 366 367 368 369 370 371
# Replace KWSYS_NAMESPACE with cmsys
cmake_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  SEARCHFOR="$3"
  REPLACEWITH="$4"
372
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
373
    cat "${INFILE}" | 
374 375 376
      sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}${_tmp}"
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
377
        #echo "Files are the same"
378
        rm -f "${OUTFILE}${_tmp}"
379
      else
380
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
381 382
      fi
    fi
Brad King's avatar
Brad King committed
383
  else
384
    cmake_error 1 "Cannot find file ${INFILE}"
385 386 387
  fi
}

388 389 390 391 392 393
cmake_kwsys_config_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  shift 2
  APPEND="$*"
394 395
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
    echo "${APPEND}" > "${OUTFILE}${_tmp}"
396 397 398
    cat "${INFILE}" | 
      sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
                s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
399 400
                s/@KWSYS_LFS_AVAILABLE@/${KWSYS_LFS_AVAILABLE}/g;
                s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g;
401
                s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
402
                s/@KWSYS_IOS_USE_ANSI@/${KWSYS_IOS_USE_ANSI}/g;
403
                s/@KWSYS_IOS_HAVE_STD@/${KWSYS_IOS_HAVE_STD}/g;
404 405 406
                s/@KWSYS_IOS_USE_SSTREAM@/${KWSYS_IOS_USE_SSTREAM}/g;
                s/@KWSYS_IOS_USE_STRSTREAM_H@/${KWSYS_IOS_USE_STRSTREAM_H}/g;
                s/@KWSYS_IOS_USE_STRSTREA_H@/${KWSYS_IOS_USE_STRSTREA_H}/g;
407
                s/@KWSYS_IOS_HAVE_BINARY@/${KWSYS_IOS_HAVE_BINARY}/g;
408
                s/@KWSYS_STL_HAVE_STD@/${KWSYS_STL_HAVE_STD}/g;
409 410
                s/@KWSYS_STL_STRING_HAVE_ISTREAM@/${KWSYS_STL_STRING_HAVE_ISTREAM}/g;
                s/@KWSYS_STL_STRING_HAVE_OSTREAM@/${KWSYS_STL_STRING_HAVE_OSTREAM}/g;
411
                s/@KWSYS_STL_STRING_HAVE_NEQ_CHAR@/${KWSYS_STL_STRING_HAVE_NEQ_CHAR}/g;
412 413 414
                s/@KWSYS_STL_HAS_ITERATOR_TRAITS@/${KWSYS_STL_HAS_ITERATOR_TRAITS}/g;
                s/@KWSYS_STL_HAS_ITERATOR_CATEGORY@/${KWSYS_STL_HAS_ITERATOR_CATEGORY}/g;
                s/@KWSYS_STL_HAS___ITERATOR_CATEGORY@/${KWSYS_STL_HAS___ITERATOR_CATEGORY}/g;
415
                s/@KWSYS_STL_HAS_ALLOCATOR_TEMPLATE@/${KWSYS_STL_HAS_ALLOCATOR_TEMPLATE}/g;
416
                s/@KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE@/${KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE}/g;
417
                s/@KWSYS_STL_HAS_ALLOCATOR_REBIND@/${KWSYS_STL_HAS_ALLOCATOR_REBIND}/g;
418
                s/@KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT@/${KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT}/g;
419
                s/@KWSYS_STL_HAS_ALLOCATOR_OBJECTS@/${KWSYS_STL_HAS_ALLOCATOR_OBJECTS}/g;
420
                s/@KWSYS_CXX_HAS_CSTDDEF@/${KWSYS_CXX_HAS_CSTDDEF}/g;
421 422 423
                s/@KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS@/${KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS}/g;
                s/@KWSYS_CXX_HAS_MEMBER_TEMPLATES@/${KWSYS_CXX_HAS_MEMBER_TEMPLATES}/g;
                s/@KWSYS_CXX_HAS_FULL_SPECIALIZATION@/${KWSYS_CXX_HAS_FULL_SPECIALIZATION}/g;
424
                s/@KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP@/${KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP}/g;
425 426 427
                s/@KWSYS_STAT_HAS_ST_MTIM@/${KWSYS_STAT_HAS_ST_MTIM}/g;}" >> "${OUTFILE}${_tmp}"
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
428
        #echo "Files are the same"
429
        rm -f "${OUTFILE}${_tmp}"
430
      else
431
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
432 433 434 435 436 437
      fi
    fi
  else
    cmake_error 2 "Cannot find file ${INFILE}"
  fi
}
438
# Write string into a file
439 440 441 442 443 444 445
cmake_report ()
{
  FILE=$1
  shift
  echo "$*" >> ${FILE}
}

446
# Escape spaces in strings
447 448 449 450 451
cmake_escape ()
{
  echo $1 | sed "s/ /\\\\ /g"
}

452 453 454 455 456 457
# Strip prefix from argument
cmake_arg ()
{
  echo "$1" | sed "s/^${2-[^=]*=}//"
}

458
# Write message to the log
459 460 461 462 463
cmake_log ()
{
  echo "$*" >> cmake_bootstrap.log
}

464
# Return temp file
465 466
cmake_tmp_file ()
{
467
  echo "cmake_bootstrap_$$_test"
468 469
}

470 471
# Run a compiler test. First argument is compiler, second one are compiler
# flags, third one is test source file to be compiled
472 473 474 475 476 477 478 479 480 481 482
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}"
483 484
  echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
  echo "----------  file   -----------------------"
485
  cat "${TESTFILE}"
486
  echo "------------------------------------------"
487 488 489
  "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  RES=$?
  if [ "${RES}" -ne "0" ]; then
490 491
    echo "Test failed to compile"
    return 1
492 493
  fi
  if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
494
    echo "Test failed to produce executable"
495 496 497 498 499 500
    return 2
  fi
  ./${TMPFILE}
  RES=$?
  rm -f "${TMPFILE}"
  if [ "${RES}" -ne "0" ]; then
501
    echo "Test produced non-zero return code"
502 503
    return 3
  fi
504
  echo "Test succeded"
505 506 507
  return 0
}

508
# Run a make test. First argument is the make interpreter.
509 510
cmake_try_make ()
{
511 512
  MAKE_PROC="$1"
  MAKE_FLAGS="$2"
513
  echo "Try: ${MAKE_PROC}"
514
  "${MAKE_PROC}" ${MAKE_FLAGS}
515 516
  RES=$?
  if [ "${RES}" -ne "0" ]; then
517 518
    echo "${MAKE_PROC} does not work"
    return 1
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
  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
}

535
# Parse arguments
536
cmake_verbose=
537
cmake_parallel_make=
538
cmake_ccache_enabled=
539
cmake_prefix_dir="${cmake_default_prefix}"
540 541
while test $# != 0; do
  case "$1" in
542 543 544 545 546 547 548
  --prefix=*) dir=`cmake_arg "$1"`
              cmake_prefix_dir=`cmake_fix_slashes "$dir"` ;;
  --parallel=*) cmake_parallel_make=`cmake_arg "$1"` ;;
  --datadir=*) cmake_data_dir=`cmake_arg "$1"` ;;
  --docdir=*) cmake_doc_dir=`cmake_arg "$1"` ;;
  --mandir=*) cmake_man_dir=`cmake_arg "$1"` ;;
  --init=*) cmake_init_file=`cmake_arg "$1"` ;;
549 550 551
  --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" ;;
  --system-bzip2|--system-curl|--system-expat|--system-libarchive|--system-zlib)
552 553
    lib=`cmake_arg "$1" "--system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
554
  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-libarchive|--no-system-zlib)
555 556
    lib=`cmake_arg "$1" "--no-system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=0" ;;
557 558
  --qt-gui) cmake_bootstrap_qt_gui="1" ;;
  --no-qt-gui) cmake_bootstrap_qt_gui="0" ;;
559
  --qt-qmake=*) cmake_bootstrap_qt_qmake=`cmake_arg "$1"` ;;
560 561 562 563
  --help) cmake_usage ;;
  --version) cmake_version_display ; exit 2 ;;
  --verbose) cmake_verbose=TRUE ;;
  --enable-ccache) cmake_ccache_enabled=TRUE ;;
564
  --) shift; break ;;
565 566 567
  *) die "Unknown option: $1" ;;
  esac
  shift
568 569
done

570
# If verbose, display some information about bootstrap
571 572 573 574 575 576
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}"
577 578 579 580
  if [ "x${cmake_parallel_make}" != "x" ]; then
    echo "Doing parallel make: ${cmake_parallel_make}"
  fi
  echo ""
581 582 583
fi

echo "---------------------------------------------"
584
# Get CMake version
585
echo "`cmake_version_display`"
586

587 588 589 590 591 592 593 594 595 596 597 598 599
# 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?
600 601
  if [ -d "${cmake_source_dir}/Bootstrap${_cmk}" ]; then
    cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap${_cmk}\".
602
Looks like somebody did bootstrap CMake in the source tree, but now you are
603
trying to do bootstrap in the binary tree. Please remove Bootstrap${_cmk}
604 605 606 607
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
608
    if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
609 610 611 612 613 614 615 616
      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

617
# Make bootstrap directory
618 619
[ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
if [ ! -d "${cmake_bootstrap_dir}" ]; then
620
  cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
621 622 623
fi
cd "${cmake_bootstrap_dir}"

Brad King's avatar
Brad King committed
624 625
[ -d "cmsys" ] || mkdir "cmsys"
if [ ! -d "cmsys" ]; then
626
  cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
Brad King's avatar
Brad King committed
627 628
fi

629 630 631 632 633 634
for a in stl ios; do
  [ -d "cmsys/${a}" ] || mkdir "cmsys/${a}"
  if [ ! -d "cmsys/${a}" ]; then
    cmake_error 5 "Cannot create directory ${cmake_bootstrap_dir}/cmsys/${a}"
  fi
done
Brad King's avatar
Brad King committed
635

636
# Delete all the bootstrap files
637
rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
638 639
rm -f "${cmake_bootstrap_dir}/cmConfigure.h${_tmp}"
rm -f "${cmake_bootstrap_dir}/cmVersionConfig.h${_tmp}"
640

641
# If exist compiler flags, set them
642 643
cmake_c_flags=${CFLAGS}
cmake_cxx_flags=${CXXFLAGS}
Bill Hoffman's avatar
Bill Hoffman committed
644
cmake_ld_flags=${LDFLAGS}
645

646 647 648 649 650
# Add Cygwin-specific flags
if ${cmake_system_cygwin}; then
  cmake_ld_flags="${LDFLAGS} -Wl,--enable-auto-import"
fi

651
# Add CoreFoundation framework on Darwin
652
if ${cmake_system_darwin}; then
653
  cmake_ld_flags="${LDFLAGS} -framework CoreFoundation"
654 655
fi

656 657 658 659 660
# Add BeOS toolkits...
if ${cmake_system_beos}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

661 662 663 664 665
# Add Haiku toolkits...
if ${cmake_system_haiku}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
#-----------------------------------------------------------------------------
# Detect known toolchains on some platforms.
cmake_toolchains=''
case "${cmake_system}" in
  *AIX*)   cmake_toolchains='XL GNU' ;;
  *CYGWIN*) cmake_toolchains='GNU' ;;
  *Darwin*) cmake_toolchains='GNU Clang' ;;
  *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

#-----------------------------------------------------------------------------
727 728 729
# Test C compiler
cmake_c_compiler=

730
# If CC is set, use that for compiler, otherwise use list of known compilers
731 732 733
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_c_compilers="\${cmake_toolchain_${cmake_toolchain}_CC}"
elif [ -n "${CC}" ]; then
734 735 736 737 738
  cmake_c_compilers="${CC}"
else
  cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
fi

739
# Check if C compiler works
740
TMPFILE=`cmake_tmp_file`
741
echo '
742 743
#ifdef __cplusplus
# error "The CMAKE_C_COMPILER is set to a C++ compiler"
744 745
#endif

746 747 748
#include<stdio.h>

#if defined(__CLASSIC_C__)
749 750 751 752
int main(argc, argv)
  int argc;
  char* argv[];
#else
Andy Cedilnik's avatar
Andy Cedilnik committed
753
int main(int argc, char* argv[])
754
#endif
755
{
756
  printf("%d%c", (argv != 0), (char)0x0a);
Andy Cedilnik's avatar
Andy Cedilnik committed
757
  return argc-1;
758
}
759
' > "${TMPFILE}.c"
760
for a in ${cmake_c_compilers}; do
761 762
  if [ -z "${cmake_c_compiler}" ] && \
    cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
763 764 765 766 767 768
    cmake_c_compiler="${a}"
  fi
done
rm -f "${TMPFILE}.c"

if [ -z "${cmake_c_compiler}" ]; then
769
  cmake_error 6 "Cannot find appropriate C compiler on this system.
Bill Hoffman's avatar
Bill Hoffman committed
770 771 772
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.
"
773 774 775
fi
echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"

776
#-----------------------------------------------------------------------------
777 778
# Test CXX compiler
cmake_cxx_compiler=
779

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

782
# If CC is set, use that for compiler, otherwise use list of known compilers
783 784 785
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_cxx_compilers="\${cmake_toolchain_${cmake_toolchain}_CXX}"
elif [ -n "${CXX}" ]; then
786 787 788 789 790
  cmake_cxx_compilers="${CXX}"
else
  cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
fi

791
# Check if C++ compiler works
792
TMPFILE=`cmake_tmp_file`
793
echo '
794 795 796 797 798 799
#if defined(TEST1)
# include <iostream>
#else
# include <iostream.h>
#endif

800 801 802 803 804 805 806 807
class NeedCXX 
{
public:
  NeedCXX() { this->Foo = 1; }
  int GetFoo() { return this->Foo; }
private:
  int Foo;
};
808 809
int main()
{
810
  NeedCXX c;
811 812 813 814 815
#ifdef TEST3
  cout << c.GetFoo() << endl;
#else
  std::cout << c.GetFoo() << std::endl;
#endif
816 817
  return 0;
}
818
' > "${TMPFILE}.cxx"
819
for a in ${cmake_cxx_compilers}; do
820 821 822 823 824 825
  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
826 827 828 829
done
rm -f "${TMPFILE}.cxx"

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

836
#-----------------------------------------------------------------------------
837 838 839
# Test Make

cmake_make_processor=
840
cmake_make_flags=
841 842

# If MAKE is set, use that for make processor, otherwise use list of known make
843 844 845 846 847 848 849 850 851 852
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}"
853
echo '
854
test: test.c
855
	"'"${cmake_c_compiler}"'" '"${cmake_ld_flags} ${cmake_c_flags}"' -o test test.c
856 857
'>"Makefile"
echo '
858
#include <stdio.h>
859
int main(){ printf("1%c", (char)0x0a); return 0; }
860
' > "test.c"
861
cmake_original_make_flags="${cmake_make_flags}"
862 863 864
if [ "x${cmake_parallel_make}" != "x" ]; then
  cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
fi
865
for a in ${cmake_make_processors}; do
866
  if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
867 868 869
    cmake_make_processor="${a}"
  fi
done
870 871 872 873 874
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
875
      if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
876 877 878 879 880
        cmake_make_processor="${a}"
      fi
    done
  fi
fi
881 882
cd "${cmake_bootstrap_dir}"

883
if [ -z "${cmake_make_processor}" ]; then
884
  cmake_error 8 "Cannot find appropriate Makefile processor on this system.
885 886
Please specify one using environment variable MAKE."
fi
887
rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
888 889 890 891 892 893
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
894

895 896
# Ok, we have CC, CXX, and MAKE.

897
# Test C++ compiler features
Andy Cedilnik's avatar
Andy Cedilnik committed
898

899 900 901
# Are we GCC?

TMPFILE=`cmake_tmp_file`
902
echo '
903 904 905 906
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#include <iostream>
int main() { std::cout << "This is GNU" << std::endl; return 0;}
#endif
907
' > ${TMPFILE}.cxx
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
cmake_cxx_compiler_is_gnu=0
if cmake_try_run "${cmake_cxx_compiler}" \
  "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  cmake_cxx_compiler_is_gnu=1
fi
if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then
  echo "${cmake_cxx_compiler} is GNU compiler"
else
  echo "${cmake_cxx_compiler} is not GNU compiler"
fi
rm -f "${TMPFILE}.cxx"

if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
  # Check for non-GNU compiler flags

  # If we are on IRIX, check for -LANG:std
  cmake_test_flags="-LANG:std"
  if [ "x${cmake_system}" = "xIRIX64" ]; then
    TMPFILE=`cmake_tmp_file`
927
    echo '
928
    #include <iostream>
929 930
    int main() { std::cout << "No need for '"${cmake_test_flags}"'" << std::endl; return 0;}
' > ${TMPFILE}.cxx
931
    cmake_need_lang_std=0
932
    if cmake_try_run "${cmake_cxx_compiler}" \
933 934 935 936 937 938 939
      "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      :
    else
      if cmake_try_run "${cmake_cxx_compiler}" \
        "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
        cmake_need_lang_std=1
      fi
Andy Cedilnik's avatar
Andy Cedilnik committed
940
    fi
941 942 943 944 945 946 947
    if [ "x${cmake_need_lang_std}" = "x1" ]; then
      cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
      echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.cxx"
Andy Cedilnik's avatar
Andy Cedilnik committed
948
  fi
949
  cmake_test_flags=
950

951 952 953 954
  # If we are on OSF, check for -timplicit_local -no_implicit_include
  cmake_test_flags="-timplicit_local -no_implicit_include"
  if [ "x${cmake_system}" = "xOSF1" ]; then
    TMPFILE=`cmake_tmp_file`
955
    echo '
956
    #include <iostream>
957 958
    int main() { std::cout << "We need '"${cmake_test_flags}"'" << std::endl; return 0;}
' > ${TMPFILE}.cxx
959 960 961 962 963 964 965 966 967 968 969 970 971 972
    cmake_need_flags=1
    if cmake_try_run "${cmake_cxx_compiler}" \
      "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      :
    else
      cmake_need_flags=0
    fi
    if [ "x${cmake_need_flags}" = "x1" ]; then
      cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
      echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.cxx"
973
  fi
974
  cmake_test_flags=
975

976 977 978 979
  # If we are on OSF, check for -std strict_ansi -nopure_cname
  cmake_test_flags="-std strict_ansi -nopure_cname"
  if [ "x${cmake_system}" = "xOSF1" ]; then
    TMPFILE=`cmake_tmp_file`
980
    echo '
981
    #include <iostream>
982 983
    int main() { std::cout << "We need '"${cmake_test_flags}"'" << std::endl; return 0;}
' > ${TMPFILE}.cxx
984 985 986 987 988 989 990 991 992 993 994 995 996 997
    cmake_need_flags=1
    if cmake_try_run "${cmake_cxx_compiler}" \
      "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      :
    else
      cmake_need_flags=0
    fi
    if [ "x${cmake_need_flags}" = "x1" ]; then
      cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
      echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.cxx"
998
  fi
999
  cmake_test_flags=
Andy Cedilnik's avatar
Andy Cedilnik committed
1000

1001 1002 1003 1004
  # If we are on HP-UX, check for -Ae for the C compiler.
  cmake_test_flags="-Ae"
  if [ "x${cmake_system}" = "xHP-UX" ]; then
    TMPFILE=`cmake_tmp_file`
1005
    echo '
1006
    int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
1007
' > ${TMPFILE}.c
1008 1009 1010 1011 1012 1013 1014 1015
    cmake_need_Ae=0
    if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
      :
    else
      if cmake_try_run "${cmake_c_compiler}" \
        "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
        cmake_need_Ae=1
      fi
1016
    fi
1017 1018 1019 1020 1021 1022 1023
    if [ "x${cmake_need_Ae}" = "x1" ]; then
      cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
      echo "${cmake_c_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.c"
1024
  fi
1025
  cmake_test_flags=
1026 1027
fi

Brad King's avatar