Skip to content

Commit 4d8ab09

Browse files
committed
Fixes some hints
1 parent 2e3115d commit 4d8ab09

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

cmake/opentelemetry-proto.cmake

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ if(TARGET protobuf::libprotobuf)
236236
".*(protobuf).*")
237237
foreach(protobuf_lib_file ${protobuf_lib_files})
238238
if(protobuf_lib_file MATCHES
239-
"(^|[\\\\\\/])[^\\\\\\/]*protobuf[^\\\\\\/]*.a$")
239+
"(^|[\\\\\\/])[^\\\\\\/]*protobuf[^\\\\\\/]*\\.(a|lib)$")
240240
set(protobuf_lib_type "STATIC_LIBRARY")
241241
break()
242242
endif()
@@ -247,7 +247,7 @@ else()
247247
target_link_libraries(opentelemetry_proto PUBLIC ${Protobuf_LIBRARIES})
248248
foreach(protobuf_lib_file ${Protobuf_LIBRARIES})
249249
if(protobuf_lib_file MATCHES
250-
"(^|[\\\\\\/])[^\\\\\\/]*protobuf[^\\\\\\/]*.a$")
250+
"(^|[\\\\\\/])[^\\\\\\/]*protobuf[^\\\\\\/]*\\.(a|lib)$")
251251
set(protobuf_lib_type "STATIC_LIBRARY")
252252
break()
253253
endif()
@@ -380,7 +380,26 @@ if(WITH_OTLP_GRPC)
380380
list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
381381
target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto)
382382

383+
# gRPC uses numerous global variables, which can lead to conflicts when a
384+
# user's dynamic libraries, executables, and otel-cpp are all built as dynamic
385+
# libraries and linked against a statically built gRPC library. This may
386+
# result in crashes. To prevent such conflicts, we also need to build
387+
# opentelemetry_exporter_otlp_grpc_client as a static library.
383388
get_target_property(grpc_lib_type gRPC::grpc++ TYPE)
389+
# grpc_lib_type may be "INTERFACE_LIBRARY" in some build systems, such as
390+
# conan.
391+
if(grpc_lib_type STREQUAL "INTERFACE_LIBRARY")
392+
project_build_tools_recursive_scan_imported_locations(
393+
grpc_lib_files TARGET_NAME gRPC::grpc++ TARGET_MATCH ".*(grpc|gRPC).*")
394+
foreach(grpc_lib_file ${grpc_lib_files})
395+
if(grpc_lib_file MATCHES
396+
"(^|[\\\\\\/])[^\\\\\\/]*grpc[^\\\\\\/]*\\.(a|lib)$")
397+
set(grpc_lib_type "STATIC_LIBRARY")
398+
break()
399+
endif()
400+
endforeach()
401+
endif()
402+
384403
if(grpc_lib_type STREQUAL "SHARED_LIBRARY")
385404
target_link_libraries(opentelemetry_proto_grpc PUBLIC gRPC::grpc++)
386405
endif()

exporters/otlp/CMakeLists.txt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,9 @@ target_link_libraries(opentelemetry_otlp_recordable
3333

3434
if(WITH_OTLP_GRPC)
3535
find_package(gRPC REQUIRED)
36-
# gRPC uses numerous global variables, which can lead to conflicts when a
37-
# user's dynamic libraries, executables, and otel-cpp are all built as dynamic
38-
# libraries and linked against a statically built gRPC library. This may
39-
# result in crashes. To prevent such conflicts, we also need to build
40-
# opentelemetry_exporter_otlp_grpc_client as a static library.
41-
get_target_property(grpc_lib_type gRPC::grpc++ TYPE)
42-
# grpc_lib_type may be "INTERFACE_LIBRARY" in some build systems, such as
43-
# conan.
44-
if(grpc_lib_type STREQUAL "INTERFACE_LIBRARY")
45-
project_build_tools_recursive_scan_imported_locations(
46-
grpc_lib_files TARGET_NAME gRPC::grpc++ TARGET_MATCH ".*(grpc|gRPC).*")
47-
foreach(grpc_lib_file ${grpc_lib_files})
48-
if(grpc_lib_file MATCHES "(^|[\\\\\\/])[^\\\\\\/]*grpc[^\\\\\\/]*.a$")
49-
set(grpc_lib_type "STATIC_LIBRARY")
50-
break()
51-
endif()
52-
endforeach()
36+
if(NOT DEFINED grpc_lib_type)
37+
message(
38+
FATAL_ERROR "cmake/opentelemetry-proto.cmake should be included first")
5339
endif()
5440
if(grpc_lib_type STREQUAL "STATIC_LIBRARY" OR protobuf_lib_type STREQUAL
5541
"STATIC_LIBRARY")
@@ -74,8 +60,9 @@ if(WITH_OTLP_GRPC)
7460
opentelemetry_exporter_otlp_grpc_client
7561
PUBLIC opentelemetry_sdk opentelemetry_common
7662
# gRPC::grpc++ must be linked before opentelemetry_proto_grpc.
77-
opentelemetry_proto_grpc
78-
PRIVATE gRPC::grpc++ opentelemetry_ext)
63+
"$<BUILD_INTERFACE:opentelemetry_proto_grpc>"
64+
PRIVATE "$<INSTALL_INTERFACE:opentelemetry_proto_grpc>" gRPC::grpc++
65+
opentelemetry_ext)
7966

8067
get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++
8168
INTERFACE_INCLUDE_DIRECTORIES)

0 commit comments

Comments
 (0)