bootstrap 27 KB

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