CMakeLists.txt 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. cmake_minimum_required(VERSION 3.16)
  2. project(grpcaddressbookserver 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/addressbookserver")
  19. set(generated_sources
  20. ${CMAKE_CURRENT_BINARY_DIR}/addressbook.pb.cc
  21. ${CMAKE_CURRENT_BINARY_DIR}/addressbook.grpc.pb.cc)
  22. set_source_files_properties(${generated_sources} PROPERTIES GENERATED TRUE)
  23. qt_add_executable(grpcaddressbookserver main.cpp ${generated_sources})
  24. target_include_directories(grpcaddressbookserver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  25. _qt_internal_protobuf_reference_generate(TARGET grpcaddressbookserver
  26. GENERATED_SOURCES ${generated_sources}
  27. PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../addressbook/proto/addressbook.proto")
  28. target_link_libraries(grpcaddressbookserver PRIVATE protobuf::libprotobuf gRPC::grpc++ gRPC::grpc)
  29. if(MSVC)
  30. target_compile_definitions(grpcaddressbookserver PRIVATE _WIN32_WINNT=0x600 _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
  31. endif()
  32. if(UNIX AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  33. target_compile_options(grpcaddressbookserver PRIVATE -Wno-error=array-bounds)
  34. endif()
  35. install(TARGETS grpcaddressbookserver
  36. RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
  37. BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
  38. LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
  39. )
  40. add_custom_command(TARGET grpcaddressbookserver
  41. COMMAND ${CMAKE_COMMAND} -E copy
  42. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/cert.pem"
  43. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/key.pem"
  44. "$<TARGET_FILE_DIR:grpcaddressbookserver>"
  45. )
  46. install(FILES
  47. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/cert.pem"
  48. "${CMAKE_CURRENT_SOURCE_DIR}/../ssl/key.pem"
  49. DESTINATION "${INSTALL_EXAMPLEDIR}"
  50. )