Skip to content

Commit 549f2b0

Browse files
authored
[TEST] test examples in CI with CMake Part 1 (#3449)
1 parent d64b653 commit 549f2b0

File tree

21 files changed

+164
-52
lines changed

21 files changed

+164
-52
lines changed

.github/workflows/cmake_install.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ jobs:
254254
run: |
255255
sudo -E ./ci/setup_cmake.sh
256256
conan install install/conan/conanfile_stable.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
257+
conan cache clean --source --build
257258
- name: Run Tests (static libs)
258259
env:
259260
BUILD_SHARED_LIBS: 'OFF'
@@ -297,6 +298,7 @@ jobs:
297298
run: |
298299
sudo -E ./ci/setup_cmake.sh
299300
conan install install/conan/conanfile_latest.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
301+
conan cache clean --source --build
300302
- name: Run Tests (static libs)
301303
env:
302304
BUILD_SHARED_LIBS: 'OFF'
@@ -330,7 +332,9 @@ jobs:
330332
./ci/setup_cmake_macos.sh
331333
conan profile detect --force
332334
- name: Install or build all dependencies with Conan
333-
run: conan install install/conan/conanfile_stable.txt --build=missing -of /Users/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
335+
run: |
336+
conan install install/conan/conanfile_stable.txt --build=missing -of /Users/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD}
337+
conan cache clean --source --build
334338
- name: Run Tests (static libs)
335339
env:
336340
BUILD_SHARED_LIBS: 'OFF'

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Increment the:
1515

1616
## [Unreleased]
1717

18+
* [TEST] Test examples in CI with CMake Part 1
19+
[#3449](https://github.com/open-telemetry/opentelemetry-cpp/pull/3449)
20+
1821
## [1.21 2025-05-28]
1922

2023
* [BUILD] Remove WITH_ABSEIL

ci/do_ci.ps1

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,8 @@ switch ($action) {
7777
if ($exit -ne 0) {
7878
exit $exit
7979
}
80-
ctest -C Debug
81-
$exit = $LASTEXITCODE
82-
if ($exit -ne 0) {
83-
exit $exit
84-
}
8580
$env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH"
86-
examples\simple\Debug\example_simple.exe
87-
$exit = $LASTEXITCODE
88-
if ($exit -ne 0) {
89-
exit $exit
90-
}
91-
examples\metrics_simple\Debug\metrics_ostream_example.exe
92-
$exit = $LASTEXITCODE
93-
if ($exit -ne 0) {
94-
exit $exit
95-
}
96-
examples\logs_simple\Debug\example_logs_simple.exe
81+
ctest -C Debug
9782
$exit = $LASTEXITCODE
9883
if ($exit -ne 0) {
9984
exit $exit
@@ -115,23 +100,8 @@ switch ($action) {
115100
if ($exit -ne 0) {
116101
exit $exit
117102
}
118-
ctest -C Debug
119-
$exit = $LASTEXITCODE
120-
if ($exit -ne 0) {
121-
exit $exit
122-
}
123103
$env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH"
124-
examples\simple\Debug\example_simple.exe
125-
$exit = $LASTEXITCODE
126-
if ($exit -ne 0) {
127-
exit $exit
128-
}
129-
examples\metrics_simple\Debug\metrics_ostream_example.exe
130-
$exit = $LASTEXITCODE
131-
if ($exit -ne 0) {
132-
exit $exit
133-
}
134-
examples\logs_simple\Debug\example_logs_simple.exe
104+
ctest -C Debug
135105
$exit = $LASTEXITCODE
136106
if ($exit -ne 0) {
137107
exit $exit
@@ -277,6 +247,7 @@ switch ($action) {
277247
if ($exit -ne 0) {
278248
exit $exit
279249
}
250+
$env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH"
280251
ctest -C Debug
281252
$exit = $LASTEXITCODE
282253
if ($exit -ne 0) {
@@ -467,13 +438,13 @@ switch ($action) {
467438
$CMAKE_OPTIONS = @(
468439
"-DCMAKE_CXX_STANDARD=17",
469440
"-DVCPKG_TARGET_TRIPLET=x64-windows",
470-
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
441+
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake",
442+
"-DOPENTELEMETRY_BUILD_DLL=1"
471443
)
472444

473445
cmake $SRC_DIR `
474446
$CMAKE_OPTIONS `
475447
"-DCMAKE_INSTALL_PREFIX=$INSTALL_TEST_DIR" `
476-
-DOPENTELEMETRY_BUILD_DLL=1 `
477448
-DWITH_ABI_VERSION_1=ON `
478449
-DWITH_ABI_VERSION_2=OFF `
479450
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON `

examples/batch/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ add_executable(batch_span_processor_example main.cc)
55
target_link_libraries(
66
batch_span_processor_example PRIVATE opentelemetry-cpp::ostream_span_exporter
77
opentelemetry-cpp::trace)
8+
9+
if(BUILD_TESTING)
10+
add_test(NAME examples.batch
11+
COMMAND "$<TARGET_FILE:batch_span_processor_example>")
12+
endif()

examples/common/foo_library/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
add_library(common_foo_library foo_library.h foo_library.cc)
55

6-
set_target_version(common_foo_library)
7-
86
if(DEFINED OPENTELEMETRY_BUILD_DLL)
97
target_compile_definitions(common_foo_library
108
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)

examples/common/logs_foo_library/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
add_library(common_logs_foo_library foo_library.h foo_library.cc)
55

6-
set_target_version(common_logs_foo_library)
7-
86
if(DEFINED OPENTELEMETRY_BUILD_DLL)
97
target_compile_definitions(common_logs_foo_library
108
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)

examples/common/metrics_foo_library/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
add_library(common_metrics_foo_library foo_library.h foo_library.cc)
55

6-
set_target_version(common_metrics_foo_library)
7-
86
if(DEFINED OPENTELEMETRY_BUILD_DLL)
97
target_compile_definitions(common_metrics_foo_library
108
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)

examples/etw_threads/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ add_executable(etw_threadpool main.cc)
88
target_link_libraries(
99
etw_threadpool PRIVATE Threads::Threads opentelemetry-cpp::api
1010
opentelemetry-cpp::etw_exporter)
11+
12+
if(BUILD_TESTING)
13+
add_test(NAME examples.etw_threads COMMAND "$<TARGET_FILE:etw_threadpool>")
14+
endif()

examples/grpc/CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,35 @@ set(example_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/messages.pb.h")
1212
set(example_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/messages.grpc.pb.cc")
1313
set(example_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/messages.grpc.pb.h")
1414

15+
if(NOT TARGET gRPC::grpc_cpp_plugin)
16+
message(
17+
FATAL_ERROR
18+
"gRPC::grpc_cpp_plugin target not found. Please ensure that gRPC is installed and found with find_package."
19+
)
20+
endif()
21+
22+
if(NOT DEFINED PROTOBUF_PROTOC_EXECUTABLE)
23+
if(NOT TARGET protobuf::protoc)
24+
message(
25+
FATAL_ERROR
26+
"protobuf::protoc target not found. Please ensure that Protobuf is installed and found with find_package."
27+
)
28+
endif()
29+
set(PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
30+
endif()
31+
1532
add_custom_command(
1633
OUTPUT "${example_proto_srcs}" "${example_proto_hdrs}" "${example_grpc_srcs}"
1734
"${example_grpc_hdrs}"
1835
COMMAND
1936
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}"
2037
"--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" "--proto_path=${proto_file_path}"
21-
"--plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN_EXECUTABLE}" "${proto_file}")
38+
"--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
39+
"${proto_file}")
2240

2341
add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}
2442
${example_proto_srcs} ${example_proto_hdrs})
2543

26-
patch_protobuf_targets(example_grpc_proto)
27-
2844
# Disable include-what-you-use on generated code.
2945
set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")
3046

@@ -45,5 +61,4 @@ foreach(_target client server)
4561
target_link_libraries(
4662
${_target} PRIVATE example_grpc_proto
4763
opentelemetry-cpp::ostream_span_exporter)
48-
patch_protobuf_targets(${_target})
4964
endforeach()

examples/grpc/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int main(int argc, char **argv)
127127
uint16_t port;
128128
if (argc > 1)
129129
{
130-
port = atoi(argv[1]);
130+
port = static_cast<uint16_t>(atoi(argv[1]));
131131
}
132132
else
133133
{

0 commit comments

Comments
 (0)