CMake: Fix qt6_generate_foreign_qml_types

We had the tst_qmlsplitlib test failing in in-source builds only,
because qt6_wrap_cpp is called on the generated sources and this sets
SKIP_AUTOMOC ON. Later in the build, the consumer of the
corresponding moc_XXX.cpp.json file errors out, because it cannot find
the file.

The test worked in out-of-source builds, because the paths of the
generated files were relative: add_custom_command generated the files in
the build dir. qt6_wrap_cpp got the relative paths and assumed them
relative to the source dir and did set SKIP_AUTOMOC on non-existent
source files. AUTOMOC took care of generating moc_XXX.cpp and
moc_XXX.cpp.json, and all was well.

Clearly, the consumer of the moc_XXX.cpp.json files expects them to be
generated by AUTOMOC.

Fix this by
- using absolute paths for the generated files to make sure
  target_sources gets the correct paths
- removing the qt6_wrap_cpp call

Pick-to: 6.5 6.4
Fixes: QTBUG-110117
Change-Id: I01bcd8e37f57cf30ea06a7dd1fd8844367b58a14
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Joerg Bornemann 2023-01-26 09:57:23 +01:00
parent 59d6cf324d
commit 2d97f9bdf0
1 changed files with 10 additions and 2 deletions

View File

@ -2302,8 +2302,17 @@ function(qt6_generate_foreign_qml_types source_target destination_qml_target)
message(FATAL_ERROR "Need target metatypes.json file")
endif()
get_target_property(automoc_enabled ${destination_qml_target} AUTOMOC)
if(NOT automoc_enabled)
message(FATAL_ERROR "qt6_generate_foreign_qml_types requires AUTOMOC to be enabled "
"on target '${destination_qml_target}'.")
endif()
set(registration_files_base ${source_target}_${destination_qml_target})
set(additional_sources ${registration_files_base}.cpp ${registration_files_base}.h)
set(additional_sources
"${CMAKE_CURRENT_BINARY_DIR}/${registration_files_base}.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/${registration_files_base}.h"
)
_qt_internal_get_tool_wrapper_script_path(tool_wrapper)
add_custom_command(
@ -2324,7 +2333,6 @@ function(qt6_generate_foreign_qml_types source_target destination_qml_target)
)
target_sources(${destination_qml_target} PRIVATE ${additional_sources})
qt6_wrap_cpp(${additional_sources} TARGET ${destination_qml_target})
endfunction()
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)