Bläddra i källkod

Enable echoserver build when grpc_plugin_cpp present in system

Alexey Edelev 5 år sedan
förälder
incheckning
165e01440d
3 ändrade filer med 25 tillägg och 19 borttagningar
  1. 10 3
      CMakeLists.txt
  2. 1 4
      tests/test_grpc/CMakeLists.txt
  3. 14 12
      tests/test_grpc/echoserver/CMakeLists.txt

+ 10 - 3
CMakeLists.txt

@@ -4,7 +4,15 @@ cmake_minimum_required(VERSION 3.1)
 project(qtprotobuf)
 
 find_package(Protobuf)
-if (NOT Protobuf_FOUND OR Protobuf_VERSION VERSION_LESS "3.1.0")
+
+if(NOT DEFINED gRPC_CPP_PLUGIN_EXECUTABLE)
+    find_program(gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
+    if(gRPC_CPP_PLUGIN_EXECUTABLE STREQUAL gRPC_CPP_PLUGIN_EXECUTABLE-NOTFOUND)
+        unset(gRPC_CPP_PLUGIN_EXECUTABLE)
+    endif()
+endif()
+
+if (NOT DEFINED gRPC_CPP_PLUGIN_EXECUTABLE)
     # if no approprite Protobuf installed, there is no appropriate version of gRPC neither
     # the next include provides both from sources 
     include(cmake/gRPCBuild.cmake)
@@ -15,10 +23,9 @@ if (NOT Protobuf_FOUND OR Protobuf_VERSION VERSION_LESS "3.1.0")
     set(Protobuf_LIBRARIES libprotobuf)
 
     set(gRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:grpc_cpp_plugin>)
-    # TODO when find_package(gRPC) is used, assign variable as follows 
-    # set(gRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
 endif()
 
+
 # grpc target requires QT version not less than 5.11
 # earlier versions do not provide required Http2DirectAttribute: https://doc.qt.io/qt-5/whatsnew511.html
 find_package(Qt5 COMPONENTS Core Network Qml REQUIRED)

+ 1 - 4
tests/test_grpc/CMakeLists.txt

@@ -77,7 +77,4 @@ endif()
 target_include_directories(${testtarget} PRIVATE ${GENERATED_SOURCES_DIR})
 add_dependencies(${testtarget} ${test_sources_generation})
 
-# FIXME: remove the following if-statement when find_package(gRPC) is employed
-if (NOT Protobuf_FOUND OR Protobuf_VERSION VERSION_LESS "3.1.0")
-    add_subdirectory(echoserver)
-endif()
+add_subdirectory(echoserver)

+ 14 - 12
tests/test_grpc/echoserver/CMakeLists.txt

@@ -1,17 +1,19 @@
-file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/../proto/*.proto)
+if(NOT DEFINED gRPC_CPP_PLUGIN_EXECUTABLE)
+    message(FATAL_ERROR "gRPC plugin is not found set full path to grpc_cpp_plugin using -DgRPC_CPP_PLUGIN_EXECUTABLE=</path/to/grpc_cpp_plugin>")
+endif()
 
+file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/../proto/*.proto)
 add_custom_target(echoserver_src_generation)
 add_custom_command(
-      TARGET echoserver_src_generation
-      COMMAND ${Protobuf_PROTOC_EXECUTABLE}
-      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
-        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-        -I="${CMAKE_CURRENT_SOURCE_DIR}/../proto/"
-        --plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}"
-        ${PROTO_FILES}
-      DEPENDS ${PROTO_FILES})
-
-set(GENERATED_SOURCES 
+    TARGET echoserver_src_generation
+    COMMAND ${Protobuf_PROTOC_EXECUTABLE}
+    ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
+    --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
+    -I="${CMAKE_CURRENT_SOURCE_DIR}/../proto/"
+    --plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}"
+    ${PROTO_FILES}
+    DEPENDS ${PROTO_FILES})
+set(GENERATED_SOURCES
     "${CMAKE_CURRENT_BINARY_DIR}/simpletest.grpc.pb.cc"
     "${CMAKE_CURRENT_BINARY_DIR}/simpletest.pb.cc"
     "${CMAKE_CURRENT_BINARY_DIR}/testservice.grpc.pb.cc"
@@ -21,5 +23,5 @@ set_source_files_properties(${GENERATED_SOURCES} PROPERTIES GENERATED TRUE)
 add_executable(echoserver main.cpp ${GENERATED_SOURCES})
 target_link_libraries(echoserver grpc++ ${Protobuf_LIBRARIES})
 target_include_directories(echoserver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-add_dependencies(echoserver echoserver_src_generation)
 
+add_dependencies(echoserver echoserver_src_generation)