Browse Source

Split protobuf support libraries

- Make separate library for grpc
- Move rename lib folder to protobuf
- Decrease minimum required Qt version to 5.8.0
Alexey Edelev 6 years ago
parent
commit
a684764d38

+ 2 - 1
CMakeLists.txt

@@ -29,7 +29,8 @@ elseif(NOT DEFINED MAKE_TESTS)
     set(MAKE_TESTS ON)
 endif()
 
-add_subdirectory("src/lib")
+add_subdirectory("src/protobuf")
+add_subdirectory("src/grpc")
 add_subdirectory("src/generator")
 
 message(STATUS "QTPROTOBUF_GENERATOR_EXEC_PATH: ${QTPROTOBUF_GENERATOR_EXEC_PATH}")

+ 4 - 4
src/generator/templates.cpp

@@ -137,17 +137,17 @@ const char *Templates::ClientMethodDeclarationAsyncTemplate = "Q_INVOKABLE bool
 const char *Templates::ServerMethodDeclarationTemplate = "Q_INVOKABLE virtual $return_type$ $method_name$(const $param_type$ &$param_name$) = 0;\n";
 
 
-const char *Templates::ConstructorDefinitionSyncTemplate = "$classname$::$classname$() : $parent_class$(\"$service_name$\")\n"
+const char *Templates::ConstructorDefinitionSyncTemplate = "\n$classname$::$classname$() : $parent_class$(\"$service_name$\")\n"
                                                            "{\n"
                                                            "}\n";
-const char *Templates::ClientMethodDefinitionSyncTemplate = "bool $classname$::$method_name$(const $param_type$ &$param_name$, $return_type$ &$return_name$)\n"
+const char *Templates::ClientMethodDefinitionSyncTemplate = "\nbool $classname$::$method_name$(const $param_type$ &$param_name$, $return_type$ &$return_name$)\n"
                                                             "{\n"
                                                             "    return call(\"$method_name$\", $param_name$, $return_name$);\n"
                                                             "}\n";
-const char *Templates::ClientMethodDefinitionAsyncTemplate = "bool $classname$::$method_name$(const $param_type$ &$param_name$, const qtprotobuf::AsyncReply<$return_type$> &reply)\n"
+const char *Templates::ClientMethodDefinitionAsyncTemplate = "\nbool $classname$::$method_name$(const $param_type$ &$param_name$, const qtprotobuf::AsyncReply<$return_type$> &reply)\n"
                                                              "{\n"
                                                              "    //TODO: call transport method to serialize this method\n"
-                                                             "    return false;"
+                                                             "    return false;\n"
                                                              "}\n";
 
 const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::string> Templates::TypeReflection = {

+ 35 - 0
src/grpc/CMakeLists.txt

@@ -0,0 +1,35 @@
+find_package(Qt5 COMPONENTS Core Network REQUIRED)
+if (Qt5Core_VERSION VERSION_LESS "5.8.0")
+    message(FATAL_ERROR "Required Qt version is 5.8+")
+endif()
+
+set(GRPC_SUPPORT_LIBRARY_TARGET qtgrpc)
+
+include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/src/protobuf)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+
+if(Qt5_POSITION_INDEPENDENT_CODE)
+  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+endif()
+
+
+file(GLOB SOURCES asyncreply.cpp
+    abstractchannel.cpp
+    http2channel.cpp
+    abstractclient.cpp)
+
+file(GLOB HEADERS asyncreply.h
+    abstractchannel.h
+    http2channel.h
+    abstractclient.h)
+
+add_library(${GRPC_SUPPORT_LIBRARY_TARGET} ${SOURCES})
+set_target_properties(${GRPC_SUPPORT_LIBRARY_TARGET} PROPERTIES PUBLIC_HEADER "${HEADERS}")
+target_link_libraries(${GRPC_SUPPORT_LIBRARY_TARGET} qtprotobufsupport Qt5::Core Qt5::Network)
+
+install(TARGETS ${GRPC_SUPPORT_LIBRARY_TARGET}
+    ARCHIVE DESTINATION lib
+    PUBLIC_HEADER DESTINATION include)

+ 0 - 0
src/lib/abstractchannel.cpp → src/grpc/abstractchannel.cpp


+ 0 - 0
src/lib/abstractchannel.h → src/grpc/abstractchannel.h


+ 0 - 0
src/lib/abstractclient.cpp → src/grpc/abstractclient.cpp


+ 0 - 0
src/lib/abstractclient.h → src/grpc/abstractclient.h


+ 0 - 0
src/lib/asyncreply.cpp → src/grpc/asyncreply.cpp


+ 0 - 0
src/lib/asyncreply.h → src/grpc/asyncreply.h


+ 0 - 0
src/lib/http2channel.cpp → src/grpc/http2channel.cpp


+ 0 - 0
src/lib/http2channel.h → src/grpc/http2channel.h


+ 6 - 14
src/lib/CMakeLists.txt → src/protobuf/CMakeLists.txt

@@ -1,6 +1,6 @@
-find_package(Qt5 COMPONENTS Core Network REQUIRED)
-if (Qt5Core_VERSION VERSION_LESS "5.12.0")
-    message(FATAL_ERROR "Required Qt version is 5.12+")
+find_package(Qt5 COMPONENTS Core REQUIRED)
+if (Qt5Core_VERSION VERSION_LESS "5.8.0")
+    message(FATAL_ERROR "Required Qt version is 5.8+")
 endif()
 
 set(SUPPORT_LIBRARY_TARGET qtprotobufsupport)
@@ -19,25 +19,17 @@ file(GLOB SOURCES universallistmodelbase.cpp
     universallistmodel.cpp
     protobufobject.cpp
     qtprotobuf.cpp
-    qtprotobuflogging.cpp
-    asyncreply.cpp
-    abstractchannel.cpp
-    http2channel.cpp
-    abstractclient.cpp)
+    qtprotobuflogging.cpp)
 
 file(GLOB HEADERS universallistmodelbase.h
     universallistmodel.h
     protobufobject.h
     qtprotobuftypes.h
-    qtprotobuf.h
-    asyncreply.h
-    abstractchannel.h
-    http2channel.h
-    abstractclient.h)
+    qtprotobuf.h)
 
 add_library(${SUPPORT_LIBRARY_TARGET} ${SOURCES})
 set_target_properties(${SUPPORT_LIBRARY_TARGET} PROPERTIES PUBLIC_HEADER "${HEADERS}")
-target_link_libraries(${SUPPORT_LIBRARY_TARGET} Qt5::Core Qt5::Network)
+target_link_libraries(${SUPPORT_LIBRARY_TARGET} Qt5::Core)
 
 install(TARGETS ${SUPPORT_LIBRARY_TARGET}
     ARCHIVE DESTINATION lib

+ 0 - 0
src/lib/protobufobject.cpp → src/protobuf/protobufobject.cpp


+ 0 - 0
src/lib/protobufobject.h → src/protobuf/protobufobject.h


+ 0 - 0
src/lib/qtprotobuf.cpp → src/protobuf/qtprotobuf.cpp


+ 4 - 3
src/lib/qtprotobuf.h → src/protobuf/qtprotobuf.h

@@ -26,11 +26,12 @@
 #pragma once
 
 #include <qtprotobuftypes.h>
+#include <qtprotobuflogging.h>
 #include <QDebug>
 
 //registerProtobufType Not a part of API
-#define registerProtobufType(X) qDebug() << # X << "Type Id: " << qRegisterMetaType<X>(# X);\
-                              qDebug() << # X << "Type Id: " << qRegisterMetaType<X>("qtprotobuf::"# X);
+#define registerProtobufType(X) qRegisterMetaType<X>(# X);\
+                                qRegisterMetaType<X>("qtprotobuf::"# X);
 
 namespace qtprotobuf {
 
@@ -38,7 +39,7 @@ class QtProtobuf {
 public:
     static void init() {
         static bool registationDone = false;
-        Q_ASSERT_X(!registationDone, "QtProtobuf", "Protobuf registation is already done");
+        Q_ASSERT_X(!registationDone, "QtProtobuf", "Protobuf registration is already done");
         if (!registationDone) {
             registerProtobufType(int32);
             registerProtobufType(int64);

+ 0 - 0
src/lib/qtprotobuflogging.cpp → src/protobuf/qtprotobuflogging.cpp


+ 0 - 0
src/lib/qtprotobuflogging.h → src/protobuf/qtprotobuflogging.h


+ 0 - 0
src/lib/qtprotobuftypes.h → src/protobuf/qtprotobuftypes.h


+ 0 - 0
src/lib/universallistmodel.cpp → src/protobuf/universallistmodel.cpp


+ 0 - 0
src/lib/universallistmodel.h → src/protobuf/universallistmodel.h


+ 0 - 0
src/lib/universallistmodelbase.cpp → src/protobuf/universallistmodelbase.cpp


+ 0 - 0
src/lib/universallistmodelbase.h → src/protobuf/universallistmodelbase.h


+ 3 - 3
tests/CMakeLists.txt

@@ -29,7 +29,7 @@ file(GLOB GENERATED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/*.cpp)
 list(FILTER GENERATED_SOURCES EXCLUDE REGEX "moc_.*cpp")
 QT5_WRAP_CPP(MOC_SOURCES ${GENERATED_HEADERS})
 
-include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src/lib)
+include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src/protobuf ${CMAKE_SOURCE_DIR}/src/grpc)
 
 if(WIN32)
     #Set  path to GTest build libraries
@@ -53,8 +53,8 @@ file(GLOB PROTOS proto/*.proto)
 set(testtarget "qtprotobuf_test")
 add_executable(${testtarget} ${SOURCES} ${MOC_SOURCES} ${GENERATED_SOURCES} ${PROTOS})
 if(WIN32)
-    target_link_libraries(${testtarget} "${GTEST_BOTH_LIBRARIES}/gmock_main.lib" "${GTEST_BOTH_LIBRARIES}/gmock.lib" qtprotobufsupport Qt5::Core)
+    target_link_libraries(${testtarget} "${GTEST_BOTH_LIBRARIES}/gmock_main.lib" "${GTEST_BOTH_LIBRARIES}/gmock.lib" qtprotobufsupport qtgrpc Qt5::Core)
 elseif(UNIX)
-    target_link_libraries(${testtarget} gtest qtprotobufsupport Qt5::Core)
+    target_link_libraries(${testtarget} gtest qtprotobufsupport qtgrpc Qt5::Core)
 endif()
 add_dependencies(${testtarget} ${testgeneration})