Update to 2.8.10.2
[platform/upstream/cmake.git] / bootstrap
1 #!/bin/sh
2 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
3 # file Copyright.txt or https://cmake.org/licensing for details.
4
5 die() {
6   echo "$@" 1>&2 ; exit 1
7 }
8
9 # Compile flag extraction function.
10 cmake_extract_standard_flags()
11 {
12   cd "${cmake_source_dir}/Modules/Compiler/"
13   for file in ${1:-*}-${2}.cmake; do
14     cat "${file}" \
15       | sed -n "s/ *set *( *CMAKE_${2}${3}_EXTENSION_COMPILE_OPTION *\"\{0,1\}\([^\")]*\).*/\1/p" \
16       | tr ';' ' '
17   done
18 }
19
20 # Version number extraction function.
21 cmake_version_component()
22 {
23   cat "${cmake_source_dir}/Source/CMakeVersion.cmake" | sed -n "
24 /^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
25 "
26 }
27
28 # Install destination extraction function.
29 cmake_install_dest_default()
30 {
31   cat "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake" | sed -n '
32 /^ *set(CMAKE_'"${1}"'_DIR_DEFAULT.*) # '"${2}"'$/ {
33   s/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT *"\([^"]*\)").*$/\1/
34   s/${CMake_VERSION_MAJOR}/'"${cmake_version_major}"'/
35   s/${CMake_VERSION_MINOR}/'"${cmake_version_minor}"'/
36   s/${CMake_VERSION_PATCH}/'"${cmake_version_patch}"'/
37   p
38   q
39 }
40 '
41 }
42
43 cmake_toupper()
44 {
45     echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
46 }
47
48 # Detect system and directory information.
49 cmake_system=`uname`
50 cmake_source_dir=`cd "\`dirname \"$0\"\`";pwd`
51 cmake_binary_dir=`pwd`
52
53 # Load version information.
54 cmake_version_major="`cmake_version_component MAJOR`"
55 cmake_version_minor="`cmake_version_component MINOR`"
56 cmake_version_patch="`cmake_version_component PATCH`"
57 cmake_version="${cmake_version_major}.${cmake_version_minor}.${cmake_version_patch}"
58 cmake_version_rc="`cmake_version_component RC`"
59 if [ "$cmake_version_rc" != "" ]; then
60   cmake_version="${cmake_version}-rc${cmake_version_rc}"
61 fi
62
63 cmake_copyright="`grep '^Copyright .* Kitware' "${cmake_source_dir}/Copyright.txt"`"
64
65 cmake_bin_dir_keyword="OTHER"
66 cmake_data_dir_keyword="OTHER"
67 cmake_doc_dir_keyword="OTHER"
68 cmake_man_dir_keyword="OTHER"
69 cmake_xdgdata_dir_keyword="OTHER"
70 cmake_bin_dir=""
71 cmake_data_dir=""
72 cmake_doc_dir=""
73 cmake_man_dir=""
74 cmake_xdgdata_dir=""
75 cmake_init_file=""
76 cmake_bootstrap_system_libs=""
77 cmake_bootstrap_qt_gui=""
78 cmake_bootstrap_qt_qmake=""
79 cmake_bootstrap_server=""
80 cmake_sphinx_man=""
81 cmake_sphinx_html=""
82 cmake_sphinx_qthelp=""
83 cmake_sphinx_build=""
84 cmake_sphinx_flags=""
85
86 # Determine whether this is a Cygwin environment.
87 if echo "${cmake_system}" | grep CYGWIN >/dev/null 2>&1; then
88   cmake_system_cygwin=true
89   cmake_doc_dir_keyword="CYGWIN"
90   cmake_man_dir_keyword="CYGWIN"
91 else
92   cmake_system_cygwin=false
93 fi
94
95 # Determine whether this is a MinGW environment.
96 if echo "${cmake_system}" | grep 'MINGW\|MSYS' >/dev/null 2>&1; then
97   cmake_system_mingw=true
98 else
99   cmake_system_mingw=false
100 fi
101
102 # Determine whether this is OS X
103 if echo "${cmake_system}" | grep Darwin >/dev/null 2>&1; then
104   cmake_system_darwin=true
105 else
106   cmake_system_darwin=false
107 fi
108
109 # Determine whether this is BeOS
110 if echo "${cmake_system}" | grep BeOS >/dev/null 2>&1; then
111   cmake_system_beos=true
112   cmake_doc_dir_keyword="HAIKU"
113   cmake_man_dir_keyword="HAIKU"
114 else
115   cmake_system_beos=false
116 fi
117
118 # Determine whether this is Haiku
119 if echo "${cmake_system}" | grep Haiku >/dev/null 2>&1; then
120   cmake_system_haiku=true
121   cmake_doc_dir_keyword="HAIKU"
122   cmake_man_dir_keyword="HAIKU"
123 else
124   cmake_system_haiku=false
125 fi
126
127 # Determine whether this is OpenVMS
128 if echo "${cmake_system}" | grep OpenVMS >/dev/null 2>&1; then
129   cmake_system_openvms=true
130 else
131   cmake_system_openvms=false
132 fi
133
134 # Determine whether this is HP-UX
135 if echo "${cmake_system}" | grep HP-UX >/dev/null 2>&1; then
136   cmake_system_hpux=true
137 else
138   cmake_system_hpux=false
139 fi
140
141 # Determine whether this is Linux
142 if echo "${cmake_system}" | grep Linux >/dev/null 2>&1; then
143   cmake_system_linux=true
144 else
145   cmake_system_linux=false
146  fi
147
148 # Determine whether this is a PA-RISC machine
149 # This only works for Linux or HP-UX, not other PA-RISC OSs (BSD maybe?). Also
150 # may falsely detect parisc on HP-UX m68k
151 cmake_machine_parisc=false
152 if ${cmake_system_linux}; then
153   if uname -m | grep parisc >/dev/null 2>&1; then
154     cmake_machine_parisc=true
155   fi
156 elif ${cmake_system_hpux}; then
157   if uname -m | grep ia64 >/dev/null 2>&1; then : ; else
158     cmake_machine_parisc=true
159   fi
160 fi
161
162 # Choose the generator to use for bootstrapping.
163 if ${cmake_system_mingw}; then
164   # Bootstrapping from an MSYS prompt.
165   cmake_bootstrap_generator="MSYS Makefiles"
166 else
167   # Bootstrapping from a standard UNIX prompt.
168   cmake_bootstrap_generator="Unix Makefiles"
169 fi
170
171 # Choose tools and extensions for this platform.
172 if ${cmake_system_openvms}; then
173   _tmp="_tmp"
174   _cmk="_cmk"
175   _diff=`which diff`
176 else
177   _tmp=".tmp"
178   _cmk=".cmk"
179   _diff="diff"
180 fi
181
182 # Construct bootstrap directory name.
183 cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap${_cmk}"
184
185 # Helper function to fix windows paths.
186 case "${cmake_system}" in
187 *MINGW*)
188   cmake_fix_slashes()
189   {
190     cmd //c echo "$(echo "$1" | sed 's/\\/\//g')" | sed 's/^"//;s/" *$//'
191   }
192   ;;
193 *)
194   cmake_fix_slashes()
195   {
196     echo "$1" | sed 's/\\/\//g'
197   }
198   ;;
199 esac
200
201 # Choose the default install prefix.
202 if ${cmake_system_mingw}; then
203   if [ "x${PROGRAMFILES}" != "x" ]; then
204     cmake_default_prefix=`cmake_fix_slashes "${PROGRAMFILES}/CMake"`
205   elif [ "x${ProgramFiles}" != "x" ]; then
206     cmake_default_prefix=`cmake_fix_slashes "${ProgramFiles}/CMake"`
207   elif [ "x${SYSTEMDRIVE}" != "x" ]; then
208     cmake_default_prefix=`cmake_fix_slashes "${SYSTEMDRIVE}/Program Files/CMake"`
209   elif [ "x${SystemDrive}" != "x" ]; then
210     cmake_default_prefix=`cmake_fix_slashes "${SystemDrive}/Program Files/CMake"`
211   else
212     cmake_default_prefix="c:/Program Files/CMake"
213   fi
214 elif ${cmake_system_haiku}; then
215   cmake_default_prefix=`finddir B_COMMON_DIRECTORY`
216 else
217   cmake_default_prefix="/usr/local"
218 fi
219
220 # Lookup default install destinations.
221 cmake_bin_dir_default="`cmake_install_dest_default BIN ${cmake_bin_dir_keyword}`"
222 cmake_data_dir_default="`cmake_install_dest_default DATA ${cmake_data_dir_keyword}`"
223 cmake_doc_dir_default="`cmake_install_dest_default DOC ${cmake_doc_dir_keyword}`"
224 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 CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
228 CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
229 CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
230
231 CMAKE_PROBLEMATIC_FILES="\
232   CMakeCache.txt \
233   CMakeSystem.cmake \
234   CMakeCCompiler.cmake \
235   CMakeCXXCompiler.cmake \
236   */CMakeSystem.cmake \
237   */CMakeCCompiler.cmake \
238   */CMakeCXXCompiler.cmake \
239   Source/cmConfigure.h \
240   Source/CTest/Curl/config.h \
241   Utilities/cmexpat/expatConfig.h \
242   Utilities/cmexpat/expatDllConfig.h \
243   "
244
245 CMAKE_UNUSED_SOURCES="\
246   cmGlobalXCodeGenerator \
247   cmLocalXCodeGenerator \
248   cmXCodeObject \
249   cmXCode21Object \
250   cmSourceGroup \
251 "
252
253 CMAKE_CXX_SOURCES="\
254   cmAddCustomCommandCommand \
255   cmAddCustomTargetCommand \
256   cmAddDefinitionsCommand \
257   cmAddDependenciesCommand \
258   cmAddExecutableCommand \
259   cmAddLibraryCommand \
260   cmAddSubDirectoryCommand \
261   cmAddTestCommand \
262   cmBreakCommand \
263   cmBuildCommand \
264   cmCMakeMinimumRequired \
265   cmCMakePolicyCommand \
266   cmCPackPropertiesGenerator \
267   cmCacheManager \
268   cmCommand \
269   cmCommandArgumentParserHelper \
270   cmCommandArgumentsHelper \
271   cmCommands \
272   cmCommonTargetGenerator \
273   cmComputeComponentGraph \
274   cmComputeLinkDepends \
275   cmComputeLinkInformation \
276   cmComputeTargetDepends \
277   cmConditionEvaluator \
278   cmConfigureFileCommand \
279   cmContinueCommand \
280   cmCoreTryCompile \
281   cmCreateTestSourceList \
282   cmCustomCommand \
283   cmCustomCommandGenerator \
284   cmDefinePropertyCommand \
285   cmDefinitions \
286   cmDepends \
287   cmDependsC \
288   cmDisallowedCommand \
289   cmDocumentationFormatter \
290   cmEnableLanguageCommand \
291   cmEnableTestingCommand \
292   cmExecProgramCommand \
293   cmExecuteProcessCommand \
294   cmExpandedCommandArgument \
295   cmExportBuildFileGenerator \
296   cmExportFileGenerator \
297   cmExportInstallFileGenerator \
298   cmExportSet \
299   cmExportSetMap \
300   cmExportTryCompileFileGenerator \
301   cmExprParserHelper \
302   cmExternalMakefileProjectGenerator \
303   cmFileCommand \
304   cmFileTimeComparison \
305   cmFindBase \
306   cmFindCommon \
307   cmFindFileCommand \
308   cmFindLibraryCommand \
309   cmFindPackageCommand \
310   cmFindPathCommand \
311   cmFindProgramCommand \
312   cmForEachCommand \
313   cmFunctionCommand \
314   cmGeneratedFileStream \
315   cmGeneratorExpression \
316   cmGeneratorExpressionContext \
317   cmGeneratorExpressionDAGChecker \
318   cmGeneratorExpressionEvaluationFile \
319   cmGeneratorExpressionEvaluator \
320   cmGeneratorExpressionLexer \
321   cmGeneratorExpressionNode \
322   cmGeneratorExpressionParser \
323   cmGeneratorTarget \
324   cmGetCMakePropertyCommand \
325   cmGetDirectoryPropertyCommand \
326   cmGetFilenameComponentCommand \
327   cmGetPropertyCommand \
328   cmGetSourceFilePropertyCommand \
329   cmGetTargetPropertyCommand \
330   cmGetTestPropertyCommand \
331   cmGlobalCommonGenerator \
332   cmGlobalGenerator \
333   cmGlobalUnixMakefileGenerator3 \
334   cmHexFileConverter \
335   cmIfCommand \
336   cmIncludeCommand \
337   cmIncludeDirectoryCommand \
338   cmIncludeRegularExpressionCommand \
339   cmInstallCommand \
340   cmInstallCommandArguments \
341   cmInstallDirectoryGenerator \
342   cmInstallExportGenerator \
343   cmInstallFilesCommand \
344   cmInstallFilesGenerator \
345   cmInstallGenerator \
346   cmInstallScriptGenerator \
347   cmInstallTargetGenerator \
348   cmInstallTargetsCommand \
349   cmInstalledFile \
350   cmLinkDirectoriesCommand \
351   cmLinkLineComputer \
352   cmListCommand \
353   cmListFileCache \
354   cmLocalCommonGenerator \
355   cmLocalGenerator \
356   cmLocalUnixMakefileGenerator3 \
357   cmMSVC60LinkLineComputer \
358   cmMacroCommand \
359   cmMakeDirectoryCommand \
360   cmMakefile \
361   cmMakefileExecutableTargetGenerator \
362   cmMakefileLibraryTargetGenerator \
363   cmMakefileTargetGenerator \
364   cmMakefileUtilityTargetGenerator \
365   cmMarkAsAdvancedCommand \
366   cmMathCommand \
367   cmMessageCommand \
368   cmMessenger \
369   cmNewLineStyle \
370   cmOSXBundleGenerator \
371   cmOptionCommand \
372   cmOrderDirectories \
373   cmOutputConverter \
374   cmParseArgumentsCommand \
375   cmPathLabel \
376   cmPolicies \
377   cmProcessOutput \
378   cmProjectCommand \
379   cmProperty \
380   cmPropertyDefinition \
381   cmPropertyDefinitionMap \
382   cmPropertyMap \
383   cmReturnCommand \
384   cmRulePlaceholderExpander \
385   cmScriptGenerator \
386   cmSearchPath \
387   cmSeparateArgumentsCommand \
388   cmSetCommand \
389   cmSetDirectoryPropertiesCommand \
390   cmSetPropertyCommand \
391   cmSetSourceFilesPropertiesCommand \
392   cmSetTargetPropertiesCommand \
393   cmSetTestsPropertiesCommand \
394   cmSiteNameCommand \
395   cmSourceFile \
396   cmSourceFileLocation \
397   cmState \
398   cmStateDirectory \
399   cmStateSnapshot \
400   cmStringCommand \
401   cmSubdirCommand \
402   cmSystemTools \
403   cmTarget \
404   cmTargetLinkLibrariesCommand \
405   cmTargetPropertyComputer \
406   cmTest \
407   cmTestGenerator \
408   cmTimestamp \
409   cmTryCompileCommand \
410   cmTryRunCommand \
411   cmUnexpectedCommand \
412   cmUnsetCommand \
413   cmVersion \
414   cmWhileCommand \
415   cmWorkingDirectory \
416   cmake  \
417   cmakemain \
418   cmcmd  \
419 "
420
421 if ${cmake_system_mingw}; then
422   CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES}\
423     cmGlobalMSYSMakefileGenerator \
424     cmGlobalMinGWMakefileGenerator"
425 fi
426
427 LexerParser_CXX_SOURCES="\
428   cmCommandArgumentLexer \
429   cmCommandArgumentParser \
430   cmExprLexer \
431   cmExprParser \
432 "
433
434 LexerParser_C_SOURCES="\
435   cmListFileLexer \
436 "
437
438 if ${cmake_system_mingw}; then
439   KWSYS_C_SOURCES="\
440     EncodingC \
441     ProcessWin32 \
442     String \
443     System \
444     Terminal"
445 else
446   KWSYS_C_SOURCES="\
447     EncodingC \
448     ProcessUNIX \
449     String \
450     System \
451     Terminal"
452 fi
453
454 KWSYS_CXX_SOURCES="\
455   Directory \
456   EncodingCXX \
457   FStream \
458   Glob \
459   RegularExpression \
460   SystemTools"
461
462 KWSYS_FILES="\
463   Directory.hxx \
464   Encoding.h \
465   Encoding.hxx \
466   FStream.hxx \
467   Glob.hxx \
468   Process.h \
469   RegularExpression.hxx \
470   String.h \
471   String.hxx \
472   System.h \
473   SystemTools.hxx \
474   Terminal.h"
475
476 # Display CMake bootstrap usage
477 cmake_usage()
478 {
479 echo '
480 Usage: '"$0"' [<options>...] [-- <cmake-options>...]
481 Options: [defaults in brackets after descriptions]
482 Configuration:
483   --help                  print this message
484   --version               only print version information
485   --verbose               display more information
486   --parallel=n            bootstrap cmake in parallel, where n is
487                           number of nodes [1]
488   --enable-ccache         Enable ccache when building cmake
489   --init=FILE             load FILE as script to populate cache
490   --system-libs           use all system-installed third-party libraries
491                           (for use only by package maintainers)
492   --no-system-libs        use all cmake-provided third-party libraries
493                           (default)
494   --system-curl           use system-installed curl library
495   --no-system-curl        use cmake-provided curl library (default)
496   --system-expat          use system-installed expat library
497   --no-system-expat       use cmake-provided expat library (default)
498   --system-jsoncpp        use system-installed jsoncpp library
499   --no-system-jsoncpp     use cmake-provided jsoncpp library (default)
500   --system-zlib           use system-installed zlib library
501   --no-system-zlib        use cmake-provided zlib library (default)
502   --system-bzip2          use system-installed bzip2 library
503   --no-system-bzip2       use cmake-provided bzip2 library (default)
504   --system-liblzma        use system-installed liblzma library
505   --no-system-liblzma     use cmake-provided liblzma library (default)
506   --system-libarchive     use system-installed libarchive library
507   --no-system-libarchive  use cmake-provided libarchive library (default)
508   --system-librhash       use system-installed librhash library
509   --no-system-librhash    use cmake-provided librhash library (default)
510
511   --qt-gui                build the Qt-based GUI (requires Qt >= 4.2)
512   --no-qt-gui             do not build the Qt-based GUI (default)
513   --qt-qmake=<qmake>      use <qmake> as the qmake executable to find Qt
514
515   --server                enable the server mode (default if supported)
516   --no-server             disable the server mode
517
518   --sphinx-man            build man pages with Sphinx
519   --sphinx-html           build html help with Sphinx
520   --sphinx-qthelp         build qch help with Sphinx
521   --sphinx-build=<sb>     use <sb> as the sphinx-build executable
522   --sphinx-flags=<flags>  pass <flags> to sphinx-build executable
523
524 Directory and file names:
525   --prefix=PREFIX         install files in tree rooted at PREFIX
526                           ['"${cmake_default_prefix}"']
527   --bindir=DIR            install binaries in PREFIX/DIR
528                           ['"${cmake_bin_dir_default}"']
529   --datadir=DIR           install data files in PREFIX/DIR
530                           ['"${cmake_data_dir_default}"']
531   --docdir=DIR            install documentation files in PREFIX/DIR
532                           ['"${cmake_doc_dir_default}"']
533   --mandir=DIR            install man pages files in PREFIX/DIR/manN
534                           ['"${cmake_man_dir_default}"']
535   --xdgdatadir=DIR        install XDG specific files in PREFIX/DIR
536                           ['"${cmake_xdgdata_dir_default}"']
537 '
538   exit 10
539 }
540
541 # Display CMake bootstrap usage
542 cmake_version_display()
543 {
544   echo "CMake ${cmake_version}, ${cmake_copyright}"
545 }
546
547 # Display CMake bootstrap error, display the log file and exit
548 cmake_error()
549 {
550   res=$1
551   shift 1
552   echo "---------------------------------------------"
553   echo "Error when bootstrapping CMake:"
554   echo "$*"
555   echo "---------------------------------------------"
556   if [ -f cmake_bootstrap.log ]; then
557     echo "Log of errors: `pwd`/cmake_bootstrap.log"
558     #cat cmake_bootstrap.log
559     echo "---------------------------------------------"
560   fi
561   exit ${res}
562 }
563
564 cmake_generate_file ()
565 {
566   OUTFILE="$1"
567   CONTENT="$2"
568   echo "$CONTENT" > "$OUTFILE.tmp"
569   if "${_diff}" "$OUTFILE.tmp" "$OUTFILE" > /dev/null 2> /dev/null ; then
570     rm -f "$OUTFILE.tmp"
571   else
572     mv -f "$OUTFILE.tmp" "$OUTFILE"
573   fi
574 }
575
576 # Replace KWSYS_NAMESPACE with cmsys
577 cmake_replace_string ()
578 {
579   INFILE="$1"
580   OUTFILE="$2"
581   SEARCHFOR="$3"
582   REPLACEWITH="$4"
583   if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
584     cat "${INFILE}" |
585       sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}${_tmp}"
586     if [ -f "${OUTFILE}${_tmp}" ]; then
587       if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
588         #echo "Files are the same"
589         rm -f "${OUTFILE}${_tmp}"
590       else
591         mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
592       fi
593     fi
594   else
595     cmake_error 1 "Cannot find file ${INFILE}"
596   fi
597 }
598
599 cmake_kwsys_config_replace_string ()
600 {
601   INFILE="$1"
602   OUTFILE="$2"
603   shift 2
604   APPEND="$*"
605   if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
606     echo "${APPEND}" > "${OUTFILE}${_tmp}"
607     cat "${INFILE}" |
608       sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
609                 s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
610                 s/@KWSYS_LFS_AVAILABLE@/${KWSYS_LFS_AVAILABLE}/g;
611                 s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g;
612                 s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
613                 s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g;
614                 s/@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@/${KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H}/g;
615                }" >> "${OUTFILE}${_tmp}"
616     if [ -f "${OUTFILE}${_tmp}" ]; then
617       if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
618         #echo "Files are the same"
619         rm -f "${OUTFILE}${_tmp}"
620       else
621         mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
622       fi
623     fi
624   else
625     cmake_error 2 "Cannot find file ${INFILE}"
626   fi
627 }
628 # Write string into a file
629 cmake_report ()
630 {
631   FILE=$1
632   shift
633   echo "$*" >> ${FILE}
634 }
635
636 # Escape spaces in strings
637 cmake_escape ()
638 {
639   echo $1 | sed "s/ /\\\\ /g"
640 }
641
642 # Strip prefix from argument
643 cmake_arg ()
644 {
645   echo "$1" | sed "s/^${2-[^=]*=}//"
646 }
647
648 # Write message to the log
649 cmake_log ()
650 {
651   echo "$*" >> cmake_bootstrap.log
652 }
653
654 # Return temp file
655 cmake_tmp_file ()
656 {
657   echo "cmake_bootstrap_$$_test"
658 }
659
660 # Run a compiler test. First argument is compiler, second one are compiler
661 # flags, third one is test source file to be compiled
662 cmake_try_run ()
663 {
664   COMPILER=$1
665   FLAGS=$2
666   TESTFILE=$3
667   if [ ! -f "${TESTFILE}" ]; then
668     echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
669     exit 4
670   fi
671   TMPFILE=`cmake_tmp_file`
672   echo "Try: ${COMPILER}"
673   echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
674   echo "----------  file   -----------------------"
675   cat "${TESTFILE}"
676   echo "------------------------------------------"
677   "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
678   RES=$?
679   if [ "${RES}" -ne "0" ]; then
680     echo "Test failed to compile"
681     return 1
682   fi
683   if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
684     echo "Test failed to produce executable"
685     return 2
686   fi
687   ./${TMPFILE}
688   RES=$?
689   rm -f "${TMPFILE}"
690   if [ "${RES}" -ne "0" ]; then
691     echo "Test produced non-zero return code"
692     return 3
693   fi
694   echo "Test succeeded"
695   return 0
696 }
697
698 # Run a make test. First argument is the make interpreter.
699 cmake_try_make ()
700 {
701   MAKE_PROC="$1"
702   MAKE_FLAGS="$2"
703   echo "Try: ${MAKE_PROC}"
704   "${MAKE_PROC}" ${MAKE_FLAGS}
705   RES=$?
706   if [ "${RES}" -ne "0" ]; then
707     echo "${MAKE_PROC} does not work"
708     return 1
709   fi
710   if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
711     echo "${COMPILER} does not produce output"
712     return 2
713   fi
714   ./test
715   RES=$?
716   rm -f "test"
717   if [ "${RES}" -ne "0" ]; then
718     echo "${MAKE_PROC} produces strange executable"
719     return 3
720   fi
721   echo "${MAKE_PROC} works"
722   return 0
723 }
724
725 # Parse arguments
726 cmake_verbose=
727 cmake_parallel_make=
728 cmake_ccache_enabled=
729 cmake_prefix_dir="${cmake_default_prefix}"
730 while test $# != 0; do
731   case "$1" in
732   --prefix=*) dir=`cmake_arg "$1"`
733               cmake_prefix_dir=`cmake_fix_slashes "$dir"` ;;
734   --parallel=*) cmake_parallel_make=`cmake_arg "$1"` ;;
735   --bindir=*) cmake_bin_dir=`cmake_arg "$1"` ;;
736   --datadir=*) cmake_data_dir=`cmake_arg "$1"` ;;
737   --docdir=*) cmake_doc_dir=`cmake_arg "$1"` ;;
738   --mandir=*) cmake_man_dir=`cmake_arg "$1"` ;;
739   --xdgdatadir=*) cmake_xdgdata_dir=`cmake_arg "$1"` ;;
740   --init=*) cmake_init_file=`cmake_arg "$1"` ;;
741   --system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" ;;
742   --no-system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" ;;
743   --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-librhash|--system-zlib|--system-liblzma)
744     lib=`cmake_arg "$1" "--system-"`
745     cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
746   --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-librhash|--no-system-zlib|--no-system-liblzma)
747     lib=`cmake_arg "$1" "--no-system-"`
748     cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=0" ;;
749   --qt-gui) cmake_bootstrap_qt_gui="1" ;;
750   --no-qt-gui) cmake_bootstrap_qt_gui="0" ;;
751   --qt-qmake=*) cmake_bootstrap_qt_qmake=`cmake_arg "$1"` ;;
752   --server) cmake_bootstrap_server="1" ;;
753   --no-server) cmake_bootstrap_server="0" ;;
754   --sphinx-man) cmake_sphinx_man="1" ;;
755   --sphinx-html) cmake_sphinx_html="1" ;;
756   --sphinx-qthelp) cmake_sphinx_qthelp="1" ;;
757   --sphinx-build=*) cmake_sphinx_build=`cmake_arg "$1"` ;;
758   --sphinx-flags=*) cmake_sphinx_flags=`cmake_arg "$1"` ;;
759   --help) cmake_usage ;;
760   --version) cmake_version_display ; exit 2 ;;
761   --verbose) cmake_verbose=TRUE ;;
762   --enable-ccache) cmake_ccache_enabled=TRUE ;;
763   --) shift; break ;;
764   *) die "Unknown option: $1" ;;
765   esac
766   shift
767 done
768
769 # If verbose, display some information about bootstrap
770 if [ -n "${cmake_verbose}" ]; then
771   echo "---------------------------------------------"
772   echo "Source directory: ${cmake_source_dir}"
773   echo "Binary directory: ${cmake_binary_dir}"
774   echo "Prefix directory: ${cmake_prefix_dir}"
775   echo "System:           ${cmake_system}"
776   if [ "x${cmake_parallel_make}" != "x" ]; then
777     echo "Doing parallel make: ${cmake_parallel_make}"
778   fi
779   echo ""
780 fi
781
782 echo "---------------------------------------------"
783 # Get CMake version
784 echo "`cmake_version_display`"
785
786 # Check for in-source build
787 cmake_in_source_build=
788 if [ -f "${cmake_binary_dir}/Source/cmake.cxx" -a \
789      -f "${cmake_binary_dir}/Source/cmake.h" ]; then
790   if [ -n "${cmake_verbose}" ]; then
791     echo "Warning: This is an in-source build"
792   fi
793   cmake_in_source_build=TRUE
794 fi
795
796 # If this is not an in-source build, then Bootstrap stuff should not exist.
797 if [ -z "${cmake_in_source_build}" ]; then
798   # Did somebody bootstrap in the source tree?
799   if [ -d "${cmake_source_dir}/Bootstrap${_cmk}" ]; then
800     cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap${_cmk}\".
801 Looks like somebody did bootstrap CMake in the source tree, but now you are
802 trying to do bootstrap in the binary tree. Please remove Bootstrap${_cmk}
803 directory from the source tree."
804   fi
805   # Is there a cache in the source tree?
806   for cmake_problematic_file in ${CMAKE_PROBLEMATIC_FILES}; do
807     if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
808       cmake_error 10 "Found \"${cmake_source_dir}/${cmake_problematic_file}\".
809 Looks like somebody tried to build CMake in the source tree, but now you are
810 trying to do bootstrap in the binary tree. Please remove \"${cmake_problematic_file}\"
811 from the source tree."
812     fi
813   done
814 fi
815
816 # Make bootstrap directory
817 [ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
818 if [ ! -d "${cmake_bootstrap_dir}" ]; then
819   cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
820 fi
821 cd "${cmake_bootstrap_dir}"
822
823 [ -d "cmsys" ] || mkdir "cmsys"
824 if [ ! -d "cmsys" ]; then
825   cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
826 fi
827
828 # Delete all the bootstrap files
829 rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
830 rm -f "${cmake_bootstrap_dir}/cmConfigure.h${_tmp}"
831 rm -f "${cmake_bootstrap_dir}/cmVersionConfig.h${_tmp}"
832
833 # If building in-source, remove any cmConfigure.h that may
834 # have been created by a previous run of the bootstrap cmake.
835 if [ -n "${cmake_in_source_build}" ]; then
836   rm -f "${cmake_source_dir}/Source/cmConfigure.h"
837 fi
838
839 # If exist compiler flags, set them
840 cmake_c_flags=${CFLAGS}
841 cmake_cxx_flags=${CXXFLAGS}
842 cmake_ld_flags=${LDFLAGS}
843
844 # Add Cygwin-specific flags
845 if ${cmake_system_cygwin}; then
846   cmake_ld_flags="${LDFLAGS} -Wl,--enable-auto-import"
847 fi
848
849 # Add CoreFoundation framework on Darwin
850 if ${cmake_system_darwin}; then
851   cmake_ld_flags="${LDFLAGS} -framework CoreFoundation"
852 fi
853
854 # Add BeOS toolkits...
855 if ${cmake_system_beos}; then
856   cmake_ld_flags="${LDFLAGS} -lroot -lbe"
857 fi
858
859 # Add Haiku toolkits...
860 if ${cmake_system_haiku}; then
861   cmake_ld_flags="${LDFLAGS} -lroot -lbe"
862 fi
863
864 # Workaround for short jump tables on PA-RISC
865 if ${cmake_machine_parisc}; then
866   if ${cmake_c_compiler_is_gnu}; then
867     cmake_c_flags="${CFLAGS} -mlong-calls"
868   fi
869   if ${cmake_cxx_compiler_is_gnu}; then
870     cmake_cxx_flags="${CXXFLAGS} -mlong-calls"
871   fi
872 fi
873
874 #-----------------------------------------------------------------------------
875 # Detect known toolchains on some platforms.
876 cmake_toolchains=''
877 case "${cmake_system}" in
878   *AIX*)   cmake_toolchains='XL GNU' ;;
879   *CYGWIN*) cmake_toolchains='GNU' ;;
880   *Darwin*) cmake_toolchains='Clang GNU' ;;
881   *Linux*) cmake_toolchains='GNU Clang XL PGI PathScale' ;;
882   *MINGW*) cmake_toolchains='GNU' ;;
883 esac
884
885 # Toolchain compiler name table.
886 cmake_toolchain_Clang_CC='clang'
887 cmake_toolchain_Clang_CXX='clang++'
888 cmake_toolchain_GNU_CC='gcc'
889 cmake_toolchain_GNU_CXX='g++'
890 cmake_toolchain_PGI_CC='pgcc'
891 cmake_toolchain_PGI_CXX='pgCC'
892 cmake_toolchain_PathScale_CC='pathcc'
893 cmake_toolchain_PathScale_CXX='pathCC'
894 cmake_toolchain_XL_CC='xlc'
895 cmake_toolchain_XL_CXX='xlC'
896
897 cmake_toolchain_try()
898 {
899   tc="$1"
900   TMPFILE=`cmake_tmp_file`
901
902   eval "tc_CC=\${cmake_toolchain_${tc}_CC}"
903   echo 'int main() { return 0; }' > "${TMPFILE}.c"
904   cmake_try_run "$tc_CC" "" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1
905   tc_result_CC="$?"
906   rm -f "${TMPFILE}.c"
907   test "${tc_result_CC}" = "0" || return 1
908
909   eval "tc_CXX=\${cmake_toolchain_${tc}_CXX}"
910   echo 'int main() { return 0; }' > "${TMPFILE}.cpp"
911   cmake_try_run "$tc_CXX" "" "${TMPFILE}.cpp" >> cmake_bootstrap.log 2>&1
912   tc_result_CXX="$?"
913   rm -f "${TMPFILE}.cpp"
914   test "${tc_result_CXX}" = "0" || return 1
915
916   cmake_toolchain="$tc"
917 }
918
919 cmake_toolchain_detect()
920 {
921   cmake_toolchain=
922   for tc in ${cmake_toolchains}; do
923     echo "Checking for $tc toolchain" >> cmake_bootstrap.log 2>&1
924     cmake_toolchain_try "$tc" &&
925     echo "Found $tc toolchain" &&
926     break
927   done
928 }
929
930 if [ -z "${CC}" -a -z "${CXX}" ]; then
931   cmake_toolchain_detect
932 fi
933
934 #-----------------------------------------------------------------------------
935 # Test C compiler
936 cmake_c_compiler=
937
938 # If CC is set, use that for compiler, otherwise use list of known compilers
939 if [ -n "${cmake_toolchain}" ]; then
940   eval cmake_c_compilers="\${cmake_toolchain_${cmake_toolchain}_CC}"
941 elif [ -n "${CC}" ]; then
942   cmake_c_compilers="${CC}"
943 else
944   cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
945 fi
946
947 # Check if C compiler works
948 TMPFILE=`cmake_tmp_file`
949 echo '
950 #ifdef __cplusplus
951 # error "The CMAKE_C_COMPILER is set to a C++ compiler"
952 #endif
953
954 #include<stdio.h>
955
956 #if defined(__CLASSIC_C__)
957 int main(argc, argv)
958   int argc;
959   char* argv[];
960 #else
961 int main(int argc, char* argv[])
962 #endif
963 {
964   printf("%d%c", (argv != 0), (char)0x0a);
965   return argc-1;
966 }
967 ' > "${TMPFILE}.c"
968 for a in ${cmake_c_compilers}; do
969   if [ -z "${cmake_c_compiler}" ] && \
970     cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
971     cmake_c_compiler="${a}"
972   fi
973 done
974 for std in 11 99 90; do
975   try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" C \"${std}\"`"
976   for flag in $try_flags; do
977     echo "Checking whether ${cmake_c_compiler} supports ${flag}" >> cmake_bootstrap.log 2>&1
978     if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags} ${flag}" \
979       "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
980       cmake_c_flags="${cmake_c_flags} ${flag}"
981       break 2
982     fi
983   done
984 done
985 rm -f "${TMPFILE}.c"
986
987 if [ -z "${cmake_c_compiler}" ]; then
988   cmake_error 6 "Cannot find appropriate C compiler on this system.
989 Please specify one using environment variable CC.
990 See cmake_bootstrap.log for compilers attempted.
991 "
992 fi
993 echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
994
995 #-----------------------------------------------------------------------------
996 # Test CXX compiler
997 cmake_cxx_compiler=
998
999 # On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.
1000
1001 # If CC is set, use that for compiler, otherwise use list of known compilers
1002 if [ -n "${cmake_toolchain}" ]; then
1003   eval cmake_cxx_compilers="\${cmake_toolchain_${cmake_toolchain}_CXX}"
1004 elif [ -n "${CXX}" ]; then
1005   cmake_cxx_compilers="${CXX}"
1006 else
1007   cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
1008 fi
1009
1010 # Check if C++ compiler works
1011 TMPFILE=`cmake_tmp_file`
1012 echo '
1013 #if defined(TEST1)
1014 # include <iostream>
1015 #else
1016 # include <iostream.h>
1017 #endif
1018
1019 #if __cplusplus >= 201103L && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140
1020 #error "SunPro <= 5.13 C++ 11 mode not supported due to bug in move semantics."
1021 #endif
1022
1023 class NeedCXX
1024 {
1025 public:
1026   NeedCXX() { this->Foo = 1; }
1027   int GetFoo() { return this->Foo; }
1028 private:
1029   int Foo;
1030 };
1031 int main()
1032 {
1033   NeedCXX c;
1034 #ifdef TEST3
1035   cout << c.GetFoo() << endl;
1036 #else
1037   std::cout << c.GetFoo() << std::endl;
1038 #endif
1039   return 0;
1040 }
1041 ' > "${TMPFILE}.cxx"
1042 for a in ${cmake_cxx_compilers}; do
1043   for b in 1 2 3; do
1044     if [ -z "${cmake_cxx_compiler}" ] && \
1045       cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
1046       cmake_cxx_compiler="${a}"
1047     fi
1048   done
1049 done
1050 for std in 14 11 98; do
1051   try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" CXX \"${std}\"`"
1052   for flag in $try_flags; do
1053     echo "Checking for wheter ${cmake_cxx_flags} supports ${flag}" >> cmake_bootstrap.log 2>&1
1054     if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags} ${flag} -DTEST1" \
1055       "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
1056       cmake_cxx_flags="${cmake_cxx_flags} ${flag} "
1057       break 2
1058     fi
1059   done
1060 done
1061 rm -f "${TMPFILE}.cxx"
1062
1063 if [ -z "${cmake_cxx_compiler}" ]; then
1064   cmake_error 7 "Cannot find appropriate C++ compiler on this system.
1065 Please specify one using environment variable CXX.
1066 See cmake_bootstrap.log for compilers attempted."
1067 fi
1068 echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
1069
1070 #-----------------------------------------------------------------------------
1071 # Test Make
1072
1073 cmake_make_processor=
1074 cmake_make_flags=
1075
1076 # If MAKE is set, use that for make processor, otherwise use list of known make
1077 if [ -n "${MAKE}" ]; then
1078   cmake_make_processors="${MAKE}"
1079 else
1080   cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
1081 fi
1082
1083 TMPFILE="`cmake_tmp_file`_dir"
1084 rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
1085 mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
1086 cd "${cmake_bootstrap_dir}/${TMPFILE}"
1087 echo '
1088 test: test.c
1089         "'"${cmake_c_compiler}"'" '"${cmake_ld_flags} ${cmake_c_flags}"' -o test test.c
1090 '>"Makefile"
1091 echo '
1092 #include <stdio.h>
1093 int main(){ printf("1%c", (char)0x0a); return 0; }
1094 ' > "test.c"
1095 cmake_original_make_flags="${cmake_make_flags}"
1096 if [ "x${cmake_parallel_make}" != "x" ]; then
1097   cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
1098 fi
1099 for a in ${cmake_make_processors}; do
1100   if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
1101     cmake_make_processor="${a}"
1102   fi
1103 done
1104 cmake_full_make_flags="${cmake_make_flags}"
1105 if [ "x${cmake_original_make_flags}" != "x${cmake_make_flags}" ]; then
1106   if [ -z "${cmake_make_processor}" ]; then
1107     cmake_make_flags="${cmake_original_make_flags}"
1108     for a in ${cmake_make_processors}; do
1109       if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
1110         cmake_make_processor="${a}"
1111       fi
1112     done
1113   fi
1114 fi
1115 cd "${cmake_bootstrap_dir}"
1116
1117 if [ -z "${cmake_make_processor}" ]; then
1118   cmake_error 8 "Cannot find appropriate Makefile processor on this system.
1119 Please specify one using environment variable MAKE."
1120 fi
1121 rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
1122 echo "Makefile processor on this system is: ${cmake_make_processor}"
1123 if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
1124   echo "---------------------------------------------"
1125   echo "Makefile processor ${cmake_make_processor} does not support parallel build"
1126   echo "---------------------------------------------"
1127 fi
1128
1129 # Ok, we have CC, CXX, and MAKE.
1130
1131 # Test C++ compiler features
1132
1133 # Are we GCC?
1134
1135 TMPFILE=`cmake_tmp_file`
1136 echo '
1137 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
1138 #include <iostream>
1139 int main() { std::cout << "This is GNU" << std::endl; return 0;}
1140 #endif
1141 ' > ${TMPFILE}.cxx
1142 cmake_cxx_compiler_is_gnu=0
1143 if cmake_try_run "${cmake_cxx_compiler}" \
1144   "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
1145   cmake_cxx_compiler_is_gnu=1
1146 fi
1147 if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then
1148   echo "${cmake_cxx_compiler} is GNU compiler"
1149 else
1150   echo "${cmake_cxx_compiler} is not GNU compiler"
1151 fi
1152 rm -f "${TMPFILE}.cxx"
1153
1154 if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
1155   # Check for non-GNU compiler flags
1156
1157   # If we are on HP-UX, check for -Ae for the C compiler.
1158   if [ "x${cmake_system}" = "xHP-UX" ]; then
1159     cmake_test_flags="-Ae"
1160     TMPFILE=`cmake_tmp_file`
1161     echo '
1162     int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
1163 ' > ${TMPFILE}.c
1164     cmake_need_Ae=0
1165     if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
1166       :
1167     else
1168       if cmake_try_run "${cmake_c_compiler}" \
1169         "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
1170         cmake_need_Ae=1
1171       fi
1172     fi
1173     if [ "x${cmake_need_Ae}" = "x1" ]; then
1174       cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
1175       echo "${cmake_c_compiler} needs ${cmake_test_flags}"
1176     else
1177       echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
1178     fi
1179     rm -f "${TMPFILE}.c"
1180     echo '
1181     #include <iostream>
1182     int main(int argc, char** argv) {
1183     for(int i=0; i < 1; ++i);
1184     for(int i=0; i < 1; ++i);
1185     (void)argc; (void)argv; return 0; }
1186 ' > ${TMPFILE}.cxx
1187     cmake_need_AAstd98=0
1188     cmake_test_flags="-AA +hpxstd98"
1189     if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
1190       :
1191     else
1192       if cmake_try_run "${cmake_cxx_compiler}" \
1193         "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
1194         cmake_need_AAstd98=1
1195       fi
1196     fi
1197     if [ "x${cmake_need_AAstd98}" = "x1" ]; then
1198       cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
1199       echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
1200     else
1201       echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
1202     fi
1203   fi
1204   cmake_test_flags=
1205 fi
1206
1207
1208 # Test for kwsys features
1209 KWSYS_NAME_IS_KWSYS=0
1210 KWSYS_BUILD_SHARED=0
1211 KWSYS_LFS_AVAILABLE=0
1212 KWSYS_LFS_REQUESTED=0
1213 KWSYS_STL_HAS_WSTRING=0
1214 KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H=0
1215 KWSYS_CXX_HAS_SETENV=0
1216 KWSYS_CXX_HAS_UNSETENV=0
1217 KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=0
1218 KWSYS_CXX_HAS_UTIMENSAT=0
1219 KWSYS_CXX_HAS_UTIMES=0
1220
1221 if cmake_try_run "${cmake_cxx_compiler}" \
1222   "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_SETENV" \
1223   "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
1224   KWSYS_CXX_HAS_SETENV=1
1225   echo "${cmake_cxx_compiler} has setenv"
1226 else
1227   echo "${cmake_cxx_compiler} does not have setenv"
1228 fi
1229
1230 if cmake_try_run "${cmake_cxx_compiler}" \
1231   "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_UNSETENV" \
1232   "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
1233   KWSYS_CXX_HAS_UNSETENV=1
1234   echo "${cmake_cxx_compiler} has unsetenv"
1235 else
1236   echo "${cmake_cxx_compiler} does not have unsetenv"
1237 fi
1238
1239 if cmake_try_run "${cmake_cxx_compiler}" \
1240   "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H" \
1241   "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
1242   KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=1
1243   echo "${cmake_cxx_compiler} has environ in stdlib.h"
1244 else
1245   echo "${cmake_cxx_compiler} does not have environ in stdlib.h"
1246 fi
1247
1248 if cmake_try_run "${cmake_cxx_compiler}" \
1249   "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_WSTRING" \
1250   "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
1251   KWSYS_STL_HAS_WSTRING=1
1252   echo "${cmake_cxx_compiler} has stl wstring"
1253 else
1254   echo "${cmake_cxx_compiler} does not have stl wstring"
1255 fi
1256
1257 if cmake_try_run "${cmake_cxx_compiler}" \
1258   "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H" \
1259   "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
1260   KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H=1
1261   echo "${cmake_cxx_compiler} has <ext/stdio_filebuf.h>"
1262 else
1263   echo "${cmake_cxx_compiler} does not have <ext/stdio_filebuf.h>"
1264 fi
1265
1266 # Just to be safe, let us store compiler and flags to the header file
1267
1268 cmake_bootstrap_version='$Revision$'
1269 cmake_compiler_settings_comment="/*
1270  * Generated by ${cmake_source_dir}/bootstrap
1271  * Version:     ${cmake_bootstrap_version}
1272  *
1273  * Source directory: ${cmake_source_dir}
1274  * Binary directory: ${cmake_bootstrap_dir}
1275  *
1276  * C compiler:   ${cmake_c_compiler}
1277  * C flags:      ${cmake_c_flags}
1278  *
1279  * C++ compiler: ${cmake_cxx_compiler}
1280  * C++ flags:    ${cmake_cxx_flags}
1281  *
1282  * Make:         ${cmake_make_processor}
1283  *
1284  * Sources:
1285  * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
1286  * LexerParser Sources:
1287  * ${LexerParser_CXX_SOURCES} ${LexerParser_C_SOURCES}
1288  * kwSys Sources:
1289  * ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
1290  */
1291 "
1292
1293 cmake_report cmConfigure.h${_tmp} "${cmake_compiler_settings_comment}"
1294
1295 # When bootstrapping on MinGW with MSYS we must convert the source
1296 # directory to a windows path.
1297 if ${cmake_system_mingw}; then
1298     CMAKE_BOOTSTRAP_SOURCE_DIR=`cd "${cmake_source_dir}"; pwd -W`
1299     CMAKE_BOOTSTRAP_BINARY_DIR=`cd "${cmake_binary_dir}"; pwd -W`
1300 else
1301     CMAKE_BOOTSTRAP_SOURCE_DIR="${cmake_source_dir}"
1302     CMAKE_BOOTSTRAP_BINARY_DIR="${cmake_binary_dir}"
1303 fi
1304
1305 # Write CMake version
1306 cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_MAJOR ${cmake_version_major}"
1307 cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_MINOR ${cmake_version_minor}"
1308 cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_PATCH ${cmake_version_patch}"
1309 cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION \"${cmake_version}\""
1310 cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP_SOURCE_DIR \"${CMAKE_BOOTSTRAP_SOURCE_DIR}\""
1311 cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP_BINARY_DIR \"${CMAKE_BOOTSTRAP_BINARY_DIR}\""
1312 cmake_report cmConfigure.h${_tmp} "#define CMAKE_BIN_DIR \"/bootstrap-not-insalled\""
1313 cmake_report cmConfigure.h${_tmp} "#define CMAKE_DATA_DIR \"/bootstrap-not-insalled\""
1314 cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP"
1315 cmake_report cmConfigure.h${_tmp} "#define CM_EQ_DELETE"
1316 cmake_report cmConfigure.h${_tmp} "#define CM_FALLTHROUGH"
1317 cmake_report cmConfigure.h${_tmp} "#define CM_NULLPTR 0"
1318 cmake_report cmConfigure.h${_tmp} "#define CM_OVERRIDE"
1319 cmake_report cmConfigure.h${_tmp} "#define CM_DISABLE_COPY(Class)"
1320
1321 # Regenerate configured headers
1322 for h in Configure VersionConfig; do
1323   if "${_diff}" cm${h}.h cm${h}.h${_tmp} > /dev/null 2> /dev/null; then
1324     rm -f cm${h}.h${_tmp}
1325   else
1326     mv -f cm${h}.h${_tmp} cm${h}.h
1327   fi
1328 done
1329
1330 # Prepare KWSYS
1331 cmake_kwsys_config_replace_string \
1332   "${cmake_source_dir}/Source/kwsys/Configure.hxx.in" \
1333   "${cmake_bootstrap_dir}/cmsys/Configure.hxx" \
1334   "${cmake_compiler_settings_comment}"
1335 cmake_kwsys_config_replace_string \
1336   "${cmake_source_dir}/Source/kwsys/Configure.h.in" \
1337   "${cmake_bootstrap_dir}/cmsys/Configure.h" \
1338   "${cmake_compiler_settings_comment}"
1339
1340 for a in ${KWSYS_FILES}; do
1341   cmake_replace_string "${cmake_source_dir}/Source/kwsys/${a}.in" \
1342      "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
1343 done
1344
1345 cmake_generate_file "${cmake_bootstrap_dir}/cmThirdParty.h" ""
1346
1347 # Generate Makefile
1348 dep="cmConfigure.h cmsys/*.hxx cmsys/*.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
1349 objs=""
1350 for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${LexerParser_CXX_SOURCES} ${LexerParser_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
1351   objs="${objs} ${a}.o"
1352 done
1353
1354 if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
1355   cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
1356 fi
1357
1358 if [ "x${cmake_c_flags}" != "x" ]; then
1359   cmake_c_flags="${cmake_c_flags} "
1360 fi
1361
1362 if [ "x${cmake_cxx_flags}" != "x" ]; then
1363   cmake_cxx_flags="${cmake_cxx_flags} "
1364 fi
1365
1366 cmake_c_flags_String="-DKWSYS_STRING_C"
1367 if ${cmake_system_mingw}; then
1368   cmake_c_flags_EncodingC="-DKWSYS_ENCODING_DEFAULT_CODEPAGE=CP_ACP"
1369   cmake_cxx_flags_EncodingCXX="${cmake_c_flags_EncodingC}"
1370   cmake_cxx_flags_cmProcessOutput="${cmake_c_flags_EncodingC}"
1371 fi
1372 cmake_cxx_flags_SystemTools="
1373   -DKWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV}
1374   -DKWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV}
1375   -DKWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}
1376   -DKWSYS_CXX_HAS_UTIMENSAT=${KWSYS_CXX_HAS_UTIMENSAT}
1377   -DKWSYS_CXX_HAS_UTIMES=${KWSYS_CXX_HAS_UTIMES}
1378 "
1379 cmake_c_flags="${cmake_c_flags} \
1380   -I`cmake_escape \"${cmake_bootstrap_dir}\"` \
1381   -I`cmake_escape \"${cmake_source_dir}/Source\"` \
1382   -I`cmake_escape \"${cmake_source_dir}/Source/LexerParser\"` \
1383   -I`cmake_escape \"${cmake_source_dir}/Utilities\"`"
1384 cmake_cxx_flags="${cmake_cxx_flags} \
1385   -I`cmake_escape \"${cmake_bootstrap_dir}\"` \
1386   -I`cmake_escape \"${cmake_source_dir}/Source\"` \
1387   -I`cmake_escape \"${cmake_source_dir}/Source/LexerParser\"` \
1388   -I`cmake_escape \"${cmake_source_dir}/Utilities\"`"
1389 echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
1390 echo "  ${cmake_cxx_compiler} ${cmake_ld_flags} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
1391 for a in ${CMAKE_CXX_SOURCES}; do
1392   src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
1393   src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
1394   echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
1395   echo "        ${cmake_cxx_compiler} ${cmake_cxx_flags} ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
1396 done
1397 for a in ${CMAKE_C_SOURCES}; do
1398   src=`cmake_escape "${cmake_source_dir}/Source/${a}.c"`
1399   echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
1400   echo "        ${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
1401 done
1402 for a in ${LexerParser_CXX_SOURCES}; do
1403   src=`cmake_escape "${cmake_source_dir}/Source/LexerParser/${a}.cxx"`
1404   src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
1405   echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
1406   echo "        ${cmake_cxx_compiler} ${cmake_cxx_flags} ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
1407 done
1408 for a in ${LexerParser_C_SOURCES}; do
1409   src=`cmake_escape "${cmake_source_dir}/Source/LexerParser/${a}.c"`
1410   echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
1411   echo "        ${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
1412 done
1413 for a in ${KWSYS_C_SOURCES}; do
1414   src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.c"`
1415   src_flags=`eval echo \\${cmake_c_flags_\${a}}`
1416   echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
1417   echo "        ${cmake_c_compiler} ${cmake_c_flags} -DKWSYS_NAMESPACE=cmsys ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
1418 done
1419 for a in ${KWSYS_CXX_SOURCES}; do
1420   src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.cxx"`
1421   src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
1422   echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
1423   echo "        ${cmake_cxx_compiler} ${cmake_cxx_flags} -DKWSYS_NAMESPACE=cmsys ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
1424 done
1425 echo '
1426 rebuild_cache:
1427         cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
1428 ' >> "${cmake_bootstrap_dir}/Makefile"
1429
1430 # Write our default settings to Bootstrap${_cmk}/InitialCacheFlags.cmake.
1431 echo '
1432 # Generated by '"${cmake_source_dir}"'/bootstrap
1433 # Default cmake settings.  These may be overridden any settings below.
1434 set (CMAKE_INSTALL_PREFIX "'"${cmake_prefix_dir}"'" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
1435 set (CMAKE_DOC_DIR "'"${cmake_doc_dir}"'" CACHE PATH "Install location for documentation (relative to prefix)." FORCE)
1436 set (CMAKE_MAN_DIR "'"${cmake_man_dir}"'" CACHE PATH "Install location for man pages (relative to prefix)." FORCE)
1437 set (CMAKE_BIN_DIR "'"${cmake_bin_dir}"'" CACHE PATH "Install location for binaries (relative to prefix)." FORCE)
1438 set (CMAKE_DATA_DIR "'"${cmake_data_dir}"'" CACHE PATH "Install location for data (relative to prefix)." FORCE)
1439 set (CMAKE_XDGDATA_DIR "'"${cmake_xdgdata_dir}"'" CACHE PATH "Install location for XDG specific files (relative to prefix)." FORCE)
1440 ' > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1441
1442 # Add configuration settings given as command-line options.
1443 if [ "x${cmake_bootstrap_qt_gui}" != "x" ]; then
1444   echo '
1445 set (BUILD_QtDialog '"${cmake_bootstrap_qt_gui}"' CACHE BOOL "Build Qt dialog for CMake" FORCE)
1446 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1447 fi
1448 if [ "x${cmake_bootstrap_qt_qmake}" != "x" ]; then
1449   echo '
1450 set (QT_QMAKE_EXECUTABLE "'"${cmake_bootstrap_qt_qmake}"'" CACHE FILEPATH "Location of Qt qmake" FORCE)
1451 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1452 fi
1453 if [ "x${cmake_bootstrap_server}" != "x" ]; then
1454   echo '
1455 set (CMake_ENABLE_SERVER_MODE '"${cmake_bootstrap_server}"' CACHE BOOL "Enable server mode" FORCE)
1456 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1457 fi
1458 if [ "x${cmake_sphinx_man}" != "x" ]; then
1459   echo '
1460 set (SPHINX_MAN "'"${cmake_sphinx_man}"'" CACHE BOOL "Build man pages with Sphinx" FORCE)
1461 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1462 fi
1463 if [ "x${cmake_sphinx_html}" != "x" ]; then
1464   echo '
1465 set (SPHINX_HTML "'"${cmake_sphinx_html}"'" CACHE BOOL "Build html help with Sphinx" FORCE)
1466 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1467 fi
1468 if [ "x${cmake_sphinx_qthelp}" != "x" ]; then
1469   echo '
1470 set (SPHINX_QTHELP "'"${cmake_sphinx_qthelp}"'" CACHE BOOL "Build qch help with Sphinx" FORCE)
1471 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1472 fi
1473 if [ "x${cmake_sphinx_build}" != "x" ]; then
1474   echo '
1475 set (SPHINX_EXECUTABLE "'"${cmake_sphinx_build}"'" CACHE FILEPATH "Location of Qt sphinx-build" FORCE)
1476 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1477 fi
1478 if [ "x${cmake_sphinx_flags}" != "x" ]; then
1479   echo '
1480 set (SPHINX_FLAGS [==['"${cmake_sphinx_flags}"']==] CACHE STRING "Flags to pass to sphinx-build" FORCE)
1481 ' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1482 fi
1483
1484 # Add user-specified settings.  Handle relative-path case for
1485 # specification of cmake_init_file.
1486 (
1487 cd "${cmake_binary_dir}"
1488 if [ -f "${cmake_init_file}" ]; then
1489   cat "${cmake_init_file}" >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
1490 fi
1491 )
1492
1493 echo "---------------------------------------------"
1494
1495 # Run make to build bootstrap cmake
1496 if [ "x${cmake_parallel_make}" != "x" ]; then
1497   ${cmake_make_processor} ${cmake_make_flags}
1498 else
1499   ${cmake_make_processor}
1500 fi
1501 RES=$?
1502 if [ "${RES}" -ne "0" ]; then
1503   cmake_error 9 "Problem while running ${cmake_make_processor}"
1504 fi
1505 cd "${cmake_binary_dir}"
1506
1507 # Set C, CXX, and MAKE environment variables, so that real real cmake will be
1508 # build with same compiler and make
1509 CC="${cmake_c_compiler}"
1510 CXX="${cmake_cxx_compiler}"
1511 if [ -n "${cmake_ccache_enabled}" ]; then
1512   CC="ccache ${CC}"
1513   CXX="ccache ${CXX}"
1514 fi
1515 MAKE="${cmake_make_processor}"
1516 export CC
1517 export CXX
1518 export MAKE
1519
1520 # Run bootstrap CMake to configure real CMake
1521 cmake_options="-DCMAKE_BOOTSTRAP=1"
1522 if [ -n "${cmake_verbose}" ]; then
1523   cmake_options="${cmake_options} -DCMAKE_VERBOSE_MAKEFILE=1"
1524 fi
1525 "${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake" "-G${cmake_bootstrap_generator}" ${cmake_options} ${cmake_bootstrap_system_libs} "$@"
1526 RES=$?
1527 if [ "${RES}" -ne "0" ]; then
1528   cmake_error 11 "Problem while running initial CMake"
1529 fi
1530
1531 echo "---------------------------------------------"
1532
1533 # And we are done. Now just run make
1534 echo "CMake has bootstrapped.  Now run ${cmake_make_processor}."