bootstrap 30 KB

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