]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cmake: add cmake 4 support ceph-cmake4
authorEdwin Rodriguez <edwin.rodriguez1@ibm.com>
Thu, 2 Oct 2025 14:46:51 +0000 (10:46 -0400)
committerEdwin Rodriguez <edwin.rodriguez1@ibm.com>
Mon, 20 Oct 2025 21:02:57 +0000 (17:02 -0400)
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>
cmake/modules/BuildOpentelemetry.cmake
do_cmake.sh

index 48b219e9c0fc2f67152054aceaff28e483d9fd42..532dae63e3042eaf8f8e47cf0059115dd075ed67 100644 (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}
index c31bdfe79169024608bcfba11b1979dd1623fd59..a3b901fb66acbcb94e0f38d3895caf0852a4a8a7 100755 (executable)
@@ -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