Extract metatype information as part of library finalization

Make qt_finalize_target call qt6_extract_metatypes() on any library
targets if the finalization is deferred and the target uses automoc.

This makes sure the metatype information is always available when
necessary (e.g. in QML's foreign types setting).

[ChangeLog][CMake][Important Behavior Changes] With CMake 3.19 or later
qt_extract_metatypes() is automatically called during target
finalization for libraries that use automoc now. This has no
effect if you've already manually called qt_extract_metatypes() before,
but it does make sure that the metatypes are also generated if you
haven't.

Task-number: QTBUG-121199
Fixes: QTBUG-101143
Fixes: QTBUG-99051
Change-Id: If72ce5887a9cd71a4c15e9509b2eaab5af271adf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Andrei Golubev 2022-02-22 16:39:10 +01:00 committed by Ulf Hermann
parent 674dfdf226
commit 0f5f1bfeff
2 changed files with 25 additions and 0 deletions

View File

@ -835,6 +835,17 @@ function(qt6_finalize_target target)
endif()
endif()
if(target_type STREQUAL "SHARED_LIBRARY" OR
target_type STREQUAL "STATIC_LIBRARY" OR
target_type STREQUAL "MODULE_LIBRARY" OR
target_type STREQUAL "OBJECT_LIBRARY")
get_target_property(is_immediately_finalized "${target}" _qt_is_immediately_finalized)
get_target_property(uses_automoc ${target} AUTOMOC)
if(uses_automoc AND NOT is_immediately_finalized)
qt6_extract_metatypes(${target})
endif()
endif()
set_target_properties(${target} PROPERTIES _qt_is_finalized TRUE)
endfunction()

View File

@ -52,4 +52,18 @@ example, to pass it to another command or to install it), use the
\c OUTPUT_FILES option to provide the name of a variable in which to store its
absolute path.
\section1 Automatic metatype extraction
Since Qt 6.8, if you have not disabled \c{AUTOMOC} and either are using CMake
3.19 or later or are calling \l{qt6_finalize_target}{qt_finalize_target()}
manually, then \c{qt_extract_metatypes()} is automatically called as part of the
finalization step for \l{qt_add_library}. This has no effect if you have
manually called \c{qt_extract_metatypes()} before the finalization, possibly
with custom arguments. However, it does make sure that the metatypes are also
produced if you haven't. This is important if any of the types in the library
are used as part of any QML types any time in the future and has no downsides.
Furthermore, \l{qt_add_qml_module} automatically invokes
\c{qt_extract_metatypes()} for its target.
*/