cmake: add cmake 4 support

This change improves the CMAKE variable detection logic in do_cmake.sh
to allow users to override the CMAKE binary used for building.

Changes:
- Add conditional check to only set CMAKE if not already set
- Add detection for cmake version 4.x and later (prioritized)
- Maintain backward compatibility with cmake3 fallback
- Allow users to specify custom CMAKE path via environment variable
- Pass CMAKE_POLICY_VERSION_MINIMUM if set to submodule build steps for
    older modules

This enables users to use a specific cmake binary by setting the CMAKE
environment variable before running the script:
  CMAKE=/custom/path/to/cmake ./do_cmake.sh

Additionally, the script now automatically detects and uses cmake 4.x+
when available, falling back to cmake3 or cmake as needed. This supports
building Ceph with newer cmake versions while maintaining compatibility
with existing build environments.

Fixes: https://tracker.ceph.com/issues/73523
Signed-off-by: Edwin Rodriguez <edwin.rodriguez1@ibm.com>
This commit is contained in:
Edwin Rodriguez 2025-10-02 10:46:51 -04:00
parent e288069c4f
commit 802195ec97
2 changed files with 22 additions and 4 deletions

View File

@ -47,6 +47,16 @@ function(build_opentelemetry)
list(APPEND opentelemetry_CMAKE_ARGS -DBoost_INCLUDE_DIR=${CMAKE_BINARY_DIR}/boost/include)
endif()
# Check if CMake version is >= 4.0.0
if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")
# Use CMAKE_POLICY_VERSION_MINIMUM if set, otherwise default to 3.5
if(DEFINED CMAKE_POLICY_VERSION_MINIMUM)
list(APPEND opentelemetry_CMAKE_ARGS -DCMAKE_POLICY_VERSION_MINIMUM=${CMAKE_POLICY_VERSION_MINIMUM})
else()
list(APPEND opentelemetry_CMAKE_ARGS -DCMAKE_POLICY_VERSION_MINIMUM=3.5)
endif()
endif()
include(ExternalProject)
ExternalProject_Add(opentelemetry-cpp
SOURCE_DIR ${opentelemetry_SOURCE_DIR}

View File

@ -87,10 +87,18 @@ ARGS+=" -DCMAKE_C_COMPILER=$c_compiler"
mkdir $BUILD_DIR
cd $BUILD_DIR
if type cmake3 > /dev/null 2>&1 ; then
CMAKE=cmake3
else
CMAKE=cmake
# Only set CMAKE variable if not already set by user/environment.
# This allows users to override with a custom cmake binary via environment variable.
# Priority order: cmake 4.x+ (if available) -> cmake3 -> cmake (fallback)
if [ -z "${CMAKE}" ]; then
if type cmake > /dev/null 2>&1 && cmake --version | grep -qE 'cmake version [4-9]\.'; then
CMAKE=cmake
elif type cmake3 > /dev/null 2>&1; then
CMAKE=cmake3
else
CMAKE=cmake
fi
fi
${CMAKE} $ARGS "$@" $CEPH_GIT_DIR || exit 1
set +x