bootstrap 29 KB

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