CMakeLists.txt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. cmake_minimum_required(VERSION 3.16)
  2. project(grpcsimplechatserver LANGUAGES CXX)
  3. find_package(gRPC CONFIG QUIET)
  4. find_package(Protobuf CONFIG QUIET)
  5. # gRPC servers require reference gRPC and protobuf implementation
  6. if(NOT TARGET gRPC::grpc_cpp_plugin
  7. OR NOT TARGET gRPC::grpc++
  8. OR NOT TARGET protobuf::libprotobuf
  9. OR NOT TARGET protobuf::protoc)
  10. message(AUTOR_WARNING "gRPC is not found. The ${PROJECT_NAME} example won't be built.")
  11. return ()
  12. endif()
  13. set(CMAKE_AUTOMOC ON)
  14. set(CMAKE_AUTOUIC ON)
  15. if(NOT DEFINED INSTALL_EXAMPLESDIR)
  16. set(INSTALL_EXAMPLESDIR "examples")
  17. endif()
  18. set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/grpc/simplechatserver")
  19. set(generated_sources
  20. "${CMAKE_CURRENT_BINARY_DIR}/simplechat.pb.cc"
  21. "${CMAKE_CURRENT_BINARY_DIR}/simplechat.grpc.pb.cc"
  22. )
  23. set_source_files_properties(${generated_sources} PROPERTIES GENERATED TRUE)
  24. qt_add_executable(grpcsimplechatserver main.cpp ${generated_sources})
  25. target_include_directories(grpcsimplechatserver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  26. _qt_internal_protobuf_reference_generate(TARGET grpcsimplechatserver
  27. GENERATED_SOURCES ${generated_sources}
  28. PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../simplechat/proto/simplechat.proto")
  29. target_link_libraries(grpcsimplechatserver PRIVATE protobuf::libprotobuf gRPC::grpc++ gRPC::grpc)
  30. if(MSVC)
  31. target_compile_definitions(grpcsimplechatserver PRIVATE _WIN32_WINNT=0x600 _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
  32. endif()
  33. if(UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  34. target_compile_options(grpcsimplechatserver PRIVATE -Wno-error=array-bounds)
  35. endif()
  36. install(TARGETS grpcsimplechatserver
  37. RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
  38. BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
  39. LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
  40. )
  41. add_custom_command(TARGET grpcsimplechatserver
  42. COMMAND ${CMAKE_COMMAND} -E copy
  43. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/cert.pem"
  44. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/key.pem"
  45. "$<TARGET_FILE_DIR:grpcsimplechatserver>"
  46. )
  47. install(FILES
  48. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/cert.pem"
  49. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/key.pem"
  50. DESTINATION "${INSTALL_EXAMPLEDIR}"
  51. )