Skip to content

Commit 77bd169

Browse files
Merge pull request #89 from yanghang8612/support_for_historical_cmake
Support for historical cmake
2 parents f7b3df3 + 5222902 commit 77bd169

File tree

3 files changed

+72
-9
lines changed

3 files changed

+72
-9
lines changed

.circleci/install_cmake.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
# Usage: ./install_cmake.sh 3.28.3
3+
# Installs a specific CMake version on macOS from Kitware releases.
4+
# Layout:
5+
# /usr/local/cmake-<version>/CMake.app/Contents/bin/{cmake,ccmake,cpack,ctest}
6+
# Symlinks:
7+
# /usr/local/bin/{cmake,ccmake,cpack,ctest} -> .../Contents/bin/<tool>
8+
# Works on both Intel and Apple Silicon (uses "macos-universal" tarball).
9+
10+
set -euo pipefail
11+
12+
if [ -z "${1:-}" ]; then
13+
echo "Usage: $0 <cmake-version>"
14+
exit 1
15+
fi
16+
17+
VERSION="$1"
18+
INSTALL_DIR="/usr/local/cmake-$VERSION"
19+
TARBALL="cmake-$VERSION-macos-universal.tar.gz"
20+
URL="https://github.com/Kitware/CMake/releases/download/v$VERSION/$TARBALL"
21+
TMPFILE="/tmp/$TARBALL"
22+
23+
# Require basic tools
24+
for cmd in curl tar; do
25+
command -v "$cmd" >/dev/null || { echo "Missing $cmd"; exit 1; }
26+
done
27+
28+
# Skip if already installed
29+
if [ -d "$INSTALL_DIR" ] && [ -x "$INSTALL_DIR/CMake.app/Contents/bin/cmake" ]; then
30+
echo "CMake $VERSION already installed at $INSTALL_DIR"
31+
else
32+
echo "Downloading $URL ..."
33+
# --fail makes curl exit non-zero on 404/5xx; -L follows redirects
34+
curl -fL "$URL" -o "$TMPFILE"
35+
36+
echo "Creating $INSTALL_DIR and extracting..."
37+
sudo mkdir -p "$INSTALL_DIR"
38+
39+
# The tarball contains a top-level directory (e.g., cmake-<ver>-macos-universal/*)
40+
# We strip that first component so CMake.app ends up directly under $INSTALL_DIR.
41+
sudo tar -xzf "$TMPFILE" -C "$INSTALL_DIR" --strip-components=1
42+
43+
# Work around Gatekeeper quarantine if present (harmless if attribute absent)
44+
if command -v xattr >/dev/null; then
45+
sudo xattr -dr com.apple.quarantine "$INSTALL_DIR/CMake.app" || true
46+
fi
47+
48+
# Sanity check
49+
if [ ! -x "$INSTALL_DIR/CMake.app/Contents/bin/cmake" ]; then
50+
echo "Error: cmake binary not found under $INSTALL_DIR/CMake.app/Contents/bin"
51+
exit 1
52+
fi
53+
fi
54+
55+
echo "Linking command-line tools into /usr/local/bin ..."
56+
for tool in cmake ccmake cpack ctest; do
57+
sudo ln -sfn "$INSTALL_DIR/CMake.app/Contents/bin/$tool" "/usr/local/bin/$tool"
58+
done
59+
60+
# Optional: link cmake-gui (will open the GUI app)
61+
if [ -x "$INSTALL_DIR/CMake.app/Contents/bin/cmake-gui" ]; then
62+
sudo ln -sfn "$INSTALL_DIR/CMake.app/Contents/bin/cmake-gui" /usr/local/bin/cmake-gui
63+
fi
64+
65+
echo "CMake $VERSION installed successfully."
66+
which cmake
67+
cmake --version

.circleci/osx_install_dependencies.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ then
5252
brew untap homebrew/homebrew-cask-versions
5353
brew update
5454
brew upgrade
55-
brew install cmake
55+
# brew install cmake
5656
brew install wget
5757
brew install coreutils
5858
brew install diffutils
5959
brew install grep
6060

61+
# install historical cmake
62+
chmod +x .circleci/install_cmake.sh
63+
.circleci/install_cmake.sh 3.28.3
64+
6165
# boost
6266
boost_version="1.84.0"
6367
boost_package="boost_${boost_version//./_}.tar.bz2"

CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})
5050

5151
find_package(Threads)
5252

53-
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
54-
if (CMAKE_VERSION VERSION_EQUAL "4.0.3" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "15.0.0.15000040")
55-
# for Apple clang 15 under cmake 4.0.0, disable pedantic warnings explicitly as it fails to treat boost properly as
56-
# system library, warnings propagate
57-
set(PEDANTIC OFF)
58-
endif()
59-
endif()
60-
6153
if(NOT PEDANTIC)
6254
message(WARNING "-- Pedantic build flags turned off. Warnings will not make compilation fail. This is NOT recommended in development builds.")
6355
endif()

0 commit comments

Comments
 (0)