1
0

bootstrap 29 KB

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