Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build opentelemetry-proto collector interface with cmake only if WITH_OTLP_GRPC is enabled. #1061

Merged
merged 4 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ endif()
if(WITH_OTLP)
set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf)
find_package(gRPC)
if(WITH_OTLP_GRPC)
find_package(gRPC)
endif()
if((NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND) OR (NOT gRPC_FOUND))
if(WIN32 AND (NOT DEFINED CMAKE_TOOLCHAIN_FILE))
install_windows_deps()
Expand All @@ -346,7 +348,7 @@ if(WITH_OTLP)
if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND)
find_package(Protobuf REQUIRED)
endif()
if(NOT gRPC_FOUND)
if(WITH_OTLP_GRPC AND NOT gRPC_FOUND)
find_package(gRPC)
endif()
if(WIN32)
Expand Down
47 changes: 46 additions & 1 deletion cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,48 +79,56 @@ set(TRACE_SERVICE_PB_CPP_FILE
set(TRACE_SERVICE_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/trace/v1/trace_service.pb.h"
)
if(WITH_OTLP_GRPC)
set(TRACE_SERVICE_GRPC_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.cc"
)
set(TRACE_SERVICE_GRPC_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"
)
endif()
set(LOGS_SERVICE_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/logs/v1/logs_service.pb.cc"
)
set(LOGS_SERVICE_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/logs/v1/logs_service.pb.h"
)
if(WITH_OTLP_GRPC)
set(LOGS_SERVICE_GRPC_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.cc"
)
set(LOGS_SERVICE_GRPC_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h"
)
endif()
set(METRICS_SERVICE_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc"
)
set(METRICS_SERVICE_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h"
)
if(WITH_OTLP_GRPC)
set(METRICS_SERVICE_GRPC_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc"
)
set(METRICS_SERVICE_GRPC_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h"
)
endif()

foreach(IMPORT_DIR ${PROTOBUF_IMPORT_DIRS})
list(APPEND PROTOBUF_INCLUDE_FLAGS "-I${IMPORT_DIR}")
endforeach()


if(WITH_OTLP_GRPC)
if(CMAKE_CROSSCOMPILING)
find_program(gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
else()
set(gRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
endif()
endif()

if(WITH_OTLP_GRPC)
add_custom_command(
OUTPUT ${COMMON_PB_H_FILE}
${COMMON_PB_CPP_FILE}
Expand Down Expand Up @@ -151,9 +159,34 @@ add_custom_command(
--plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" ${COMMON_PROTO}
${RESOURCE_PROTO} ${TRACE_PROTO} ${LOGS_PROTO} ${METRICS_PROTO}
${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO} ${METRICS_SERVICE_PROTO})
else()
add_custom_command(
OUTPUT ${COMMON_PB_H_FILE}
${COMMON_PB_CPP_FILE}
${RESOURCE_PB_H_FILE}
${RESOURCE_PB_CPP_FILE}
${TRACE_PB_H_FILE}
${TRACE_PB_CPP_FILE}
${LOGS_PB_H_FILE}
${LOGS_PB_CPP_FILE}
${METRICS_PB_H_FILE}
${METRICS_PB_CPP_FILE}
${TRACE_SERVICE_PB_H_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_PB_H_FILE}
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_H_FILE}
${METRICS_SERVICE_PB_CPP_FILE}
COMMAND
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--proto_path=${PROTO_PATH}"
${PROTOBUF_INCLUDE_FLAGS} "--cpp_out=${GENERATED_PROTOBUF_PATH}"
${COMMON_PROTO} ${RESOURCE_PROTO} ${TRACE_PROTO} ${LOGS_PROTO} ${METRICS_PROTO}
${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO} ${METRICS_SERVICE_PROTO})
endif()

include_directories("${GENERATED_PROTOBUF_PATH}")

if(WITH_OTLP_GRPC)
add_library(
opentelemetry_proto STATIC
${COMMON_PB_CPP_FILE}
Expand All @@ -167,6 +200,18 @@ add_library(
${LOGS_SERVICE_GRPC_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_GRPC_PB_CPP_FILE})
else()
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})
endif()

if(needs_proto_download)
add_dependencies(opentelemetry_proto opentelemetry-proto)
Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ add_subdirectory(common)
include_directories(common)
if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP)
add_subdirectory(otlp)
endif()
if(WITH_OTLP_GRPC)
add_subdirectory(grpc)
endif()
if(WITH_ETW)
Expand Down