aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@qt.io>2021-02-15 12:41:11 +1100
committerCraig Scott <craig.scott@qt.io>2021-02-24 10:39:20 +1100
commitc71c48f5125c116f01f615f51f10e4f2877b2b1d (patch)
tree1b7ec66e84f3be335126db1c5a032e594de63b4d /src
parent7e029878c0f0ba43640d031aee9250fe4e713b41 (diff)
Add finalizer to call qt6_import_qml_plugins() automatically
Any target created by a call to qt6_add_executable() that also links to the Qml target will now automatically call qt6_import_qml_plugins() in qt6_finalize_executable() for scenarios that need it. This is only relevant for static builds and only when not doing a top level Qt superbuild. The finalizers feature requires CMake 3.18. If using an earlier CMake version, the project is still responsible for calling qt6_import_qml_plugins() itself. Fixes: QTBUG-86669 Pick-to: 6.1 Change-Id: I0f0b3f700ab6f1240b2373cb4155f52dc8991d2e Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/Qt6QmlConfigExtras.cmake.in13
-rw-r--r--src/qml/Qt6QmlMacros.cmake11
2 files changed, 24 insertions, 0 deletions
diff --git a/src/qml/Qt6QmlConfigExtras.cmake.in b/src/qml/Qt6QmlConfigExtras.cmake.in
new file mode 100644
index 0000000000..3d5be2c22c
--- /dev/null
+++ b/src/qml/Qt6QmlConfigExtras.cmake.in
@@ -0,0 +1,13 @@
+if(NOT QT_NO_CREATE_TARGETS AND
+ NOT "@BUILD_SHARED_LIBS@" AND # Only needed if Qt was built statically
+ CMAKE_VERSION VERSION_GREATER_EQUAL 3.18) # Finalizers require cmake_language(CALL)
+ set(target @QT_CMAKE_EXPORT_NAMESPACE@::Qml)
+ get_property(aliased_target TARGET ${target} PROPERTY ALIASED_TARGET)
+ if(aliased_target)
+ set(target "${aliased_target}")
+ endif()
+ set_property(TARGET ${target} PROPERTY
+ INTERFACE_QT_EXECUTABLE_FINALIZERS
+ qt@PROJECT_VERSION_MAJOR@_import_qml_plugins
+ )
+endif()
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index fb65bd88a7..c7800a16e2 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -1088,10 +1088,21 @@ endfunction()
include(CMakeParseArguments)
+# This function is called as a finalizer in qt6_finalize_executable() for any
+# target that links against the Qml library for a statically built Qt.
function(qt6_import_qml_plugins target)
if(QT6_IS_SHARED_LIBS_BUILD)
return()
endif()
+
+ # Protect against being called multiple times in case we are being called
+ # explicitly before the finalizer is invoked.
+ get_target_property(alreadyImported ${target} _QT_QML_PLUGINS_IMPORTED)
+ if(alreadyImported)
+ return()
+ endif()
+ set_target_properties(${target} PROPERTIES _QT_QML_PLUGINS_IMPORTED TRUE)
+
set(options)
set(oneValueArgs "PATH_TO_SCAN")
set(multiValueArgs)