11# Copyright The OpenTelemetry Authors
22# SPDX-License-Identifier: Apache-2.0
33
4+ if (protobuf_lib_type STREQUAL "STATIC_LIBRARY" )
5+ set (OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE STATIC )
6+ else ()
7+ set (OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE)
8+ endif ()
9+
410add_library (
511 opentelemetry_otlp_recordable
6- src/otlp_environment.cc src/otlp_log_recordable.cc src/otlp_recordable.cc
7- src/otlp_populate_attribute_utils.cc src/otlp_recordable_utils.cc
12+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE}
13+ src/otlp_environment.cc
14+ src/otlp_log_recordable.cc
15+ src/otlp_recordable.cc
16+ src/otlp_populate_attribute_utils.cc
17+ src/otlp_recordable_utils.cc
818 src/otlp_metric_utils.cc)
919set_target_properties (opentelemetry_otlp_recordable PROPERTIES EXPORT_NAME
1020 otlp_recordable)
@@ -23,10 +33,20 @@ target_link_libraries(opentelemetry_otlp_recordable
2333
2434if (WITH_OTLP_GRPC)
2535 find_package (gRPC REQUIRED)
36+ if (NOT DEFINED grpc_lib_type)
37+ message (
38+ FATAL_ERROR "cmake/opentelemetry-proto.cmake should be included first" )
39+ endif ()
40+ if (grpc_lib_type STREQUAL "STATIC_LIBRARY" OR protobuf_lib_type STREQUAL
41+ "STATIC_LIBRARY" )
42+ set (OPENTELEMETRY_OTLP_GRPC_CLIENT_LIB_TYPE STATIC )
43+ else ()
44+ set (OPENTELEMETRY_OTLP_GRPC_CLIENT_LIB_TYPE)
45+ endif ()
2646 add_library (
2747 opentelemetry_exporter_otlp_grpc_client
28- src/otlp_grpc_client.cc src/otlp_grpc_client_factory .cc
29- src/otlp_grpc_utils.cc)
48+ ${OPENTELEMETRY_OTLP_GRPC_CLIENT_LIB_TYPE} src/otlp_grpc_client .cc
49+ src/otlp_grpc_client_factory.cc src/ otlp_grpc_utils.cc)
3050 set_target_properties (opentelemetry_exporter_otlp_grpc_client
3151 PROPERTIES EXPORT_NAME otlp_grpc_client)
3252 set_target_version(opentelemetry_exporter_otlp_grpc_client)
@@ -40,8 +60,9 @@ if(WITH_OTLP_GRPC)
4060 opentelemetry_exporter_otlp_grpc_client
4161 PUBLIC opentelemetry_sdk opentelemetry_common
4262 # gRPC::grpc++ must be linked before opentelemetry_proto_grpc.
43- opentelemetry_proto_grpc
44- PRIVATE gRPC::grpc++ opentelemetry_ext)
63+ "$<BUILD_INTERFACE:opentelemetry_proto_grpc>"
64+ PRIVATE "$<INSTALL_INTERFACE:opentelemetry_proto_grpc>" gRPC::grpc++
65+ opentelemetry_ext)
4566
4667 get_target_property (GRPC_INCLUDE_DIRECTORY gRPC::grpc++
4768 INTERFACE_INCLUDE_DIRECTORIES )
@@ -60,8 +81,8 @@ if(WITH_OTLP_GRPC)
6081
6182 add_library (
6283 opentelemetry_exporter_otlp_grpc
63- src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory .cc
64- src/otlp_grpc_exporter_options.cc)
84+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_grpc_exporter .cc
85+ src/otlp_grpc_exporter_factory.cc src/ otlp_grpc_exporter_options.cc)
6586
6687 set_target_properties (opentelemetry_exporter_otlp_grpc
6788 PROPERTIES EXPORT_NAME otlp_grpc_exporter)
@@ -76,7 +97,7 @@ if(WITH_OTLP_GRPC)
7697
7798 add_library (
7899 opentelemetry_exporter_otlp_grpc_log
79- src/otlp_grpc_log_record_exporter.cc
100+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_grpc_log_record_exporter.cc
80101 src/otlp_grpc_log_record_exporter_factory.cc
81102 src/otlp_grpc_log_record_exporter_options.cc)
82103
@@ -94,7 +115,8 @@ if(WITH_OTLP_GRPC)
94115
95116 add_library (
96117 opentelemetry_exporter_otlp_grpc_metrics
97- src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc
118+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_grpc_metric_exporter.cc
119+ src/otlp_grpc_metric_exporter_factory.cc
98120 src/otlp_grpc_metric_exporter_options.cc)
99121
100122 set_target_properties (opentelemetry_exporter_otlp_grpc_metrics
@@ -111,8 +133,10 @@ if(WITH_OTLP_GRPC)
111133endif ()
112134
113135if (WITH_OTLP_HTTP)
114- add_library (opentelemetry_exporter_otlp_http_client src/otlp_http.cc
115- src/otlp_http_client.cc)
136+ add_library (
137+ opentelemetry_exporter_otlp_http_client
138+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_http.cc
139+ src/otlp_http_client.cc)
116140 set_target_properties (opentelemetry_exporter_otlp_http_client
117141 PROPERTIES EXPORT_NAME otlp_http_client)
118142 set_target_version(opentelemetry_exporter_otlp_http_client)
@@ -141,8 +165,8 @@ if(WITH_OTLP_HTTP)
141165
142166 add_library (
143167 opentelemetry_exporter_otlp_http
144- src/otlp_http_exporter.cc src/otlp_http_exporter_factory .cc
145- src/otlp_http_exporter_options.cc)
168+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_http_exporter .cc
169+ src/otlp_http_exporter_factory.cc src/ otlp_http_exporter_options.cc)
146170
147171 set_target_properties (opentelemetry_exporter_otlp_http
148172 PROPERTIES EXPORT_NAME otlp_http_exporter)
@@ -157,7 +181,7 @@ if(WITH_OTLP_HTTP)
157181
158182 add_library (
159183 opentelemetry_exporter_otlp_http_log
160- src/otlp_http_log_record_exporter.cc
184+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_http_log_record_exporter.cc
161185 src/otlp_http_log_record_exporter_factory.cc
162186 src/otlp_http_log_record_exporter_options.cc)
163187
@@ -175,7 +199,8 @@ if(WITH_OTLP_HTTP)
175199
176200 add_library (
177201 opentelemetry_exporter_otlp_http_metric
178- src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc
202+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_http_metric_exporter.cc
203+ src/otlp_http_metric_exporter_factory.cc
179204 src/otlp_http_metric_exporter_options.cc)
180205
181206 set_target_properties (opentelemetry_exporter_otlp_http_metric
@@ -192,7 +217,8 @@ if(WITH_OTLP_HTTP)
192217endif ()
193218
194219if (WITH_OTLP_FILE)
195- add_library (opentelemetry_exporter_otlp_file_client src/otlp_file_client.cc)
220+ add_library (opentelemetry_exporter_otlp_file_client
221+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_file_client.cc)
196222 set_target_properties (opentelemetry_exporter_otlp_file_client
197223 PROPERTIES EXPORT_NAME otlp_file_client)
198224 set_target_version(opentelemetry_exporter_otlp_file_client)
@@ -216,8 +242,8 @@ if(WITH_OTLP_FILE)
216242
217243 add_library (
218244 opentelemetry_exporter_otlp_file
219- src/otlp_file_exporter.cc src/otlp_file_exporter_factory .cc
220- src/otlp_file_exporter_options.cc)
245+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_file_exporter .cc
246+ src/otlp_file_exporter_factory.cc src/ otlp_file_exporter_options.cc)
221247
222248 set_target_properties (opentelemetry_exporter_otlp_file
223249 PROPERTIES EXPORT_NAME otlp_file_exporter)
@@ -232,7 +258,7 @@ if(WITH_OTLP_FILE)
232258
233259 add_library (
234260 opentelemetry_exporter_otlp_file_log
235- src/otlp_file_log_record_exporter.cc
261+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_file_log_record_exporter.cc
236262 src/otlp_file_log_record_exporter_factory.cc
237263 src/otlp_file_log_record_exporter_options.cc)
238264
@@ -250,7 +276,8 @@ if(WITH_OTLP_FILE)
250276
251277 add_library (
252278 opentelemetry_exporter_otlp_file_metric
253- src/otlp_file_metric_exporter.cc src/otlp_file_metric_exporter_factory.cc
279+ ${OPENTELEMETRY_OTLP_TARGETS_LIB_TYPE} src/otlp_file_metric_exporter.cc
280+ src/otlp_file_metric_exporter_factory.cc
254281 src/otlp_file_metric_exporter_options.cc)
255282
256283 set_target_properties (opentelemetry_exporter_otlp_file_metric
@@ -371,7 +398,7 @@ if(BUILD_TESTING)
371398 add_executable (otlp_grpc_exporter_test test /otlp_grpc_exporter_test.cc)
372399 target_link_libraries (
373400 otlp_grpc_exporter_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
374- ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc gRPC::grpc++ )
401+ ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc)
375402 gtest_add_tests(
376403 TARGET otlp_grpc_exporter_test
377404 TEST_PREFIX exporter.otlp.
0 commit comments