Преглед на файлове

Force usage of internal targets for in-tree build

- Add check for local targets for examples and tests
- Rename test helper file
- Refactor test helper functions and add extra helpers for
  examples
- Replace global variable that hold protoparser.go by Generator target
  property
- Enable well known types for windows
- Update CI rules for windows

Fixes: #172, #183, #12
Alexey Edelev преди 4 години
родител
ревизия
1ceacf28b0

+ 16 - 3
.ci/qt_installer_windows.qs

@@ -19,20 +19,33 @@ Controller.prototype.IntroductionPageCallback = function() {
     gui.clickButton(buttons.NextButton);
 }
 
-Controller.prototype.TargetDirectoryPageCallback = function()
-{
+Controller.prototype.TargetDirectoryPageCallback = function() {
     gui.currentPageWidget().TargetDirectoryLineEdit.setText("C:/Qt");
     gui.clickButton(buttons.NextButton);
 }
 
+Controller.prototype.DynamicTelemetryPluginFormCallback = function() {
+    var page = gui.pageWidgetByObjectName("DynamicTelemetryPluginForm");
+    page.statisticGroupBox.disableStatisticRadioButton.setChecked(true);
+    gui.clickButton(buttons.NextButton);
+}
+
 Controller.prototype.ComponentSelectionPageCallback = function() {
     var widget = gui.currentPageWidget();
     widget.deselectAll();
-    widget.selectComponent("qt.qt5.5132.win32_msvc2017");
+    widget.selectComponent("qt.qt5.5152.win32_msvc2019");
 
     gui.clickButton(buttons.NextButton);
 }
 
+Controller.prototype.ObligationsPageCallback = function()
+{
+    var page = gui.pageWidgetByObjectName("ObligationsPage");
+    page.obligationsAgreement.setChecked(true);
+    page.completeChanged();
+    gui.clickButton(buttons.NextButton);
+}
+
 Controller.prototype.LicenseAgreementPageCallback = function() {
     gui.currentPageWidget().AcceptLicenseRadioButton.setChecked(true);
     gui.clickButton(buttons.NextButton);

+ 5 - 5
.travis.yml

@@ -10,18 +10,18 @@ branches:
   - 0.5
   - ci_check
 before_install:
-  - wget -q https://download.qt.io/official_releases/qt/5.13/5.13.2/qt-opensource-windows-x86-5.13.2.exe
+  - wget -q https://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe -O qt-unified-windows-x86-online.exe
 install:
   - choco install golang
   - choco install yasm
-  - ./qt-opensource-windows-x86-5.13.2.exe --script ./.ci/qt_installer_windows.qs
+  - ./qt-unified-windows-x86-online.exe --script ./.ci/qt_installer_windows.qs -d
 script:
   - mkdir build
   - cd build
   - setx GOROOT "c:\Go"
-  - setx path "%path%;C:\Qt\5.13.2\msvc2017\bin;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools"
+  - setx path "%path%;C:\Qt\5.15.2\msvc2019\bin;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools"
   - set GOROOT="c:\Go"
-  - set PATH="%PATH%;C:\Qt\5.13.2\msvc2017\bin;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools"
-  - cmake -DCMAKE_PREFIX_PATH="C:\Qt\5.13.2\msvc2017;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools" -DBUILD_SHARED_LIBS=OFF ..
+  - set PATH="%PATH%;C:\Qt\5.15.2\msvc2019\bin;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools"
+  - cmake -DCMAKE_PREFIX_PATH="C:\Qt\5.15.2\msvc2019;C:\Go\bin;C:\ProgramData\chocolatey\lib\yasm\tools" -DBUILD_SHARED_LIBS=OFF ..
   - cmake --build .
   - ctest -C DEBUG -E qtgrpc_* --output-on-failure

+ 1 - 3
CMakeLists.txt

@@ -73,9 +73,7 @@ if(QT_PROTOBUF_FIELD_ENUM)
     set(EXTRA_TYPE_LIBRARIES_OPTIONS "FIELDENUM ${EXTRA_TYPE_LIBRARIES_OPTIONS}")
 endif()
 
-if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
-    add_subdirectory("src/wellknowntypes")
-endif()
+add_subdirectory("src/wellknowntypes")
 add_subdirectory("src/qttypes")
 
 if(QT_PROTOBUF_MAKE_TESTS)

+ 8 - 5
cmake/QtProtobufGen.cmake

@@ -68,6 +68,11 @@ function(qtprotobuf_generate)
             message(FATAL_ERROR "Golang is mandatory dependency for QtProtobuf if GENERATED_HEADERS is not specified. Please install it and ensure that it's accessible by PATH environment variable")
         endif()
 
+        get_target_property(PROTO_PARSER ${QT_PROTOBUF_PROJECT}::${GENERATOR_TARGET} PROTO_PARSER)
+        if(NOT PROTO_PARSER)
+            message(FATAL_ERROR "Unable to locate parsemessages.go script")
+        endif()
+
         foreach(PROTO_FILE IN LISTS qtprotobuf_generate_PROTO_FILES)
             get_filename_component(BASE_DIR ${PROTO_FILE} DIRECTORY)
             set(PROTO_INCLUDES "-I\"${BASE_DIR}\"" ${PROTO_INCLUDES})
@@ -149,11 +154,9 @@ function(qtprotobuf_generate)
             $<TARGET_PROPERTY:${QT_PROTOBUF_PROJECT}::QtGrpc,INTERFACE_INCLUDE_DIRECTORIES>)
     endif()
 
-    if(NOT WIN32)
-        if(TARGET ${QT_PROTOBUF_PROJECT}::QtProtobufWellKnownTypes)
-            target_include_directories(${GENERATED_TARGET_NAME} PRIVATE
-                $<TARGET_PROPERTY:${QT_PROTOBUF_PROJECT}::QtProtobufWellKnownTypes,INTERFACE_INCLUDE_DIRECTORIES>)
-        endif()
+    if(TARGET ${QT_PROTOBUF_PROJECT}::QtProtobufWellKnownTypes)
+        target_include_directories(${GENERATED_TARGET_NAME} PRIVATE
+            $<TARGET_PROPERTY:${QT_PROTOBUF_PROJECT}::QtProtobufWellKnownTypes,INTERFACE_INCLUDE_DIRECTORIES>)
     endif()
 
     if(TARGET ${QT_PROTOBUF_PROJECT}::QtProtobufQtTypes)

+ 109 - 0
cmake/QtProtobufInternalHelpers.cmake

@@ -0,0 +1,109 @@
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufCommon.cmake)
+
+macro(qt_protobuf_internal_find_dependencies)
+    find_package(Qt5 COMPONENTS Core Qml Network REQUIRED)
+    find_package(Threads REQUIRED)
+    if(NOT TARGET ${QT_PROTOBUF_PROJECT}::QtProtobuf)
+        find_package(${QT_PROTOBUF_PROJECT} COMPONENTS QtProtobuf REQUIRED)
+    endif()
+    if(NOT TARGET ${QT_PROTOBUF_PROJECT}::QtGrpc)
+        find_package(${QT_PROTOBUF_PROJECT} COMPONENTS QtGrpc REQUIRED)
+    endif()
+    if(QT_PROTOBUF_STATIC)
+        add_definitions(-DQT_PROTOBUF_STATIC)# add_definitions is used because old cmake versions
+                                             # compatibility
+    endif()
+
+    set(CMAKE_POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
+    set(CMAKE_AUTOMOC ON)
+    set(CMAKE_AUTORCC ON)
+endmacro()
+
+
+function(qt_protobuf_internal_add_test_target)
+    set(options MULTI QML FIELDENUM)
+    set(oneValueArgs QML_DIR TARGET)
+    set(multiValueArgs SOURCES GENERATED_HEADERS EXCLUDE_HEADERS PROTO_FILES PROTO_INCLUDES)
+    cmake_parse_arguments(add_test_target "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+    find_package(Qt5 COMPONENTS Test REQUIRED)
+
+    ## test sources build
+    # policy enables automoc for generated files
+    if(${CMAKE_VERSION} VERSION_GREATER "3.10.0")
+        cmake_policy(SET CMP0071 NEW)
+    endif()
+
+    set(CMAKE_POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
+
+    set(GENERATED_SOURCES_DIR ${CMAKE_CURRENT_BINARY_DIR}/${add_test_target_TARGET}_generated)
+
+    if(DEFINED add_test_target_PROTO_FILES)
+        file(GLOB PROTO_FILES ABSOLUTE ${add_test_target_PROTO_FILES})
+    else()
+        file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto)
+    endif()
+
+    add_executable(${add_test_target_TARGET} ${add_test_target_SOURCES})
+
+    set(EXTRA_OPTIONS COMMENTS)
+    if(add_test_target_MULTI)
+        set(EXTRA_OPTIONS ${EXTRA_OPTIONS} MULTI)
+    endif()
+    if(add_test_target_QML)
+        set(EXTRA_OPTIONS ${EXTRA_OPTIONS} QML)
+    endif()
+    if(add_test_target_FIELDENUM)
+        set(EXTRA_OPTIONS ${EXTRA_OPTIONS} FIELDENUM)
+    endif()
+
+    qtprotobuf_generate(TARGET ${add_test_target_TARGET}
+        OUT_DIR ${GENERATED_SOURCES_DIR}
+        PROTO_FILES ${PROTO_FILES}
+        GENERATED_HEADERS ${add_test_target_GENERATED_HEADERS}
+        EXCLUDE_HEADERS ${add_test_target_EXCLUDE_HEADERS}
+        ${EXTRA_OPTIONS}
+        PROTO_INCLUDES ${add_test_target_PROTO_INCLUDES})
+
+    target_link_libraries(${add_test_target_TARGET} PUBLIC gtest_main
+                                                           gtest
+                                                           ${QT_PROTOBUF_PROJECT}::QtProtobuf
+                                                           ${QT_PROTOBUF_PROJECT}::QtGrpc
+                                                           Qt5::Core
+                                                           Qt5::Test
+                                                           Qt5::Network
+                                                           ${CMAKE_THREAD_LIBS_INIT})
+    if (${add_test_target_QML})
+        target_link_libraries(${add_test_target_TARGET} PUBLIC Qt5::Qml)
+    endif()
+endfunction()
+
+function(qt_protobuf_internal_add_example_target)
+    set(options)
+    set(oneValueArgs TARGET QML_DIR)
+    set(multiValueArgs SOURCES PROTO_FILES RESOURCES)
+    cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+    find_package(Qt5 COMPONENTS Quick REQUIRED)
+
+    set(CMAKE_INCLUDE_CURRENT_DIR ON)
+    set(CMAKE_AUTOMOC ON)
+    set(CMAKE_AUTORCC ON)
+
+    file(GLOB PROTO_FILES ABSOLUTE ${arg_PROTO_FILES})
+    file(GLOB SOURCES ${arg_SOURCES})
+
+    add_executable(${TARGET} ${SOURCES} ${arg_RESOURCES})
+    qtprotobuf_generate(TARGET ${TARGET}
+        OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated
+        PROTO_FILES ${PROTO_FILES}
+        QML)
+
+    add_target_windeployqt(TARGET ${TARGET} QML_DIR ${arg_QML_DIR})
+
+    target_link_libraries(${TARGET} PRIVATE examples_common
+                                            QtProtobufProject::QtProtobuf
+                                            QtProtobufProject::QtGrpc
+                                            Qt5::Quick
+                                            Qt5::Qml)
+endfunction()

+ 0 - 56
cmake/QtProtobufTest.cmake

@@ -1,56 +0,0 @@
-find_package(${QT_PROTOBUF_PROJECT} COMPONENTS QtProtobuf QtGrpc REQUIRED)
-
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufCommon.cmake)
-
-function(add_test_target)
-    set(options MULTI QML FIELDENUM)
-    set(oneValueArgs QML_DIR TARGET)
-    set(multiValueArgs SOURCES GENERATED_HEADERS EXCLUDE_HEADERS PROTO_FILES PROTO_INCLUDES)
-    cmake_parse_arguments(add_test_target "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
-    find_package(Threads REQUIRED)
-    find_package(Qt5 COMPONENTS Test REQUIRED)
-    ## test sources build
-    # policy enables automoc for generated files
-    if(${CMAKE_VERSION} VERSION_GREATER "3.10.0")
-        cmake_policy(SET CMP0071 NEW)
-    endif()
-
-    set(GENERATED_SOURCES_DIR ${CMAKE_CURRENT_BINARY_DIR}/${add_test_target_TARGET}_generated)
-
-    if(DEFINED add_test_target_PROTO_FILES)
-        file(GLOB PROTO_FILES ABSOLUTE ${add_test_target_PROTO_FILES})
-    else()
-        file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto)
-    endif()
-
-    add_executable(${add_test_target_TARGET} ${add_test_target_SOURCES})
-
-    set(EXTRA_OPTIONS COMMENTS)
-    if(add_test_target_MULTI)
-        set(EXTRA_OPTIONS ${EXTRA_OPTIONS} MULTI)
-    endif()
-    if(add_test_target_QML)
-        set(EXTRA_OPTIONS ${EXTRA_OPTIONS} QML)
-    endif()
-    if(add_test_target_FIELDENUM)
-        set(EXTRA_OPTIONS ${EXTRA_OPTIONS} FIELDENUM)
-    endif()
-
-    qtprotobuf_generate(TARGET ${add_test_target_TARGET}
-        OUT_DIR ${GENERATED_SOURCES_DIR}
-        PROTO_FILES ${PROTO_FILES}
-        GENERATED_HEADERS ${add_test_target_GENERATED_HEADERS}
-        EXCLUDE_HEADERS ${add_test_target_EXCLUDE_HEADERS}
-        ${EXTRA_OPTIONS}
-        PROTO_INCLUDES ${add_test_target_PROTO_INCLUDES})
-
-    if(Qt5_POSITION_INDEPENDENT_CODE)
-        set_target_properties(${add_test_target_TARGET} PROPERTIES POSITION_INDEPENDENT_CODE FALSE)
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
-    endif()
-    target_link_libraries(${add_test_target_TARGET} PUBLIC gtest_main gtest ${QT_PROTOBUF_PROJECT}::QtProtobuf ${QT_PROTOBUF_PROJECT}::QtGrpc Qt5::Core Qt5::Test Qt5::Network ${CMAKE_THREAD_LIBS_INIT})
-    if (${add_test_target_QML})
-        target_link_libraries(${add_test_target_TARGET} PUBLIC Qt5::Qml)
-    endif()
-endfunction(add_test_target)

+ 8 - 20
examples/addressbook/CMakeLists.txt

@@ -1,28 +1,16 @@
 set(TARGET addressbook)
 
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
 
-find_package(Qt5 COMPONENTS Core Quick Network REQUIRED)
-find_package(QtProtobufProject CONFIG REQUIRED COMPONENTS QtProtobuf QtGrpc)
-
-file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/proto/addressbook.proto)
-
-file(GLOB SOURCES main.cpp
-    addressbookengine.cpp)
-
-add_executable(${TARGET} ${SOURCES} resources.qrc)
-qtprotobuf_generate(TARGET ${TARGET}
-    OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated
-    PROTO_FILES ${PROTO_FILES}
-    QML)
-
-add_target_windeployqt(TARGET ${TARGET} QML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml)
+qt_protobuf_internal_add_example_target(TARGET ${TARGET}
+                   PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/proto/addressbook.proto"
+                   SOURCES main.cpp
+                           addressbookengine.cpp
+                   RESOURCES resources.qrc
+                   QML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml)
 
 add_custom_command(TARGET ${TARGET}
     COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../addressbookserver/cert.pem $<TARGET_FILE_DIR:${TARGET}>)
 
-target_link_libraries(${TARGET} PRIVATE examples_common QtProtobufProject::QtProtobuf QtProtobufProject::QtGrpc Qt5::Quick Qt5::Qml)
-
 set(CLIENT_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 20 - 6
examples/clienttutorial/CMakeLists.txt

@@ -9,14 +9,28 @@ set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
 
 find_package(Qt5 COMPONENTS Core Quick REQUIRED)
-find_package(QtProtobufProject COMPONENTS QtProtobuf QtGrpc REQUIRED)
+set(CMAKE_POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
+
+if(NOT TARGET ${QT_PROTOBUF_PROJECT}::QtProtobuf)
+    find_package(${QT_PROTOBUF_PROJECT} COMPONENTS QtProtobuf REQUIRED)
+endif()
+if(NOT TARGET ${QT_PROTOBUF_PROJECT}::QtGrpc)
+    find_package(${QT_PROTOBUF_PROJECT} COMPONENTS QtGrpc REQUIRED)
+endif()
 
 add_executable(clienttutorial main.cpp echoclientengine.cpp qml.qrc)
 
-qtprotobuf_generate(TARGET clienttutorial PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tutorial.proto QML TRUE)
+qtprotobuf_generate(TARGET clienttutorial
+                    PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tutorial.proto
+                    QML TRUE)
 
 target_compile_definitions(clienttutorial
-  PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
-target_link_libraries(clienttutorial
-  PRIVATE Qt5::Core Qt5::Quick)
-target_link_libraries(clienttutorial PRIVATE QtProtobufProject::QtGrpc QtProtobufProject::QtProtobuf)
+                           PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
+if(QT_PROTOBUF_STATIC)
+   add_definitions(-DQT_PROTOBUF_STATIC)# add_definitions is used because old cmake versions
+                                        # compatibility
+endif()
+target_link_libraries(clienttutorial PRIVATE Qt5::Core
+                                             Qt5::Quick
+                                             QtProtobufProject::QtGrpc
+                                             QtProtobufProject::QtProtobuf)

+ 12 - 24
examples/simplechat/CMakeLists.txt

@@ -1,28 +1,16 @@
 set(TARGET simplechat)
 
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-
-find_package(Qt5 COMPONENTS Core Quick Network REQUIRED)
-find_package(QtProtobufProject CONFIG REQUIRED COMPONENTS QtProtobuf QtGrpc)
-
-file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/proto/simplechat.proto)
-
-file(GLOB SOURCES main.cpp
-    simplechatengine.cpp
-)
-
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../simplechatserver/cert.pem DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
-
-add_executable(${TARGET} ${SOURCES} resources.qrc)
-qtprotobuf_generate(TARGET ${TARGET}
-    OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated
-    PROTO_FILES ${PROTO_FILES}
-    QML)
-
-add_target_windeployqt(TARGET ${TARGET} QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-
-target_link_libraries(${TARGET} PRIVATE examples_common QtProtobufProject::QtProtobuf QtProtobufProject::QtGrpc Qt5::Quick Qt5::Qml)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
+
+qt_protobuf_internal_add_example_target(TARGET ${TARGET}
+                   PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/proto/simplechat.proto"
+                   SOURCES main.cpp
+                           simplechatengine.cpp
+                   RESOURCES resources.qrc
+                   QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+add_custom_command(TARGET ${TARGET}
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../addressbookserver/cert.pem $<TARGET_FILE_DIR:${TARGET}>)
 
 set(CLIENT_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 2 - 0
src/generator/CMakeLists.txt

@@ -58,6 +58,8 @@ configure_file("${QT_PROTOBUF_CMAKE_DIR}/QtProtobufGen.cmake" "${QT_PROTOBUF_BIN
 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/parsemessages.go" "${QT_PROTOBUF_BINARY_DIR}/parsemessages.go" COPYONLY)
 configure_file("${QT_PROTOBUF_CMAKE_DIR}/ProtobufLookup.cmake" "${QT_PROTOBUF_BINARY_DIR}/ProtobufLookup.cmake" COPYONLY)
 
+set_property(TARGET ${TARGET} PROPERTY PROTO_PARSER "${QT_PROTOBUF_BINARY_DIR}/parsemessages.go")
+
 if(QT_PROTOBUF_INSTALL)
     install(TARGETS ${TARGET}
         EXPORT ${TARGET_EXPORT} COMPONENT dev

+ 2 - 1
src/generator/GeneratorConfig.cmake.in

@@ -4,7 +4,8 @@ if(NOT TARGET @TARGET@ AND NOT @TARGET@_BINARY_DIR)
     include("${CMAKE_CURRENT_LIST_DIR}/@TARGET_EXPORT@.cmake")
 endif()
 
+set_property(TARGET @TARGET@ PROPERTY PROTO_PARSER "${CMAKE_CURRENT_LIST_DIR}/parsemessages.go")
+
 @PACKAGE_INIT@
-set(PROTO_PARSER "${CMAKE_CURRENT_LIST_DIR}/parsemessages.go")
 set(GENERATOR_TARGET "@GENERATOR_TARGET@")
 include("${CMAKE_CURRENT_LIST_DIR}/QtProtobufGen.cmake")

+ 2 - 2
src/grpc/CMakeLists.txt

@@ -69,9 +69,9 @@ add_library(${TARGET} ${SOURCES})
 
 if(NOT BUILD_SHARED_LIBS)
     if(WIN32)
-        message(WARNING "Static version of QtGrpc is not fully tested on Win32 platforms")
+        message(WARNING "Static version of ${TARGET} is not fully tested on Win32 platforms")
     endif()
-    target_compile_definitions(${TARGET} PRIVATE QT_PROTOBUF_STATIC)
+    target_compile_definitions(${TARGET} PUBLIC QT_PROTOBUF_STATIC)
     set(QT_PROTOBUF_EXTRA_CONFIG "staticlib") #extra config for .pri file in case if static build enabled
 endif()
 

+ 6 - 7
src/protobuf/CMakeLists.txt

@@ -7,17 +7,16 @@ set(TARGET_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
 set(TARGET_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
 set(TARGET_BINDIR ${CMAKE_INSTALL_BINDIR})
 
+find_package(Qt5 COMPONENTS Core Qml REQUIRED)
+
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
 
-find_package(Qt5 COMPONENTS Core Qml REQUIRED)
-
 if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/3rdparty/microjson/CMakeLists.txt")
     set(MICROJSON_MAKE_TESTS OFF)
     set(MICROJSON_OBJECT_LIB_ONLY ON)
     add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/microjson")
     message(STATUS "Using microjson from 3rdparty")
-    message("Note: microjson will be added to install set")
 else()
     message(FATAL_ERROR "microjson is not found.")
 endif()
@@ -77,13 +76,13 @@ protobuf_generate_qt_headers(PUBLIC_HEADER ${PUBLIC_HEADER} COMPONENT ${TARGET})
 
 add_library(${TARGET} ${SOURCES})
 
-set(QT_PROTOBUF_STATIC OFF)
+set(QT_PROTOBUF_STATIC OFF CACHE INTERNAL "")
 if(NOT BUILD_SHARED_LIBS)
-    set(QT_PROTOBUF_STATIC ON)
+    set(QT_PROTOBUF_STATIC ON CACHE INTERNAL "" FORCE)
     if(WIN32)
-        message(WARNING "Static version of QtProtobuf is not fully tested on Win32 platforms")
+        message(WARNING "Static version of ${TARGET} is not fully tested on Win32 platforms")
     endif()
-    target_compile_definitions(${TARGET} PRIVATE QT_PROTOBUF_STATIC)
+    target_compile_definitions(${TARGET} PUBLIC QT_PROTOBUF_STATIC)
     set(QT_PROTOBUF_EXTRA_COMPILE_DIFINITIONS QT_PROTOBUF_STATIC)
     set(QT_PROTOBUF_EXTRA_CONFIG "staticlib") #extra config for .pri file in case if static build enabled
 endif()

+ 3 - 1
src/protobuf/QtProtobufConfig.cmake.in

@@ -19,5 +19,7 @@ endif()
 
 @PACKAGE_INIT@
 if(QT_PROTOBUF_STATIC)
-    add_definitions(-DQT_PROTOBUF_STATIC)#Old cmake versions compatibility
+    add_definitions(-DQT_PROTOBUF_STATIC)# add_definitions is used because old cmake versions
+                                         # compatibility
 endif()
+

+ 1 - 1
src/protobuf/qprotobufjsonserializer.cpp

@@ -73,7 +73,7 @@ public:
         L listValue = propertyValue.value<L>();
         QByteArray result("[");
         for (auto value : listValue) {
-            result += QString::number(value) + ",";
+            result += QString::number(value).toUtf8() + ",";
         }
         if (listValue.size() > 0) {
             result.resize(result.size() - 1);//Remove trailing `,`

+ 1 - 1
src/protobuf/quick/CMakeLists.txt

@@ -29,7 +29,7 @@ if(NOT BUILD_SHARED_LIBS)
     if(WIN32)
         message(WARNING "Static version of QtProtobuf is not fully tested on Win32 platforms")
     endif()
-    target_compile_definitions(${TARGET} PRIVATE QT_PROTOBUF_STATIC QT_STATICPLUGIN PUBLIC QT_PROTOBUF_QUICK_PLUGIN_NAME="QtProtobufQuickPlugin")
+    target_compile_definitions(${TARGET} PUBLIC QT_STATICPLUGIN QT_PROTOBUF_QUICK_PLUGIN_NAME="QtProtobufQuickPlugin")
 endif()
 
 target_link_libraries(${TARGET} PRIVATE Qt5::Core Qt5::Qml ${QT_PROTOBUF_PROJECT}::QtProtobuf)

+ 9 - 3
src/qttypes/CMakeLists.txt

@@ -7,15 +7,14 @@ set(TARGET_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
 set(TARGET_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
 set(TARGET_BINDIR ${CMAKE_INSTALL_BINDIR})
 
+find_package(Qt5 COMPONENTS Core Gui Qml REQUIRED)
+
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
 
-find_package(Qt5 COMPONENTS Core Gui Qml REQUIRED)
-find_package(Protobuf QUIET)
 if(NOT TARGET ${GENERATOR_TARGET})
     find_package(QtProtobufProject COMPONENTS Generator CONFIG REQUIRED)
 else()
-    set(PROTO_PARSER ${QT_PROTOBUF_BINARY_DIR}/parsemessages.go)
     include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufGen.cmake)
 endif()
 
@@ -37,6 +36,13 @@ protobuf_generate_qt_headers(PUBLIC_HEADER ${HEADERS} COMPONENT QtProtobuf)
 
 add_library(${TARGET} ${SOURCES})
 
+if(NOT BUILD_SHARED_LIBS)
+    if(WIN32)
+        message(WARNING "Static version of ${TARGET} is not fully tested on Win32 platforms")
+    endif()
+    target_compile_definitions(${TARGET} PUBLIC QT_PROTOBUF_STATIC)
+endif()
+
 file(GLOB PROTO_FILE ${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/Qt*.proto)
 qtprotobuf_generate(TARGET ${TARGET}
     OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated

+ 7 - 1
src/wellknowntypes/CMakeLists.txt

@@ -15,7 +15,6 @@ find_package(Protobuf QUIET)
 if(NOT TARGET ${GENERATOR_TARGET})
     find_package(QtProtobufProject COMPONENTS Generator CONFIG REQUIRED)
 else()
-    set(PROTO_PARSER ${QT_PROTOBUF_BINARY_DIR}/parsemessages.go)
     include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufGen.cmake)
 endif()
 
@@ -93,6 +92,13 @@ target_include_directories(${TARGET} PUBLIC
 
 add_library(${QT_PROTOBUF_PROJECT}::${TARGET} ALIAS ${TARGET})
 
+if(NOT BUILD_SHARED_LIBS)
+    if(WIN32)
+        message(WARNING "Static version of ${TARGET} is not fully tested on Win32 platforms")
+    endif()
+    target_compile_definitions(${TARGET} PUBLIC QT_PROTOBUF_STATIC)
+endif()
+
 target_link_libraries(${TARGET} PUBLIC Qt5::Core Qt5::Qml ${QT_PROTOBUF_PROJECT}::QtProtobuf)
 
 include(CMakePackageConfigHelpers)

+ 1 - 3
tests/CMakeLists.txt

@@ -2,9 +2,7 @@ add_subdirectory("test_protobuf")
 add_subdirectory("test_qml")
 add_subdirectory("test_protobuf_multifile")
 add_subdirectory("test_qprotobuf_serializer_plugin")
-if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
-    add_subdirectory("test_wellknowntypes")
-endif()
+add_subdirectory("test_wellknowntypes")
 add_subdirectory("test_qttypes")
 if(gRPC_FOUND)
     add_subdirectory("test_grpc")

+ 4 - 3
tests/test_grpc/CMakeLists.txt

@@ -1,12 +1,13 @@
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
 
 # clients
-add_test_target(TARGET qtgrpc_test
+qt_protobuf_internal_add_test_target(TARGET qtgrpc_test
     SOURCES clienttest.cpp QML)
 add_target_windeployqt(TARGET qtgrpc_test
     QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 
-add_test_target(TARGET qtgrpc_secure_test
+qt_protobuf_internal_add_test_target(TARGET qtgrpc_secure_test
     SOURCES sslclienttest.cpp)
 add_target_windeployqt(TARGET qtgrpc_secure_test
     QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})

+ 3 - 4
tests/test_grpc_qml/CMakeLists.txt

@@ -1,7 +1,6 @@
-find_package(Qt5 COMPONENTS Core Quick Network Test QuickTest REQUIRED)
-find_package(QtProtobufProject COMPONENTS QtGrpc REQUIRED)
-
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
+find_package(Qt5 COMPONENTS Quick QuickTest REQUIRED)
 
 set(CMAKE_AUTOMOC OFF)
 

+ 3 - 2
tests/test_protobuf/CMakeLists.txt

@@ -1,6 +1,7 @@
 set(TARGET qtprotobuf_test)
 
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
 
 file(GLOB SOURCES
     simpletest.cpp
@@ -16,7 +17,7 @@ if(NOT WIN32)
     list(APPEND SOURCES internalstest.cpp)
 endif()
 
-add_test_target(TARGET ${TARGET}
+qt_protobuf_internal_add_test_target(TARGET ${TARGET}
     SOURCES ${SOURCES}
     QML FIELDENUM)
 add_target_windeployqt(TARGET ${TARGET}

+ 3 - 2
tests/test_protobuf_multifile/CMakeLists.txt

@@ -1,6 +1,7 @@
 set(TARGET qtprotobuf_test_multifile)
 
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
 
 file(GLOB SOURCES
     simpletest.cpp
@@ -8,7 +9,7 @@ file(GLOB SOURCES
 
 file(GLOB PROTO_FILES ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/../test_protobuf/proto/*.proto)
 
-add_test_target(TARGET ${TARGET}
+qt_protobuf_internal_add_test_target(TARGET ${TARGET}
     PROTO_FILES ${PROTO_FILES}
     SOURCES ${SOURCES}
     QML

+ 3 - 4
tests/test_qml/CMakeLists.txt

@@ -1,9 +1,8 @@
 set(TARGET qtprotobuf_qml_test)
 
-find_package(Qt5 COMPONENTS Core Quick Network Test QuickTest REQUIRED)
-find_package(QtProtobufProject COMPONENTS QtProtobuf REQUIRED)
-
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
+find_package(Qt5 COMPONENTS Quick QuickTest REQUIRED)
 
 set(CMAKE_AUTOMOC OFF)
 

+ 11 - 3
tests/test_qprotobuf_serializer_plugin/CMakeLists.txt

@@ -1,15 +1,23 @@
 set(TARGET qtprotobuf_plugin_test)
 
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
+find_package(Qt5 CONFIG COMPONENTS Test REQUIRED)
 
 find_package(Threads REQUIRED)
-find_package(Qt5 COMPONENTS Test REQUIRED)
 
 file(GLOB SOURCES
     serializationplugintest.cpp)
 
 add_executable(${TARGET} ${SOURCES})
-target_link_libraries(${TARGET} PRIVATE gtest_main gtest ${QT_PROTOBUF_PROJECT}::QtProtobuf ${QT_PROTOBUF_PROJECT}::QtGrpc Qt5::Core Qt5::Test Qt5::Network ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(${TARGET} PRIVATE gtest_main
+                                        gtest
+                                        ${QT_PROTOBUF_PROJECT}::QtProtobuf
+                                        ${QT_PROTOBUF_PROJECT}::QtGrpc
+                                        Qt5::Core
+                                        Qt5::Test
+                                        Qt5::Network
+                                        ${CMAKE_THREAD_LIBS_INIT})
 add_target_windeployqt(TARGET ${TARGET}
     QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 

+ 7 - 3
tests/test_qttypes/CMakeLists.txt

@@ -1,13 +1,17 @@
 set(TARGET qttypes_test)
 
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
-find_package(QtProtobufProject CONFIG COMPONENTS QtProtobuf QtProtobufQtTypes REQUIRED)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
+
+if(NOT TARGET QtProtobufProject::QtProtobufQtTypes)
+    find_package(QtProtobufProject CONFIG COMPONENTS QtProtobufQtTypes REQUIRED)
+endif()
 
 file(GLOB SOURCES
     qtcoretest.cpp
     qtguitest.cpp)
 
-add_test_target(TARGET ${TARGET}
+qt_protobuf_internal_add_test_target(TARGET ${TARGET}
     SOURCES ${SOURCES}
     PROTO_INCLUDES $<TARGET_PROPERTY:${QT_PROTOBUF_PROJECT}::QtProtobufQtTypes,PROTO_INCLUDES>
     QML)

+ 7 - 3
tests/test_wellknowntypes/CMakeLists.txt

@@ -1,12 +1,16 @@
 set(TARGET wellknowntypes_test)
 
-include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufTest.cmake)
-find_package(QtProtobufProject CONFIG COMPONENTS QtProtobuf QtGrpc QtProtobufWellKnownTypes REQUIRED)
+include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufInternalHelpers.cmake)
+qt_protobuf_internal_find_dependencies()
+
+if(NOT TARGET QtProtobufProject::QtProtobufQtTypes)
+    find_package(QtProtobufProject CONFIG COMPONENTS QtProtobufWellKnownTypes REQUIRED)
+endif()
 
 file(GLOB SOURCES
     simpletest.cpp)
 
-add_test_target(TARGET ${TARGET}
+qt_protobuf_internal_add_test_target(TARGET ${TARGET}
     SOURCES ${SOURCES}
     PROTO_INCLUDES $<TARGET_PROPERTY:${QT_PROTOBUF_PROJECT}::QtProtobufWellKnownTypes,PROTO_INCLUDES>
     QML)