Add support for user-specified protoc

Make it possible to specify your own protoc when building protobuf in
a submodule.

When cross-compiling, we need to build the protobuf libraries for the
target architecture, yet we need to use a protoc executable built for
the host architecture.
pull/21476/head
Zack Galbreath 5 years ago
parent aad827f9f6
commit 64731f3c62
  1. 18
      cmake/protobuf.cmake

@ -39,7 +39,11 @@ if(gRPC_PROTOBUF_PROVIDER STREQUAL "module")
endif()
if(TARGET protoc)
set(_gRPC_PROTOBUF_PROTOC protoc)
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protoc>)
if(CMAKE_CROSSCOMPILING)
find_program(_gRPC_PROTOBUF_PROTOC_EXECUTABLE protoc)
else()
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protoc>)
endif()
endif()
# For well-known .proto files distributed with protobuf
set(_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR "${PROTOBUF_ROOT_DIR}/src")
@ -73,10 +77,18 @@ elseif(gRPC_PROTOBUF_PROVIDER STREQUAL "package")
endif()
if(TARGET protobuf::protoc)
set(_gRPC_PROTOBUF_PROTOC protobuf::protoc)
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protobuf::protoc>)
if(CMAKE_CROSSCOMPILING)
find_program(_gRPC_PROTOBUF_PROTOC_EXECUTABLE protoc)
else()
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protobuf::protoc>)
endif()
else()
set(_gRPC_PROTOBUF_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE})
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
if(CMAKE_CROSSCOMPILING)
find_program(_gRPC_PROTOBUF_PROTOC_EXECUTABLE protoc)
else()
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
endif()
endif()
set(_gRPC_FIND_PROTOBUF "if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND)\n find_package(Protobuf ${gRPC_PROTOBUF_PACKAGE_TYPE})\nendif()")
endif()

Loading…
Cancel
Save