[CMake] Fixed _gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR (#37627)

gRPC has been passing the wrong directory of `_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR`  to protoc. While protoc often works around this by searching its own installation directory for proto files, this isn't always successful. Let's fix this bug to ensure consistent behavior.

Fixes: https://github.com/grpc/grpc/issues/37411

Closes #37627

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37627 from veblush:protobuf-cmake-wkt 412f4a6f87
PiperOrigin-RevId: 678428224
pull/37622/head
Esun Kim 5 months ago committed by Copybara-Service
parent e11336112a
commit 169ccf7a70
  1. 5
      cmake/protobuf.cmake

@ -65,12 +65,11 @@ elseif(gRPC_PROTOBUF_PROVIDER STREQUAL "package")
endif()
if(TARGET protobuf::libprotoc)
set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc)
# extract the include dir from target's properties
get_target_property(_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR protobuf::libprotoc INTERFACE_INCLUDE_DIRECTORIES)
else()
set(_gRPC_PROTOBUF_PROTOC_LIBRARIES ${PROTOBUF_PROTOC_LIBRARIES})
set(_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR ${PROTOBUF_INCLUDE_DIRS})
endif()
# Well-known proto files are expected to be in the Protobuf include directory.
get_target_property(_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR ${_gRPC_PROTOBUF_LIBRARIES} INTERFACE_INCLUDE_DIRECTORIES)
if(TARGET protobuf::protoc)
set(_gRPC_PROTOBUF_PROTOC protobuf::protoc)
if(CMAKE_CROSSCOMPILING)

Loading…
Cancel
Save