blob: 5774e62eb1837867097f7f1f4324f268d8be1540 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From cc6dbabea0e452ebc93682df860a79ed9a45722e Mon Sep 17 00:00:00 2001
2From: Alexey Firago <alexey_firago@mentor.com>
3Date: Fri, 20 Oct 2017 00:04:19 +0300
4Subject: [PATCH] CMakeLists.txt: Fix grpc_cpp_plugin path during
5 cross-compilation
6
7Signed-off-by: Alexey Firago <alexey_firago@mentor.com>
8---
9 CMakeLists.txt | 9 ++++++++-
10 templates/CMakeLists.txt.template | 9 ++++++++-
11 2 files changed, 16 insertions(+), 2 deletions(-)
12
13diff --git a/CMakeLists.txt b/CMakeLists.txt
14index f9cd630..9663934 100644
15--- a/CMakeLists.txt
16+++ b/CMakeLists.txt
17@@ -328,6 +328,13 @@ function(protobuf_generate_grpc_cpp)
18 return()
19 endif()
20
21+ #if cross-compiling, find host plugin
22+ if(CMAKE_CROSSCOMPILING)
23+ find_program(gRPC_CPP_PLUGIN grpc_cpp_plugin)
24+ else()
25+ set(gRPC_CPP_PLUGIN $<TARGET_FILE:grpc_cpp_plugin>)
26+ endif()
27+
28 set(_protobuf_include_path -I . -I ${PROTOBUF_WELLKNOWN_IMPORT_DIR})
29 foreach(FIL ${ARGN})
30 get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
31@@ -345,7 +352,7 @@ function(protobuf_generate_grpc_cpp)
32 COMMAND ${_gRPC_PROTOBUF_PROTOC_EXECUTABLE}
33 ARGS --grpc_out=generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}
34 --cpp_out=${_gRPC_PROTO_GENS_DIR}
35- --plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin>
36+ --plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN}
37 ${_protobuf_include_path}
38 ${REL_FIL}
39 DEPENDS ${ABS_FIL} ${_gRPC_PROTOBUF_PROTOC} grpc_cpp_plugin
40diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template
41index 64daf04..a7e8629 100644
42--- a/templates/CMakeLists.txt.template
43+++ b/templates/CMakeLists.txt.template
44@@ -373,6 +373,13 @@
45 return()
46 endif()
47
48+ #if cross-compiling, find host plugin
49+ if(CMAKE_CROSSCOMPILING)
50+ find_program(gRPC_CPP_PLUGIN grpc_cpp_plugin)
51+ else()
52+ set(gRPC_CPP_PLUGIN $<TARGET_FILE:grpc_cpp_plugin>)
53+ endif()
54+
55 set(_protobuf_include_path -I . -I <%text>${PROTOBUF_WELLKNOWN_IMPORT_DIR}</%text>)
56 foreach(FIL <%text>${ARGN}</%text>)
57 get_filename_component(ABS_FIL <%text>${FIL}</%text> ABSOLUTE)
58@@ -390,7 +397,7 @@
59 COMMAND <%text>${_gRPC_PROTOBUF_PROTOC_EXECUTABLE}</%text>
60 ARGS --grpc_out=<%text>generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}</%text>
61 --cpp_out=<%text>${_gRPC_PROTO_GENS_DIR}</%text>
62- --plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin>
63+ --plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN}
64 <%text>${_protobuf_include_path}</%text>
65 <%text>${REL_FIL}</%text>
66 DEPENDS <%text>${ABS_FIL}</%text> <%text>${_gRPC_PROTOBUF_PROTOC}</%text> grpc_cpp_plugin
67--
682.7.4