forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
410 lines (356 loc) · 15.5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
add_library(
opentelemetry_otlp_recordable
src/otlp_environment.cc src/otlp_log_recordable.cc src/otlp_recordable.cc
src/otlp_populate_attribute_utils.cc src/otlp_recordable_utils.cc
src/otlp_metric_utils.cc)
set_target_properties(opentelemetry_otlp_recordable PROPERTIES EXPORT_NAME
otlp_recordable)
set_target_version(opentelemetry_otlp_recordable)
target_include_directories(
opentelemetry_otlp_recordable
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
set(OPENTELEMETRY_OTLP_TARGETS opentelemetry_otlp_recordable)
target_link_libraries(opentelemetry_otlp_recordable PUBLIC opentelemetry_logs)
target_link_libraries(opentelemetry_otlp_recordable
PUBLIC opentelemetry_metrics)
if(WITH_OTLP_GRPC)
find_package(gRPC REQUIRED)
add_library(opentelemetry_exporter_otlp_grpc_client src/otlp_grpc_client.cc
src/otlp_grpc_utils.cc)
set_target_properties(opentelemetry_exporter_otlp_grpc_client
PROPERTIES EXPORT_NAME otlp_grpc_client)
set_target_version(opentelemetry_exporter_otlp_grpc_client)
# Because opentelemetry_proto_grpc depends on gRPC, and gRPC can only be
# linked in one dynamic library or executable (otherwise, there may be
# conflicts with some global variables in certain versions of gRPC), we have
# switched the link for opentelemetry_exporter_otlp_grpc_client into all
# targets that depend on opentelemetry_proto_grpc.
target_link_libraries(
opentelemetry_exporter_otlp_grpc_client
PUBLIC opentelemetry_sdk opentelemetry_common opentelemetry_ext
# gRPC::grpc++ must be linked before opentelemetry_proto_grpc.
opentelemetry_proto_grpc
PRIVATE gRPC::grpc++)
get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++
INTERFACE_INCLUDE_DIRECTORIES)
if(GRPC_INCLUDE_DIRECTORY)
target_include_directories(
opentelemetry_exporter_otlp_grpc_client
PUBLIC "$<BUILD_INTERFACE:${GRPC_INCLUDE_DIRECTORY}>")
endif()
target_include_directories(
opentelemetry_exporter_otlp_grpc_client
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
list(APPEND OPENTELEMETRY_OTLP_TARGETS
opentelemetry_exporter_otlp_grpc_client)
add_library(
opentelemetry_exporter_otlp_grpc
src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc
src/otlp_grpc_exporter_options.cc)
set_target_properties(opentelemetry_exporter_otlp_grpc
PROPERTIES EXPORT_NAME otlp_grpc_exporter)
set_target_version(opentelemetry_exporter_otlp_grpc)
target_link_libraries(
opentelemetry_exporter_otlp_grpc
PUBLIC opentelemetry_otlp_recordable
opentelemetry_exporter_otlp_grpc_client)
list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc)
add_library(
opentelemetry_exporter_otlp_grpc_log
src/otlp_grpc_log_record_exporter.cc
src/otlp_grpc_log_record_exporter_factory.cc
src/otlp_grpc_log_record_exporter_options.cc)
set_target_properties(opentelemetry_exporter_otlp_grpc_log
PROPERTIES EXPORT_NAME otlp_grpc_log_record_exporter)
set_target_version(opentelemetry_exporter_otlp_grpc_log)
target_link_libraries(
opentelemetry_exporter_otlp_grpc_log
PUBLIC opentelemetry_otlp_recordable
opentelemetry_exporter_otlp_grpc_client)
list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc_log)
add_library(
opentelemetry_exporter_otlp_grpc_metrics
src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc
src/otlp_grpc_metric_exporter_options.cc)
set_target_properties(opentelemetry_exporter_otlp_grpc_metrics
PROPERTIES EXPORT_NAME otlp_grpc_metrics_exporter)
set_target_version(opentelemetry_exporter_otlp_grpc_metrics)
target_link_libraries(
opentelemetry_exporter_otlp_grpc_metrics
PUBLIC opentelemetry_otlp_recordable
opentelemetry_exporter_otlp_grpc_client)
list(APPEND OPENTELEMETRY_OTLP_TARGETS
opentelemetry_exporter_otlp_grpc_metrics)
endif()
if(WITH_OTLP_HTTP)
add_library(opentelemetry_exporter_otlp_http_client src/otlp_http_client.cc)
set_target_properties(opentelemetry_exporter_otlp_http_client
PROPERTIES EXPORT_NAME otlp_http_client)
set_target_version(opentelemetry_exporter_otlp_http_client)
target_link_libraries(
opentelemetry_exporter_otlp_http_client
PUBLIC opentelemetry_sdk opentelemetry_ext
PRIVATE opentelemetry_proto opentelemetry_http_client_curl
nlohmann_json::nlohmann_json)
if(TARGET absl::strings)
target_link_libraries(opentelemetry_exporter_otlp_http_client
PUBLIC absl::strings)
endif()
if(nlohmann_json_clone)
add_dependencies(opentelemetry_exporter_otlp_http_client
nlohmann_json::nlohmann_json)
endif()
target_include_directories(
opentelemetry_exporter_otlp_http_client
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
list(APPEND OPENTELEMETRY_OTLP_TARGETS
opentelemetry_exporter_otlp_http_client)
add_library(
opentelemetry_exporter_otlp_http
src/otlp_http_exporter.cc src/otlp_http_exporter_factory.cc
src/otlp_http_exporter_options.cc)
set_target_properties(opentelemetry_exporter_otlp_http
PROPERTIES EXPORT_NAME otlp_http_exporter)
set_target_version(opentelemetry_exporter_otlp_http)
target_link_libraries(
opentelemetry_exporter_otlp_http
PUBLIC opentelemetry_otlp_recordable
opentelemetry_exporter_otlp_http_client)
list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http)
add_library(
opentelemetry_exporter_otlp_http_log
src/otlp_http_log_record_exporter.cc
src/otlp_http_log_record_exporter_factory.cc
src/otlp_http_log_record_exporter_options.cc)
set_target_properties(opentelemetry_exporter_otlp_http_log
PROPERTIES EXPORT_NAME otlp_http_log_record_exporter)
set_target_version(opentelemetry_exporter_otlp_http_log)
target_link_libraries(
opentelemetry_exporter_otlp_http_log
PUBLIC opentelemetry_otlp_recordable
opentelemetry_exporter_otlp_http_client)
list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_log)
add_library(
opentelemetry_exporter_otlp_http_metric
src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc
src/otlp_http_metric_exporter_options.cc)
set_target_properties(opentelemetry_exporter_otlp_http_metric
PROPERTIES EXPORT_NAME otlp_http_metric_exporter)
set_target_version(opentelemetry_exporter_otlp_http_metric)
target_link_libraries(
opentelemetry_exporter_otlp_http_metric
PUBLIC opentelemetry_otlp_recordable
opentelemetry_exporter_otlp_http_client)
list(APPEND OPENTELEMETRY_OTLP_TARGETS
opentelemetry_exporter_otlp_http_metric)
endif()
target_link_libraries(
opentelemetry_otlp_recordable
PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto)
if(OPENTELEMETRY_INSTALL)
install(
TARGETS ${OPENTELEMETRY_OTLP_TARGETS}
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
DIRECTORY include/opentelemetry/exporters/otlp
DESTINATION include/opentelemetry/exporters
FILES_MATCHING
PATTERN "*.h")
endif()
if(BUILD_TESTING)
add_executable(otlp_recordable_test test/otlp_recordable_test.cc)
target_link_libraries(
otlp_recordable_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_otlp_recordable protobuf::libprotobuf)
gtest_add_tests(
TARGET otlp_recordable_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_recordable_test)
add_executable(otlp_log_recordable_test test/otlp_log_recordable_test.cc)
target_link_libraries(otlp_log_recordable_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} opentelemetry_otlp_recordable)
gtest_add_tests(
TARGET otlp_log_recordable_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_log_recordable_test)
add_executable(otlp_metrics_serialization_test
test/otlp_metrics_serialization_test.cc)
target_link_libraries(
otlp_metrics_serialization_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} opentelemetry_otlp_recordable
protobuf::libprotobuf)
gtest_add_tests(
TARGET otlp_metrics_serialization_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_metrics_serialization_test)
if(NOT GMOCK_LIB AND TARGET GTest::gmock)
set(GMOCK_LIB GTest::gmock)
elseif(MSVC)
# Explicitly specify that we consume GTest from shared library. The rest of
# code logic below determines whether we link Release or Debug flavor of the
# library. These flavors have different prefix on Windows, gmock and gmockd
# respectively.
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
if(GMOCK_LIB)
# unset GMOCK_LIB to force find_library to redo the lookup, as the cached
# entry could cause linking to incorrect flavor of gmock and leading to
# runtime error.
unset(GMOCK_LIB CACHE)
endif()
endif()
if(NOT GMOCK_LIB)
if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib)
else()
find_library(GMOCK_LIB gmock PATH_SUFFIXES lib)
endif()
endif()
if(WITH_OTLP_GRPC)
add_executable(otlp_grpc_exporter_test test/otlp_grpc_exporter_test.cc)
target_link_libraries(
otlp_grpc_exporter_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB} opentelemetry_exporter_otlp_grpc)
gtest_add_tests(
TARGET otlp_grpc_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_exporter_test)
add_executable(otlp_grpc_exporter_factory_test
test/otlp_grpc_exporter_factory_test.cc)
target_link_libraries(
otlp_grpc_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc)
gtest_add_tests(
TARGET otlp_grpc_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_exporter_factory_test)
add_executable(otlp_grpc_log_record_exporter_test
test/otlp_grpc_log_record_exporter_test.cc)
target_link_libraries(
otlp_grpc_log_record_exporter_test
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB}
opentelemetry_exporter_otlp_grpc
opentelemetry_exporter_otlp_grpc_log
opentelemetry_trace
opentelemetry_logs)
gtest_add_tests(
TARGET otlp_grpc_log_record_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_log_record_exporter_test)
add_executable(otlp_grpc_log_record_exporter_factory_test
test/otlp_grpc_log_record_exporter_factory_test.cc)
target_link_libraries(
otlp_grpc_log_record_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB}
opentelemetry_exporter_otlp_grpc_log opentelemetry_logs)
gtest_add_tests(
TARGET otlp_grpc_log_record_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_log_record_exporter_factory_test)
add_executable(otlp_grpc_metric_exporter_test
test/otlp_grpc_metric_exporter_test.cc)
target_link_libraries(
otlp_grpc_metric_exporter_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc
opentelemetry_exporter_otlp_grpc_metrics)
gtest_add_tests(
TARGET otlp_grpc_metric_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_metric_exporter_test)
add_executable(otlp_grpc_metric_exporter_factory_test
test/otlp_grpc_metric_exporter_factory_test.cc)
target_link_libraries(
otlp_grpc_metric_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB}
opentelemetry_exporter_otlp_grpc_metrics opentelemetry_metrics)
gtest_add_tests(
TARGET otlp_grpc_metric_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_metric_exporter_factory_test)
endif()
if(WITH_OTLP_HTTP)
add_executable(otlp_http_exporter_test test/otlp_http_exporter_test.cc)
target_link_libraries(
otlp_http_exporter_test
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB}
opentelemetry_exporter_otlp_http
opentelemetry_http_client_nosend
nlohmann_json::nlohmann_json
protobuf::libprotobuf)
gtest_add_tests(
TARGET otlp_http_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_exporter_test)
add_executable(otlp_http_exporter_factory_test
test/otlp_http_exporter_factory_test.cc)
target_link_libraries(
otlp_http_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_http)
gtest_add_tests(
TARGET otlp_http_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_exporter_factory_test)
add_executable(otlp_http_log_record_exporter_test
test/otlp_http_log_record_exporter_test.cc)
target_link_libraries(
otlp_http_log_record_exporter_test
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB}
opentelemetry_exporter_otlp_http_log
opentelemetry_logs
opentelemetry_http_client_nosend
nlohmann_json::nlohmann_json)
gtest_add_tests(
TARGET otlp_http_log_record_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_log_record_exporter_test)
add_executable(otlp_http_log_record_exporter_factory_test
test/otlp_http_log_record_exporter_factory_test.cc)
target_link_libraries(
otlp_http_log_record_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB}
opentelemetry_exporter_otlp_http_log opentelemetry_logs)
gtest_add_tests(
TARGET otlp_http_log_record_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_log_record_exporter_factory_test)
add_executable(otlp_http_metric_exporter_test
test/otlp_http_metric_exporter_test.cc)
target_link_libraries(
otlp_http_metric_exporter_test
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB}
opentelemetry_exporter_otlp_http_metric
opentelemetry_metrics
opentelemetry_http_client_nosend
nlohmann_json::nlohmann_json
protobuf::libprotobuf)
gtest_add_tests(
TARGET otlp_http_metric_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_metric_exporter_test)
add_executable(otlp_http_metric_exporter_factory_test
test/otlp_http_metric_exporter_factory_test.cc)
target_link_libraries(
otlp_http_metric_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB}
opentelemetry_exporter_otlp_http_metric opentelemetry_metrics)
gtest_add_tests(
TARGET otlp_http_metric_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_metric_exporter_factory_test)
endif()
endif() # BUILD_TESTING