bootstrap 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. #!/bin/sh
  2. CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
  3. CMAKE_KNOWN_CXX_COMPILERS="CC g++ c++ xlC icc como aCC"
  4. CMAKE_KNOWN_MAKE_PROCESSORS="make gmake"
  5. CMAKE_SOURCES="\
  6. cmake \
  7. cmakewizard \
  8. cmakemain \
  9. cmMakeDepend \
  10. cmMakefile \
  11. cmDocumentation \
  12. cmGlobalGenerator \
  13. cmLocalGenerator \
  14. cmRegularExpression \
  15. cmSourceFile \
  16. cmSystemTools \
  17. cmDirectory \
  18. cmGlobalUnixMakefileGenerator \
  19. cmLocalUnixMakefileGenerator \
  20. cmCommands \
  21. cmTarget \
  22. cmCustomCommand \
  23. cmCacheManager \
  24. cmListFileCache \
  25. cmVariableWatch \
  26. cmSourceGroup"
  27. cmake_source_dir=`echo $0 | sed -n '/\//{s/\/[^\/]*$//;p;}'`
  28. cmake_source_dir=`(cd "${cmake_source_dir}";pwd)`
  29. cmake_binary_dir=`pwd`
  30. cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap"
  31. cmake_usage()
  32. {
  33. cat<<EOF
  34. Usage: $0 [options]
  35. Options: [defaults in brackets after descriptions]
  36. Configuration:
  37. --help print this message
  38. --verbose display more information
  39. Directory and file names:
  40. --prefix=PREFIX install architecture-independent files in PREFIX
  41. [/usr/local]
  42. EOF
  43. exit 10
  44. }
  45. cmake_verbose=
  46. cmake_prefix_dir="/usr/local"
  47. for a in "$@"; do
  48. if echo $a | grep "^--prefix="; then
  49. cmake_prefix_dir=`echo $a | sed "s/^--prefix=//"`
  50. fi
  51. if echo $a | grep "^--help"; then
  52. cmake_usage
  53. fi
  54. if echo $a | grep "^--verbose"; then
  55. cmake_verbose=TRUE
  56. fi
  57. done
  58. if [ -n "${cmake_verbose}" ]; then
  59. echo "---------------------------------------------"
  60. echo "Source directory: ${cmake_source_dir}"
  61. echo "Binary directory: ${cmake_binary_dir}"
  62. echo "Prefix directory: ${cmake_prefix_dir}"
  63. fi
  64. echo "---------------------------------------------"
  65. [ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
  66. if [ ! -d "${cmake_bootstrap_dir}" ]; then
  67. echo "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
  68. exit 5
  69. fi
  70. cd "${cmake_bootstrap_dir}"
  71. rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
  72. rm -f "${cmake_bootstrap_dir}/cmConfigure.h"
  73. cmake_report ()
  74. {
  75. FILE=$1
  76. shift
  77. echo "$*" >> ${FILE}
  78. }
  79. cmake_escape ()
  80. {
  81. echo $1 | sed "s/ /\\\\ /g"
  82. }
  83. cmake_log ()
  84. {
  85. echo "$*" >> cmake_bootstrap.log
  86. }
  87. cmake_tmp_file ()
  88. {
  89. echo "cmake_bootstrap_$$.test"
  90. }
  91. cmake_try_run ()
  92. {
  93. COMPILER=$1
  94. FLAGS=$2
  95. TESTFILE=$3
  96. if [ ! -f "${TESTFILE}" ]; then
  97. echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
  98. exit 4
  99. fi
  100. TMPFILE=`cmake_tmp_file`
  101. echo "Try: ${COMPILER}"
  102. "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  103. RES=$?
  104. if [ "${RES}" -ne "0" ]; then
  105. echo "${COMPILER} does not work";return 1
  106. fi
  107. if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
  108. echo "${COMPILER} does not produce output"
  109. return 2
  110. fi
  111. ./${TMPFILE}
  112. RES=$?
  113. rm -f "${TMPFILE}"
  114. if [ "${RES}" -ne "0" ]; then
  115. echo "${COMPILER} produces strange executable"
  116. return 3
  117. fi
  118. echo "${COMPILER} works"
  119. return 0
  120. }
  121. cmake_try_make ()
  122. {
  123. MAKE_PROC=$1
  124. echo "Try: ${MAKE_PROC}"
  125. ${MAKE_PROC}
  126. RES=$?
  127. if [ "${RES}" -ne "0" ]; then
  128. echo "${MAKE_PROC} does not work";return 1
  129. fi
  130. if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
  131. echo "${COMPILER} does not produce output"
  132. return 2
  133. fi
  134. ./test
  135. RES=$?
  136. rm -f "test"
  137. if [ "${RES}" -ne "0" ]; then
  138. echo "${MAKE_PROC} produces strange executable"
  139. return 3
  140. fi
  141. echo "${MAKE_PROC} works"
  142. return 0
  143. }
  144. cmake_c_flags=${CFLAGS}
  145. cmake_cxx_flags=${CXXFLAGS}
  146. # Test C compiler
  147. cmake_c_compiler=
  148. if [ -n "${CC}" ]; then
  149. cmake_c_compilers="${CC}"
  150. else
  151. cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
  152. fi
  153. TMPFILE=`cmake_tmp_file`
  154. cat>"${TMPFILE}.c"<<EOF
  155. #include<stdio.h>
  156. int main()
  157. {
  158. printf("1\n");
  159. return 0;
  160. }
  161. EOF
  162. for a in ${cmake_c_compilers}; do
  163. if [ -z "${cmake_c_compiler}" ] && cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  164. cmake_c_compiler="${a}"
  165. fi
  166. done
  167. rm -f "${TMPFILE}.c"
  168. if [ -z "${cmake_c_compiler}" ]; then
  169. echo "Cannot find apropriate C compiler on this system."
  170. echo "Please specify one using environment variable CC."
  171. exit 1
  172. fi
  173. echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
  174. # Test CXX compiler
  175. cmake_cxx_compiler=
  176. if [ -n "${CXX}" ]; then
  177. cmake_cxx_compilers="${CXX}"
  178. else
  179. cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
  180. fi
  181. TMPFILE=`cmake_tmp_file`
  182. cat>"${TMPFILE}.cxx"<<EOF
  183. #include<iostream.h>
  184. int main()
  185. {
  186. cout << 1 << endl;
  187. return 0;
  188. }
  189. EOF
  190. for a in ${cmake_cxx_compilers}; do
  191. if [ -z "${cmake_cxx_compiler}" ] && cmake_try_run "${a}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  192. cmake_cxx_compiler="${a}"
  193. fi
  194. done
  195. rm -f "${TMPFILE}.cxx"
  196. if [ -z "${cmake_cxx_compiler}" ]; then
  197. echo "Cannot find apropriate C++ compiler on this system."
  198. echo "Please specify one using environment variable CXX."
  199. exit 1
  200. fi
  201. echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
  202. # Test Make
  203. cmake_make_processor=
  204. if [ -n "${MAKE}" ]; then
  205. cmake_make_processors="${MAKE}"
  206. else
  207. cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
  208. fi
  209. TMPFILE="`cmake_tmp_file`_dir"
  210. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  211. mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
  212. cd "${cmake_bootstrap_dir}/${TMPFILE}"
  213. cat>"Makefile"<<EOF
  214. test: test.c
  215. ${cmake_c_compiler} -o test test.c
  216. EOF
  217. cat>"test.c"<<EOF
  218. #include <stdio.h>
  219. int main(){ printf("1\n"); return 0; }
  220. EOF
  221. for a in ${cmake_make_processors}; do
  222. if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" >> cmake_bootstrap.log 2>&1; then
  223. cmake_make_processor="${a}"
  224. fi
  225. done
  226. cd "${cmake_bootstrap_dir}"
  227. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  228. echo "Make processor on this system is: ${cmake_make_processor}"
  229. # Test C++ compiler features
  230. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${cmake_source_dir}/Modules/TestForSTDNamespace.cxx" >> cmake_bootstrap.log 2>&1; then
  231. cmake_report cmConfigure.h "/* #undef CMAKE_NO_STD_NAMESPACE */"
  232. echo "${cmake_cxx_compiler} has STD namespace"
  233. else
  234. cmake_report cmConfigure.h "#define CMAKE_NO_STD_NAMESPACE 1"
  235. echo "${cmake_cxx_compiler} does not have STD namespace"
  236. fi
  237. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${cmake_source_dir}/Modules/TestForANSIStreamHeaders.cxx" >> cmake_bootstrap.log 2>&1; then
  238. cmake_report cmConfigure.h "/* #undef CMAKE_NO_ANSI_STREAM_HEADERS */"
  239. echo "${cmake_cxx_compiler} has ANSI stream headers"
  240. else
  241. cmake_report cmConfigure.h "#define CMAKE_NO_ANSI_STREAM_HEADERS 1"
  242. echo "${cmake_cxx_compiler} does not have ANSI stream headers"
  243. fi
  244. TMPFILE=`cmake_tmp_file`
  245. cat>${TMPFILE}.cxx<<EOF
  246. #include <sstream>
  247. int main() { return 0;}
  248. EOF
  249. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  250. cmake_report cmConfigure.h "/* #undef CMAKE_NO_ANSI_STRING_STREAM */"
  251. echo "${cmake_cxx_compiler} has ANSI string streams"
  252. else
  253. cmake_report cmConfigure.h "#define CMAKE_NO_ANSI_STRING_STREAM 1"
  254. echo "${cmake_cxx_compiler} does not have ANSI string streams"
  255. fi
  256. rm -f "${TMPFILE}.cxx"
  257. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${cmake_source_dir}/Modules/TestForAnsiForScope.cxx" >> cmake_bootstrap.log 2>&1; then
  258. cmake_report cmConfigure.h "/* #undef CMAKE_NO_ANSI_FOR_SCOPE */"
  259. echo "${cmake_cxx_compiler} has ANSI for scoping"
  260. else
  261. cmake_report cmConfigure.h "#define CMAKE_NO_ANSI_FOR_SCOPE 1"
  262. echo "${cmake_cxx_compiler} does not have ANSI for scoping"
  263. fi
  264. # Get CMake version
  265. for a in MAJOR MINOR PATCH; do
  266. CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
  267. cmake_report cmConfigure.h "#define CMake_VERSION_${a} ${CMake_VERSION}"
  268. done
  269. # Generate Makefile
  270. dep="cmConfigure.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
  271. objs=""
  272. for a in ${CMAKE_SOURCES}; do
  273. objs="${objs} ${a}.o"
  274. done
  275. cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags} -DCMAKE_ROOT_DIR='\"`cmake_escape \"${cmake_source_dir}\"`\"' -DCMAKE_BOOTSTRAP -I`cmake_escape \"${cmake_source_dir}/Source\"` -I${cmake_bootstrap_dir}"
  276. echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
  277. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
  278. for a in ${CMAKE_SOURCES}; do
  279. src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
  280. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  281. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  282. done
  283. # Write prefix to Bootstrap/InitialConfigureFlags.cmake
  284. echo "SET (CMAKE_CONFIGURE_INSTALL_PREFIX \"${cmake_prefix_dir}\" CACHE PATH \"Install path prefix, prepended onto install directories, For CMake this will always override CMAKE_INSTALL_PREFIX in the cache.\")" > "${cmake_bootstrap_dir}/InitialConfigureFlags.cmake"
  285. echo "---------------------------------------------"
  286. ${cmake_make_processor}
  287. RES=$?
  288. if [ "${RES}" -ne "0" ]; then
  289. echo "Problem while bootstrapping CMake"
  290. exit 8
  291. fi
  292. cd "${cmake_binary_dir}"
  293. "${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}"
  294. echo "---------------------------------------------"