bootstrap 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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. if [ "x${cmake_parallel_make}" != "x" ]; then
  434. cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
  435. fi
  436. for a in ${cmake_make_processors}; do
  437. if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
  438. cmake_make_processor="${a}"
  439. fi
  440. done
  441. cd "${cmake_bootstrap_dir}"
  442. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  443. if [ -z "${cmake_make_processor}" ]; then
  444. cmake_error 8 "Cannot find appropriate Makefile processor on this system.
  445. Please specify one using environment variable MAKE."
  446. fi
  447. echo "Make processor on this system is: ${cmake_make_processor}"
  448. # Ok, we have CC, CXX, and MAKE.
  449. # Test C++ compiler features
  450. # If we are on IRIX, check for -LANG:std
  451. cmake_test_flags="-LANG:std"
  452. if [ "x${cmake_system}" = "xIRIX64" ]; then
  453. TMPFILE=`cmake_tmp_file`
  454. cat > ${TMPFILE}.cxx <<EOF
  455. #include <iostream>
  456. int main() { std::cout << "No need for ${cmake_test_flags}" << std::endl; return 0;}
  457. EOF
  458. cmake_need_lang_std=0
  459. if cmake_try_run "${cmake_cxx_compiler}" \
  460. "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  461. :
  462. else
  463. if cmake_try_run "${cmake_cxx_compiler}" \
  464. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  465. cmake_need_lang_std=1
  466. fi
  467. fi
  468. if [ "x${cmake_need_lang_std}" = "x1" ]; then
  469. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  470. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  471. else
  472. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  473. fi
  474. rm -f "${TMPFILE}.cxx"
  475. fi
  476. cmake_test_flags=
  477. # If we are on OSF, check for -timplicit_local -no_implicit_include
  478. cmake_test_flags="-timplicit_local -no_implicit_include"
  479. if [ "x${cmake_system}" = "xOSF1" ]; then
  480. TMPFILE=`cmake_tmp_file`
  481. cat > ${TMPFILE}.cxx <<EOF
  482. #include <iostream>
  483. int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
  484. EOF
  485. cmake_need_flags=1
  486. if cmake_try_run "${cmake_cxx_compiler}" \
  487. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  488. :
  489. else
  490. cmake_need_flags=0
  491. fi
  492. if [ "x${cmake_need_flags}" = "x1" ]; then
  493. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  494. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  495. else
  496. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  497. fi
  498. rm -f "${TMPFILE}.cxx"
  499. fi
  500. cmake_test_flags=
  501. # If we are on OSF, check for -std strict_ansi -nopure_cname
  502. cmake_test_flags="-std strict_ansi -nopure_cname"
  503. if [ "x${cmake_system}" = "xOSF1" ]; then
  504. TMPFILE=`cmake_tmp_file`
  505. cat > ${TMPFILE}.cxx <<EOF
  506. #include <iostream>
  507. int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
  508. EOF
  509. cmake_need_flags=1
  510. if cmake_try_run "${cmake_cxx_compiler}" \
  511. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  512. :
  513. else
  514. cmake_need_flags=0
  515. fi
  516. if [ "x${cmake_need_flags}" = "x1" ]; then
  517. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  518. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  519. else
  520. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  521. fi
  522. rm -f "${TMPFILE}.cxx"
  523. fi
  524. cmake_test_flags=
  525. # If we are on HP-UX, check for -Ae for the C compiler.
  526. cmake_test_flags="-Ae"
  527. if [ "x${cmake_system}" = "xHP-UX" ]; then
  528. TMPFILE=`cmake_tmp_file`
  529. cat > ${TMPFILE}.c <<EOF
  530. int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
  531. EOF
  532. cmake_need_Ae=0
  533. if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  534. :
  535. else
  536. if cmake_try_run "${cmake_c_compiler}" \
  537. "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  538. cmake_need_Ae=1
  539. fi
  540. fi
  541. if [ "x${cmake_need_Ae}" = "x1" ]; then
  542. cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
  543. echo "${cmake_c_compiler} needs ${cmake_test_flags}"
  544. else
  545. echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
  546. fi
  547. rm -f "${TMPFILE}.c"
  548. fi
  549. cmake_test_flags=
  550. # Test for kwsys features
  551. KWSYS_NAME_IS_KWSYS=0
  552. KWSYS_BUILD_SHARED=0
  553. KWSYS_IOS_USE_STRSTREAM_H=0
  554. KWSYS_IOS_USE_STRSTREA_H=0
  555. KWSYS_IOS_HAVE_STD=0
  556. KWSYS_IOS_USE_SSTREAM=0
  557. KWSYS_IOS_USE_ANSI=0
  558. KWSYS_STL_HAVE_STD=0
  559. if cmake_try_run "${cmake_cxx_compiler}" \
  560. "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAVE_STD" \
  561. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  562. KWSYS_STL_HAVE_STD=1
  563. echo "${cmake_cxx_compiler} has STL in std:: namespace"
  564. else
  565. echo "${cmake_cxx_compiler} does not have STL in std:: namespace"
  566. fi
  567. if cmake_try_run "${cmake_cxx_compiler}" \
  568. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_ANSI" \
  569. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  570. KWSYS_IOS_USE_ANSI=1
  571. echo "${cmake_cxx_compiler} has ANSI streams"
  572. else
  573. echo "${cmake_cxx_compiler} does not have ANSI streams"
  574. fi
  575. if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
  576. if cmake_try_run "${cmake_cxx_compiler}" \
  577. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_HAVE_STD" \
  578. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  579. KWSYS_IOS_HAVE_STD=1
  580. echo "${cmake_cxx_compiler} has streams in std:: namespace"
  581. else
  582. echo "${cmake_cxx_compiler} does not have streams in std:: namespace"
  583. fi
  584. if cmake_try_run "${cmake_cxx_compiler}" \
  585. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_SSTREAM" \
  586. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  587. KWSYS_IOS_USE_SSTREAM=1
  588. echo "${cmake_cxx_compiler} has sstream"
  589. else
  590. echo "${cmake_cxx_compiler} does not have sstream"
  591. fi
  592. fi
  593. if [ "x$KWSYS_IOS_USE_SSTREAM" = "x0" ]; then
  594. if cmake_try_run "${cmake_cxx_compiler}" \
  595. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREAM_H" \
  596. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  597. KWSYS_IOS_USE_STRSTREAM_H=1
  598. echo "${cmake_cxx_compiler} has strstream.h"
  599. else
  600. echo "${cmake_cxx_compiler} does not have strstream.h"
  601. fi
  602. if [ "x$KWSYS_IOS_USE_STRSTREAM_H" = "x0" ]; then
  603. if cmake_try_run "${cmake_cxx_compiler}" \
  604. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREA_H" \
  605. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  606. KWSYS_IOS_USE_STRSTREA_H=1
  607. echo "${cmake_cxx_compiler} has strstrea.h"
  608. else
  609. echo "${cmake_cxx_compiler} does not have strstrea.h"
  610. fi
  611. fi
  612. fi
  613. # Just to be safe, let us store compiler and flags to the header file
  614. cmake_bootstrap_version='$Revision$'
  615. cmake_compiler_settings_comment="/*
  616. * Generated by ${cmake_source_dir}/bootstrap
  617. * Version: ${cmake_bootstrap_version}
  618. *
  619. * Source directory: ${cmake_source_dir}
  620. * Binary directory: ${cmake_bootstrap_dir}
  621. *
  622. * C compiler: ${cmake_c_compiler}
  623. * C flags: ${cmake_c_flags}
  624. *
  625. * C++ compiler: ${cmake_cxx_compiler}
  626. * C++ flags: ${cmake_cxx_flags}
  627. *
  628. * Make: ${cmake_make_processor}
  629. *
  630. * Sources:
  631. * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
  632. * kwSys Sources:
  633. * ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
  634. */
  635. "
  636. cmake_report cmConfigure.h.tmp "${cmake_compiler_settings_comment}"
  637. if [ "x$KWSYS_STL_HAVE_STD" = "x1" ]; then
  638. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_STD_NAMESPACE */"
  639. else
  640. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_STD_NAMESPACE 1"
  641. fi
  642. if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
  643. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STREAM_HEADERS */"
  644. else
  645. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STREAM_HEADERS 1"
  646. fi
  647. if [ "x$KWSYS_IOS_USE_SSTREAM" = "x1" ]; then
  648. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STRING_STREAM */"
  649. else
  650. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STRING_STREAM 1"
  651. fi
  652. # Test for ansi FOR scope
  653. if cmake_try_run "${cmake_cxx_compiler}" \
  654. "${cmake_cxx_flags}" \
  655. "${cmake_source_dir}/Modules/TestForAnsiForScope.cxx" >> cmake_bootstrap.log 2>&1; then
  656. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_FOR_SCOPE */"
  657. echo "${cmake_cxx_compiler} has ANSI for scoping"
  658. else
  659. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_FOR_SCOPE 1"
  660. echo "${cmake_cxx_compiler} does not have ANSI for scoping"
  661. fi
  662. # Write CMake version
  663. for a in MAJOR MINOR PATCH; do
  664. CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | \
  665. grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
  666. cmake_report cmConfigure.h.tmp "#define CMake_VERSION_${a} ${CMake_VERSION}"
  667. done
  668. cmake_report cmConfigure.h.tmp "#define CMAKE_ROOT_DIR \"${cmake_source_dir}\""
  669. cmake_report cmConfigure.h.tmp "#define CMAKE_DATA_DIR \"${cmake_data_dir}\""
  670. cmake_report cmConfigure.h.tmp "#define CMAKE_BOOTSTRAP"
  671. # Regenerate real cmConfigure.h
  672. if diff cmConfigure.h cmConfigure.h.tmp > /dev/null 2> /dev/null; then
  673. rm -f cmConfigure.h.tmp
  674. else
  675. mv -f cmConfigure.h.tmp cmConfigure.h
  676. fi
  677. # Prepare KWSYS
  678. cmake_kwsys_config_replace_string \
  679. "${cmake_source_dir}/Source/kwsys/Configure.hxx.in" \
  680. "${cmake_bootstrap_dir}/cmsys/Configure.hxx" \
  681. "${cmake_compiler_settings_comment}"
  682. cmake_kwsys_config_replace_string \
  683. "${cmake_source_dir}/Source/kwsys/Configure.h.in" \
  684. "${cmake_bootstrap_dir}/cmsys/Configure.h" \
  685. "${cmake_compiler_settings_comment}"
  686. for a in ${KWSYS_FILES}; do
  687. cmake_replace_string "${cmake_source_dir}/Source/kwsys/${a}.in" \
  688. "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
  689. done
  690. for a in ${KWSYS_IOS_FILES}; do
  691. cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_ios_${a}.h.in" \
  692. "${cmake_bootstrap_dir}/cmsys/ios/${a}" KWSYS_NAMESPACE cmsys
  693. done
  694. cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_stl.h.in" \
  695. "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" KWSYS_NAMESPACE cmsys
  696. for a in string vector; do
  697. cmake_replace_string "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" \
  698. "${cmake_bootstrap_dir}/cmsys/stl/${a}" KWSYS_STL_HEADER ${a}
  699. done
  700. # Generate Makefile
  701. dep="cmConfigure.h cmsys/Configure.hxx cmsys/Configure.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
  702. objs=""
  703. for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
  704. objs="${objs} ${a}.o"
  705. done
  706. if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
  707. cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
  708. fi
  709. if [ "x${cmake_c_flags}" != "x" ]; then
  710. cmake_c_flags="${cmake_c_flags} "
  711. fi
  712. if [ "x${cmake_cxx_flags}" != "x" ]; then
  713. cmake_cxx_flags="${cmake_cxx_flags} "
  714. fi
  715. cmake_c_flags="${cmake_c_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
  716. -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
  717. cmake_cxx_flags="${cmake_cxx_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
  718. -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
  719. echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
  720. echo " ${cmake_cxx_compiler} ${LDFLAGS} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
  721. for a in ${CMAKE_CXX_SOURCES}; do
  722. src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
  723. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  724. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  725. done
  726. for a in ${CMAKE_C_SOURCES}; do
  727. src=`cmake_escape "${cmake_source_dir}/Source/${a}.c"`
  728. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  729. echo " ${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  730. done
  731. for a in ${KWSYS_C_SOURCES}; do
  732. src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.c"`
  733. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  734. echo " ${cmake_c_compiler} ${cmake_c_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  735. done
  736. for a in ${KWSYS_CXX_SOURCES}; do
  737. src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.cxx"`
  738. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  739. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  740. done
  741. cat>>"${cmake_bootstrap_dir}/Makefile"<<EOF
  742. rebuild_cache:
  743. cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
  744. EOF
  745. # Write our default settings to Bootstrap.cmk/InitialCacheFlags.cmake.
  746. cat > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake" <<EOF
  747. # Generated by ${cmake_source_dir}/bootstrap
  748. # Default cmake settings. These may be overridden any settings below.
  749. SET (CMAKE_INSTALL_PREFIX "${cmake_prefix_dir}" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
  750. SET (CMAKE_DOC_DIR "${cmake_doc_dir}" CACHE PATH "Install location for documentation (relative to prefix)." FORCE)
  751. SET (CMAKE_MAN_DIR "${cmake_man_dir}" CACHE PATH "Install location for man pages (relative to prefix)." FORCE)
  752. SET (CMAKE_DATA_DIR "${cmake_data_dir}" CACHE PATH "Install location for data (relative to prefix)." FORCE)
  753. EOF
  754. # Add user-specified settings. Handle relative-path case for
  755. # specification of cmake_init_file.
  756. (
  757. cd "${cmake_binary_dir}"
  758. if [ -f "${cmake_init_file}" ]; then
  759. cat "${cmake_init_file}" >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
  760. fi
  761. )
  762. echo "---------------------------------------------"
  763. # Run make to build bootstrap cmake
  764. if [ "x${cmake_parallel_make}" != "x" ]; then
  765. ${cmake_make_processor} ${cmake_make_flags}
  766. else
  767. ${cmake_make_processor}
  768. fi
  769. RES=$?
  770. if [ "${RES}" -ne "0" ]; then
  771. cmake_error 9 "Problem while running ${cmake_make_processor}"
  772. fi
  773. cd "${cmake_binary_dir}"
  774. # Set C, CXX, and MAKE environment variables, so that real real cmake will be
  775. # build with same compiler and make
  776. CC="${cmake_c_compiler}"
  777. CXX="${cmake_cxx_compiler}"
  778. MAKE="${cmake_make_processor}"
  779. export CC
  780. export CXX
  781. export MAKE
  782. # Run bootstrap CMake to configure real CMake
  783. "${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
  784. echo "---------------------------------------------"
  785. # And we are done. Now just run make
  786. echo "CMake has bootstrapped. Now run ${cmake_make_processor}."