2023-01-20 16:43:29 +00:00
|
|
|
# Copyright (C) 2023 The Qt Company Ltd.
|
2024-03-15 13:09:34 +00:00
|
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2023-01-20 16:43:29 +00:00
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.16)
|
|
|
|
|
|
|
|
|
|
project(GrpcChatServer LANGUAGES CXX)
|
|
|
|
|
|
2023-02-27 16:13:11 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2024-09-10 12:31:47 +00:00
|
|
|
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
|
2023-02-27 16:13:11 +00:00
|
|
|
|
2023-01-20 16:43:29 +00:00
|
|
|
# Qt6::Grpc module is not used directly in this project. But this allows to find Qt6::Grpc's
|
|
|
|
|
# dependencies without setting extra cmake module paths.
|
|
|
|
|
find_package(Qt6 COMPONENTS Grpc)
|
2024-09-10 12:31:47 +00:00
|
|
|
find_package(protobuf)
|
|
|
|
|
find_package(gRPC)
|
2023-01-20 16:43:29 +00:00
|
|
|
|
2024-09-10 12:31:47 +00:00
|
|
|
if(NOT TARGET gRPC::grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc
|
|
|
|
|
OR NOT TARGET gRPC::grpc++)
|
2023-01-20 16:43:29 +00:00
|
|
|
message(WARNING "Dependencies of QtGrpc test server not found. Skipping.")
|
|
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
2024-08-23 10:00:47 +00:00
|
|
|
if(MINGW)
|
|
|
|
|
message(WARNING "${PROJECT_NAME} uses reference grpc++ library that doesn't officially support"
|
|
|
|
|
" MinGW. Please use the MSVC compiler to build this example. The correct work is not"
|
|
|
|
|
" guaranteed otherwise.")
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-01-20 16:43:29 +00:00
|
|
|
set(proto_files "${CMAKE_CURRENT_LIST_DIR}/../proto/simplechat.proto")
|
|
|
|
|
set(out_dir "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
|
|
|
|
|
set(generated_files
|
|
|
|
|
"${out_dir}/simplechat.pb.h" "${out_dir}/simplechat.pb.cc"
|
|
|
|
|
"${out_dir}/simplechat.grpc.pb.h" "${out_dir}/simplechat.grpc.pb.cc")
|
|
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
|
OUTPUT ${generated_files}
|
|
|
|
|
COMMAND
|
|
|
|
|
$<TARGET_FILE:WrapProtoc::WrapProtoc>
|
|
|
|
|
ARGS
|
|
|
|
|
--grpc_out "${out_dir}"
|
|
|
|
|
--cpp_out "${out_dir}"
|
|
|
|
|
"-I${CMAKE_CURRENT_LIST_DIR}/../proto/"
|
2024-09-10 12:31:47 +00:00
|
|
|
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
|
2023-01-20 16:43:29 +00:00
|
|
|
"${proto_files}"
|
|
|
|
|
WORKING_DIRECTORY ${out_dir}
|
|
|
|
|
DEPENDS "${proto_files}"
|
|
|
|
|
COMMENT "Generating gRPC ${target} sources..."
|
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
|
VERBATIM
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE)
|
|
|
|
|
|
|
|
|
|
add_executable(grpcchatserver
|
|
|
|
|
${generated_files}
|
|
|
|
|
main.cpp
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
target_include_directories(grpcchatserver PRIVATE ${out_dir})
|
2024-09-10 12:31:47 +00:00
|
|
|
target_link_libraries(grpcchatserver PRIVATE gRPC::grpc++ protobuf::libprotobuf)
|
2023-01-20 16:43:29 +00:00
|
|
|
|
|
|
|
|
install(TARGETS grpcchatserver
|
|
|
|
|
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
|
|
|
|
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
|
|
|
|
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
|
|
|
|
)
|