CMakeLists.txt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. qt_find_package(gRPC CONFIG)
  2. # gRPC tests require reference gRPC and protobuf implementation
  3. if(NOT TARGET gRPC::grpc_cpp_plugin
  4. OR NOT TARGET gRPC::grpc++
  5. OR NOT TARGET protobuf::libprotobuf
  6. OR NOT TARGET protobuf::protoc)
  7. endif()
  8. function(qt_internal_protobuf_reference_generate)
  9. set(options)
  10. set(oneValueArgs OUTPUT_DIRECTORY TARGET)
  11. set(multiValueArgs GENERATED_SOURCES PROTO_FILES)
  12. cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  13. set(generated_target "${arg_TARGET}_generate")
  14. foreach(proto_file IN LISTS arg_PROTO_FILES)
  15. get_filename_component(dir "${proto_file}" DIRECTORY)
  16. list(APPEND proto_includes "-I${dir}")
  17. endforeach()
  18. if(NOT DEFINED arg_OUTPUT_DIRECTORY)
  19. set(output_directory "${CMAKE_CURRENT_BINARY_DIR}")
  20. else()
  21. set(output_directory "${arg_OUTPUT_DIRECTORY}")
  22. endif()
  23. file(MAKE_DIRECTORY "${OUTPUT_DIRECTORY}")
  24. if(NOT TARGET gRPC::grpc_cpp_plugin)
  25. message(FATAL_ERROR "gRPC plugin is not found")
  26. endif()
  27. add_custom_command(
  28. OUTPUT ${arg_GENERATED_SOURCES}
  29. COMMAND protobuf::protoc
  30. ARGS --grpc_out="${output_directory}"
  31. --cpp_out="${output_directory}"
  32. ${proto_includes}
  33. "--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
  34. ${arg_PROTO_FILES}
  35. DEPENDS
  36. ${arg_PROTO_FILES}
  37. gRPC::grpc_cpp_plugin
  38. )
  39. add_custom_target(${generated_target} DEPENDS ${arg_PROTO_FILES} ${arg_GENERATED_SOURCES})
  40. add_dependencies(${arg_TARGET} ${generated_target})
  41. endfunction()
  42. qt_protobuf_generate(GENERATED_TARGET grpc_tests_common_gen
  43. PROTO_FILES
  44. proto/simpletest.proto
  45. proto/testservice.proto
  46. # TODO Qt6: Restore QML support
  47. # QML
  48. )
  49. add_subdirectory(echoserver)
  50. qt_internal_add_test(grpc_client_basic
  51. SOURCES
  52. clienttest.cpp
  53. LIBRARIES
  54. Qt::Grpc
  55. Qt::Protobuf
  56. DEFINES
  57. QT_GRPC_SERVER_EXECUTABLE=\"$<TARGET_FILE:echoserver>\"
  58. )
  59. _qt_internal_link_protobuf_objects(grpc_client_basic grpc_tests_common_gen)
  60. # TODO Qt6: Enable secure connection test later
  61. #add_subdirectory(secureechoserver)
  62. #qt_internal_add_test(grpc_client_secure
  63. # SOURCES
  64. # sslclienttest.cpp
  65. # LIBRARIES
  66. # Qt::Grpc
  67. # Qt::Protobuf
  68. # DEFINES
  69. # QT_GRPC_SERVER_EXECUTABLE=\"$<TARGET_FILE:secureechoserver>\"
  70. #)
  71. #_qt_internal_link_protobuf_objects(grpc_client_secure grpc_tests_common_gen)