diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index c77a87488d..4c512071e9 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)