From 892b11c7f90106d61f132fa07fb6be1b1a7ecebf Mon Sep 17 00:00:00 2001
From: Burak Hancerli <burak.hancerli@qt.io>
Date: Wed, 22 Jan 2025 17:50:35 +0100
Subject: [PATCH] add: link all available qml modules on the system

---
 CMakeLists.txt           | 31 ++++++++++++++++++++++++++++++-
 src/importdummy_wasm.qml | 40 ----------------------------------------
 2 files changed, 30 insertions(+), 41 deletions(-)
 delete mode 100644 src/importdummy_wasm.qml

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab5b962..2b6091e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,7 +29,6 @@ if(QT_VERSION VERSION_LESS QT_MINIMUM_VERSION)
 endif()
 
 qt_add_executable(${PROJECT_NAME}
-    src/importdummy_wasm.qml
     src/main.cpp
     src/designviewer.cpp src/designviewer.h
 )
@@ -60,6 +59,36 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
 
 qt6_import_qml_plugins(${PROJECT_NAME})
 
+# Get all imported targets.
+get_property(imported_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY IMPORTED_TARGETS)
+foreach(imported_target IN LISTS imported_targets)
+    # Get all qml module targets, they would have the _qt_qml_module_installed_plugin_target
+    # property set.
+    get_target_property(qml_plugin_target "${imported_target}" _qt_qml_module_installed_plugin_target)
+    if(qml_plugin_target)
+        # list of conflicting targets
+        # Graphs           X Charts
+        # Graphs           X DataVisualizationQml
+        # lottieqtplugin   X libQt6Bodymovin
+        # QuickVectorImage X QuickVectorImageGenerator
+
+        # Charts and QuickVectorImageGenerator cannot found in the imported targets
+        # so the counterparts are skipped instead (Graphs and QuickVectorImage)
+        set(targets_to_skip "Qt6::Graphs;Qt6::lottieqtplugin;Qt6::QuickVectorImage")
+        if(imported_target IN_LIST targets_to_skip)
+            message(STATUS "Skipping target: ${imported_target} -> ${qml_plugin_target}")
+            continue()
+        endif()
+        message(STATUS "Imported target: ${imported_target} -> ${qml_plugin_target}")
+        get_target_property(module_plugin_target_type "${qml_plugin_target}" TYPE)
+        # Get only those qml plugins that are static libraries, and link them to the app.
+        if(module_plugin_target_type STREQUAL "STATIC_LIBRARY")
+            message(STATUS "Imported target: ${qml_plugin_target} linked")
+            target_link_libraries(qtdesignviewer PRIVATE "${qml_plugin_target}")
+        endif()
+    endif()
+endforeach()
+
 # BEGIN --install configuration
 install(
     FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.html
diff --git a/src/importdummy_wasm.qml b/src/importdummy_wasm.qml
deleted file mode 100644
index 05bf0b3..0000000
--- a/src/importdummy_wasm.qml
+++ /dev/null
@@ -1,40 +0,0 @@
-// Hack to force the qml plugins to be linked statically
-
-import QtQuick
-import QtQuick.Controls
-
-import QtQml
-import QtQml.Models
-import QtQml.StateMachine
-
-import QtQuick3D
-import QtQuick3D.AssetUtils
-import QtQuick3D.Effects
-import QtQuick3D.Helpers
-import QtQuick3D.ParticleEffects
-import QtQuick3D.Particles3D
-import QtQuick.VirtualKeyboard
-import QtQuick.Timeline
-import QtQuick.Timeline.BlendTrees
-
-import QtQuick.Studio.Application
-import QtQuick.Studio.Components
-import QtQuick.Studio.Effects
-import QtQuick.Studio.EventSimulator
-import QtQuick.Studio.EventSystem
-import QtQuick.Studio.LogicHelper
-import QtQuick.Studio.MultiText
-import QtQuick.Studio.Utils
-import QtQuick.Studio.DesignEffects
-
-import QtQuickUltralite.Extras
-import QtQuickUltralite.Layers
-
-import FlowView
-import Qt.labs.folderlistmodel
-
-ApplicationWindow {
-    visible: true
-    width: 640
-    height: 480
-}
-- 
GitLab