Skip to content

Commit 08b9b3a

Browse files
committed
update setup_cmake* scripts to verify the versions installed
1 parent b6908f0 commit 08b9b3a

File tree

3 files changed

+86
-26
lines changed

3 files changed

+86
-26
lines changed

ci/setup_cmake.ps1

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,37 @@ choco uninstall cmake cmake.install -y --remove-dependencies --skip-autouninstal
1212
Write-Host "Installing CMake version $CMAKE_VERSION ..."
1313
choco install cmake --version=$CMAKE_VERSION --allow-downgrade -y --force --no-progress
1414

15-
cmake --version
15+
function Get-Version {
16+
param (
17+
[string]$output
18+
)
19+
if ($output -match '(\d+\.\d+\.\d+)') {
20+
return $matches[1]
21+
}
22+
return $null
23+
}
24+
25+
$cmakeOutput = & cmake --version | Select-Object -First 1
26+
$ctestOutput = & ctest --version | Select-Object -First 1
27+
$cpackOutput = & cpack --version | Select-Object -First 1
28+
29+
$cmakeVersion = Get-Version $cmakeOutput
30+
$ctestVersion = Get-Version $ctestOutput
31+
$cpackVersion = Get-Version $cpackOutput
32+
33+
Write-Host "cmake version $cmakeVersion detected"
34+
Write-Host "ctest version $ctestVersion detected"
35+
Write-Host "cpack version $cpackVersion detected"
36+
37+
if ($cmakeVersion -ne $CMAKE_VERSION) {
38+
Write-Error "CMake version mismatch: expected $CMAKE_VERSION, installed $cmakeVersion"
39+
exit 1
40+
}
41+
if ($ctestVersion -ne $CMAKE_VERSION) {
42+
Write-Error "CTest version mismatch: expected $CMAKE_VERSION, installed $ctestVersion"
43+
exit 1
44+
}
45+
if ($cpackVersion -ne $CMAKE_VERSION) {
46+
Write-Error "CPack version mismatch: expected $CMAKE_VERSION, installed $cpackVersion"
47+
exit 1
48+
}

ci/setup_cmake.sh

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,43 @@
66
set -e
77

88
CMAKE_VERSION=${CMAKE_VERSION:-3.31.6}
9-
CMAKE_DIR="cmake-$CMAKE_VERSION-linux-x86_64"
10-
CMAKE_TAR="$CMAKE_DIR.tar.gz"
11-
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/$CMAKE_TAR"
9+
CMAKE_DIR="cmake-${CMAKE_VERSION}-linux-x86_64"
10+
CMAKE_TAR="${CMAKE_DIR}.tar.gz"
11+
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_TAR}"
1212

13-
echo "Installing CMake version: $CMAKE_VERSION"
13+
INSTALL_DIR="/opt/cmake"
14+
15+
echo "Installing CMake version: ${CMAKE_VERSION}..."
1416

1517
apt-get update && apt-get remove --purge -y cmake || true
1618

1719
apt-get install -y wget tar
1820

19-
wget "$CMAKE_URL"
20-
21-
tar -xzf "$CMAKE_TAR"
21+
wget "${CMAKE_URL}"
2222

23-
mkdir -p /opt/cmake
24-
mv "$CMAKE_DIR" /opt/cmake/cmake
23+
mkdir -p "${INSTALL_DIR}"
24+
tar --strip-components=1 -xzf "${CMAKE_TAR}" -C "${INSTALL_DIR}"
2525

26-
for file in /opt/cmake/cmake/bin/*; do
27-
ln -sf "$file" "/usr/local/bin/$(basename "$file")"
26+
for executable in "${INSTALL_DIR}/bin/"*; do
27+
exe_name=$(basename "$executable")
28+
ln -sf "$executable" "/usr/local/bin/$exe_name"
2829
done
2930

30-
rm -f "$CMAKE_TAR"
31+
rm -f "${CMAKE_TAR}"
32+
33+
echo "Verifying installed versions..."
34+
35+
for executable in cmake ctest cpack; do
36+
if command -v "$executable" >/dev/null 2>&1; then
37+
ACTUAL_VERSION=$("$executable" --version | grep -Eo '[0-9]+(\.[0-9]+)*' | head -n 1)
38+
echo "$executable version: $ACTUAL_VERSION detected"
39+
if [ "$ACTUAL_VERSION" != "$CMAKE_VERSION" ]; then
40+
echo "E: $executable version mismatch. Expected $CMAKE_VERSION, found '$ACTUAL_VERSION'" >&2
41+
exit 1
42+
fi
43+
else
44+
echo "E: $executable is not installed or not in PATH." >&2
45+
exit 1
46+
fi
47+
done
3148

32-
cmake --version

ci/setup_cmake_macos.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,41 @@ CMAKE_TAR="${CMAKE_PKG}.tar.gz"
1111
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_TAR}"
1212

1313
INSTALL_DIR="/opt/cmake"
14-
BIN_DIR="${INSTALL_DIR}/cmake/CMake.app/Contents/bin"
1514

1615
echo "Installing CMake version ${CMAKE_VERSION}..."
1716

18-
if brew list cmake >/dev/null 2>&1; then
19-
echo "Removing existing Homebrew-installed CMake..."
20-
brew uninstall cmake
21-
fi
17+
brew uninstall cmake || true
2218

2319
if ! command -v wget >/dev/null 2>&1; then
24-
echo "wget not found. Installing wget via Homebrew..."
20+
echo "Installing wget..."
2521
brew install wget
2622
fi
2723

2824
wget -q "${CMAKE_URL}"
29-
tar -xzf "${CMAKE_TAR}"
30-
3125
sudo mkdir -p "${INSTALL_DIR}"
32-
sudo mv "${CMAKE_PKG}" "${INSTALL_DIR}/cmake"
26+
sudo tar --strip-components=1 -xzf "${CMAKE_TAR}" -C "${INSTALL_DIR}"
3327

34-
for file in "${BIN_DIR}"/*; do
35-
sudo ln -sf "${file}" "/usr/local/bin/$(basename "${file}")"
28+
BINARY_DIR="${INSTALL_DIR}/CMake.app/Contents/bin"
29+
30+
for executable in "${BINARY_DIR}/"*; do
31+
exe_name=$(basename "$executable")
32+
sudo ln -sf "$executable" "/usr/local/bin/$exe_name"
3633
done
3734

3835
rm -f "${CMAKE_TAR}"
3936

40-
cmake --version
37+
echo "Verifying installed versions..."
38+
39+
for executable in cmake ctest cpack; do
40+
if command -v "$executable" >/dev/null 2>&1; then
41+
ACTUAL_VERSION=$("$executable" --version | grep -Eo '[0-9]+(\.[0-9]+)*' | head -n 1)
42+
echo "$executable version: $ACTUAL_VERSION detected"
43+
if [ "$ACTUAL_VERSION" != "$CMAKE_VERSION" ]; then
44+
echo "E: $executable version mismatch. Expected $CMAKE_VERSION, found '$ACTUAL_VERSION'" >&2
45+
exit 1
46+
fi
47+
else
48+
echo "E: $executable is not installed or not in PATH." >&2
49+
exit 1
50+
fi
51+
done

0 commit comments

Comments
 (0)