From 9437a1f2bda651fe82a0d1eed3aaa68dae8a4ad8 Mon Sep 17 00:00:00 2001 From: Dennis Oberst Date: Mon, 3 Mar 2025 15:45:27 +0100 Subject: [PATCH] qtgrpc chat example: fix deployment The deployment was incomplete. Fix it by: * Building the dependent qtgrpc_chat_client_proto library as a static library * Add the server directory path for reading credentials universally Amends: cb35d20adbc6cccef26f1c87310b84609ea2da8d. Fixes: QTBUG-134266 Pick-to: 6.9.0 6.9 6.8.3 6.8 Change-Id: I0666c445fbce159436c5b084ffd77d4191e04213 Reviewed-by: Alexey Edelev --- examples/grpc/chat/CMakeLists.txt | 2 ++ examples/grpc/chat/client/CMakeLists.txt | 3 ++- examples/grpc/chat/server/CMakeLists.txt | 4 ++++ examples/grpc/chat/server/main.cpp | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/grpc/chat/CMakeLists.txt b/examples/grpc/chat/CMakeLists.txt index d8d6904a..41ceb190 100644 --- a/examples/grpc/chat/CMakeLists.txt +++ b/examples/grpc/chat/CMakeLists.txt @@ -4,5 +4,7 @@ cmake_minimum_required(VERSION 3.16) project(QtGrpcChat LANGUAGES CXX) +find_package(Qt6 REQUIRED COMPONENTS Qml) # Needed for deployment + add_subdirectory(server) add_subdirectory(client) diff --git a/examples/grpc/chat/client/CMakeLists.txt b/examples/grpc/chat/client/CMakeLists.txt index f16210f4..ea411aeb 100644 --- a/examples/grpc/chat/client/CMakeLists.txt +++ b/examples/grpc/chat/client/CMakeLists.txt @@ -78,6 +78,7 @@ if(GRPC_CHAT_USE_EMOJI_FONT) endif() #! [client-setup-1] +add_library(qtgrpc_chat_client_proto STATIC) qt_add_protobuf(qtgrpc_chat_client_proto QML QML_URI QtGrpcChat.Proto @@ -132,7 +133,7 @@ target_link_libraries(qtgrpc_chat_client qtgrpc_chat_client_proto ) -install(TARGETS qtgrpc_chat_client +install(TARGETS qtgrpc_chat_client qtgrpc_chat_client_proto RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/grpc/chat/server/CMakeLists.txt b/examples/grpc/chat/server/CMakeLists.txt index e253d2cb..ee66d9e1 100644 --- a/examples/grpc/chat/server/CMakeLists.txt +++ b/examples/grpc/chat/server/CMakeLists.txt @@ -77,6 +77,10 @@ add_executable(qtgrpc_chat_server target_include_directories(qtgrpc_chat_server PRIVATE ${proto_out}) target_link_libraries(qtgrpc_chat_server PRIVATE gRPC::grpc++ gRPC::grpc++_reflection) +target_compile_definitions(qtgrpc_chat_server + PRIVATE SERVER_DIR="$" +) + install(TARGETS qtgrpc_chat_server RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/grpc/chat/server/main.cpp b/examples/grpc/chat/server/main.cpp index f401f4b1..14e51675 100644 --- a/examples/grpc/chat/server/main.cpp +++ b/examples/grpc/chat/server/main.cpp @@ -374,8 +374,8 @@ int main(int /* argc */, char * /* argv */[]) //! [server-ssl] grpc::SslServerCredentialsOptions sslOpts; sslOpts.pem_key_cert_pairs.emplace_back(grpc::SslServerCredentialsOptions::PemKeyCertPair{ - readFromFile("credentials/localhost.key"), - readFromFile("credentials/localhost.crt"), + readFromFile(SERVER_DIR "/credentials/localhost.key"), + readFromFile(SERVER_DIR "/credentials/localhost.crt"), }); builder.AddListeningPort(QtGrpcChatService::httpsAddress(), grpc::SslServerCredentials(sslOpts)); builder.AddListeningPort(QtGrpcChatService::httpAddress(), grpc::InsecureServerCredentials());