diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-02-22 16:39:10 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-04-17 11:53:13 +0200 |
commit | 0f5f1bfeffc685bb1917fde5de2c4bcc59385e0a (patch) | |
tree | 0ad3fe450709fb644843e403ec47dee3ec625ac0 | |
parent | 674dfdf226542cc33129899df9833847cb6f4629 (diff) |
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>
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 11 | ||||
-rw-r--r-- | src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index d3203c5cd9..04b5c4f62e 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -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() diff --git a/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc b/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc index 7d9cd936ff..7ec8d90f9b 100644 --- a/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc +++ b/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc @@ -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. + */ |