Skip to content

Commit

Permalink
Fix gRPC linking on ELF ABI.
Browse files Browse the repository at this point in the history
Signed-off-by: WenTao Ou <[email protected]>
  • Loading branch information
owent committed Apr 16, 2023
1 parent 33a8102 commit 69763b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
7 changes: 5 additions & 2 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ include_directories("${GENERATED_PROTOBUF_PATH}")
unset(OTELCPP_PROTO_TARGET_OPTIONS)
if(CMAKE_SYSTEM_NAME MATCHES "Windows|MinGW|WindowsStore")
list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC)
elseif(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
list(APPEND OTELCPP_PROTO_TARGET_OPTIONS SHARED)
else()
list(APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC)
endif()

list(
Expand Down Expand Up @@ -285,10 +289,9 @@ if(WITH_OTLP_GRPC)
if(WITH_ABSEIL)
find_package(absl CONFIG)
if(TARGET absl::synchronization)
target_link_libraries(opentelemetry_proto INTERFACE absl::synchronization)
target_link_libraries(opentelemetry_proto PRIVATE absl::synchronization)
endif()
endif()
target_link_libraries(opentelemetry_proto PUBLIC gRPC::grpc++)
endif()

if(BUILD_SHARED_LIBS)
Expand Down
26 changes: 17 additions & 9 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,31 @@ target_include_directories(
"$<INSTALL_INTERFACE:include>")

set(OPENTELEMETRY_OTLP_TARGETS opentelemetry_otlp_recordable)
target_link_libraries(
opentelemetry_otlp_recordable
PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto)

if(WITH_LOGS_PREVIEW)
target_link_libraries(opentelemetry_otlp_recordable PUBLIC opentelemetry_logs)
endif()
target_link_libraries(opentelemetry_otlp_recordable
PUBLIC opentelemetry_metrics)

set(OPENTELEMETRY_PROTO_LINK_NAME opentelemetry_proto)
if(WITH_OTLP_GRPC)
# Because opentelemetry_proto may depend 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.
set(OPENTELEMETRY_PROTO_LINK_NAME opentelemetry_exporter_otlp_grpc_client)
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)
target_link_libraries(
opentelemetry_exporter_otlp_grpc_client
PUBLIC opentelemetry_sdk opentelemetry_ext opentelemetry_proto)

target_link_libraries(opentelemetry_exporter_otlp_grpc_client
PRIVATE gRPC::grpc++)
PUBLIC opentelemetry_sdk opentelemetry_ext
# gRPC::grpc++ must be linked before opentelemetry_proto.
opentelemetry_proto gRPC::grpc++)
get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++
INTERFACE_INCLUDE_DIRECTORIES)
if(GRPC_INCLUDE_DIRECTORY)
Expand Down Expand Up @@ -102,8 +105,8 @@ if(WITH_OTLP_HTTP)
PROPERTIES EXPORT_NAME otlp_http_client)
target_link_libraries(
opentelemetry_exporter_otlp_http_client
PUBLIC opentelemetry_sdk opentelemetry_proto opentelemetry_http_client_curl
nlohmann_json::nlohmann_json)
PUBLIC opentelemetry_sdk ${OPENTELEMETRY_PROTO_LINK_NAME}
opentelemetry_http_client_curl nlohmann_json::nlohmann_json)
if(nlohmann_json_clone)
add_dependencies(opentelemetry_exporter_otlp_http_client
nlohmann_json::nlohmann_json)
Expand Down Expand Up @@ -162,6 +165,11 @@ if(WITH_OTLP_HTTP)
opentelemetry_exporter_otlp_http_metric)
endif()

target_link_libraries(
opentelemetry_otlp_recordable
PUBLIC opentelemetry_trace opentelemetry_resources
${OPENTELEMETRY_PROTO_LINK_NAME})

if(OPENTELEMETRY_INSTALL)
install(
TARGETS ${OPENTELEMETRY_OTLP_TARGETS}
Expand Down

0 comments on commit 69763b5

Please sign in to comment.