bootstrap 9.8 KB

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