diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2023-01-26 09:57:23 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2023-01-26 14:38:22 +0100 |
commit | 2d97f9bdf0d21997a6ee7e43d1364803842aa635 (patch) | |
tree | 7aadb1476437b17af96794714412619ecdb7354e | |
parent | 59d6cf324dfb80febf65dd735990b4e9e3a7e54b (diff) |
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>
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 90a53e77b1..fce7156a55 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -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) |