Improve install-cmake script (#20836)

- Don't output junk to stderr when cmake unavailable
- Kitware PPA does not include up to date bins for all distros (e.g.
Ubuntu 24 only has 3.30.2 although 3.30.4 has been out for a while) so
don't try to force install a specific version. Take the best we can get.
This commit is contained in:
Peter Tripp 2024-11-18 21:39:57 +00:00 committed by GitHub
parent e2552b9add
commit 5b317f60df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,7 +35,7 @@ CMAKE_VERSION="${CMAKE_VERSION:-${1:-3.30.4}}"
if [ "$(whoami)" = root ]; then SUDO=; else SUDO="$(command -v sudo || command -v doas || true)"; fi
if cmake --version | grep -q "$CMAKE_VERSION"; then
if cmake --version 2>/dev/null | grep -q "$CMAKE_VERSION"; then
echo "CMake $CMAKE_VERSION is already installed."
exit 0
elif [ -e /usr/local/bin/cmake ]; then
@ -51,7 +51,7 @@ elif [ -e /etc/lsb-release ] && grep -qP 'DISTRIB_ID=Ubuntu' /etc/lsb-release; t
echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" \
| $SUDO tee /etc/apt/sources.list.d/kitware.list >/dev/null
$SUDO apt-get update
$SUDO apt-get install -y kitware-archive-keyring cmake==$CMAKE_VERSION
$SUDO apt-get install -y kitware-archive-keyring cmake
else
arch="$(uname -m)"
if [ "$arch" != "x86_64" ] && [ "$arch" != "aarch64" ]; then