STYLE: Nightly Version update
[cmake.git] / bootstrap
blobabf27d38c21e95d71884536711797bf1a8a825db
1 #!/bin/sh
3 #=========================================================================
5 # Program: CMake - Cross-Platform Makefile Generator
6 # Module: $RCSfile: bootstrap,v $
7 # Language: Bourne Shell
8 # Date: $Date: 2005-03-09 20:51:30 $
9 # Version: $Revision: 1.51 $
11 # Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
12 # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
14 # This software is distributed WITHOUT ANY WARRANTY; without even
15 # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 # PURPOSE. See the above copyright notices for more information.
18 #=========================================================================
20 CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
21 CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
22 CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
24 CMAKE_PROBLEMATIC_FILES="\
25 CMakeCache.txt \
26 CMakeSystem.cmake \
27 CMakeCCompiler.cmake \
28 CMakeCXXCompiler.cmake \
29 Source/cmConfigure.h \
30 Source/CTest/Curl/config.h \
31 Utilities/cmexpat/expatConfig.h \
32 Utilities/cmexpat/expatDllConfig.h \
35 CMAKE_CXX_SOURCES="\
36 cmake \
37 cmakewizard \
38 cmakemain \
39 cmDepends \
40 cmDependsC \
41 cmMakeDepend \
42 cmMakefile \
43 cmGeneratedFileStream \
44 cmGlobalGenerator \
45 cmLocalGenerator \
46 cmSourceFile \
47 cmSystemTools \
48 cmGlobalUnixMakefileGenerator \
49 cmGlobalXCodeGenerator \
50 cmLocalXCodeGenerator \
51 cmXCodeObject \
52 cmLocalUnixMakefileGenerator \
53 cmLocalUnixMakefileGenerator2 \
54 cmBootstrapCommands \
55 cmCommands \
56 cmTarget \
57 cmCustomCommand \
58 cmCacheManager \
59 cmListFileCache \
60 cmOrderLinkDirectories \
61 cmSourceGroup"
63 CMAKE_C_SOURCES="\
64 cmListFileLexer \
67 KWSYS_C_SOURCES="\
68 ProcessUNIX"
70 KWSYS_CXX_SOURCES="\
71 Directory \
72 RegularExpression \
73 SystemTools"
75 KWSYS_FILES="\
76 Directory.hxx \
77 Process.h \
78 RegularExpression.hxx \
79 SystemTools.hxx"
81 KWSYS_IOS_FILES="
82 fstream \
83 iosfwd \
84 iostream \
85 sstream"
87 cmake_system=`uname`
89 cmake_source_dir=`echo $0 | sed -n '/\//{s/\/[^\/]*$//;p;}'`
90 cmake_source_dir=`(cd "${cmake_source_dir}";pwd)`
91 cmake_binary_dir=`pwd`
92 cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap.cmk"
93 cmake_data_dir="/share/CMake"
94 cmake_doc_dir="/doc/CMake"
95 cmake_man_dir="/man"
96 cmake_init_file=""
98 # Display CMake bootstrap usage
99 cmake_usage()
101 cat <<EOF
102 Usage: $0 [options]
103 Options: [defaults in brackets after descriptions]
104 Configuration:
105 --help print this message
106 --version only print version information
107 --verbose display more information
108 --parallel=n bootstrap cmake in parallel, where n is
109 number of nodes [1]
110 --init=FILE use FILE for cmake initialization
112 Directory and file names:
113 --prefix=PREFIX install files in tree rooted at PREFIX
114 [/usr/local]
115 --datadir=DIR install data files in PREFIX/DIR
116 [/share/CMake]
117 --docdir=DIR install documentation files in PREFIX/DIR
118 [/doc/CMake]
119 --mandir=DIR install man pages files in PREFIX/DIR/manN
120 [/man]
122 exit 10
125 # Display CMake bootstrap usage
126 cmake_version()
128 # Get CMake version
129 CMAKE_VERSION=""
130 for a in MAJOR MINOR PATCH; do
131 CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | \
132 grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
133 CMAKE_VERSION="${CMAKE_VERSION}.${CMake_VERSION}"
134 done
135 CMAKE_VERSION=`echo $CMAKE_VERSION | sed "s/\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)/\1.\2-\3/"`
136 echo "CMake ${CMAKE_VERSION}, Copyright (c) 2002 Kitware, Inc., Insight Consortium"
139 # Display CMake bootstrap error, display the log file and exit
140 cmake_error()
142 res=$1
143 shift 1
144 echo "---------------------------------------------"
145 echo "Error when bootstrapping CMake:"
146 echo "$*"
147 echo "---------------------------------------------"
148 if [ -f cmake_bootstrap.log ]; then
149 echo "Log of errors: `pwd`/cmake_bootstrap.log"
150 #cat cmake_bootstrap.log
151 echo "---------------------------------------------"
153 exit ${res}
156 # Replace KWSYS_NAMESPACE with cmsys
157 cmake_replace_string ()
159 INFILE="$1"
160 OUTFILE="$2"
161 SEARCHFOR="$3"
162 REPLACEWITH="$4"
163 if [ -f "${INFILE}" ]; then
164 cat "${INFILE}" |
165 sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}.tmp"
166 if [ -f "${OUTFILE}.tmp" ]; then
167 if diff "${OUTFILE}" "${OUTFILE}.tmp" > /dev/null 2> /dev/null ; then
168 #echo "Files are the same"
169 rm -f "${OUTFILE}.tmp"
170 else
171 mv -f "${OUTFILE}.tmp" "${OUTFILE}"
174 else
175 cmake_error 1 "Cannot find file ${INFILE}"
179 cmake_kwsys_config_replace_string ()
181 INFILE="$1"
182 OUTFILE="$2"
183 shift 2
184 APPEND="$*"
185 if [ -f "${INFILE}" ]; then
186 echo "${APPEND}" > "${OUTFILE}.tmp"
187 cat "${INFILE}" |
188 sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
189 s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
190 s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
191 s/@KWSYS_IOS_USE_ANSI@/${KWSYS_IOS_USE_ANSI}/g;
192 s/@KWSYS_IOS_HAVE_STD@/${KWSYS_IOS_HAVE_STD}/g;
193 s/@KWSYS_IOS_USE_SSTREAM@/${KWSYS_IOS_USE_SSTREAM}/g;
194 s/@KWSYS_IOS_USE_STRSTREAM_H@/${KWSYS_IOS_USE_STRSTREAM_H}/g;
195 s/@KWSYS_IOS_USE_STRSTREA_H@/${KWSYS_IOS_USE_STRSTREA_H}/g;
196 s/@KWSYS_STL_HAVE_STD@/${KWSYS_STL_HAVE_STD}/g;
197 s/@KWSYS_STAT_HAS_ST_MTIM@/${KWSYS_STAT_HAS_ST_MTIM}/g;}" >> "${OUTFILE}.tmp"
198 if [ -f "${OUTFILE}.tmp" ]; then
199 if diff "${OUTFILE}" "${OUTFILE}.tmp" > /dev/null 2> /dev/null ; then
200 #echo "Files are the same"
201 rm -f "${OUTFILE}.tmp"
202 else
203 mv -f "${OUTFILE}.tmp" "${OUTFILE}"
206 else
207 cmake_error 2 "Cannot find file ${INFILE}"
210 # Write string into a file
211 cmake_report ()
213 FILE=$1
214 shift
215 echo "$*" >> ${FILE}
218 # Escape spaces in strings
219 cmake_escape ()
221 echo $1 | sed "s/ /\\\\ /g"
224 # Write message to the log
225 cmake_log ()
227 echo "$*" >> cmake_bootstrap.log
230 # Return temp file
231 cmake_tmp_file ()
233 echo "cmake_bootstrap_$$.test"
236 # Run a compiler test. First argument is compiler, second one are compiler
237 # flags, third one is test source file to be compiled
238 cmake_try_run ()
240 COMPILER=$1
241 FLAGS=$2
242 TESTFILE=$3
243 if [ ! -f "${TESTFILE}" ]; then
244 echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
245 exit 4
247 TMPFILE=`cmake_tmp_file`
248 echo "Try: ${COMPILER}"
249 echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
250 echo "---------- file -----------------------"
251 cat ${TESTFILE}
252 echo "------------------------------------------"
253 "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
254 RES=$?
255 if [ "${RES}" -ne "0" ]; then
256 echo "Test failed to compile"
257 return 1
259 if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
260 echo "Test failed to produce executable"
261 return 2
263 ./${TMPFILE}
264 RES=$?
265 rm -f "${TMPFILE}"
266 if [ "${RES}" -ne "0" ]; then
267 echo "Test produced non-zero return code"
268 return 3
270 echo "Test succeded"
271 return 0
274 # Run a make test. First argument is the make interpreter.
275 cmake_try_make ()
277 MAKE_PROC="$1"
278 MAKE_FLAGS="$2"
279 echo "Try: ${MAKE_PROC}"
280 "${MAKE_PROC}" ${MAKE_FLAGS}
281 RES=$?
282 if [ "${RES}" -ne "0" ]; then
283 echo "${MAKE_PROC} does not work"
284 return 1
286 if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
287 echo "${COMPILER} does not produce output"
288 return 2
290 ./test
291 RES=$?
292 rm -f "test"
293 if [ "${RES}" -ne "0" ]; then
294 echo "${MAKE_PROC} produces strange executable"
295 return 3
297 echo "${MAKE_PROC} works"
298 return 0
301 # Parse arguments
302 cmake_verbose=
303 cmake_parallel_make=
304 cmake_prefix_dir="/usr/local"
305 for a in "$@"; do
306 if echo $a | grep "^--prefix=" > /dev/null 2> /dev/null; then
307 cmake_prefix_dir=`echo $a | sed "s/^--prefix=//"`
309 if echo $a | grep "^--parallel=" > /dev/null 2> /dev/null; then
310 cmake_parallel_make=`echo $a | sed "s/^--parallel=//" | grep "[0-9][0-9]*"`
312 if echo $a | grep "^--datadir=" > /dev/null 2> /dev/null; then
313 cmake_data_dir=`echo $a | sed "s/^--datadir=//"`
315 if echo $a | grep "^--docdir=" > /dev/null 2> /dev/null; then
316 cmake_doc_dir=`echo $a | sed "s/^--docdir=//"`
318 if echo $a | grep "^--mandir=" > /dev/null 2> /dev/null; then
319 cmake_man_dir=`echo $a | sed "s/^--mandir=//"`
321 if echo $a | grep "^--init=" > /dev/null 2> /dev/null; then
322 cmake_init_file=`echo $a | sed "s/^--init=//"`
324 if echo $a | grep "^--help" > /dev/null 2> /dev/null; then
325 cmake_usage
327 if echo $a | grep "^--version" > /dev/null 2> /dev/null; then
328 cmake_version
329 exit 2
331 if echo $a | grep "^--verbose" > /dev/null 2> /dev/null; then
332 cmake_verbose=TRUE
334 done
336 # If verbose, display some information about bootstrap
337 if [ -n "${cmake_verbose}" ]; then
338 echo "---------------------------------------------"
339 echo "Source directory: ${cmake_source_dir}"
340 echo "Binary directory: ${cmake_binary_dir}"
341 echo "Prefix directory: ${cmake_prefix_dir}"
342 echo "System: ${cmake_system}"
343 if [ "x${cmake_parallel_make}" != "x" ]; then
344 echo "Doing parallel make: ${cmake_parallel_make}"
346 echo ""
349 echo "---------------------------------------------"
350 # Get CMake version
351 echo "`cmake_version`"
353 # Check for in-source build
354 cmake_in_source_build=
355 if [ -f "${cmake_binary_dir}/Source/cmake.cxx" -a \
356 -f "${cmake_binary_dir}/Source/cmake.h" ]; then
357 if [ -n "${cmake_verbose}" ]; then
358 echo "Warning: This is an in-source build"
360 cmake_in_source_build=TRUE
363 # If this is not an in-source build, then Bootstrap stuff should not exist.
364 if [ -z "${cmake_in_source_build}" ]; then
365 # Did somebody bootstrap in the source tree?
366 if [ -d "${cmake_source_dir}/Bootstrap.cmk" ]; then
367 cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap.cmk\".
368 Looks like somebody did bootstrap CMake in the source tree, but now you are
369 trying to do bootstrap in the binary tree. Please remove Bootstrap.cmk
370 directory from the source tree."
372 # Is there a cache in the source tree?
373 for cmake_problematic_file in ${CMAKE_PROBLEMATIC_FILES}; do
374 if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
375 cmake_error 10 "Found \"${cmake_source_dir}/${cmake_problematic_file}\".
376 Looks like somebody tried to build CMake in the source tree, but now you are
377 trying to do bootstrap in the binary tree. Please remove \"${cmake_problematic_file}\"
378 from the source tree."
380 done
383 # Make bootstrap directory
384 [ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
385 if [ ! -d "${cmake_bootstrap_dir}" ]; then
386 cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
388 cd "${cmake_bootstrap_dir}"
390 [ -d "cmsys" ] || mkdir "cmsys"
391 if [ ! -d "cmsys" ]; then
392 cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
395 for a in stl ios; do
396 [ -d "cmsys/${a}" ] || mkdir "cmsys/${a}"
397 if [ ! -d "cmsys/${a}" ]; then
398 cmake_error 5 "Cannot create directory ${cmake_bootstrap_dir}/cmsys/${a}"
400 done
402 # Delete all the bootstrap files
403 rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
404 rm -f "${cmake_bootstrap_dir}/cmConfigure.h.tmp"
406 # If exist compiler flags, set them
407 cmake_c_flags=${CFLAGS}
408 cmake_cxx_flags=${CXXFLAGS}
410 # Test C compiler
411 cmake_c_compiler=
413 # If CC is set, use that for compiler, otherwise use list of known compilers
414 if [ -n "${CC}" ]; then
415 cmake_c_compilers="${CC}"
416 else
417 cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
420 # Check if C compiler works
421 TMPFILE=`cmake_tmp_file`
422 cat > "${TMPFILE}.c" <<EOF
423 #include<stdio.h>
424 int main()
426 printf("1\n");
427 return 0;
430 for a in ${cmake_c_compilers}; do
431 if [ -z "${cmake_c_compiler}" ] && \
432 cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
433 cmake_c_compiler="${a}"
435 done
436 rm -f "${TMPFILE}.c"
438 if [ -z "${cmake_c_compiler}" ]; then
439 cmake_error 6 "Cannot find appropriate C compiler on this system.
440 Please specify one using environment variable CC.
441 See cmake_bootstrap.log for compilers attempted.
444 echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
446 # Test CXX compiler
447 cmake_cxx_compiler=
449 # On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.
451 # If CC is set, use that for compiler, otherwise use list of known compilers
452 if [ -n "${CXX}" ]; then
453 cmake_cxx_compilers="${CXX}"
454 else
455 cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
458 # Check if C++ compiler works
459 TMPFILE=`cmake_tmp_file`
460 cat > "${TMPFILE}.cxx" <<EOF
461 #if defined(TEST1)
462 # include <iostream>
463 #else
464 # include <iostream.h>
465 #endif
467 class NeedCXX
469 public:
470 NeedCXX() { this->Foo = 1; }
471 int GetFoo() { return this->Foo; }
472 private:
473 int Foo;
475 int main()
477 NeedCXX c;
478 #ifdef TEST3
479 cout << c.GetFoo() << endl;
480 #else
481 std::cout << c.GetFoo() << std::endl;
482 #endif
483 return 0;
486 for a in ${cmake_cxx_compilers}; do
487 for b in 1 2 3; do
488 if [ -z "${cmake_cxx_compiler}" ] && \
489 cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
490 cmake_cxx_compiler="${a}"
492 done
493 done
494 rm -f "${TMPFILE}.cxx"
496 if [ -z "${cmake_cxx_compiler}" ]; then
497 cmake_error 7 "Cannot find appropriate C++ compiler on this system.
498 Please specify one using environment variable CXX.
499 See cmake_bootstrap.log for compilers attempted."
501 echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
503 # Test Make
505 cmake_make_processor=
506 cmake_make_flags=
508 # If MAKE is set, use that for make processor, otherwise use list of known make
509 if [ -n "${MAKE}" ]; then
510 cmake_make_processors="${MAKE}"
511 else
512 cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
515 TMPFILE="`cmake_tmp_file`_dir"
516 rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
517 mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
518 cd "${cmake_bootstrap_dir}/${TMPFILE}"
519 cat>"Makefile"<<EOF
520 test: test.c
521 "${cmake_c_compiler}" -o test test.c
523 cat>"test.c"<<EOF
524 #include <stdio.h>
525 int main(){ printf("1\n"); return 0; }
527 cmake_original_make_flags="${cmake_make_flags}"
528 if [ "x${cmake_parallel_make}" != "x" ]; then
529 cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
531 for a in ${cmake_make_processors}; do
532 if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
533 cmake_make_processor="${a}"
535 done
536 cmake_full_make_flags="${cmake_make_flags}"
537 if [ "x${cmake_original_make_flags}" != "x${cmake_make_flags}" ]; then
538 if [ -z "${cmake_make_processor}" ]; then
539 cmake_make_flags="${cmake_original_make_flags}"
540 for a in ${cmake_make_processors}; do
541 if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
542 cmake_make_processor="${a}"
544 done
547 cd "${cmake_bootstrap_dir}"
548 rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
550 if [ -z "${cmake_make_processor}" ]; then
551 cmake_error 8 "Cannot find appropriate Makefile processor on this system.
552 Please specify one using environment variable MAKE."
554 echo "Makefile processor on this system is: ${cmake_make_processor}"
555 if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
556 echo "---------------------------------------------"
557 echo "Makefile processor ${cmake_make_processor} does not support parallel build"
558 echo "---------------------------------------------"
561 # Ok, we have CC, CXX, and MAKE.
563 # Test C++ compiler features
565 # Are we GCC?
567 TMPFILE=`cmake_tmp_file`
568 cat > ${TMPFILE}.cxx <<EOF
569 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
570 #include <iostream>
571 int main() { std::cout << "This is GNU" << std::endl; return 0;}
572 #endif
574 cmake_cxx_compiler_is_gnu=0
575 if cmake_try_run "${cmake_cxx_compiler}" \
576 "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
577 cmake_cxx_compiler_is_gnu=1
579 if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then
580 echo "${cmake_cxx_compiler} is GNU compiler"
581 else
582 echo "${cmake_cxx_compiler} is not GNU compiler"
584 rm -f "${TMPFILE}.cxx"
586 if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
587 # Check for non-GNU compiler flags
589 # If we are on IRIX, check for -LANG:std
590 cmake_test_flags="-LANG:std"
591 if [ "x${cmake_system}" = "xIRIX64" ]; then
592 TMPFILE=`cmake_tmp_file`
593 cat > ${TMPFILE}.cxx <<EOF
594 #include <iostream>
595 int main() { std::cout << "No need for ${cmake_test_flags}" << std::endl; return 0;}
597 cmake_need_lang_std=0
598 if cmake_try_run "${cmake_cxx_compiler}" \
599 "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
601 else
602 if cmake_try_run "${cmake_cxx_compiler}" \
603 "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
604 cmake_need_lang_std=1
607 if [ "x${cmake_need_lang_std}" = "x1" ]; then
608 cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
609 echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
610 else
611 echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
613 rm -f "${TMPFILE}.cxx"
615 cmake_test_flags=
617 # If we are on OSF, check for -timplicit_local -no_implicit_include
618 cmake_test_flags="-timplicit_local -no_implicit_include"
619 if [ "x${cmake_system}" = "xOSF1" ]; then
620 TMPFILE=`cmake_tmp_file`
621 cat > ${TMPFILE}.cxx <<EOF
622 #include <iostream>
623 int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
625 cmake_need_flags=1
626 if cmake_try_run "${cmake_cxx_compiler}" \
627 "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
629 else
630 cmake_need_flags=0
632 if [ "x${cmake_need_flags}" = "x1" ]; then
633 cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
634 echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
635 else
636 echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
638 rm -f "${TMPFILE}.cxx"
640 cmake_test_flags=
642 # If we are on OSF, check for -std strict_ansi -nopure_cname
643 cmake_test_flags="-std strict_ansi -nopure_cname"
644 if [ "x${cmake_system}" = "xOSF1" ]; then
645 TMPFILE=`cmake_tmp_file`
646 cat > ${TMPFILE}.cxx <<EOF
647 #include <iostream>
648 int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
650 cmake_need_flags=1
651 if cmake_try_run "${cmake_cxx_compiler}" \
652 "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
654 else
655 cmake_need_flags=0
657 if [ "x${cmake_need_flags}" = "x1" ]; then
658 cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
659 echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
660 else
661 echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
663 rm -f "${TMPFILE}.cxx"
665 cmake_test_flags=
667 # If we are on HP-UX, check for -Ae for the C compiler.
668 cmake_test_flags="-Ae"
669 if [ "x${cmake_system}" = "xHP-UX" ]; then
670 TMPFILE=`cmake_tmp_file`
671 cat > ${TMPFILE}.c <<EOF
672 int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
674 cmake_need_Ae=0
675 if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
677 else
678 if cmake_try_run "${cmake_c_compiler}" \
679 "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
680 cmake_need_Ae=1
683 if [ "x${cmake_need_Ae}" = "x1" ]; then
684 cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
685 echo "${cmake_c_compiler} needs ${cmake_test_flags}"
686 else
687 echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
689 rm -f "${TMPFILE}.c"
691 cmake_test_flags=
694 # Test for kwsys features
695 KWSYS_NAME_IS_KWSYS=0
696 KWSYS_BUILD_SHARED=0
697 KWSYS_IOS_USE_STRSTREAM_H=0
698 KWSYS_IOS_USE_STRSTREA_H=0
699 KWSYS_IOS_HAVE_STD=0
700 KWSYS_IOS_USE_SSTREAM=0
701 KWSYS_IOS_USE_ANSI=0
702 KWSYS_STL_HAVE_STD=0
703 KWSYS_STAT_HAS_ST_MTIM=0
705 if cmake_try_run "${cmake_cxx_compiler}" \
706 "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAVE_STD" \
707 "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
708 KWSYS_STL_HAVE_STD=1
709 echo "${cmake_cxx_compiler} has STL in std:: namespace"
710 else
711 echo "${cmake_cxx_compiler} does not have STL in std:: namespace"
714 if cmake_try_run "${cmake_cxx_compiler}" \
715 "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_ANSI" \
716 "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
717 KWSYS_IOS_USE_ANSI=1
718 echo "${cmake_cxx_compiler} has ANSI streams"
719 else
720 echo "${cmake_cxx_compiler} does not have ANSI streams"
723 if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
724 if cmake_try_run "${cmake_cxx_compiler}" \
725 "${cmake_cxx_flags} -DTEST_KWSYS_IOS_HAVE_STD" \
726 "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
727 KWSYS_IOS_HAVE_STD=1
728 echo "${cmake_cxx_compiler} has streams in std:: namespace"
729 else
730 echo "${cmake_cxx_compiler} does not have streams in std:: namespace"
732 if cmake_try_run "${cmake_cxx_compiler}" \
733 "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_SSTREAM" \
734 "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
735 KWSYS_IOS_USE_SSTREAM=1
736 echo "${cmake_cxx_compiler} has sstream"
737 else
738 echo "${cmake_cxx_compiler} does not have sstream"
742 if [ "x$KWSYS_IOS_USE_SSTREAM" = "x0" ]; then
743 if cmake_try_run "${cmake_cxx_compiler}" \
744 "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREAM_H" \
745 "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
746 KWSYS_IOS_USE_STRSTREAM_H=1
747 echo "${cmake_cxx_compiler} has strstream.h"
748 else
749 echo "${cmake_cxx_compiler} does not have strstream.h"
751 if [ "x$KWSYS_IOS_USE_STRSTREAM_H" = "x0" ]; then
752 if cmake_try_run "${cmake_cxx_compiler}" \
753 "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREA_H" \
754 "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
755 KWSYS_IOS_USE_STRSTREA_H=1
756 echo "${cmake_cxx_compiler} has strstrea.h"
757 else
758 echo "${cmake_cxx_compiler} does not have strstrea.h"
763 if cmake_try_run "${cmake_cxx_compiler}" \
764 "${cmake_cxx_flags} -DTEST_KWSYS_STAT_HAS_ST_MTIM" \
765 "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
766 KWSYS_STAT_HAS_ST_MTIM=1
767 echo "${cmake_cxx_compiler} has struct stat with st_mtim member"
768 else
769 echo "${cmake_cxx_compiler} does not have struct stat with st_mtim member"
772 # Just to be safe, let us store compiler and flags to the header file
774 cmake_bootstrap_version='$Revision: 1.51 $'
775 cmake_compiler_settings_comment="/*
776 * Generated by ${cmake_source_dir}/bootstrap
777 * Version: ${cmake_bootstrap_version}
779 * Source directory: ${cmake_source_dir}
780 * Binary directory: ${cmake_bootstrap_dir}
782 * C compiler: ${cmake_c_compiler}
783 * C flags: ${cmake_c_flags}
785 * C++ compiler: ${cmake_cxx_compiler}
786 * C++ flags: ${cmake_cxx_flags}
788 * Make: ${cmake_make_processor}
790 * Sources:
791 * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
792 * kwSys Sources:
793 * ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
797 cmake_report cmConfigure.h.tmp "${cmake_compiler_settings_comment}"
799 if [ "x$KWSYS_STL_HAVE_STD" = "x1" ]; then
800 cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_STD_NAMESPACE */"
801 else
802 cmake_report cmConfigure.h.tmp "#define CMAKE_NO_STD_NAMESPACE 1"
805 if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
806 cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STREAM_HEADERS */"
807 else
808 cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STREAM_HEADERS 1"
811 if [ "x$KWSYS_IOS_USE_SSTREAM" = "x1" ]; then
812 cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STRING_STREAM */"
813 else
814 cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STRING_STREAM 1"
817 # Test for ansi FOR scope
818 if cmake_try_run "${cmake_cxx_compiler}" \
819 "${cmake_cxx_flags}" \
820 "${cmake_source_dir}/Modules/TestForAnsiForScope.cxx" >> cmake_bootstrap.log 2>&1; then
821 cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_FOR_SCOPE */"
822 echo "${cmake_cxx_compiler} has ANSI for scoping"
823 else
824 cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_FOR_SCOPE 1"
825 echo "${cmake_cxx_compiler} does not have ANSI for scoping"
828 # Write CMake version
829 for a in MAJOR MINOR PATCH; do
830 CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | \
831 grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
832 cmake_report cmConfigure.h.tmp "#define CMake_VERSION_${a} ${CMake_VERSION}"
833 done
834 cmake_report cmConfigure.h.tmp "#define CMAKE_ROOT_DIR \"${cmake_source_dir}\""
835 cmake_report cmConfigure.h.tmp "#define CMAKE_DATA_DIR \"${cmake_data_dir}\""
836 cmake_report cmConfigure.h.tmp "#define CMAKE_BOOTSTRAP"
838 # Regenerate real cmConfigure.h
839 if diff cmConfigure.h cmConfigure.h.tmp > /dev/null 2> /dev/null; then
840 rm -f cmConfigure.h.tmp
841 else
842 mv -f cmConfigure.h.tmp cmConfigure.h
845 # Prepare KWSYS
846 cmake_kwsys_config_replace_string \
847 "${cmake_source_dir}/Source/kwsys/Configure.hxx.in" \
848 "${cmake_bootstrap_dir}/cmsys/Configure.hxx" \
849 "${cmake_compiler_settings_comment}"
850 cmake_kwsys_config_replace_string \
851 "${cmake_source_dir}/Source/kwsys/Configure.h.in" \
852 "${cmake_bootstrap_dir}/cmsys/Configure.h" \
853 "${cmake_compiler_settings_comment}"
855 for a in ${KWSYS_FILES}; do
856 cmake_replace_string "${cmake_source_dir}/Source/kwsys/${a}.in" \
857 "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
858 done
860 for a in ${KWSYS_IOS_FILES}; do
861 cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_ios_${a}.h.in" \
862 "${cmake_bootstrap_dir}/cmsys/ios/${a}" KWSYS_NAMESPACE cmsys
863 done
865 cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_stl.h.in" \
866 "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" KWSYS_NAMESPACE cmsys
868 for a in string vector map; do
869 cmake_replace_string "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" \
870 "${cmake_bootstrap_dir}/cmsys/stl/${a}" KWSYS_STL_HEADER ${a}
871 done
873 # Generate Makefile
874 dep="cmConfigure.h cmsys/Configure.hxx cmsys/Configure.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
875 objs=""
876 for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
877 objs="${objs} ${a}.o"
878 done
880 # Generate dependencies for cmBootstrapCommands.cxx
881 for file in `grep "#include.*cm[^.]*.cxx" "${cmake_source_dir}/Source/cmBootstrapCommands.cxx" | sed "s/.* \"\(.*\)\"/\1/"`; do
882 cmBootstrapCommandsDeps="${cmBootstrapCommandsDeps} `cmake_escape "${cmake_source_dir}/Source/$file"`"
883 done
884 cmBootstrapCommandsDeps=`echo $cmBootstrapCommandsDeps`
886 if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
887 cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
890 if [ "x${cmake_c_flags}" != "x" ]; then
891 cmake_c_flags="${cmake_c_flags} "
894 if [ "x${cmake_cxx_flags}" != "x" ]; then
895 cmake_cxx_flags="${cmake_cxx_flags} "
898 cmake_c_flags="${cmake_c_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
899 -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
900 cmake_cxx_flags="${cmake_cxx_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
901 -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
902 echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
903 echo " ${cmake_cxx_compiler} ${LDFLAGS} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
904 for a in ${CMAKE_CXX_SOURCES}; do
905 src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
906 echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
907 echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
908 done
909 echo "cmBootstrapCommands.o : $cmBootstrapCommandsDeps" >> "${cmake_bootstrap_dir}/Makefile"
910 for a in ${CMAKE_C_SOURCES}; do
911 src=`cmake_escape "${cmake_source_dir}/Source/${a}.c"`
912 echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
913 echo " ${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
914 done
915 for a in ${KWSYS_C_SOURCES}; do
916 src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.c"`
917 echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
918 echo " ${cmake_c_compiler} ${cmake_c_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
919 done
920 for a in ${KWSYS_CXX_SOURCES}; do
921 src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.cxx"`
922 echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
923 echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
924 done
925 cat>>"${cmake_bootstrap_dir}/Makefile"<<EOF
926 rebuild_cache:
927 cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
930 # Write our default settings to Bootstrap.cmk/InitialCacheFlags.cmake.
931 cat > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake" <<EOF
932 # Generated by ${cmake_source_dir}/bootstrap
933 # Default cmake settings. These may be overridden any settings below.
934 SET (CMAKE_INSTALL_PREFIX "${cmake_prefix_dir}" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
935 SET (CMAKE_DOC_DIR "${cmake_doc_dir}" CACHE PATH "Install location for documentation (relative to prefix)." FORCE)
936 SET (CMAKE_MAN_DIR "${cmake_man_dir}" CACHE PATH "Install location for man pages (relative to prefix)." FORCE)
937 SET (CMAKE_DATA_DIR "${cmake_data_dir}" CACHE PATH "Install location for data (relative to prefix)." FORCE)
940 # Add user-specified settings. Handle relative-path case for
941 # specification of cmake_init_file.
943 cd "${cmake_binary_dir}"
944 if [ -f "${cmake_init_file}" ]; then
945 cat "${cmake_init_file}" >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
949 echo "---------------------------------------------"
951 # Run make to build bootstrap cmake
952 if [ "x${cmake_parallel_make}" != "x" ]; then
953 ${cmake_make_processor} ${cmake_make_flags}
954 else
955 ${cmake_make_processor}
957 RES=$?
958 if [ "${RES}" -ne "0" ]; then
959 cmake_error 9 "Problem while running ${cmake_make_processor}"
961 cd "${cmake_binary_dir}"
963 # Set C, CXX, and MAKE environment variables, so that real real cmake will be
964 # build with same compiler and make
965 CC="${cmake_c_compiler}"
966 CXX="${cmake_cxx_compiler}"
967 MAKE="${cmake_make_processor}"
968 export CC
969 export CXX
970 export MAKE
972 # Run bootstrap CMake to configure real CMake
973 "${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
974 RES=$?
975 if [ "${RES}" -ne "0" ]; then
976 cmake_error 11 "Problem while running initial CMake"
979 echo "---------------------------------------------"
981 # And we are done. Now just run make
982 echo "CMake has bootstrapped. Now run ${cmake_make_processor}."