Fix the GENERATE_PACKAGE_SUBFOLDERS option for Qml modules

Add the missing include directory to workaround QTBUG-115499.
Make sure that '$<TARGET_PROPERTY' genex is evaluated for
_protobuf_registration targets.

TODO: Extra include directories should be removed since they might
lead to ambiguous include records if .proto files contain messages
with same name but in different protobuf packages.

Fixes: QTBUG-114077
Task-number: QTBUG-115499
Pick-to: 6.6
Change-Id: Ifb9002435b20034967f202a5dc94ec51a3704f64
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
This commit is contained in:
Alexey Edelev 2023-07-25 12:42:21 +02:00
parent 9a41966511
commit 6dda607f6d
2 changed files with 9 additions and 1 deletions

View File

@ -275,6 +275,7 @@ function(qt6_add_protobuf target)
set(output_directory "${arg_OUTPUT_DIRECTORY}")
endif()
set(extra_include_directories "")
set(cpp_sources "")
set(idx 0)
foreach(f IN LISTS proto_files)
@ -286,6 +287,8 @@ function(qt6_add_protobuf target)
endif()
string(REPLACE "." "/" package_full_path "${package}/")
math(EXPR idx "${idx} + 1")
list(APPEND extra_include_directories
"$<BUILD_INTERFACE:${output_directory}/${package_full_path}>")
else()
set(package_full_path "")
endif()
@ -384,6 +387,10 @@ function(qt6_add_protobuf target)
PRIVATE "/Zc:__cplusplus" "/permissive-" "/bigobj")
endif()
# TODO: adding these include paths might cause the ambiguous include handling if
# two different packages contain messages with the same name. This should be fixed
# in moc and qmltypesregistar, see QTBUG-115499.
target_include_directories(${target} PRIVATE ${extra_include_directories})
target_link_libraries(${target} PRIVATE
${QT_CMAKE_EXPORT_NAMESPACE}::Protobuf
)
@ -398,7 +405,7 @@ function(qt6_add_protobuf target)
add_dependencies(${target} ${target}_protobuf_registration)
target_include_directories(${target}_protobuf_registration
PRIVATE "$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>")
PRIVATE "$<GENEX_EVAL:$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>>")
target_link_libraries(${target}_protobuf_registration
PRIVATE
${QT_CMAKE_EXPORT_NAMESPACE}::Platform

View File

@ -19,6 +19,7 @@ qt_add_protobuf(tst_protobuf_basictypes_qml_gen
PROTO_FILES
../../shared/data/proto/basicmessages.proto
QML
GENERATE_PACKAGE_SUBFOLDERS
FIELD_ENUM
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated"
)