aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorZack Galbreath <zack.galbreath@kitware.com>2019-12-03 14:20:06 -0500
committerZack Galbreath <zack.galbreath@kitware.com>2019-12-18 10:04:39 -0500
commit64731f3c6202b5395387f1952ef4b18f381f2fc8 (patch)
treeed04d38abacaf6927184eca99d6c0b16b90220f4 /cmake
parentaad827f9f60afdabd06cc29ef3c8ab6c7d0f3008 (diff)
downloadgrpc-grpc-64731f3c6202b5395387f1952ef4b18f381f2fc8.tar.gz
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.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/protobuf.cmake18
1 files changed, 15 insertions, 3 deletions
diff --git a/cmake/protobuf.cmake b/cmake/protobuf.cmake
index a37e0d5cbd..f23f65d40e 100644
--- a/cmake/protobuf.cmake
+++ b/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()