Skip to content
Snippets Groups Projects
Commit 2ad2c2d7 authored by Brad King's avatar Brad King
Browse files

bootstrap: Detect known C/C++ compiler toolchains

Look for a C/C++ compiler pair from known toolchains on some platforms.
This makes it less likely that mismatched compilers will be found.
Check only if the environment variables CC and CXX are both empty.
parent a55aee5c
No related branches found
No related tags found
No related merge requests found
...@@ -650,11 +650,74 @@ if ${cmake_system_haiku}; then ...@@ -650,11 +650,74 @@ if ${cmake_system_haiku}; then
cmake_ld_flags="${LDFLAGS} -lroot -lbe" cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi fi
#-----------------------------------------------------------------------------
# Detect known toolchains on some platforms.
cmake_toolchains=''
case "${cmake_system}" in
*AIX*) cmake_toolchains='XL GNU' ;;
*CYGWIN*) cmake_toolchains='GNU' ;;
*Darwin*) cmake_toolchains='GNU Clang' ;;
*Linux*) cmake_toolchains='GNU Clang XL PGI PathScale' ;;
*MINGW*) cmake_toolchains='GNU' ;;
esac
# Toolchain compiler name table.
cmake_toolchain_Clang_CC='clang'
cmake_toolchain_Clang_CXX='clang++'
cmake_toolchain_GNU_CC='gcc'
cmake_toolchain_GNU_CXX='g++'
cmake_toolchain_PGI_CC='pgcc'
cmake_toolchain_PGI_CXX='pgCC'
cmake_toolchain_PathScale_CC='pathcc'
cmake_toolchain_PathScale_CXX='pathCC'
cmake_toolchain_XL_CC='xlc'
cmake_toolchain_XL_CXX='xlC'
cmake_toolchain_try()
{
tc="$1"
TMPFILE=`cmake_tmp_file`
eval "tc_CC=\${cmake_toolchain_${tc}_CC}"
echo 'int main() { return 0; }' > "${TMPFILE}.c"
cmake_try_run "$tc_CC" "" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1
tc_result_CC="$?"
rm -f "${TMPFILE}.c"
test "${tc_result_CC}" = "0" || return 1
eval "tc_CXX=\${cmake_toolchain_${tc}_CXX}"
echo 'int main() { return 0; }' > "${TMPFILE}.cpp"
cmake_try_run "$tc_CXX" "" "${TMPFILE}.cpp" >> cmake_bootstrap.log 2>&1
tc_result_CXX="$?"
rm -f "${TMPFILE}.cpp"
test "${tc_result_CXX}" = "0" || return 1
cmake_toolchain="$tc"
}
cmake_toolchain_detect()
{
cmake_toolchain=
for tc in ${cmake_toolchains}; do
echo "Checking for $tc toolchain" >> cmake_bootstrap.log 2>&1
cmake_toolchain_try "$tc" &&
echo "Found $tc toolchain" &&
break
done
}
if [ -z "${CC}" -a -z "${CXX}" ]; then
cmake_toolchain_detect
fi
#-----------------------------------------------------------------------------
# Test C compiler # Test C compiler
cmake_c_compiler= cmake_c_compiler=
# If CC is set, use that for compiler, otherwise use list of known compilers # If CC is set, use that for compiler, otherwise use list of known compilers
if [ -n "${CC}" ]; then if [ -n "${cmake_toolchain}" ]; then
eval cmake_c_compilers="\${cmake_toolchain_${cmake_toolchain}_CC}"
elif [ -n "${CC}" ]; then
cmake_c_compilers="${CC}" cmake_c_compilers="${CC}"
else else
cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}" cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
...@@ -697,13 +760,16 @@ See cmake_bootstrap.log for compilers attempted. ...@@ -697,13 +760,16 @@ See cmake_bootstrap.log for compilers attempted.
fi fi
echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}" echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
#-----------------------------------------------------------------------------
# Test CXX compiler # Test CXX compiler
cmake_cxx_compiler= cmake_cxx_compiler=
# On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler. # On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.
# If CC is set, use that for compiler, otherwise use list of known compilers # If CC is set, use that for compiler, otherwise use list of known compilers
if [ -n "${CXX}" ]; then if [ -n "${cmake_toolchain}" ]; then
eval cmake_cxx_compilers="\${cmake_toolchain_${cmake_toolchain}_CXX}"
elif [ -n "${CXX}" ]; then
cmake_cxx_compilers="${CXX}" cmake_cxx_compilers="${CXX}"
else else
cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}" cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
...@@ -754,6 +820,7 @@ See cmake_bootstrap.log for compilers attempted." ...@@ -754,6 +820,7 @@ See cmake_bootstrap.log for compilers attempted."
fi fi
echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}" echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
#-----------------------------------------------------------------------------
# Test Make # Test Make
cmake_make_processor= cmake_make_processor=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment