File tree Expand file tree Collapse file tree 6 files changed +32
-7
lines changed
Expand file tree Collapse file tree 6 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,11 @@ function(qtprotobuf_generate)
3232 set (GENERATION_OPTIONS ${GENERATION_TYPE} )
3333
3434 if (qtprotobuf_generate_QML)
35- message (STATUS "Enabled QML generation for ${GENERATED_TARGET_NAME} " )
35+ if (NOT TARGET Qt5::Qml)
36+ message (FATAL_ERROR "Trying to enable QML support for ${GENERATED_TARGET_NAME} , but Qt5::Qml is not a target."
37+ " find_package(Qt5 COMPONENTS Qml) is missing?" )
38+ endif ()
39+ message (STATUS "Enabling QML generation for ${GENERATED_TARGET_NAME} " )
3640 set (GENERATION_OPTIONS "${GENERATION_OPTIONS} :QML" )
3741 endif ()
3842
Original file line number Diff line number Diff line change 5252#endif
5353
5454#ifndef Q_GRPC_IMPORT_QUICK_PLUGIN
55- #ifdef QT_PROTOBUF_STATIC
55+ #if defined( QT_PROTOBUF_STATIC) && defined(QT_QML_LIB) // TODO: Check how detect this in Qt6
5656 #include < QtPlugin>
5757 #include < QQmlExtensionPlugin>
5858 #define Q_GRPC_IMPORT_QUICK_PLUGIN () \
Original file line number Diff line number Diff line change 2626#pragma once // QProtobufLazyMessagePointer
2727
2828#include " qtprotobufglobal.h"
29- #include < QQmlEngine>
3029#include < QObject>
30+ #if defined(QT_QML_LIB) // TODO: Check how detect this in Qt6
31+ # include < QQmlEngine>
32+ #endif
3133
3234#include < memory>
3335#include < type_traits>
@@ -96,7 +98,12 @@ class QProtobufLazyMessagePointer {//TODO: final?
9698
9799private:
98100 void checkAndRelease () const {
99- if (m_ptr != nullptr && QQmlEngine::objectOwnership (m_ptr.get ()) == QQmlEngine::JavaScriptOwnership) {
101+ #if defined(QT_QML_LIB)
102+ bool qmlCheck = QQmlEngine::objectOwnership (m_ptr.get ()) == QQmlEngine::JavaScriptOwnership;
103+ #else
104+ bool qmlCheck = true ;
105+ #endif
106+ if (m_ptr != nullptr && qmlCheck) {
100107 m_ptr.release ();// In case if object owned by QML it's qml responsibility to clean it up
101108 QObject::disconnect (m_destroyed);
102109 }
Original file line number Diff line number Diff line change 7878 * \endcode
7979 */
8080#ifndef Q_PROTOBUF_IMPORT_QUICK_PLUGIN
81- #ifdef QT_PROTOBUF_STATIC
81+ #if defined( QT_PROTOBUF_STATIC ) && defined( QT_QML_LIB ) // TODO: Check how detect this in Qt6
8282 #include <QtPlugin>
8383 #include <QQmlExtensionPlugin>
8484 #define Q_PROTOBUF_IMPORT_QUICK_PLUGIN () \
Original file line number Diff line number Diff line change @@ -19,10 +19,19 @@ qt_protobuf_internal_add_library(ProtobufQtTypes
1919
2020
2121file (GLOB PROTO_FILE ${CMAKE_CURRENT_SOURCE_DIR} /QtProtobuf/Qt*.proto)
22+
23+ set (qml_enabled "" )
24+ if (TARGET Qt5::Qml)
25+ set (qml_enabled QML)
26+ endif ()
27+
2228qtprotobuf_generate(TARGET ProtobufQtTypes
2329 OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} /generated
2430 PROTO_FILES ${PROTO_FILE}
25- QML FOLDER ${extra_type_libraries_options} )
31+ FOLDER
32+ ${qml_enabled}
33+ ${extra_type_libraries_options}
34+ )
2635
2736target_compile_definitions (ProtobufQtTypes PRIVATE QT_BUILD_PROTOBUF_QT_TYPES_LIB)
2837
Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ function(add_wellknowntype type_name)
1515 set (lookup_dirs "${QT_PROTOBUF_SOURCE_DIR} /3rdparty/grpc/third_party/protobuf/src"
1616 ${Protobuf_INCLUDE_DIRS}
1717 )
18+
19+ set (qml_enabled "" )
20+ if (TARGET Qt5::Qml)
21+ set (qml_enabled QML)
22+ endif ()
1823 foreach (dir ${lookup_dirs} )
1924 file (GLOB PROTO_FILE "${dir} /google/protobuf/${type_name} .proto" )
2025 if (NOT "${PROTO_FILE} " STREQUAL "" )
@@ -24,7 +29,7 @@ function(add_wellknowntype type_name)
2429 OUT_DIR "${CMAKE_CURRENT_BINARY_DIR} /generated"
2530 PROTO_FILES "${PROTO_FILE} "
2631 PROTO_INCLUDES "-I\" ${dir} \" "
27- QML
32+ ${qml_enabled}
2833 FOLDER
2934 ${extra_type_libraries_options}
3035 )
You can’t perform that action at this time.
0 commit comments