From 252c5467de5c9aeff0de9726a9b2ca04fabb71a7 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Wed, 12 Mar 2025 10:58:00 +0100 Subject: [PATCH] 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 Reviewed-by: Dennis Oberst --- examples/grpc/chat/server/CMakeLists.txt | 12 ++++++++++-- examples/grpc/clientguide/server/CMakeLists.txt | 12 ++++++++++-- examples/grpc/magic8ball/server/CMakeLists.txt | 12 ++++++++++-- examples/grpc/vehicle/server/CMakeLists.txt | 12 ++++++++++-- .../grpc/client/shared/test_server/CMakeLists.txt | 12 ++++++++++-- .../benchmarks/asyncbenchserver/CMakeLists.txt | 15 +++++++++++---- .../bench_async_ref_client/CMakeLists.txt | 14 +++++++++++--- 7 files changed, 72 insertions(+), 17 deletions(-) diff --git a/examples/grpc/chat/server/CMakeLists.txt b/examples/grpc/chat/server/CMakeLists.txt index 2a68164a..bcb92e50 100644 --- a/examples/grpc/chat/server/CMakeLists.txt +++ b/examples/grpc/chat/server/CMakeLists.txt @@ -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 $) +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=$ + --plugin=protoc-gen-grpc=${grpc_cpp_plugin} ${proto_includes} ${proto_files} WORKING_DIRECTORY ${proto_out} diff --git a/examples/grpc/clientguide/server/CMakeLists.txt b/examples/grpc/clientguide/server/CMakeLists.txt index c23c2e2f..564f8ef5 100644 --- a/examples/grpc/clientguide/server/CMakeLists.txt +++ b/examples/grpc/clientguide/server/CMakeLists.txt @@ -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 $) +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=$ + --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_files}" WORKING_DIRECTORY ${proto_out} DEPENDS "${proto_files}" diff --git a/examples/grpc/magic8ball/server/CMakeLists.txt b/examples/grpc/magic8ball/server/CMakeLists.txt index 16f79a2e..7979a26a 100644 --- a/examples/grpc/magic8ball/server/CMakeLists.txt +++ b/examples/grpc/magic8ball/server/CMakeLists.txt @@ -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 $) +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=$ + --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_files}" WORKING_DIRECTORY ${out_dir} DEPENDS "${proto_files}" diff --git a/examples/grpc/vehicle/server/CMakeLists.txt b/examples/grpc/vehicle/server/CMakeLists.txt index 54ff2e78..4d2e7da1 100644 --- a/examples/grpc/vehicle/server/CMakeLists.txt +++ b/examples/grpc/vehicle/server/CMakeLists.txt @@ -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 $) +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=$ + --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_files}" WORKING_DIRECTORY ${out_dir} DEPENDS "${proto_files}" diff --git a/tests/auto/grpc/client/shared/test_server/CMakeLists.txt b/tests/auto/grpc/client/shared/test_server/CMakeLists.txt index 72ca89d3..8b3e3c20 100644 --- a/tests/auto/grpc/client/shared/test_server/CMakeLists.txt +++ b/tests/auto/grpc/client/shared/test_server/CMakeLists.txt @@ -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 $) +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=$ + --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_files}" WORKING_DIRECTORY ${out_dir} DEPENDS "${proto_files}" $ diff --git a/tests/manual/grpc/benchmarks/asyncbenchserver/CMakeLists.txt b/tests/manual/grpc/benchmarks/asyncbenchserver/CMakeLists.txt index b1676963..39d031c0 100644 --- a/tests/manual/grpc/benchmarks/asyncbenchserver/CMakeLists.txt +++ b/tests/manual/grpc/benchmarks/asyncbenchserver/CMakeLists.txt @@ -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 $) +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=$ + --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_path}" WORKING_DIRECTORY "${proto_out_dir}" DEPENDS "${proto_path}" $ - $ + ${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}" ) - diff --git a/tests/manual/grpc/benchmarks/bench_async_ref_client/CMakeLists.txt b/tests/manual/grpc/benchmarks/bench_async_ref_client/CMakeLists.txt index 086787ed..2fb0e7a4 100644 --- a/tests/manual/grpc/benchmarks/bench_async_ref_client/CMakeLists.txt +++ b/tests/manual/grpc/benchmarks/bench_async_ref_client/CMakeLists.txt @@ -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 $) +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=$ + --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_path}" WORKING_DIRECTORY "${proto_out_dir}" DEPENDS "${proto_path}" $ - $ + ${grpc_cpp_plugin} COMMENT "Generating gRPC ${target} sources..." COMMAND_EXPAND_LISTS VERBATIM