Skip to content

Commit 74d348a

Browse files
authored
[CMAKE] Fix CMake 4.x build error on MacOS runner and when building opentracing (open-telemetry#3649)
* set the CMAKE_POLICY_VERSION_MINIMUM=3.5 as a cache variable and environment variable when building opentracing-cpp to support cmake 4.x * downgrade cmake to 3.31.0 for the macos conan stable version test * don't use sudo to run the setup cmake script on macos
1 parent 4193b21 commit 74d348a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

.github/workflows/cmake_install.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ jobs:
262262
INSTALL_TEST_DIR: '/Users/runner/install_test'
263263
CXX_STANDARD: '17'
264264
CMAKE_TOOLCHAIN_FILE: '/Users/runner/conan/build/Debug/generators/conan_toolchain.cmake'
265+
CMAKE_VERSION: 3.31.0 # building the conan "stable" versions requires CMake 3.x
265266
BUILD_TYPE: 'Debug'
266267
steps:
267268
- name: Harden the runner (Audit all outbound calls)
@@ -272,6 +273,9 @@ jobs:
272273
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
273274
with:
274275
submodules: 'recursive'
276+
- name: Install CMake
277+
run: |
278+
./ci/setup_cmake_macos.sh
275279
- name: Install Conan and tools
276280
run: |
277281
brew install conan autoconf automake libtool coreutils

cmake/opentracing-cpp.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ if(NOT OpenTracing_FOUND)
2727
set(_SAVED_BUILD_TESTING ${BUILD_TESTING})
2828
endif()
2929

30+
if(DEFINED CMAKE_POLICY_VERSION_MINIMUM)
31+
set(_SAVED_CMAKE_POLICY_VERSION_MINIMUM ${CMAKE_POLICY_VERSION_MINIMUM})
32+
endif()
33+
3034
# Set the cache variables for the opentracing build
3135
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
3236
set(BUILD_MOCKTRACER OFF CACHE BOOL "" FORCE)
37+
set(CMAKE_POLICY_VERSION_MINIMUM "3.5" CACHE STRING "" FORCE)
3338

3439
FetchContent_MakeAvailable(opentracing)
3540

@@ -40,6 +45,13 @@ if(NOT OpenTracing_FOUND)
4045
unset(BUILD_TESTING CACHE)
4146
endif()
4247

48+
# Restore the saved state of CMAKE_POLICY_VERSION_MINIMUM
49+
if(DEFINED _SAVED_CMAKE_POLICY_VERSION_MINIMUM)
50+
set(CMAKE_POLICY_VERSION_MINIMUM ${_SAVED_CMAKE_POLICY_VERSION_MINIMUM} CACHE STRING "" FORCE)
51+
else()
52+
unset(CMAKE_POLICY_VERSION_MINIMUM CACHE)
53+
endif()
54+
4355
# Patch the opentracing targets to set missing includes, add namespaced alias targets, disable iwyu and clang-tidy.
4456
foreach(_target opentracing opentracing-static)
4557
if(TARGET ${_target})

0 commit comments

Comments
 (0)