Skip to content

Commit

Permalink
Allow build shared opentelemetry_proto on non-Windows platform. (#2097
Browse files Browse the repository at this point in the history
)
  • Loading branch information
owent authored May 17, 2023
1 parent c9f14e9 commit 23dfc20
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 32 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ Increment the:
[#2123](https://github.com/open-telemetry/opentelemetry-cpp/pull/2123)
* [BUILD] Build break with old curl, macro CURL_VERSION_BITS unknown
[#2102](https://github.com/open-telemetry/opentelemetry-cpp/pull/2102)
* [BUILD] Add opentelemetry_proto_grpc and allow build shared opentelemetry_proto
and opentelemetry_proto_grpc on non-Windows platform.
[#2097](https://github.com/open-telemetry/opentelemetry-cpp/pull/2097)
* [API] Add user facing Logging API and Benchmarks
[#2094](https://github.com/open-telemetry/opentelemetry-cpp/pull/2094)

Breaking changes:

* Add opentelemetry_proto_grpc and move gRPC sources into it.
[#2097](https://github.com/open-telemetry/opentelemetry-cpp/pull/2097)
* There will be no breaking changes for users who only use OTLP exporters and
do not directly use opentelemetry-cpp::proto. However, it is important to
note that `opentelemetry-cpp::proto` no longer contains generated gRPC codes
, and all components that depend on these gRPC codes should also link to
`opentelemetry-cpp::proto_grpc`.

Deprecations:

* The Jaeger Exporter is deprecated, see [DEPRECATED](./DEPRECATED.md) for details.
Expand Down
80 changes: 54 additions & 26 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,31 +229,47 @@ endif()

include_directories("${GENERATED_PROTOBUF_PATH}")

if(WITH_OTLP_GRPC)
add_library(
opentelemetry_proto STATIC
${COMMON_PB_CPP_FILE}
${RESOURCE_PB_CPP_FILE}
${TRACE_PB_CPP_FILE}
${LOGS_PB_CPP_FILE}
${METRICS_PB_CPP_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${TRACE_SERVICE_GRPC_PB_CPP_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_GRPC_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_GRPC_PB_CPP_FILE})
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()

set(OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto)
add_library(
opentelemetry_proto
${OTELCPP_PROTO_TARGET_OPTIONS}
${COMMON_PB_CPP_FILE}
${RESOURCE_PB_CPP_FILE}
${TRACE_PB_CPP_FILE}
${LOGS_PB_CPP_FILE}
${METRICS_PB_CPP_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE})

if(WITH_OTLP_GRPC)
add_library(
opentelemetry_proto STATIC
${COMMON_PB_CPP_FILE}
${RESOURCE_PB_CPP_FILE}
${TRACE_PB_CPP_FILE}
${LOGS_PB_CPP_FILE}
${METRICS_PB_CPP_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE})
opentelemetry_proto_grpc
${OTELCPP_PROTO_TARGET_OPTIONS} ${TRACE_SERVICE_GRPC_PB_CPP_FILE}
${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE})

list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto)

set_target_properties(opentelemetry_proto_grpc PROPERTIES EXPORT_NAME
proto_grpc)
patch_protobuf_targets(opentelemetry_proto_grpc)
get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++
INTERFACE_INCLUDE_DIRECTORIES)
if(GRPC_INCLUDE_DIRECTORY)
target_include_directories(
opentelemetry_proto_grpc
PUBLIC "$<BUILD_INTERFACE:${GRPC_INCLUDE_DIRECTORY}>")
endif()
endif()

if(needs_proto_download)
Expand All @@ -264,7 +280,7 @@ patch_protobuf_targets(opentelemetry_proto)

if(OPENTELEMETRY_INSTALL)
install(
TARGETS opentelemetry_proto
TARGETS ${OPENTELEMETRY_PROTO_TARGETS}
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -282,9 +298,21 @@ if(TARGET protobuf::libprotobuf)
else() # cmake 3.8 or lower
target_include_directories(opentelemetry_proto
PUBLIC ${Protobuf_INCLUDE_DIRS})
target_link_libraries(opentelemetry_proto INTERFACE ${Protobuf_LIBRARIES})
target_link_libraries(opentelemetry_proto PUBLIC ${Protobuf_LIBRARIES})
endif()

if(WITH_OTLP_GRPC)
if(WITH_ABSEIL)
find_package(absl CONFIG)
if(TARGET absl::synchronization)
target_link_libraries(opentelemetry_proto_grpc
PRIVATE absl::synchronization)
endif()
endif()
endif()

if(BUILD_SHARED_LIBS)
set_property(TARGET opentelemetry_proto PROPERTY POSITION_INDEPENDENT_CODE ON)
foreach(proto_target ${OPENTELEMETRY_PROTO_TARGETS})
set_property(TARGET ${proto_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
endforeach()
endif()
18 changes: 12 additions & 6 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ 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)
Expand All @@ -34,13 +31,18 @@ if(WITH_OTLP_GRPC)
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
opentelemetry_proto)
# gRPC::grpc++ must be linked before opentelemetry_proto_grpc.
opentelemetry_proto_grpc
PRIVATE gRPC::grpc++)

target_link_libraries(opentelemetry_exporter_otlp_grpc_client
PRIVATE gRPC::grpc++)
get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++
INTERFACE_INCLUDE_DIRECTORIES)
if(GRPC_INCLUDE_DIRECTORY)
Expand Down Expand Up @@ -174,6 +176,10 @@ if(WITH_OTLP_HTTP)
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}
Expand Down

0 comments on commit 23dfc20

Please sign in to comment.