fi
fi
}
+
+# discover_compiler takes one argument, purpose, which may be used
+# to adjust the results for a specific need. It sets three environment
+# variables `discovered_c_compiler`, `discovered_cxx_compiler` and
+# `discovered_compiler_env`. The `discovered_compiler_env` variable
+# may be blank. If not, it will contain a file that needs to be sourced
+# prior to using the compiler.
+function discover_compiler() {
+ # nb: currently purpose is not used for detection
+ local purpose="$1"
+ ci_debug "Finding compiler for ${purpose}"
+
+ local compiler_env=""
+ local cxx_compiler=g++
+ local c_compiler=gcc
+ # ubuntu/debian ci builds prefer clang
+ for i in {14..10}; do
+ if type -t "clang-$i" > /dev/null; then
+ cxx_compiler="clang++-$i"
+ c_compiler="clang-$i"
+ break
+ fi
+ done
+
+ export discovered_c_compiler="${c_compiler}"
+ export discovered_cxx_compiler="${cxx_compiler}"
+ export discovered_compiler_env="${compiler_env}"
+ return 0
+}
fi
$DRY_RUN ccache -sz # Reset the ccache statistics and show the current configuration
- local cxx_compiler=g++
- local c_compiler=gcc
- for i in $(seq 14 -1 10); do
- if type -t clang-$i > /dev/null; then
- cxx_compiler="clang++-$i"
- c_compiler="clang-$i"
- break
- fi
- done
+ if ! discover_compiler ci-build ; then
+ ci_debug "Failed to discover a compiler"
+ fi
+ local cxx_compiler="${discovered_cxx_compiler}"
+ local c_compiler="${discovered_c_compiler}"
local cmake_opts
cmake_opts+=" -DCMAKE_CXX_COMPILER=$cxx_compiler -DCMAKE_C_COMPILER=$c_compiler"
cmake_opts+=" -DCMAKE_CXX_FLAGS_DEBUG=-Werror"