@@ -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 ()
0 commit comments