Skip to content

Commit 62d9e87

Browse files
committed
Set cmake minimum required version to 3.16. Update cmake install test runner to install the min cmake version. Fix issues found
1 parent 4a0d19f commit 62d9e87

File tree

29 files changed

+110
-107
lines changed

29 files changed

+110
-107
lines changed

.github/workflows/cmake_install.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ jobs:
135135
BUILD_SHARED_LIBS: 'ON'
136136
run: ./ci/do_ci.sh cmake.install.test
137137

138-
ubuntu_2204_script_build_grpc_1_49_2:
139-
name: Ubuntu 22.04 script grpc 1.49.2 cxx14 (static libs - shared libs)
138+
ubuntu_2204_min_cmake_version:
139+
name: Ubuntu 22.04 min cmake version (static libs - shared libs)
140140
runs-on: ubuntu-22.04
141141
env:
142142
INSTALL_TEST_DIR: '/home/runner/install_test'
143+
CMAKE_VERSION: '3.16.9'
144+
GOOGLETEST_VERSION: '1.14.0'
143145
CXX_STANDARD: '14'
144146
BUILD_TYPE: 'Debug'
145147
steps:

CMakeLists.txt

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.10)
5-
6-
# See https://cmake.org/cmake/help/latest/policy/CMP0074.html required by
7-
# certain version of zlib which CURL depends on.
8-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12")
9-
cmake_policy(SET CMP0074 NEW)
10-
endif()
11-
12-
# Allow to use normal variable for option()
13-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13")
14-
cmake_policy(SET CMP0077 NEW)
15-
endif()
16-
17-
# Prefer CMAKE_MSVC_RUNTIME_LIBRARY if possible
18-
if(POLICY CMP0091)
19-
cmake_policy(SET CMP0091 NEW)
20-
endif()
4+
cmake_minimum_required(VERSION 3.16)
215

226
if(POLICY CMP0092)
237
# https://cmake.org/cmake/help/latest/policy/CMP0092.html#policy:CMP0092 Make
@@ -166,8 +150,6 @@ else()
166150
endif()
167151
endif()
168152

169-
message(STATUS "OPENTELEMETRY_ABI_VERSION_NO=${OPENTELEMETRY_ABI_VERSION_NO}")
170-
171153
if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES
172154
"OPENTELEMETRY_VERSION[ \t\r\n]+\"?([^\"]+)\"?")
173155
set(OPENTELEMETRY_VERSION ${CMAKE_MATCH_1})
@@ -178,8 +160,6 @@ else()
178160
)
179161
endif()
180162

181-
message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}")
182-
183163
option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF)
184164

185165
set(WITH_STL
@@ -399,7 +379,7 @@ if(WITH_PROMETHEUS)
399379
string(REGEX REPLACE "^v" "" prometheus-cpp_VERSION
400380
"${prometheus-cpp_VERSION}")
401381
endif()
402-
382+
set(prometheus-cpp_FOUND TRUE)
403383
message(
404384
STATUS
405385
"Using local prometheus-cpp from submodule. Version = ${prometheus-cpp_VERSION}"
@@ -421,8 +401,6 @@ if(WITH_OTLP_GRPC
421401
OR WITH_OTLP_FILE)
422402

423403
find_package(Protobuf)
424-
# Protobuf 3.22 or upper require abseil-cpp, we can find it in
425-
# opentelemetry-cpp-config.cmake
426404

427405
if(WITH_OTLP_GRPC)
428406
find_package(gRPC CONFIG)
@@ -671,8 +649,6 @@ if(BUILD_TESTING)
671649
if(GTEST_INCLUDE_DIRS)
672650
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
673651
endif()
674-
message(STATUS "GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}")
675-
message(STATUS "GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES}")
676652

677653
# Try to find gmock
678654
if(NOT GMOCK_LIB AND TARGET GTest::gmock)
@@ -800,7 +776,7 @@ if(gRPC_FOUND)
800776
message(STATUS "gRPC: ${gRPC_VERSION}")
801777
endif()
802778
if(CURL_FOUND)
803-
message(STATUS "CURL: ${CURL_VERSION}")
779+
message(STATUS "CURL: ${CURL_VERSION_STRING}")
804780
endif()
805781
if(ZLIB_FOUND)
806782
message(STATUS "ZLIB: ${ZLIB_VERSION}")

ci/install_protobuf.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if [ -e "../CMakeLists.txt" ]; then
7070
else
7171
cmake ../cmake "${CPP_PROTOBUF_BUILD_OPTIONS[@]}"
7272
fi
73-
cmake --build . -j $(nproc)
74-
cmake --install .
73+
make -j $(nproc)
74+
make install
7575
popd
7676
ldconfig

ci/setup_cmake.sh

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,43 @@
66
set -e
77

88
CMAKE_VERSION=${CMAKE_VERSION:-3.31.6}
9-
CMAKE_DIR="cmake-$CMAKE_VERSION-linux-x86_64"
10-
CMAKE_TAR="$CMAKE_DIR.tar.gz"
11-
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/$CMAKE_TAR"
9+
CMAKE_DIR="cmake-${CMAKE_VERSION}-linux-x86_64"
10+
CMAKE_TAR="${CMAKE_DIR}.tar.gz"
11+
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_TAR}"
1212

13-
echo "Installing CMake version: $CMAKE_VERSION"
13+
INSTALL_DIR="/opt/cmake"
14+
15+
echo "Installing CMake version: ${CMAKE_VERSION}..."
1416

1517
apt-get update && apt-get remove --purge -y cmake || true
1618

1719
apt-get install -y wget tar
1820

19-
wget "$CMAKE_URL"
20-
21-
tar -xzf "$CMAKE_TAR"
21+
wget "${CMAKE_URL}"
2222

23-
mkdir -p /opt/cmake
24-
mv "$CMAKE_DIR" /opt/cmake/cmake
23+
mkdir -p "${INSTALL_DIR}"
24+
tar --strip-components=1 -xzf "${CMAKE_TAR}" -C "${INSTALL_DIR}"
2525

26-
for file in /opt/cmake/cmake/bin/*; do
27-
ln -sf "$file" "/usr/local/bin/$(basename "$file")"
26+
for executable in "${INSTALL_DIR}/bin/"*; do
27+
exe_name=$(basename "$executable")
28+
ln -sf "$executable" "/usr/local/bin/$exe_name"
2829
done
2930

30-
rm -f "$CMAKE_TAR"
31+
rm -f "${CMAKE_TAR}"
32+
33+
echo "Verifying installed versions..."
34+
35+
for executable in cmake ctest cpack ccmake cmake-gui; do
36+
if command -v "$executable" >/dev/null 2>&1; then
37+
ACTUAL_VERSION=$("$executable" --version | grep -Eo '[0-9]+(\.[0-9]+)*' | head -n 1)
38+
echo "$executable version: $ACTUAL_VERSION detected"
39+
if [ "$ACTUAL_VERSION" != "$CMAKE_VERSION" ]; then
40+
echo "E: $executable version mismatch. Expected $CMAKE_VERSION, found '$ACTUAL_VERSION'" >&2
41+
exit 1
42+
fi
43+
else
44+
echo "E: $executable is not installed or not in PATH." >&2
45+
exit 1
46+
fi
47+
done
3148

32-
cmake --version

ci/setup_cmake_macos.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,40 @@ CMAKE_TAR="${CMAKE_PKG}.tar.gz"
1111
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_TAR}"
1212

1313
INSTALL_DIR="/opt/cmake"
14-
BIN_DIR="${INSTALL_DIR}/cmake/CMake.app/Contents/bin"
1514

1615
echo "Installing CMake version ${CMAKE_VERSION}..."
1716

1817
if brew list cmake >/dev/null 2>&1; then
19-
echo "Removing existing Homebrew-installed CMake..."
2018
brew uninstall cmake
2119
fi
2220

2321
if ! command -v wget >/dev/null 2>&1; then
24-
echo "wget not found. Installing wget via Homebrew..."
2522
brew install wget
2623
fi
2724

2825
wget -q "${CMAKE_URL}"
29-
tar -xzf "${CMAKE_TAR}"
26+
mkdir -p "${INSTALL_DIR}"
27+
tar --strip-components=1 -xzf "${CMAKE_TAR}" -C "${INSTALL_DIR}"
3028

31-
sudo mkdir -p "${INSTALL_DIR}"
32-
sudo mv "${CMAKE_PKG}" "${INSTALL_DIR}/cmake"
33-
34-
for file in "${BIN_DIR}"/*; do
35-
sudo ln -sf "${file}" "/usr/local/bin/$(basename "${file}")"
29+
for executable in "${INSTALL_DIR}/bin/"*; do
30+
exe_name=$(basename "$executable")
31+
ln -sf "$executable" "/usr/local/bin/$exe_name"
3632
done
3733

3834
rm -f "${CMAKE_TAR}"
3935

40-
cmake --version
36+
echo "Verifying installed versions..."
37+
38+
for executable in cmake ctest cpack ccmake cmake-gui; do
39+
if command -v "$executable" >/dev/null 2>&1; then
40+
ACTUAL_VERSION=$("$executable" --version | grep -Eo '[0-9]+(\.[0-9]+)*' | head -n 1)
41+
echo "$executable version: $ACTUAL_VERSION detected"
42+
if [ "$ACTUAL_VERSION" != "$CMAKE_VERSION" ]; then
43+
echo "E: $executable version mismatch. Expected $CMAKE_VERSION, found '$ACTUAL_VERSION'" >&2
44+
exit 1
45+
fi
46+
else
47+
echo "E: $executable is not installed or not in PATH." >&2
48+
exit 1
49+
fi
50+
done

ci/setup_grpc.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ if [[ $build_internal_abseil_cpp -ne 0 ]]; then
114114
ABSEIL_CPP_BUILD_OPTIONS=(${ABSEIL_CPP_BUILD_OPTIONS[@]} "-DBUILD_SHARED_LIBS=$build_shared_libs")
115115
fi
116116
cmake "${ABSEIL_CPP_BUILD_OPTIONS[@]}" ..
117-
cmake --build . -j${nproc} --target install && popd
117+
make -j $(nproc)
118+
make install
119+
popd
118120
fi
119121
mkdir -p build && pushd build
120122

@@ -144,8 +146,8 @@ echo "Building gRPC ${install_grpc_version}"
144146
echo "CMake build options:" "${GRPC_BUILD_OPTIONS[@]}"
145147

146148
cmake "${GRPC_BUILD_OPTIONS[@]}" ..
147-
cmake --build . -j$(nproc)
148-
cmake --install .
149+
make -j $(nproc)
150+
make install
149151
popd
150152
popd
151153

docker/grpc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
55

66
project(
77
dependencies

install/test/cmake/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.10)
4+
cmake_minimum_required(VERSION 3.16)
55
project(opentelemetry-cpp-component-install-tests LANGUAGES CXX)
66

77
if(NOT INSTALL_TEST_CMAKE_OPTIONS)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.10)
4+
cmake_minimum_required(VERSION 3.16)
55

66
project(opentelemetry-cpp-api-install-test LANGUAGES CXX)
77

@@ -11,7 +11,7 @@ find_package(GTest REQUIRED)
1111
include(GoogleTest)
1212

1313
add_executable(api_test ${INSTALL_TEST_SRC_DIR}/test_api.cc)
14-
target_link_libraries(api_test PRIVATE opentelemetry-cpp::api GTest::gtest
15-
GTest::gtest_main)
14+
target_link_libraries(api_test PRIVATE opentelemetry-cpp::api GTest::GTest
15+
GTest::Main)
1616

1717
gtest_discover_tests(api_test)

install/test/cmake/component_tests/exporters_elasticsearch/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.10)
4+
cmake_minimum_required(VERSION 3.16)
55
project(opentelemetry-cpp-exporters-elasticsearch-install-test LANGUAGES CXX)
66

77
find_package(opentelemetry-cpp REQUIRED COMPONENTS exporters_elasticsearch)
@@ -17,7 +17,7 @@ add_executable(exporters_elasticsearch_test
1717
${INSTALL_TEST_SRC_DIR}/test_exporters_elasticsearch.cc)
1818
target_link_libraries(
1919
exporters_elasticsearch_test
20-
PRIVATE opentelemetry-cpp::elasticsearch_log_record_exporter GTest::gtest
21-
GTest::gtest_main)
20+
PRIVATE opentelemetry-cpp::elasticsearch_log_record_exporter GTest::GTest
21+
GTest::Main)
2222

2323
gtest_discover_tests(exporters_elasticsearch_test)

0 commit comments

Comments
 (0)