瀏覽代碼

Add standalone tests build

- It make sense to build and run tests using the pre-installed
  QtProtobuf. This will prevent of issues in the release packages
  related to the invalid cmake build routines.
- Fix side issues found by standalone issues
- Disable the serializer plugin tests in standalone mode, since
  they requires the private headers installed, which are not
  introduced by QtProtobuf yet.
Alexey Edelev 3 年之前
父節點
當前提交
18e88b5476

+ 55 - 48
CMakeLists.txt

@@ -74,68 +74,75 @@ set(PROTOBUF_QUICK_PLUGIN_NAME protobufquickplugin)
 set(GRPC_QUICK_PLUGIN_NAME grpcquickplugin)
 
 set(QT_PROTOBUF_MAKE_TESTS ON CACHE BOOL "Enable QtProtobuf tests build")
+set(QT_PROTOBUF_STANDALONE_TESTS OFF CACHE BOOL "Enable QtProtobuf tests build")
 set(QT_PROTOBUF_MAKE_EXAMPLES ON CACHE BOOL "Enable QtProtobuf examples build")
 set(QT_PROTOBUF_MAKE_COVERAGE OFF CACHE BOOL "Enable QtProtobuf build for profiler (gcov)")
 set(QT_PROTOBUF_FIELD_ENUM OFF CACHE BOOL "Enable generation of enumeration with fields numbers for well-known and Qt types libraries")
 set(QT_PROTOBUF_NATIVE_GRPC_CHANNEL OFF CACHE BOOL "Enable native gRPC channel implementation")
 
-if(QT_PROTOBUF_NATIVE_GRPC_CHANNEL)
-    if(NOT WrapgRPC_FOUND OR NOT Threads_FOUND)
-        message("QT_PROTOBUF_NATIVE_GRPC_CHANNEL is ON, but required dependencies are not found.")
-        set(QT_PROTOBUF_NATIVE_GRPC_CHANNEL OFF)
+if(NOT QT_PROTOBUF_STANDALONE_TESTS)
+    if(QT_PROTOBUF_NATIVE_GRPC_CHANNEL)
+        if(NOT WrapgRPC_FOUND OR NOT Threads_FOUND)
+            message("QT_PROTOBUF_NATIVE_GRPC_CHANNEL is ON, but required dependencies are not found.")
+            set(QT_PROTOBUF_NATIVE_GRPC_CHANNEL OFF)
+        endif()
     endif()
-endif()
 
-if(CMAKE_CROSSCOMPILING)
-    set(QT_PROTOBUF_MAKE_TESTS OFF)
-    set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
-endif()
+    if(CMAKE_CROSSCOMPILING)
+        set(QT_PROTOBUF_MAKE_TESTS OFF)
+        set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
+    endif()
 
-set(QT_PROTOBUF_STATIC OFF CACHE INTERNAL "")
-if(NOT BUILD_SHARED_LIBS)
-    set(QT_PROTOBUF_STATIC ON CACHE INTERNAL "" FORCE)
-endif()
+    set(QT_PROTOBUF_STATIC OFF CACHE INTERNAL "" FORCE)
+    if(NOT BUILD_SHARED_LIBS)
+        set(QT_PROTOBUF_STATIC ON CACHE INTERNAL "" FORCE)
+    endif()
 
-set(extra_type_libraries_options "") #Prevent to set from outside
-if(QT_PROTOBUF_FIELD_ENUM)
-    set(extra_type_libraries_options "FIELDENUM ${extra_type_libraries_options}")
-endif()
+    set(extra_type_libraries_options "") #Prevent to set from outside
+    if(QT_PROTOBUF_FIELD_ENUM)
+        set(extra_type_libraries_options "FIELDENUM ${extra_type_libraries_options}")
+    endif()
 
-configure_package_config_file(
-    "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
-    INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
+    configure_package_config_file(
+         "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
+         INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
 
-install(FILES "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
-    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
-    COMPONENT dev
-)
-export(PACKAGE ${QT_PROTOBUF_NAMESPACE})
-install(FILES "${QT_PROTOBUF_CMAKE_DIR}/FindWrapProtobuf.cmake"
-    DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
-    COMPONENT dev
-)
+    install(FILES "${QT_PROTOBUF_BINARY_DIR}/${QT_PROTOBUF_NAMESPACE}Config.cmake"
+        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
+        COMPONENT dev
+    )
+    export(PACKAGE ${QT_PROTOBUF_NAMESPACE})
+    install(FILES "${QT_PROTOBUF_CMAKE_DIR}/FindWrapProtobuf.cmake"
+        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QT_PROTOBUF_NAMESPACE}"
+        COMPONENT dev
+    )
 
-if(NOT CMAKE_CROSSCOMPILING)
-    add_subdirectory("src/generator")
-endif()
+    if(NOT CMAKE_CROSSCOMPILING)
+        add_subdirectory("src/generator")
+    endif()
 
-add_subdirectory("src/protobuf")
-if(TARGET ${QT_VERSIONED_PREFIX}::Network)
-    if(${QT_VERSIONED_PREFIX}Core_VERSION VERSION_LESS "5.12.4")
-        # grpc target requires QT version not less than 5.12.4
-        # earlier versions Http2DirectAttribute is broken: https://doc.qt.io/qt-5/whatsnew511.html
-        #                                                  https://bugreports.qt.io/browse/QTBUG-74765
-        message(WARNING "QtGrpc requires the Qt framework version 5.12.4 or higher")
-    else()
-        add_subdirectory("src/grpc")
+    add_subdirectory("src/protobuf")
+    if(TARGET ${QT_VERSIONED_PREFIX}::Network)
+        if(${QT_VERSIONED_PREFIX}Core_VERSION VERSION_LESS "5.12.4")
+            # grpc target requires QT version not less than 5.12.4
+            # earlier versions Http2DirectAttribute is broken: https://doc.qt.io/qt-5/whatsnew511.html
+            #                                                  https://bugreports.qt.io/browse/QTBUG-74765
+            message(WARNING "QtGrpc requires the Qt framework version 5.12.4 or higher")
+        else()
+            add_subdirectory("src/grpc")
+        endif()
     endif()
-endif()
 
-if(TARGET protobuf::libprotobuf AND TARGET protobuf::protoc)
-    add_subdirectory("src/wellknowntypes")
-endif()
-if(TARGET ${QT_VERSIONED_PREFIX}::Gui AND TARGET protobuf::protoc)
-    add_subdirectory("src/qttypes")
+    if(TARGET protobuf::libprotobuf AND TARGET protobuf::protoc)
+         add_subdirectory("src/wellknowntypes")
+    endif()
+    if(TARGET ${QT_VERSIONED_PREFIX}::Gui AND TARGET protobuf::protoc)
+        add_subdirectory("src/qttypes")
+    endif()
+else()
+    # Disable any installtion rules if build tests only
+    set(QT_PROTOBUF_INSTALL FALSE CACHE INTERNAL "" FORCE)
+    set(QT_PROTOBUF_MAKE_TESTS TRUE)
 endif()
 
 if(QT_PROTOBUF_MAKE_TESTS)
@@ -149,7 +156,7 @@ if(QT_PROTOBUF_MAKE_TESTS)
     endif()
 endif()
 
-if(QT_PROTOBUF_MAKE_EXAMPLES)
+if(QT_PROTOBUF_MAKE_EXAMPLES AND NOT QT_PROTOBUF_STANDALONE_TESTS)
     if(TARGET ${QT_VERSIONED_PREFIX}::Quick)
         add_subdirectory("examples")
     else()

+ 2 - 2
src/grpc/quick/CMakeLists.txt

@@ -39,8 +39,9 @@ set_target_properties(${TARGET} PROPERTIES
     RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/QtGrpc")
 target_compile_definitions(${TARGET} PRIVATE QT_GRPC_QUICK_LIB)
 
+add_library(${QT_PROTOBUF_NAMESPACE}::${TARGET} ALIAS ${TARGET})
 if(NOT BUILD_SHARED_LIBS)
-    add_library(${QT_PROTOBUF_NAMESPACE}::${TARGET} ALIAS ${TARGET})
+    export(TARGETS ${TARGET} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake)
     if(QT_PROTOBUF_INSTALL)
         install(TARGETS ${TARGET} COMPONENT lib
             EXPORT ${TARGET_EXPORT} COMPONENT dev
@@ -49,7 +50,6 @@ if(NOT BUILD_SHARED_LIBS)
             LIBRARY DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib)
         install(EXPORT ${TARGET_EXPORT} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake DESTINATION ${TARGET_CMAKE_DIR} COMPONENT dev)
     endif()
-    export(TARGETS ${TARGET} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake)
 else()
     if(QT_PROTOBUF_INSTALL)
         install(TARGETS ${TARGET} COMPONENT lib

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

@@ -52,8 +52,9 @@ endforeach()
 
 target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${Qt5Qml_PRIVATE_INCLUDE_DIRS})
 
+add_library(${QT_PROTOBUF_NAMESPACE}::${TARGET} ALIAS ${TARGET})
 if(NOT BUILD_SHARED_LIBS)
-    add_library(${QT_PROTOBUF_NAMESPACE}::${TARGET} ALIAS ${TARGET})
+    export(TARGETS ${TARGET} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake)
     if(QT_PROTOBUF_INSTALL)
         install(TARGETS ${TARGET} COMPONENT lib
             EXPORT ${TARGET_EXPORT} COMPONENT dev
@@ -62,7 +63,6 @@ if(NOT BUILD_SHARED_LIBS)
             LIBRARY DESTINATION "${TARGET_IMPORTS_DIR}" COMPONENT lib)
         install(EXPORT ${TARGET_EXPORT} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake DESTINATION ${TARGET_CMAKE_DIR} COMPONENT dev)
     endif()
-    export(TARGETS ${TARGET} NAMESPACE ${QT_PROTOBUF_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake)
 else()
     if(QT_PROTOBUF_INSTALL)
         install(TARGETS ${TARGET} COMPONENT lib

+ 11 - 2
tests/CMakeLists.txt

@@ -1,3 +1,9 @@
+if(QT_PROTOBUF_STANDALONE_TESTS)
+    find_package(QtProtobuf COMPONENTS Protobuf ProtobufGenerator
+        OPTIONAL_COMPONENTS Grpc ProtobufWellKnownTypes ProtobufQtTypes REQUIRED
+    )
+endif()
+
 include(QtProtobufTestHelpers)
 
 add_subdirectory("test_protobuf")
@@ -5,9 +11,12 @@ if(TARGET ${QT_VERSIONED_PREFIX}::QuickTest)
     add_subdirectory("test_qml")
 endif()
 add_subdirectory("test_protobuf_multifile")
-add_subdirectory("test_qprotobuf_serializer_plugin")
 add_subdirectory("test_extra_namespace")
-add_subdirectory("test_extra_namespace_qml")
+if(NOT QT_PROTOBUF_STANDALONE_TESTS) # Disable in standalone mode as it requires some private
+                                     # headers to work properly.
+    add_subdirectory("test_extra_namespace_qml")
+    add_subdirectory("test_qprotobuf_serializer_plugin")
+endif()
 
 if(TARGET ${QT_PROTOBUF_NAMESPACE}::ProtobufWellKnownTypes)
     add_subdirectory("test_wellknowntypes")

+ 4 - 0
tests/test_extra_namespace_qml/CMakeLists.txt

@@ -24,6 +24,10 @@ qt_protobuf_internal_add_target_windeployqt(TARGET ${TARGET} QML_DIR ${CMAKE_CUR
 add_test(NAME ${TARGET} COMMAND ${TARGET})
 
 if(NOT QT_PROTOBUF_STATIC AND NOT QT_PROTOBUF_STANDALONE_TESTS)
+    set(path_separator ":")
+    if(WIN32)
+        set(path_separator "$<SEMICOLON>")
+    endif()
     set_tests_properties(${TARGET} PROPERTIES
         ENVIRONMENT "QML2_IMPORT_PATH=$ENV{QML2_IMPORT_PATH}${path_separator}\
 $<TARGET_FILE_DIR:${QT_PROTOBUF_NAMESPACE}::${PROTOBUF_QUICK_PLUGIN_NAME}>/.."

+ 14 - 6
tests/test_grpc_qml/CMakeLists.txt

@@ -18,7 +18,10 @@ target_link_libraries(qtgrpc_qml_test_http2
 qtprotobuf_link_target(qtgrpc_qml_test_http2 qtgrpc_test_qtprotobuf_gen)
 
 if(QT_PROTOBUF_STATIC)
-    target_link_libraries(qtgrpc_qml_test_http2 PRIVATE ${PROTOBUF_QUICK_PLUGIN_NAME} ${GRPC_QUICK_PLUGIN_NAME})
+    target_link_libraries(qtgrpc_qml_test_http2 PRIVATE
+        ${QT_PROTOBUF_NAMESPACE}::${PROTOBUF_QUICK_PLUGIN_NAME}
+        ${QT_PROTOBUF_NAMESPACE}::${GRPC_QUICK_PLUGIN_NAME}
+    )
 endif()
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../test_grpc/${TEST_DRIVER_NAME}.in ${TEST_DRIVER_NAME} @ONLY)
@@ -33,12 +36,17 @@ add_test(NAME qtgrpc_qml_test_http2
 qt_protobuf_internal_add_target_qml(TARGET qtgrpc_qml_test_http2 QML_FILES ${QML_FILES})
 qt_protobuf_internal_add_target_windeployqt(TARGET qtgrpc_qml_test_http2 QML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml)
 
-if(WIN32)
-    set_tests_properties(qtgrpc_qml_test_http2 PROPERTIES
-        ENVIRONMENT QML2_IMPORT_PATH=$<TARGET_FILE_DIR:${PROTOBUF_QUICK_PLUGIN_NAME}>/..\;$<TARGET_FILE_DIR:${GRPC_QUICK_PLUGIN_NAME}>/..)
-else()
+if(NOT QT_PROTOBUF_STATIC AND NOT QT_PROTOBUF_STANDALONE_TESTS)
+    set(path_separator ":")
+    if(WIN32)
+        set(path_separator "$<SEMICOLON>")
+    endif()
+
     set_tests_properties(qtgrpc_qml_test_http2 PROPERTIES
-        ENVIRONMENT QML2_IMPORT_PATH=$<TARGET_FILE_DIR:${PROTOBUF_QUICK_PLUGIN_NAME}>/..:$<TARGET_FILE_DIR:${GRPC_QUICK_PLUGIN_NAME}>/..)
+        ENVIRONMENT "QML2_IMPORT_PATH=$ENV{QML2_IMPORT_PATH}${path_separator}\
+$<TARGET_FILE_DIR:${QT_PROTOBUF_NAMESPACE}::${PROTOBUF_QUICK_PLUGIN_NAME}>/..${path_separator}\
+$<TARGET_FILE_DIR:${QT_PROTOBUF_NAMESPACE}::${GRPC_QUICK_PLUGIN_NAME}>/.."
+    )
 endif()
 
 if(QT_PROTOBUF_NATIVE_GRPC_CHANNEL)

+ 12 - 3
tests/test_qml/CMakeLists.txt

@@ -17,7 +17,7 @@ if(TARGET ${QT_PROTOBUF_NAMESPACE}::ProtobufWellKnownTypes)
 endif()
 
 if(QT_PROTOBUF_STATIC)
-    target_link_libraries(${TARGET} PRIVATE ${PROTOBUF_QUICK_PLUGIN_NAME})
+    target_link_libraries(${TARGET} PRIVATE ${QT_PROTOBUF_NAMESPACE}::${PROTOBUF_QUICK_PLUGIN_NAME})
 endif()
 
 qtprotobuf_link_target(${TARGET} qtprotobuf_test_qtprotobuf_gen)
@@ -27,5 +27,14 @@ qt_protobuf_internal_add_target_windeployqt(TARGET ${TARGET} QML_DIR ${CMAKE_CUR
 
 add_test(NAME ${TARGET} COMMAND ${TARGET})
 
-set_tests_properties(${TARGET} PROPERTIES
-    ENVIRONMENT QML2_IMPORT_PATH=$<TARGET_FILE_DIR:${PROTOBUF_QUICK_PLUGIN_NAME}>/..)
+if(NOT QT_PROTOBUF_STATIC AND NOT QT_PROTOBUF_STANDALONE_TESTS)
+    set(path_separator ":")
+    if(WIN32)
+        set(path_separator "$<SEMICOLON>")
+    endif()
+
+    set_tests_properties(${TARGET} PROPERTIES
+        ENVIRONMENT "QML2_IMPORT_PATH=$ENV{QML2_IMPORT_PATH}${path_separator}\
+$<TARGET_FILE_DIR:${QT_PROTOBUF_NAMESPACE}::${PROTOBUF_QUICK_PLUGIN_NAME}>/.."
+    )
+endif()

+ 1 - 1
tests/test_qprotobuf_serializer_plugin/CMakeLists.txt

@@ -24,5 +24,5 @@ add_subdirectory("serialization")
 
 add_test(NAME ${TARGET} COMMAND ${TARGET})
 set_tests_properties(${TARGET} PROPERTIES
-    ENVIRONMENT QT_PROTOBUF_PLUGIN_PATH=$<TARGET_FILE_DIR:serializationplugin>)
+    ENVIRONMENT "QT_PROTOBUF_PLUGIN_PATH=$<TARGET_FILE_DIR:serializationplugin>")