From 205c31239136ebe93412b6ae7987d938c3eb2376 Mon Sep 17 00:00:00 2001 From: owent Date: Tue, 30 Jun 2026 18:28:13 +0800 Subject: [PATCH 1/2] [CMAKE] Add pkg-config support for OpenTelemetry proto installation --- cmake/opentelemetry-proto.cmake | 36 ++++++++++++++++++++++++--------- cmake/pkgconfig.cmake | 2 ++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index c77a87488d..adb01709c8 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -395,15 +395,6 @@ endif() set_target_properties(opentelemetry_proto PROPERTIES EXPORT_NAME proto) patch_protobuf_targets(opentelemetry_proto) -if(OPENTELEMETRY_INSTALL) - install( - DIRECTORY ${GENERATED_PROTOBUF_PATH}/opentelemetry - DESTINATION include - COMPONENT exporters_otlp_common - FILES_MATCHING - PATTERN "*.h") -endif() - if(TARGET protobuf::libprotobuf) target_link_libraries(opentelemetry_proto PUBLIC protobuf::libprotobuf) else() # cmake 3.8 or lower @@ -424,3 +415,30 @@ if(BUILD_SHARED_LIBS) set_property(TARGET ${proto_target} PROPERTY POSITION_INDEPENDENT_CODE ON) endforeach() endif() + +if(OPENTELEMETRY_INSTALL) + install( + DIRECTORY ${GENERATED_PROTOBUF_PATH}/opentelemetry + DESTINATION include + COMPONENT exporters_otlp_common + FILES_MATCHING + PATTERN "*.h") + + include(${PROJECT_SOURCE_DIR}/cmake/pkgconfig.cmake) + + opentelemetry_add_pkgconfig( + proto + "OpenTelemetry - Protocol" + "Protocols for spans, metrics, and logs." + "protobuf" + ) + + if(WITH_OTLP_GRPC) + opentelemetry_add_pkgconfig( + proto_grpc + "OpenTelemetry - Protocol (gRPC)" + "Protocols for spans, metrics, and logs over gRPC." + "opentelemetry_proto grpc++ protobuf" + ) + endif() +endif() diff --git a/cmake/pkgconfig.cmake b/cmake/pkgconfig.cmake index 7bff4cb48c..63c1a2affd 100644 --- a/cmake/pkgconfig.cmake +++ b/cmake/pkgconfig.cmake @@ -1,6 +1,8 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +include_guard(GLOBAL) + # Unlike functions, macros do not introduce a scope. This is an advantage when # trying to set global variables, as we do here. macro (opentelemetry_set_pkgconfig_paths) From ca648f9858a74822280cdaee4a2dbff76c027af3 Mon Sep 17 00:00:00 2001 From: owent Date: Tue, 30 Jun 2026 18:39:55 +0800 Subject: [PATCH 2/2] Fixes style --- cmake/opentelemetry-proto.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index adb01709c8..4c512071e9 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -440,5 +440,5 @@ if(OPENTELEMETRY_INSTALL) "Protocols for spans, metrics, and logs over gRPC." "opentelemetry_proto grpc++ protobuf" ) - endif() + endif() endif()