Skip to content

Commit 82ec2a5

Browse files
authored
[CMAKE] update cmake files in examples directory (#3421)
1 parent ba04dbb commit 82ec2a5

File tree

21 files changed

+233
-168
lines changed

21 files changed

+233
-168
lines changed

examples/CMakeLists.txt

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

44
add_subdirectory(common)
5-
include_directories(common)
5+
66
if(WITH_OTLP_GRPC
77
OR WITH_OTLP_HTTP
88
OR WITH_OTLP_FILE)

examples/batch/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
3-
4-
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include)
5-
63
add_executable(batch_span_processor_example main.cc)
74

8-
target_link_libraries(batch_span_processor_example ${CMAKE_THREAD_LIBS_INIT}
9-
opentelemetry_exporter_ostream_span opentelemetry_trace)
5+
target_link_libraries(
6+
batch_span_processor_example PRIVATE opentelemetry-cpp::ostream_span_exporter
7+
opentelemetry-cpp::trace)

examples/common/CMakeLists.txt

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

4+
set(EXAMPLES_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR})
45
add_subdirectory(foo_library)
56
add_subdirectory(logs_foo_library)
67
add_subdirectory(metrics_foo_library)
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if(DEFINED OPENTELEMETRY_BUILD_DLL)
5-
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
6-
endif()
7-
84
add_library(common_foo_library foo_library.h foo_library.cc)
5+
96
set_target_version(common_foo_library)
107

11-
target_link_libraries(common_foo_library PUBLIC ${CMAKE_THREAD_LIBS_INIT}
12-
opentelemetry_api)
8+
if(DEFINED OPENTELEMETRY_BUILD_DLL)
9+
target_compile_definitions(common_foo_library
10+
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
11+
endif()
12+
13+
target_include_directories(common_foo_library
14+
PUBLIC "$<BUILD_INTERFACE:${EXAMPLES_COMMON_DIR}>")
15+
target_link_libraries(common_foo_library PRIVATE opentelemetry-cpp::api)
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4+
add_library(common_logs_foo_library foo_library.h foo_library.cc)
5+
6+
set_target_version(common_logs_foo_library)
7+
48
if(DEFINED OPENTELEMETRY_BUILD_DLL)
5-
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
9+
target_compile_definitions(common_logs_foo_library
10+
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
611
endif()
712

8-
add_library(common_logs_foo_library foo_library.h foo_library.cc)
9-
set_target_version(common_logs_foo_library)
13+
target_include_directories(common_logs_foo_library
14+
PUBLIC $<BUILD_INTERFACE:${EXAMPLES_COMMON_DIR}>)
1015

11-
target_link_libraries(common_logs_foo_library PUBLIC ${CMAKE_THREAD_LIBS_INIT}
12-
opentelemetry_api)
16+
target_link_libraries(common_logs_foo_library PRIVATE opentelemetry-cpp::api)
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4+
add_library(common_metrics_foo_library foo_library.h foo_library.cc)
5+
6+
set_target_version(common_metrics_foo_library)
7+
48
if(DEFINED OPENTELEMETRY_BUILD_DLL)
5-
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
9+
target_compile_definitions(common_metrics_foo_library
10+
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
611
endif()
712

8-
add_library(common_metrics_foo_library foo_library.h foo_library.cc)
9-
set_target_version(common_metrics_foo_library)
13+
target_include_directories(common_metrics_foo_library
14+
PUBLIC $<BUILD_INTERFACE:${EXAMPLES_COMMON_DIR}>)
1015

11-
target_link_libraries(common_metrics_foo_library
12-
PUBLIC ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
16+
target_link_libraries(common_metrics_foo_library PRIVATE opentelemetry-cpp::api)

examples/etw_threads/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ project(etw_threadpool)
55

66
add_executable(etw_threadpool main.cc)
77

8-
target_link_libraries(etw_threadpool ${CMAKE_THREAD_LIBS_INIT}
9-
opentelemetry_api opentelemetry_exporter_etw)
8+
target_link_libraries(
9+
etw_threadpool PRIVATE Threads::Threads opentelemetry-cpp::api
10+
opentelemetry-cpp::etw_exporter)

examples/grpc/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ patch_protobuf_targets(example_grpc_proto)
2828
# Disable include-what-you-use on generated code.
2929
set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "")
3030

31-
include_directories(
32-
${CMAKE_SOURCE_DIR}/exporters/ostream/include ${CMAKE_SOURCE_DIR}/ext/include
33-
${CMAKE_SOURCE_DIR}/api/include/ ${CMAKE_SOURCE_DIR/})
34-
35-
include_directories(${CMAKE_CURRENT_BINARY_DIR})
31+
target_include_directories(
32+
example_grpc_proto PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
3633

3734
if(TARGET protobuf::libprotobuf)
3835
target_link_libraries(example_grpc_proto PUBLIC gRPC::grpc++
@@ -45,7 +42,8 @@ endif()
4542

4643
foreach(_target client server)
4744
add_executable(${_target} "${_target}.cc")
48-
target_link_libraries(${_target} example_grpc_proto opentelemetry_trace
49-
opentelemetry_exporter_ostream_span)
45+
target_link_libraries(
46+
${_target} PRIVATE example_grpc_proto
47+
opentelemetry-cpp::ostream_span_exporter)
5048
patch_protobuf_targets(${_target})
5149
endforeach()

examples/http/CMakeLists.txt

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

4-
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include
5-
${CMAKE_SOURCE_DIR}/ext/include ${CMAKE_SOURCE_DIR/})
6-
74
add_executable(http_client client.cc)
85
add_executable(http_server server.cc)
96

107
target_link_libraries(
11-
http_client ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace
12-
opentelemetry_http_client_curl opentelemetry_exporter_ostream_span
13-
${CURL_LIBRARIES})
8+
http_client
9+
PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::http_client_curl
10+
opentelemetry-cpp::ostream_span_exporter ${CURL_LIBRARIES})
1411

1512
target_link_libraries(
16-
http_server ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace
17-
opentelemetry_http_client_curl opentelemetry_exporter_ostream_span)
13+
http_server
14+
PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::http_client_curl
15+
opentelemetry-cpp::ostream_span_exporter)

examples/logs_simple/CMakeLists.txt

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

4-
if(DEFINED OPENTELEMETRY_BUILD_DLL)
5-
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
6-
endif()
7-
8-
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include)
9-
104
add_executable(example_logs_simple main.cc)
11-
target_link_libraries(example_logs_simple ${CMAKE_THREAD_LIBS_INIT}
12-
common_logs_foo_library)
5+
target_link_libraries(example_logs_simple PRIVATE common_logs_foo_library)
136

147
if(DEFINED OPENTELEMETRY_BUILD_DLL)
15-
target_link_libraries(example_logs_simple opentelemetry_cpp)
8+
target_compile_definitions(example_logs_simple
9+
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
10+
target_link_libraries(example_logs_simple
11+
PRIVATE opentelemetry-cpp::opentelemetry_cpp)
1612
else()
1713
target_link_libraries(
18-
example_logs_simple opentelemetry_trace opentelemetry_logs
19-
opentelemetry_exporter_ostream_span opentelemetry_exporter_ostream_logs)
14+
example_logs_simple
15+
PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::logs
16+
opentelemetry-cpp::ostream_span_exporter
17+
opentelemetry-cpp::ostream_log_record_exporter)
2018
endif()
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if(DEFINED OPENTELEMETRY_BUILD_DLL)
5-
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
6-
endif()
7-
8-
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include)
9-
104
add_executable(metrics_ostream_example metrics_ostream.cc)
11-
target_link_libraries(metrics_ostream_example ${CMAKE_THREAD_LIBS_INIT}
12-
common_metrics_foo_library)
5+
6+
target_link_libraries(metrics_ostream_example
7+
PRIVATE common_metrics_foo_library)
138

149
if(DEFINED OPENTELEMETRY_BUILD_DLL)
15-
target_link_libraries(metrics_ostream_example opentelemetry_cpp)
10+
target_compile_definitions(metrics_ostream_example
11+
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
12+
target_link_libraries(metrics_ostream_example
13+
PRIVATE opentelemetry-cpp::opentelemetry_cpp)
1614
else()
1715
target_link_libraries(
18-
metrics_ostream_example opentelemetry_metrics
19-
opentelemetry_exporter_ostream_metrics opentelemetry_resources)
16+
metrics_ostream_example PRIVATE opentelemetry-cpp::metrics
17+
opentelemetry-cpp::ostream_metrics_exporter)
2018
endif()
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include
5-
${CMAKE_SOURCE_DIR}/exporters/memory/include)
6-
74
add_executable(example_multi_processor main.cc)
85
target_link_libraries(
9-
example_multi_processor ${CMAKE_THREAD_LIBS_INIT} common_foo_library
10-
opentelemetry_trace opentelemetry_exporter_ostream_span
11-
opentelemetry_exporter_in_memory)
6+
example_multi_processor
7+
PRIVATE common_foo_library opentelemetry-cpp::trace
8+
opentelemetry-cpp::ostream_span_exporter
9+
opentelemetry-cpp::in_memory_span_exporter)

examples/multithreaded/CMakeLists.txt

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

4-
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include)
5-
64
add_executable(example_multithreaded main.cc)
7-
target_link_libraries(example_multithreaded ${CMAKE_THREAD_LIBS_INIT}
8-
opentelemetry_trace opentelemetry_exporter_ostream_span)
5+
target_link_libraries(
6+
example_multithreaded PRIVATE opentelemetry-cpp::trace
7+
opentelemetry-cpp::ostream_span_exporter)

0 commit comments

Comments
 (0)