bootstrap 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. #!/bin/sh
  2. #=========================================================================
  3. #
  4. # Program: CMake - Cross-Platform Makefile Generator
  5. # Module: $RCSfile$
  6. # Language: Bourne Shell
  7. # Date: $Date$
  8. # Version: $Revision$
  9. #
  10. # Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  11. # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  12. #
  13. # This software is distributed WITHOUT ANY WARRANTY; without even
  14. # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. # PURPOSE. See the above copyright notices for more information.
  16. #
  17. #=========================================================================
  18. CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
  19. CMAKE_KNOWN_CXX_COMPILERS="CC g++ c++ xlC icc como aCC"
  20. CMAKE_KNOWN_MAKE_PROCESSORS="make gmake"
  21. CMAKE_CXX_SOURCES="\
  22. cmake \
  23. cmakewizard \
  24. cmakemain \
  25. cmMakeDepend \
  26. cmMakefile \
  27. cmDocumentation \
  28. cmGlob \
  29. cmGlobalGenerator \
  30. cmLocalGenerator \
  31. cmSourceFile \
  32. cmSystemTools \
  33. cmGlobalUnixMakefileGenerator \
  34. cmLocalUnixMakefileGenerator \
  35. cmCommands \
  36. cmTarget \
  37. cmCustomCommand \
  38. cmCacheManager \
  39. cmListFileCache \
  40. cmVariableWatch \
  41. cmSourceGroup"
  42. CMAKE_C_SOURCES="\
  43. cmListFileLexer \
  44. "
  45. KWSYS_C_SOURCES="\
  46. ProcessUNIX"
  47. KWSYS_CXX_SOURCES="\
  48. Directory \
  49. RegularExpression \
  50. SystemTools"
  51. KWSYS_FILES="\
  52. Directory.hxx \
  53. Process.h \
  54. RegularExpression.hxx \
  55. SystemTools.hxx"
  56. KWSYS_IOS_FILES="
  57. fstream \
  58. iosfwd \
  59. iostream \
  60. sstream"
  61. cmake_system=`uname`
  62. cmake_source_dir=`echo $0 | sed -n '/\//{s/\/[^\/]*$//;p;}'`
  63. cmake_source_dir=`(cd "${cmake_source_dir}";pwd)`
  64. cmake_binary_dir=`pwd`
  65. cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap.cmk"
  66. cmake_data_dir="/share/CMake"
  67. cmake_doc_dir="/doc/CMake"
  68. cmake_man_dir="/man"
  69. cmake_init_file=""
  70. # Display CMake bootstrap usage
  71. cmake_usage()
  72. {
  73. cat <<EOF
  74. Usage: $0 [options]
  75. Options: [defaults in brackets after descriptions]
  76. Configuration:
  77. --help print this message
  78. --version only print version information
  79. --verbose display more information
  80. --parallel=n bootstrap cmake in parallel, where n is
  81. number of nodes [1]
  82. --init=FILE use FILE for cmake initialization
  83. Directory and file names:
  84. --prefix=PREFIX install files in tree rooted at PREFIX
  85. [/usr/local]
  86. --datadir=DIR install data files in PREFIX/DIR
  87. [/share/CMake]
  88. --docdir=DIR install documentation files in PREFIX/DIR
  89. [/doc/CMake]
  90. --mandir=DIR install man pages files in PREFIX/DIR/manN
  91. [/man]
  92. EOF
  93. exit 10
  94. }
  95. # Display CMake bootstrap usage
  96. cmake_version()
  97. {
  98. # Get CMake version
  99. CMAKE_VERSION=""
  100. for a in MAJOR MINOR PATCH; do
  101. CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | \
  102. grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
  103. CMAKE_VERSION="${CMAKE_VERSION}.${CMake_VERSION}"
  104. done
  105. CMAKE_VERSION=`echo $CMAKE_VERSION | sed "s/\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)/\1.\2-\3/"`
  106. echo "CMake ${CMAKE_VERSION}, Copyright (c) 2002 Kitware, Inc., Insight Consortium"
  107. }
  108. # Display CMake bootstrap error, display the log file and exit
  109. cmake_error()
  110. {
  111. res=$1
  112. shift 1
  113. echo "---------------------------------------------"
  114. echo "Error when bootstrapping CMake:"
  115. echo "$*"
  116. echo "---------------------------------------------"
  117. if [ -f cmake_bootstrap.log ]; then
  118. echo "Log of errors: `pwd`/cmake_bootstrap.log"
  119. #cat cmake_bootstrap.log
  120. echo "---------------------------------------------"
  121. fi
  122. exit ${res}
  123. }
  124. # Replace KWSYS_NAMESPACE with cmsys
  125. cmake_replace_string ()
  126. {
  127. INFILE="$1"
  128. OUTFILE="$2"
  129. SEARCHFOR="$3"
  130. REPLACEWITH="$4"
  131. if [ -f "${INFILE}" ]; then
  132. cat "${INFILE}" |
  133. sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}.tmp"
  134. if [ -f "${OUTFILE}.tmp" ]; then
  135. if diff "${OUTFILE}" "${OUTFILE}.tmp" > /dev/null 2> /dev/null ; then
  136. #echo "Files are the same"
  137. rm -f "${OUTFILE}.tmp"
  138. else
  139. mv -f "${OUTFILE}.tmp" "${OUTFILE}"
  140. fi
  141. fi
  142. else
  143. cmake_error 1 "Cannot find file ${INFILE}"
  144. fi
  145. }
  146. cmake_kwsys_config_replace_string ()
  147. {
  148. INFILE="$1"
  149. OUTFILE="$2"
  150. shift 2
  151. APPEND="$*"
  152. if [ -f "${INFILE}" ]; then
  153. echo "${APPEND}" > "${OUTFILE}.tmp"
  154. cat "${INFILE}" |
  155. sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
  156. s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
  157. s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
  158. s/@KWSYS_IOS_USE_ANSI@/${KWSYS_IOS_USE_ANSI}/g;
  159. s/@KWSYS_IOS_HAVE_STD@/${KWSYS_IOS_HAVE_STD}/g;
  160. s/@KWSYS_IOS_USE_SSTREAM@/${KWSYS_IOS_USE_SSTREAM}/g;
  161. s/@KWSYS_IOS_USE_STRSTREAM_H@/${KWSYS_IOS_USE_STRSTREAM_H}/g;
  162. s/@KWSYS_IOS_USE_STRSTREA_H@/${KWSYS_IOS_USE_STRSTREA_H}/g;
  163. s/@KWSYS_STL_HAVE_STD@/${KWSYS_STL_HAVE_STD}/g;}" >> "${OUTFILE}.tmp"
  164. if [ -f "${OUTFILE}.tmp" ]; then
  165. if diff "${OUTFILE}" "${OUTFILE}.tmp" > /dev/null 2> /dev/null ; then
  166. #echo "Files are the same"
  167. rm -f "${OUTFILE}.tmp"
  168. else
  169. mv -f "${OUTFILE}.tmp" "${OUTFILE}"
  170. fi
  171. fi
  172. else
  173. cmake_error 2 "Cannot find file ${INFILE}"
  174. fi
  175. }
  176. # Write string into a file
  177. cmake_report ()
  178. {
  179. FILE=$1
  180. shift
  181. echo "$*" >> ${FILE}
  182. }
  183. # Escape spaces in strings
  184. cmake_escape ()
  185. {
  186. echo $1 | sed "s/ /\\\\ /g"
  187. }
  188. # Write message to the log
  189. cmake_log ()
  190. {
  191. echo "$*" >> cmake_bootstrap.log
  192. }
  193. # Return temp file
  194. cmake_tmp_file ()
  195. {
  196. echo "cmake_bootstrap_$$.test"
  197. }
  198. # Run a compiler test. First argument is compiler, second one are compiler
  199. # flags, third one is test source file to be compiled
  200. cmake_try_run ()
  201. {
  202. COMPILER=$1
  203. FLAGS=$2
  204. TESTFILE=$3
  205. if [ ! -f "${TESTFILE}" ]; then
  206. echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
  207. exit 4
  208. fi
  209. TMPFILE=`cmake_tmp_file`
  210. echo "Try: ${COMPILER}"
  211. echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
  212. echo "---------- file -----------------------"
  213. cat ${TESTFILE}
  214. echo "------------------------------------------"
  215. "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  216. RES=$?
  217. if [ "${RES}" -ne "0" ]; then
  218. echo "Test failed to compile"
  219. return 1
  220. fi
  221. if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
  222. echo "Test failed to produce executable"
  223. return 2
  224. fi
  225. ./${TMPFILE}
  226. RES=$?
  227. rm -f "${TMPFILE}"
  228. if [ "${RES}" -ne "0" ]; then
  229. echo "Test produced non-zero return code"
  230. return 3
  231. fi
  232. echo "Test succeded"
  233. return 0
  234. }
  235. # Run a make test. First argument is the make interpreter.
  236. cmake_try_make ()
  237. {
  238. MAKE_PROC="$1"
  239. MAKE_FLAGS="$2"
  240. echo "Try: ${MAKE_PROC}"
  241. "${MAKE_PROC}" ${MAKE_FLAGS}
  242. RES=$?
  243. if [ "${RES}" -ne "0" ]; then
  244. echo "${MAKE_PROC} does not work"
  245. return 1
  246. fi
  247. if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
  248. echo "${COMPILER} does not produce output"
  249. return 2
  250. fi
  251. ./test
  252. RES=$?
  253. rm -f "test"
  254. if [ "${RES}" -ne "0" ]; then
  255. echo "${MAKE_PROC} produces strange executable"
  256. return 3
  257. fi
  258. echo "${MAKE_PROC} works"
  259. return 0
  260. }
  261. # Parse arguments
  262. cmake_verbose=
  263. cmake_parallel_make=
  264. cmake_prefix_dir="/usr/local"
  265. for a in "$@"; do
  266. if echo $a | grep "^--prefix=" > /dev/null 2> /dev/null; then
  267. cmake_prefix_dir=`echo $a | sed "s/^--prefix=//"`
  268. fi
  269. if echo $a | grep "^--parallel=" > /dev/null 2> /dev/null; then
  270. cmake_parallel_make=`echo $a | sed "s/^--parallel=//" | grep "[0-9][0-9]*"`
  271. fi
  272. if echo $a | grep "^--datadir=" > /dev/null 2> /dev/null; then
  273. cmake_data_dir=`echo $a | sed "s/^--datadir=//"`
  274. fi
  275. if echo $a | grep "^--docdir=" > /dev/null 2> /dev/null; then
  276. cmake_doc_dir=`echo $a | sed "s/^--docdir=//"`
  277. fi
  278. if echo $a | grep "^--mandir=" > /dev/null 2> /dev/null; then
  279. cmake_man_dir=`echo $a | sed "s/^--mandir=//"`
  280. fi
  281. if echo $a | grep "^--init=" > /dev/null 2> /dev/null; then
  282. cmake_init_file=`echo $a | sed "s/^--init=//"`
  283. fi
  284. if echo $a | grep "^--help" > /dev/null 2> /dev/null; then
  285. cmake_usage
  286. fi
  287. if echo $a | grep "^--version" > /dev/null 2> /dev/null; then
  288. cmake_version
  289. exit 2
  290. fi
  291. if echo $a | grep "^--verbose" > /dev/null 2> /dev/null; then
  292. cmake_verbose=TRUE
  293. fi
  294. done
  295. # If verbose, display some information about bootstrap
  296. if [ -n "${cmake_verbose}" ]; then
  297. echo "---------------------------------------------"
  298. echo "Source directory: ${cmake_source_dir}"
  299. echo "Binary directory: ${cmake_binary_dir}"
  300. echo "Prefix directory: ${cmake_prefix_dir}"
  301. echo "System: ${cmake_system}"
  302. if [ "x${cmake_parallel_make}" != "x" ]; then
  303. echo "Doing parallel make: ${cmake_parallel_make}"
  304. fi
  305. echo ""
  306. fi
  307. echo "---------------------------------------------"
  308. # Get CMake version
  309. echo "`cmake_version`"
  310. # Make bootstrap directory
  311. [ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
  312. if [ ! -d "${cmake_bootstrap_dir}" ]; then
  313. cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
  314. fi
  315. cd "${cmake_bootstrap_dir}"
  316. [ -d "cmsys" ] || mkdir "cmsys"
  317. if [ ! -d "cmsys" ]; then
  318. cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
  319. fi
  320. for a in stl ios; do
  321. [ -d "cmsys/${a}" ] || mkdir "cmsys/${a}"
  322. if [ ! -d "cmsys/${a}" ]; then
  323. cmake_error 5 "Cannot create directory ${cmake_bootstrap_dir}/cmsys/${a}"
  324. fi
  325. done
  326. # Delete all the bootstrap files
  327. rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
  328. rm -f "${cmake_bootstrap_dir}/cmConfigure.h.tmp"
  329. # If exist compiler flags, set them
  330. cmake_c_flags=${CFLAGS}
  331. cmake_cxx_flags=${CXXFLAGS}
  332. # Test C compiler
  333. cmake_c_compiler=
  334. # If CC is set, use that for compiler, otherwise use list of known compilers
  335. if [ -n "${CC}" ]; then
  336. cmake_c_compilers="${CC}"
  337. else
  338. cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
  339. fi
  340. # Check if C compiler works
  341. TMPFILE=`cmake_tmp_file`
  342. cat > "${TMPFILE}.c" <<EOF
  343. #include<stdio.h>
  344. int main()
  345. {
  346. printf("1\n");
  347. return 0;
  348. }
  349. EOF
  350. for a in ${cmake_c_compilers}; do
  351. if [ -z "${cmake_c_compiler}" ] && \
  352. cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  353. cmake_c_compiler="${a}"
  354. fi
  355. done
  356. rm -f "${TMPFILE}.c"
  357. if [ -z "${cmake_c_compiler}" ]; then
  358. cmake_error 6 "Cannot find appropriate C compiler on this system.
  359. Please specify one using environment variable CC."
  360. fi
  361. echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
  362. # Test CXX compiler
  363. cmake_cxx_compiler=
  364. # On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.
  365. # If CC is set, use that for compiler, otherwise use list of known compilers
  366. if [ -n "${CXX}" ]; then
  367. cmake_cxx_compilers="${CXX}"
  368. else
  369. cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
  370. fi
  371. # Check if C++ compiler works
  372. TMPFILE=`cmake_tmp_file`
  373. cat > "${TMPFILE}.cxx" <<EOF
  374. #if defined(TEST1)
  375. # include <iostream>
  376. #else
  377. # include <iostream.h>
  378. #endif
  379. class NeedCXX
  380. {
  381. public:
  382. NeedCXX() { this->Foo = 1; }
  383. int GetFoo() { return this->Foo; }
  384. private:
  385. int Foo;
  386. };
  387. int main()
  388. {
  389. NeedCXX c;
  390. #ifdef TEST3
  391. cout << c.GetFoo() << endl;
  392. #else
  393. std::cout << c.GetFoo() << std::endl;
  394. #endif
  395. return 0;
  396. }
  397. EOF
  398. for a in ${cmake_cxx_compilers}; do
  399. for b in 1 2 3; do
  400. if [ -z "${cmake_cxx_compiler}" ] && \
  401. cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  402. cmake_cxx_compiler="${a}"
  403. fi
  404. done
  405. done
  406. rm -f "${TMPFILE}.cxx"
  407. if [ -z "${cmake_cxx_compiler}" ]; then
  408. cmake_error 7 "Cannot find appropriate C++ compiler on this system.
  409. Please specify one using environment variable CXX."
  410. fi
  411. echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
  412. # Test Make
  413. cmake_make_processor=
  414. cmake_make_flags=
  415. # If MAKE is set, use that for make processor, otherwise use list of known make
  416. if [ -n "${MAKE}" ]; then
  417. cmake_make_processors="${MAKE}"
  418. else
  419. cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
  420. fi
  421. TMPFILE="`cmake_tmp_file`_dir"
  422. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  423. mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
  424. cd "${cmake_bootstrap_dir}/${TMPFILE}"
  425. cat>"Makefile"<<EOF
  426. test: test.c
  427. "${cmake_c_compiler}" -o test test.c
  428. EOF
  429. cat>"test.c"<<EOF
  430. #include <stdio.h>
  431. int main(){ printf("1\n"); return 0; }
  432. EOF
  433. cmake_original_make_flags="${cmake_make_flags}"
  434. if [ "x${cmake_parallel_make}" != "x" ]; then
  435. cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
  436. fi
  437. for a in ${cmake_make_processors}; do
  438. if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
  439. cmake_make_processor="${a}"
  440. fi
  441. done
  442. cmake_full_make_flags="${cmake_make_flags}"
  443. if [ "x${cmake_original_make_flags}" != "x${cmake_make_flags}" ]; then
  444. if [ -z "${cmake_make_processor}" ]; then
  445. cmake_make_flags="${cmake_original_make_flags}"
  446. for a in ${cmake_make_processors}; do
  447. if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
  448. cmake_make_processor="${a}"
  449. fi
  450. done
  451. fi
  452. fi
  453. cd "${cmake_bootstrap_dir}"
  454. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  455. if [ -z "${cmake_make_processor}" ]; then
  456. cmake_error 8 "Cannot find appropriate Makefile processor on this system.
  457. Please specify one using environment variable MAKE."
  458. fi
  459. echo "Makefile processor on this system is: ${cmake_make_processor}"
  460. if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
  461. echo "---------------------------------------------"
  462. echo "Makefile processor ${cmake_make_processor} does not support parallel build"
  463. echo "---------------------------------------------"
  464. fi
  465. # Ok, we have CC, CXX, and MAKE.
  466. # Test C++ compiler features
  467. # Are we GCC?
  468. TMPFILE=`cmake_tmp_file`
  469. cat > ${TMPFILE}.cxx <<EOF
  470. #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
  471. #include <iostream>
  472. int main() { std::cout << "This is GNU" << std::endl; return 0;}
  473. #endif
  474. EOF
  475. cmake_cxx_compiler_is_gnu=0
  476. if cmake_try_run "${cmake_cxx_compiler}" \
  477. "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  478. cmake_cxx_compiler_is_gnu=1
  479. fi
  480. if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then
  481. echo "${cmake_cxx_compiler} is GNU compiler"
  482. else
  483. echo "${cmake_cxx_compiler} is not GNU compiler"
  484. fi
  485. rm -f "${TMPFILE}.cxx"
  486. if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
  487. # Check for non-GNU compiler flags
  488. # If we are on IRIX, check for -LANG:std
  489. cmake_test_flags="-LANG:std"
  490. if [ "x${cmake_system}" = "xIRIX64" ]; then
  491. TMPFILE=`cmake_tmp_file`
  492. cat > ${TMPFILE}.cxx <<EOF
  493. #include <iostream>
  494. int main() { std::cout << "No need for ${cmake_test_flags}" << std::endl; return 0;}
  495. EOF
  496. cmake_need_lang_std=0
  497. if cmake_try_run "${cmake_cxx_compiler}" \
  498. "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  499. :
  500. else
  501. if cmake_try_run "${cmake_cxx_compiler}" \
  502. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  503. cmake_need_lang_std=1
  504. fi
  505. fi
  506. if [ "x${cmake_need_lang_std}" = "x1" ]; then
  507. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  508. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  509. else
  510. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  511. fi
  512. rm -f "${TMPFILE}.cxx"
  513. fi
  514. cmake_test_flags=
  515. # If we are on OSF, check for -timplicit_local -no_implicit_include
  516. cmake_test_flags="-timplicit_local -no_implicit_include"
  517. if [ "x${cmake_system}" = "xOSF1" ]; then
  518. TMPFILE=`cmake_tmp_file`
  519. cat > ${TMPFILE}.cxx <<EOF
  520. #include <iostream>
  521. int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
  522. EOF
  523. cmake_need_flags=1
  524. if cmake_try_run "${cmake_cxx_compiler}" \
  525. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  526. :
  527. else
  528. cmake_need_flags=0
  529. fi
  530. if [ "x${cmake_need_flags}" = "x1" ]; then
  531. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  532. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  533. else
  534. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  535. fi
  536. rm -f "${TMPFILE}.cxx"
  537. fi
  538. cmake_test_flags=
  539. # If we are on OSF, check for -std strict_ansi -nopure_cname
  540. cmake_test_flags="-std strict_ansi -nopure_cname"
  541. if [ "x${cmake_system}" = "xOSF1" ]; then
  542. TMPFILE=`cmake_tmp_file`
  543. cat > ${TMPFILE}.cxx <<EOF
  544. #include <iostream>
  545. int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
  546. EOF
  547. cmake_need_flags=1
  548. if cmake_try_run "${cmake_cxx_compiler}" \
  549. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  550. :
  551. else
  552. cmake_need_flags=0
  553. fi
  554. if [ "x${cmake_need_flags}" = "x1" ]; then
  555. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  556. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  557. else
  558. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  559. fi
  560. rm -f "${TMPFILE}.cxx"
  561. fi
  562. cmake_test_flags=
  563. # If we are on HP-UX, check for -Ae for the C compiler.
  564. cmake_test_flags="-Ae"
  565. if [ "x${cmake_system}" = "xHP-UX" ]; then
  566. TMPFILE=`cmake_tmp_file`
  567. cat > ${TMPFILE}.c <<EOF
  568. int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
  569. EOF
  570. cmake_need_Ae=0
  571. if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  572. :
  573. else
  574. if cmake_try_run "${cmake_c_compiler}" \
  575. "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  576. cmake_need_Ae=1
  577. fi
  578. fi
  579. if [ "x${cmake_need_Ae}" = "x1" ]; then
  580. cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
  581. echo "${cmake_c_compiler} needs ${cmake_test_flags}"
  582. else
  583. echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
  584. fi
  585. rm -f "${TMPFILE}.c"
  586. fi
  587. cmake_test_flags=
  588. fi
  589. # Test for kwsys features
  590. KWSYS_NAME_IS_KWSYS=0
  591. KWSYS_BUILD_SHARED=0
  592. KWSYS_IOS_USE_STRSTREAM_H=0
  593. KWSYS_IOS_USE_STRSTREA_H=0
  594. KWSYS_IOS_HAVE_STD=0
  595. KWSYS_IOS_USE_SSTREAM=0
  596. KWSYS_IOS_USE_ANSI=0
  597. KWSYS_STL_HAVE_STD=0
  598. if cmake_try_run "${cmake_cxx_compiler}" \
  599. "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAVE_STD" \
  600. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  601. KWSYS_STL_HAVE_STD=1
  602. echo "${cmake_cxx_compiler} has STL in std:: namespace"
  603. else
  604. echo "${cmake_cxx_compiler} does not have STL in std:: namespace"
  605. fi
  606. if cmake_try_run "${cmake_cxx_compiler}" \
  607. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_ANSI" \
  608. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  609. KWSYS_IOS_USE_ANSI=1
  610. echo "${cmake_cxx_compiler} has ANSI streams"
  611. else
  612. echo "${cmake_cxx_compiler} does not have ANSI streams"
  613. fi
  614. if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
  615. if cmake_try_run "${cmake_cxx_compiler}" \
  616. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_HAVE_STD" \
  617. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  618. KWSYS_IOS_HAVE_STD=1
  619. echo "${cmake_cxx_compiler} has streams in std:: namespace"
  620. else
  621. echo "${cmake_cxx_compiler} does not have streams in std:: namespace"
  622. fi
  623. if cmake_try_run "${cmake_cxx_compiler}" \
  624. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_SSTREAM" \
  625. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  626. KWSYS_IOS_USE_SSTREAM=1
  627. echo "${cmake_cxx_compiler} has sstream"
  628. else
  629. echo "${cmake_cxx_compiler} does not have sstream"
  630. fi
  631. fi
  632. if [ "x$KWSYS_IOS_USE_SSTREAM" = "x0" ]; then
  633. if cmake_try_run "${cmake_cxx_compiler}" \
  634. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREAM_H" \
  635. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  636. KWSYS_IOS_USE_STRSTREAM_H=1
  637. echo "${cmake_cxx_compiler} has strstream.h"
  638. else
  639. echo "${cmake_cxx_compiler} does not have strstream.h"
  640. fi
  641. if [ "x$KWSYS_IOS_USE_STRSTREAM_H" = "x0" ]; then
  642. if cmake_try_run "${cmake_cxx_compiler}" \
  643. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREA_H" \
  644. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  645. KWSYS_IOS_USE_STRSTREA_H=1
  646. echo "${cmake_cxx_compiler} has strstrea.h"
  647. else
  648. echo "${cmake_cxx_compiler} does not have strstrea.h"
  649. fi
  650. fi
  651. fi
  652. # Just to be safe, let us store compiler and flags to the header file
  653. cmake_bootstrap_version='$Revision$'
  654. cmake_compiler_settings_comment="/*
  655. * Generated by ${cmake_source_dir}/bootstrap
  656. * Version: ${cmake_bootstrap_version}
  657. *
  658. * Source directory: ${cmake_source_dir}
  659. * Binary directory: ${cmake_bootstrap_dir}
  660. *
  661. * C compiler: ${cmake_c_compiler}
  662. * C flags: ${cmake_c_flags}
  663. *
  664. * C++ compiler: ${cmake_cxx_compiler}
  665. * C++ flags: ${cmake_cxx_flags}
  666. *
  667. * Make: ${cmake_make_processor}
  668. *
  669. * Sources:
  670. * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
  671. * kwSys Sources:
  672. * ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
  673. */
  674. "
  675. cmake_report cmConfigure.h.tmp "${cmake_compiler_settings_comment}"
  676. if [ "x$KWSYS_STL_HAVE_STD" = "x1" ]; then
  677. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_STD_NAMESPACE */"
  678. else
  679. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_STD_NAMESPACE 1"
  680. fi
  681. if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
  682. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STREAM_HEADERS */"
  683. else
  684. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STREAM_HEADERS 1"
  685. fi
  686. if [ "x$KWSYS_IOS_USE_SSTREAM" = "x1" ]; then
  687. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STRING_STREAM */"
  688. else
  689. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STRING_STREAM 1"
  690. fi
  691. # Test for ansi FOR scope
  692. if cmake_try_run "${cmake_cxx_compiler}" \
  693. "${cmake_cxx_flags}" \
  694. "${cmake_source_dir}/Modules/TestForAnsiForScope.cxx" >> cmake_bootstrap.log 2>&1; then
  695. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_FOR_SCOPE */"
  696. echo "${cmake_cxx_compiler} has ANSI for scoping"
  697. else
  698. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_FOR_SCOPE 1"
  699. echo "${cmake_cxx_compiler} does not have ANSI for scoping"
  700. fi
  701. # Write CMake version
  702. for a in MAJOR MINOR PATCH; do
  703. CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | \
  704. grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
  705. cmake_report cmConfigure.h.tmp "#define CMake_VERSION_${a} ${CMake_VERSION}"
  706. done
  707. cmake_report cmConfigure.h.tmp "#define CMAKE_ROOT_DIR \"${cmake_source_dir}\""
  708. cmake_report cmConfigure.h.tmp "#define CMAKE_DATA_DIR \"${cmake_data_dir}\""
  709. cmake_report cmConfigure.h.tmp "#define CMAKE_BOOTSTRAP"
  710. # Regenerate real cmConfigure.h
  711. if diff cmConfigure.h cmConfigure.h.tmp > /dev/null 2> /dev/null; then
  712. rm -f cmConfigure.h.tmp
  713. else
  714. mv -f cmConfigure.h.tmp cmConfigure.h
  715. fi
  716. # Prepare KWSYS
  717. cmake_kwsys_config_replace_string \
  718. "${cmake_source_dir}/Source/kwsys/Configure.hxx.in" \
  719. "${cmake_bootstrap_dir}/cmsys/Configure.hxx" \
  720. "${cmake_compiler_settings_comment}"
  721. cmake_kwsys_config_replace_string \
  722. "${cmake_source_dir}/Source/kwsys/Configure.h.in" \
  723. "${cmake_bootstrap_dir}/cmsys/Configure.h" \
  724. "${cmake_compiler_settings_comment}"
  725. for a in ${KWSYS_FILES}; do
  726. cmake_replace_string "${cmake_source_dir}/Source/kwsys/${a}.in" \
  727. "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
  728. done
  729. for a in ${KWSYS_IOS_FILES}; do
  730. cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_ios_${a}.h.in" \
  731. "${cmake_bootstrap_dir}/cmsys/ios/${a}" KWSYS_NAMESPACE cmsys
  732. done
  733. cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_stl.h.in" \
  734. "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" KWSYS_NAMESPACE cmsys
  735. for a in string vector map; do
  736. cmake_replace_string "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" \
  737. "${cmake_bootstrap_dir}/cmsys/stl/${a}" KWSYS_STL_HEADER ${a}
  738. done
  739. # Generate Makefile
  740. dep="cmConfigure.h cmsys/Configure.hxx cmsys/Configure.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
  741. objs=""
  742. for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
  743. objs="${objs} ${a}.o"
  744. done
  745. if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
  746. cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
  747. fi
  748. if [ "x${cmake_c_flags}" != "x" ]; then
  749. cmake_c_flags="${cmake_c_flags} "
  750. fi
  751. if [ "x${cmake_cxx_flags}" != "x" ]; then
  752. cmake_cxx_flags="${cmake_cxx_flags} "
  753. fi
  754. cmake_c_flags="${cmake_c_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
  755. -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
  756. cmake_cxx_flags="${cmake_cxx_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
  757. -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
  758. echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
  759. echo " ${cmake_cxx_compiler} ${LDFLAGS} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
  760. for a in ${CMAKE_CXX_SOURCES}; do
  761. src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
  762. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  763. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  764. done
  765. for a in ${CMAKE_C_SOURCES}; do
  766. src=`cmake_escape "${cmake_source_dir}/Source/${a}.c"`
  767. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  768. echo " ${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  769. done
  770. for a in ${KWSYS_C_SOURCES}; do
  771. src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.c"`
  772. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  773. echo " ${cmake_c_compiler} ${cmake_c_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  774. done
  775. for a in ${KWSYS_CXX_SOURCES}; do
  776. src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.cxx"`
  777. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  778. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  779. done
  780. cat>>"${cmake_bootstrap_dir}/Makefile"<<EOF
  781. rebuild_cache:
  782. cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
  783. EOF
  784. # Write our default settings to Bootstrap.cmk/InitialCacheFlags.cmake.
  785. cat > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake" <<EOF
  786. # Generated by ${cmake_source_dir}/bootstrap
  787. # Default cmake settings. These may be overridden any settings below.
  788. SET (CMAKE_INSTALL_PREFIX "${cmake_prefix_dir}" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
  789. SET (CMAKE_DOC_DIR "${cmake_doc_dir}" CACHE PATH "Install location for documentation (relative to prefix)." FORCE)
  790. SET (CMAKE_MAN_DIR "${cmake_man_dir}" CACHE PATH "Install location for man pages (relative to prefix)." FORCE)
  791. SET (CMAKE_DATA_DIR "${cmake_data_dir}" CACHE PATH "Install location for data (relative to prefix)." FORCE)
  792. EOF
  793. # Add user-specified settings. Handle relative-path case for
  794. # specification of cmake_init_file.
  795. (
  796. cd "${cmake_binary_dir}"
  797. if [ -f "${cmake_init_file}" ]; then
  798. cat "${cmake_init_file}" >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
  799. fi
  800. )
  801. echo "---------------------------------------------"
  802. # Run make to build bootstrap cmake
  803. if [ "x${cmake_parallel_make}" != "x" ]; then
  804. ${cmake_make_processor} ${cmake_make_flags}
  805. else
  806. ${cmake_make_processor}
  807. fi
  808. RES=$?
  809. if [ "${RES}" -ne "0" ]; then
  810. cmake_error 9 "Problem while running ${cmake_make_processor}"
  811. fi
  812. cd "${cmake_binary_dir}"
  813. # Set C, CXX, and MAKE environment variables, so that real real cmake will be
  814. # build with same compiler and make
  815. CC="${cmake_c_compiler}"
  816. CXX="${cmake_cxx_compiler}"
  817. MAKE="${cmake_make_processor}"
  818. export CC
  819. export CXX
  820. export MAKE
  821. # Run bootstrap CMake to configure real CMake
  822. "${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
  823. echo "---------------------------------------------"
  824. # And we are done. Now just run make
  825. echo "CMake has bootstrapped. Now run ${cmake_make_processor}."