From 802195ec97f3a4cbee5ab9d5f7a72bcedf55a79d Mon Sep 17 00:00:00 2001 From: Edwin Rodriguez Date: Thu, 2 Oct 2025 10:46:51 -0400 Subject: [PATCH] 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 --- cmake/modules/BuildOpentelemetry.cmake | 10 ++++++++++ do_cmake.sh | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmake/modules/BuildOpentelemetry.cmake b/cmake/modules/BuildOpentelemetry.cmake index 48b219e9c0fc2..532dae63e3042 100644 --- a/cmake/modules/BuildOpentelemetry.cmake +++ b/cmake/modules/BuildOpentelemetry.cmake @@ -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} diff --git a/do_cmake.sh b/do_cmake.sh index c31bdfe791690..a3b901fb66acb 100755 --- a/do_cmake.sh +++ b/do_cmake.sh @@ -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 -- 2.39.5