1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- cmake_minimum_required(VERSION 3.16)
- project(grpcaddressbookserver LANGUAGES CXX)
- find_package(gRPC CONFIG QUIET)
- find_package(Protobuf CONFIG QUIET)
- # gRPC servers require reference gRPC and protobuf implementation
- if(NOT TARGET gRPC::grpc_cpp_plugin
- OR NOT TARGET gRPC::grpc++
- OR NOT TARGET protobuf::libprotobuf
- OR NOT TARGET protobuf::protoc)
- message(AUTOR_WARNING "gRPC is not found. The ${PROJECT_NAME} example won't be built.")
- return ()
- endif()
- set(CMAKE_AUTOMOC ON)
- set(CMAKE_AUTOUIC ON)
- if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
- endif()
- set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/grpc/addressbookserver")
- set(generated_sources
- ${CMAKE_CURRENT_BINARY_DIR}/addressbook.pb.cc
- ${CMAKE_CURRENT_BINARY_DIR}/addressbook.grpc.pb.cc)
- set_source_files_properties(${generated_sources} PROPERTIES GENERATED TRUE)
- qt_add_executable(grpcaddressbookserver main.cpp ${generated_sources})
- target_include_directories(grpcaddressbookserver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
- _qt_internal_protobuf_reference_generate(TARGET grpcaddressbookserver
- GENERATED_SOURCES ${generated_sources}
- PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../addressbook/proto/addressbook.proto")
- target_link_libraries(grpcaddressbookserver PRIVATE protobuf::libprotobuf gRPC::grpc++ gRPC::grpc)
- if(MSVC)
- target_compile_definitions(grpcaddressbookserver PRIVATE _WIN32_WINNT=0x600 _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
- endif()
- if(UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- target_compile_options(grpcaddressbookserver PRIVATE -Wno-error=array-bounds)
- endif()
- install(TARGETS grpcaddressbookserver
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
- )
- add_custom_command(TARGET grpcaddressbookserver
- COMMAND ${CMAKE_COMMAND} -E copy
- "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/cert.pem"
- "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/key.pem"
- "$<TARGET_FILE_DIR:grpcaddressbookserver>"
- )
- install(FILES
- "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/cert.pem"
- "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/key.pem"
- DESTINATION "${INSTALL_EXAMPLEDIR}"
- )
|