Browse Source

Add qt-style headers generation

- Add generation of qt-style headers for public API
- Supress part of useless output for cmake
Alexey Edelev 4 years ago
parent
commit
28ea60c5d6

+ 4 - 4
CMakeLists.txt

@@ -17,7 +17,7 @@ if(Qt5Core_VERSION VERSION_LESS "5.12.3")
 endif()
 
 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/grpc/CMakeLists.txt")
-    message(STATUS "Found local gRPC sources directory. Perform all-in-one build")
+    message(STATUS "-- Found local gRPC sources directory. Perform all-in-one build")
     set(gRPC_BUILD_TESTS FALSE)
     set(protobuf_BUILD_TESTS FALSE)
     add_subdirectory("3rdparty/grpc")
@@ -80,7 +80,7 @@ if(NOT DOXYGEN_FOUND)
     find_program(DOXYGEN_EXECUTABLE doxygen)
 endif()
 if(DEFINED DOXYGEN_EXECUTABLE)
-    message(STATUS "DOXYGEN_EXECUTABLE: ${DOXYGEN_EXECUTABLE}")
+    message(STATUS "-- Using doxygen to generate documenation: ${DOXYGEN_EXECUTABLE}")
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
     add_custom_target(doc
         ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
@@ -103,9 +103,9 @@ endif()
 
 if(NOT gRPC_FOUND)
     message(WARNING "gRPC not found: some tests and examples cannot be built.")
-    message(STATUS "Force disable test")
+    message(STATUS "-- Force disable test")
     set(QTPROTOBUF_MAKE_TESTS OFF)
-    message(STATUS "Force disable examples")
+    message(STATUS "-- Force disable examples")
     set(QTPROTOBUF_MAKE_EXAMPLES OFF)
 endif()
 

+ 1 - 1
cmake/Coverage.cmake

@@ -5,7 +5,7 @@ elseif(NOT DEFINED QTPROTOBUF_MAKE_COVERAGE)
 endif()
 
 if(QTPROTOBUF_MAKE_COVERAGE AND UNIX)
-    message(STATUS "Enable gcov")
+    message(STATUS "-- Enable gcov")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
 endif()

+ 18 - 0
cmake/GenerateQtHeaders.cmake

@@ -0,0 +1,18 @@
+function(protobuf_generate_qt_headers)
+    set(options)
+    set(oneValueArgs COMPONENT)
+    set(multiValueArgs PUBLIC_HEADERS)
+    cmake_parse_arguments(protobuf_generate_qt_headers "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+    foreach(PUBLIC_HEADER IN LISTS protobuf_generate_qt_headers_PUBLIC_HEADERS)
+        get_filename_component(PUBLIC_HEADER_BASE_NAME ${PUBLIC_HEADER} NAME FALSE)
+        file(STRINGS ${PUBLIC_HEADER} CLASS_NAME REGEX "#pragma once //[a-zA-Z]+")
+        if (NOT "${CLASS_NAME}" STREQUAL "")
+            string(REPLACE "#pragma once //" "" CLASS_NAME "${CLASS_NAME}")
+            message("-- Generate Qt header for ${CLASS_NAME}")
+            configure_file("${QTPROTOBUF_CMAKE_DIR}/GeneratedHeaderTemplate" "${QTPROTOBUF_BINARY_DIR}/include/${protobuf_generate_qt_headers_COMPONENT}/${CLASS_NAME}" @ONLY)
+            set(GENERATED_PUBLIC_HEADERS ${GENERATED_PUBLIC_HEADERS} ${QTPROTOBUF_BINARY_DIR}/include/${protobuf_generate_qt_headers_COMPONENT}/${CLASS_NAME})
+        endif()
+    endforeach()
+    set(GENERATED_PUBLIC_HEADERS ${GENERATED_PUBLIC_HEADERS} PARENT_SCOPE)
+endfunction()

+ 1 - 0
cmake/GeneratedHeaderTemplate

@@ -0,0 +1 @@
+#include "@PUBLIC_HEADER_BASE_NAME@" 

+ 2 - 2
cmake/ProtobufLookup.cmake

@@ -1,4 +1,4 @@
-find_package(Protobuf CONFIG)
+find_package(Protobuf CONFIG QUIET)
 if(NOT Protobuf_FOUND)
     if(CMAKE_SIZEOF_VOID_P EQUAL 8)
         set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
@@ -33,7 +33,7 @@ if(NOT Protobuf_FOUND)
     unset(Protobuf_FOUND)
     if(TARGET protobuf::libprotoc AND TARGET protobuf::protoc AND TARGET protobuf::libprotobuf)
         set(Protobuf_FOUND TRUE)
-        message(STATUS "Found protobuf installation: ${Protobuf_PROTOC_EXECUTABLE} ${Protobuf_PROTOC_LIBRARY} ${Protobuf_LIBRARY}")
+#        message(STATUS "Found protobuf installation: ${Protobuf_PROTOC_EXECUTABLE} ${Protobuf_PROTOC_LIBRARY} ${Protobuf_LIBRARY}")
     else()
         message(FATAL_ERROR "Protobuf is a hard dependency of the project. You may install it (with gRPC) by following instructions in cmake/gRPCBuild.cmake script.")
         unset(Protobuf_LIBRARY)

+ 2 - 2
cmake/gRPCLookup.cmake

@@ -1,4 +1,4 @@
-find_package(gRPC CONFIG)
+find_package(gRPC CONFIG QUIET)
 if(NOT gRPC_FOUND)
     if(CMAKE_SIZEOF_VOID_P EQUAL 8)
         set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
@@ -30,7 +30,7 @@ if(NOT gRPC_FOUND)
 
     unset(gRPC_FOUND)
     if(TARGET gRPC::grpc++ AND TARGET gRPC::grpc AND TARGET gRPC::grpc_cpp_plugin)
-        message(STATUS "Found gRPC")
+#        message(STATUS "Found gRPC")
         set(gRPC_FOUND TRUE)
     else()
         unset(gRPC_LIBRARY)

+ 0 - 4
examples/CMakeLists.txt

@@ -2,12 +2,8 @@ add_subdirectory("examples_common")
 
 add_subdirectory("addressbook")
 add_subdirectory("addressbookserver")
-message(STATUS "CLIENT: ${CLIENT_EXEC_PATH}")
-message(STATUS "SERVER: ${SERVER_EXEC_PATH}")
 configure_file(client_server_driver.sh.in addressbook_driver.sh @ONLY)
 
 add_subdirectory("simplechat")
 add_subdirectory("simplechatserver")
-message(STATUS "CLIENT: ${CLIENT_EXEC_PATH}")
-message(STATUS "SERVER: ${SERVER_EXEC_PATH}")
 configure_file(client_server_driver.sh.in simplechat_driver.sh @ONLY)

+ 3 - 3
examples/addressbook/addressbookengine.cpp

@@ -25,9 +25,9 @@
 
 #include "addressbookengine.h"
 #include "addressbookclient.h"
-#include <qgrpchttp2channel.h>
-#include <insecurecredentials.h>
-#include <sslcredentials.h>
+#include <QGrpcHttp2Channel>
+#include <InsecureCredentials>
+#include <SslCredentials>
 
 #include <QDebug>
 #include <QFile>

+ 3 - 3
examples/simplechat/simplechatengine.cpp

@@ -25,9 +25,9 @@
 
 #include "simplechatengine.h"
 
-#include <qgrpchttp2channel.h>
-#include <insecurecredentials.h>
-#include <sslcredentials.h>
+#include <QGrpcHttp2Channel>
+#include <InsecureCredentials>
+#include <SslCredentials>
 
 #include <QDebug>
 #include <QFile>

+ 5 - 1
src/grpc/CMakeLists.txt

@@ -12,6 +12,7 @@ set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
 
 include(${QTPROTOBUF_CMAKE_DIR}/Coverage.cmake)
+include(${QTPROTOBUF_CMAKE_DIR}/GenerateQtHeaders.cmake)
 
 file(GLOB SOURCES qgrpcasyncreply.cpp
     qgrpcstatus.cpp
@@ -32,13 +33,16 @@ file(GLOB HEADERS qgrpcasyncreply.h
     insecurecredentials.h
     qtgrpcglobal.h)
 
+protobuf_generate_qt_headers(PUBLIC_HEADERS ${HEADERS} COMPONENT ${TARGET})
+
 add_library(${TARGET} SHARED ${SOURCES})
 target_compile_definitions(${TARGET} PRIVATE QT_BUILD_GRPC_LIB)
 
 add_library(${QTPROTOBUF_COMMON_NAMESPACE}::${TARGET} ALIAS ${TARGET})
-set_target_properties(${TARGET} PROPERTIES VERSION ${PROJECT_VERSION} PUBLIC_HEADER "${HEADERS}" OUTPUT_NAME ${TARGET})
+set_target_properties(${TARGET} PROPERTIES VERSION ${PROJECT_VERSION} PUBLIC_HEADER "${HEADERS};${GENERATED_PUBLIC_HEADERS}" OUTPUT_NAME ${TARGET})
 target_include_directories(${TARGET} PUBLIC 
     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+    $<BUILD_INTERFACE:${QTPROTOBUF_BINARY_DIR}/include/${TARGET}>
     $<INSTALL_INTERFACE:${TARGET_INCLUDE_DIR}>
 )
 target_link_libraries(${TARGET} PUBLIC ${QTPROTOBUF_COMMON_NAMESPACE}::QtProtobuf Qt5::Core Qt5::Network)

+ 1 - 1
src/grpc/abstractcredentials.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //AbstractCredentials
 
 #include <QString>
 #include <QHash>

+ 1 - 1
src/grpc/insecurecredentials.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //InsecureCredentials
 
 #include "abstractcredentials.h"
 

+ 1 - 1
src/grpc/qabstractgrpcchannel.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QAbstractGrpcChannel
 
 #include <QString>
 #include <QByteArray>

+ 1 - 1
src/grpc/qabstractgrpcclient.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QAbstractGrpcClient
 
 #include <memory>
 #include <functional>

+ 1 - 1
src/grpc/qgrpcasyncreply.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QGrpcAsyncReply
 
 #include <functional>
 #include <QPointer>

+ 1 - 1
src/grpc/qgrpchttp2channel.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QGrpcHttp2Channel
 
 #include "qabstractgrpcchannel.h"
 

+ 1 - 1
src/grpc/qgrpcstatus.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QGrpcStatus
 
 #include <QString>
 

+ 1 - 1
src/grpc/sslcredentials.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //SslCredentials
 
 #include "abstractcredentials.h"
 

+ 5 - 1
src/protobuf/CMakeLists.txt

@@ -14,6 +14,7 @@ set(CMAKE_AUTORCC ON)
 find_package(Qt5 COMPONENTS Core Qml REQUIRED)
 
 include(${QTPROTOBUF_CMAKE_DIR}/Coverage.cmake)
+include(${QTPROTOBUF_CMAKE_DIR}/GenerateQtHeaders.cmake)
 
 file(GLOB SOURCES
     qtprotobuf.cpp
@@ -57,14 +58,17 @@ file(GLOB PUBLIC_HEADERS
     qprotobufmetaproperty.h
     qprotobufmetaobject.h)
 
+protobuf_generate_qt_headers(PUBLIC_HEADERS ${PUBLIC_HEADERS} COMPONENT ${TARGET})
+
 add_library(${TARGET} SHARED ${SOURCES})
 target_compile_definitions(${TARGET} PRIVATE QT_BUILD_PROTOBUF_LIB PUBLIC QTPROTOBUF_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
     QTPROTOBUF_VERSION_MINOR=${PROJECT_VERSION_MINOR})
 
 add_library(${QTPROTOBUF_COMMON_NAMESPACE}::${TARGET} ALIAS ${TARGET})
-set_target_properties(${TARGET} PROPERTIES VERSION ${PROJECT_VERSION} PUBLIC_HEADER "${PUBLIC_HEADERS}" OUTPUT_NAME ${TARGET})
+set_target_properties(${TARGET} PROPERTIES VERSION ${PROJECT_VERSION} PUBLIC_HEADER "${PUBLIC_HEADERS};${GENERATED_PUBLIC_HEADERS}" OUTPUT_NAME ${TARGET})
 target_include_directories(${TARGET} PUBLIC
     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+    $<BUILD_INTERFACE:${QTPROTOBUF_BINARY_DIR}/include/${TARGET}>
     $<INSTALL_INTERFACE:${TARGET_INCLUDE_DIR}>
 )
 target_link_libraries(${TARGET} PUBLIC Qt5::Core Qt5::Qml)

+ 1 - 1
src/protobuf/qabstractprotobufserializer.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QAbstractProtobufSerializer
 
 #include <QObject>
 #include <QVariant>

+ 2 - 0
src/protobuf/qprotobufjsonserializer.h

@@ -23,6 +23,8 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#pragma once //QProtobufJsonSerializer
+
 #include "qabstractprotobufserializer.h"
 #include "qtprotobufglobal.h"
 

+ 1 - 1
src/protobuf/qprotobufmetaobject.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QProtobufMetaObject
 
 #include "qtprotobufglobal.h"
 #include "qtprotobuftypes.h"

+ 1 - 1
src/protobuf/qprotobufmetaproperty.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QProtobufMetaProperty
 
 #include <QMetaProperty>
 

+ 1 - 1
src/protobuf/qprotobufobject.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QProtobufObject
 
 #include "qabstractprotobufserializer.h"
 #include "qprotobufmetaobject.h"

+ 1 - 2
src/protobuf/qprotobufregistrationhelper.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QProtobufRegistrationHelper
 
 #include <functional>
 
@@ -41,4 +41,3 @@ public:
 };
 
 }
-

+ 1 - 1
src/protobuf/qprotobufselfcheckiterator.h

@@ -28,7 +28,7 @@
 
 #include "qtprotobufglobal.h"
 
-#pragma once
+#pragma once //QProtobufSelfcheckIterator
 
 namespace QtProtobuf {
 

+ 1 - 1
src/protobuf/qprotobufserializer.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QProtobufSerializer
 
 #include "qabstractprotobufserializer.h"
 #include "qtprotobufglobal.h"

+ 1 - 1
src/protobuf/qtprotobuftypes.h

@@ -23,7 +23,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#pragma once
+#pragma once //QtProtobufTypes
 
 #include <QList>
 #include <QMetaType>