Add the hint to find the host grpc_cpp_plugin when crosscompiling

gRPC doesn't provide the smart tool lookup when crosscompiling.
So gRPC lookup is unable to find the grpc_cpp_plugin plugin when
crosscompiling examples. Use find_program to find the plugin in
host paths.

Pick-to: 6.8 6.9
Fixes: QTBUG-134647
Change-Id: I961b180b348dee4f1b2f2523be225d3003847e4c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
This commit is contained in:
Alexey Edelev 2025-03-12 10:58:00 +01:00
parent 428e3d07b9
commit 252c5467de
7 changed files with 72 additions and 17 deletions

View File

@ -18,7 +18,15 @@ find_package(Qt6 COMPONENTS ProtobufTools ProtobufQtCoreTypes)
find_package(Protobuf)
find_package(gRPC)
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
if(CMAKE_CROSSCOMPILING)
find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE)
elseif(TARGET gRPC::grpc_cpp_plugin)
set(grpc_cpp_plugin $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
else()
set(grpc_cpp_plugin "")
endif()
if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
OR NOT TARGET gRPC::grpc++ OR NOT TARGET Qt6::ProtobufQtCoreTypes
OR NOT TARGET gRPC::grpc++_reflection)
message(WARNING "Dependencies of ${PROJECT_NAME} not found. Skipping.")
@ -57,7 +65,7 @@ add_custom_command(
ARGS
--grpc_out "${proto_out}"
--cpp_out "${proto_out}"
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
--plugin=protoc-gen-grpc=${grpc_cpp_plugin}
${proto_includes}
${proto_files}
WORKING_DIRECTORY ${proto_out}

View File

@ -10,7 +10,15 @@ find_package(protobuf)
find_package(gRPC)
find_package(Qt6 COMPONENTS ProtobufTools)
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
if(CMAKE_CROSSCOMPILING)
find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE)
elseif(TARGET gRPC::grpc_cpp_plugin)
set(grpc_cpp_plugin $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
else()
set(grpc_cpp_plugin "")
endif()
if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
OR NOT TARGET gRPC::grpc++)
message(WARNING "Dependencies of ${PROJECT_NAME} not found. Skipping.")
return()
@ -36,7 +44,7 @@ add_custom_command(
--grpc_out "${proto_out}"
--cpp_out "${proto_out}"
-I "${CMAKE_CURRENT_LIST_DIR}/../proto"
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
--plugin=protoc-gen-grpc=${grpc_cpp_plugin}
"${proto_files}"
WORKING_DIRECTORY ${proto_out}
DEPENDS "${proto_files}"

View File

@ -9,7 +9,15 @@ set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(Protobuf)
find_package(gRPC)
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET gRPC::grpc++)
if(CMAKE_CROSSCOMPILING)
find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE)
elseif(TARGET gRPC::grpc_cpp_plugin)
set(grpc_cpp_plugin $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
else()
set(grpc_cpp_plugin "")
endif()
if(NOT grpc_cpp_plugin OR NOT TARGET gRPC::grpc++)
return()
endif()
@ -38,7 +46,7 @@ add_custom_command(
--grpc_out "${out_dir}"
--cpp_out "${out_dir}"
-I "${CMAKE_CURRENT_LIST_DIR}/../proto/"
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
--plugin=protoc-gen-grpc=${grpc_cpp_plugin}
"${proto_files}"
WORKING_DIRECTORY ${out_dir}
DEPENDS "${proto_files}"

View File

@ -9,7 +9,15 @@ set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(Protobuf)
find_package(gRPC)
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET gRPC::grpc++)
if(CMAKE_CROSSCOMPILING)
find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE)
elseif(TARGET gRPC::grpc_cpp_plugin)
set(grpc_cpp_plugin $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
else()
set(grpc_cpp_plugin "")
endif()
if(NOT grpc_cpp_plugin OR NOT TARGET gRPC::grpc++)
return()
endif()
@ -41,7 +49,7 @@ add_custom_command(
--grpc_out "${out_dir}"
--cpp_out "${out_dir}"
-I "${CMAKE_CURRENT_LIST_DIR}/../proto/"
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
--plugin=protoc-gen-grpc=${grpc_cpp_plugin}
"${proto_files}"
WORKING_DIRECTORY ${out_dir}
DEPENDS "${proto_files}"

View File

@ -6,7 +6,15 @@ set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(Protobuf)
find_package(gRPC)
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
if(CMAKE_CROSSCOMPILING)
find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE)
elseif(TARGET gRPC::grpc_cpp_plugin)
set(grpc_cpp_plugin $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
else()
set(grpc_cpp_plugin "")
endif()
if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
OR NOT TARGET gRPC::grpc++)
message(WARNING "Dependencies of Qt GRPC test server not found. Skipping.")
return()
@ -34,7 +42,7 @@ add_custom_command(
--grpc_out "${out_dir}"
--cpp_out "${out_dir}"
-I "${CMAKE_CURRENT_LIST_DIR}/../../../shared/proto/"
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
--plugin=protoc-gen-grpc=${grpc_cpp_plugin}
"${proto_files}"
WORKING_DIRECTORY ${out_dir}
DEPENDS "${proto_files}" $<TARGET_FILE:WrapProtoc::WrapProtoc>

View File

@ -5,7 +5,15 @@ find_package(WrapProtoc)
find_package(Protobuf)
find_package(gRPC)
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
if(CMAKE_CROSSCOMPILING)
find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE)
elseif(TARGET gRPC::grpc_cpp_plugin)
set(grpc_cpp_plugin $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
else()
set(grpc_cpp_plugin "")
endif()
if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
OR NOT TARGET gRPC::grpc++)
message(WARNING "Dependencies of QtGrpc benchmark-server not found. Skipping.")
return()
@ -36,13 +44,13 @@ add_custom_command(
--grpc_out "${proto_out_dir}"
--cpp_out "${proto_out_dir}"
-I "${proto_include}"
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
--plugin=protoc-gen-grpc=${grpc_cpp_plugin}
"${proto_path}"
WORKING_DIRECTORY "${proto_out_dir}"
DEPENDS
"${proto_path}"
$<TARGET_FILE:WrapProtoc::WrapProtoc>
$<TARGET_FILE:gRPC::grpc_cpp_plugin>
${grpc_cpp_plugin}
COMMENT "Generating gRPC ${target} sources..."
COMMAND_EXPAND_LISTS
VERBATIM
@ -65,4 +73,3 @@ qt_internal_add_executable(
OUTPUT_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}"
)

View File

@ -5,7 +5,15 @@ find_package(WrapProtoc)
find_package(Protobuf)
find_package(gRPC)
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
if(CMAKE_CROSSCOMPILING)
find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE)
elseif(TARGET gRPC::grpc_cpp_plugin)
set(grpc_cpp_plugin $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
else()
set(grpc_cpp_plugin "")
endif()
if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
OR NOT TARGET gRPC::grpc++)
message(WARNING "Dependencies of QtGrpc bench_async_ref_client not found. Skipping.")
return()
@ -36,13 +44,13 @@ add_custom_command(
--grpc_out "${proto_out_dir}"
--cpp_out "${proto_out_dir}"
-I "${proto_include}"
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
--plugin=protoc-gen-grpc=${grpc_cpp_plugin}
"${proto_path}"
WORKING_DIRECTORY "${proto_out_dir}"
DEPENDS
"${proto_path}"
$<TARGET_FILE:WrapProtoc::WrapProtoc>
$<TARGET_FILE:gRPC::grpc_cpp_plugin>
${grpc_cpp_plugin}
COMMENT "Generating gRPC ${target} sources..."
COMMAND_EXPAND_LISTS
VERBATIM