Skip to content

Commit 2c8f006

Browse files
committed
test examples with build and install
1 parent b9cf499 commit 2c8f006

File tree

15 files changed

+143
-13
lines changed

15 files changed

+143
-13
lines changed

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/logs_simple/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ else()
1616
opentelemetry-cpp::ostream_span_exporter
1717
opentelemetry-cpp::ostream_log_record_exporter)
1818
endif()
19+
20+
if(BUILD_TESTING)
21+
add_test(NAME examples.logs_simple
22+
COMMAND "$<TARGET_FILE:example_logs_simple>")
23+
endif()

examples/metrics_simple/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ else()
1616
metrics_ostream_example PRIVATE opentelemetry-cpp::metrics
1717
opentelemetry-cpp::ostream_metrics_exporter)
1818
endif()
19+
20+
if(BUILD_TESTING)
21+
add_test(NAME examples.metrics_simple
22+
COMMAND "$<TARGET_FILE:metrics_ostream_example>")
23+
endif()

examples/multi_processor/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ target_link_libraries(
77
PRIVATE common_foo_library opentelemetry-cpp::trace
88
opentelemetry-cpp::ostream_span_exporter
99
opentelemetry-cpp::in_memory_span_exporter)
10+
11+
if(BUILD_TESTING)
12+
add_test(NAME examples.multi_processor
13+
COMMAND "$<TARGET_FILE:example_multi_processor>")
14+
endif()

examples/multithreaded/CMakeLists.txt

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

0 commit comments

Comments
 (0)