diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4330115bfb9bdbbb879b1d53e28e8ec5bbb86e0f..8d1eec2e45dc56791158ece3e9bb23c933891866 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,8 +6,81 @@ find_package( find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network WebSockets) +set(imports "") + +# Get all imported targets. +get_property(imported_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY IMPORTED_TARGETS) + +# Horrible hack for shared qt builds, to ensure we bundle all known shared library qml plugins. +# Do that by finding all qml modules, their plugins, the location of the plugins, then finding the +# path to the qmldir files of the plugins, extract the module name, and adding it as an import +# statement into a dynamically generated qml file. +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) + message(STATUS + "Imported target: ${imported_target} -> ${qml_plugin_target}") + + # Get location of the plugin file. + get_target_property(imported_location "${qml_plugin_target}" IMPORTED_LOCATION) + if(NOT EXISTS "${imported_location}") + continue() + endif() + + # Get parent dir of the plugin file. + get_filename_component(imported_location_dir "${imported_location}" DIRECTORY) + + # Build path to qmldir in the same directory. We assume the qmldir is always next + # to the plugin file. That's at least usually the case for Qt qml plugins. + set(qmldir_path "${imported_location_dir}/qmldir") + if(NOT EXISTS "${qmldir_path}") + continue() + endif() + + # Read qmldir file contents. + file(READ "${qmldir_path}" qmldir_content) + if(qmldir_content STREQUAL "") + continue() + endif() + + # Find the module name in the qmldir file + string(REGEX MATCH "module ([^\n]+)" module_match "${qmldir_content}") + if(CMAKE_MATCH_1) + # Add the module name as an import to the imports list + list(APPEND imports "import ${CMAKE_MATCH_1}") + endif() + endif() +endforeach() + +set(imports_file_path "${CMAKE_CURRENT_BINARY_DIR}/dynamic_imports.qml") + +# Needed to stop __qt_get_relative_resource_path_for_file from erroring out. +set_source_files_properties("${imports_file_path}" + PROPERTIES QT_RESOURCE_ALIAS "dynamic_imports.qml") +if(imports) + list(REMOVE_DUPLICATES imports) + string(REPLACE ";" "\n" imports "${imports}") +endif() + +# Use file(GENERATE) to prevent touching the file if the contents hasn't changed. + +set(dummy_valid_content "ApplicationWindow { + visible: true + width: 640 + height: 480 +}") +file(GENERATE OUTPUT "${imports_file_path}" CONTENT "${imports} + +${dummy_valid_content} +") + qt_add_executable(${PROJECT_NAME} - backend/importdummy.qml + # backend/importdummy.qml + "${imports_file_path}" backend/main.cpp backend/logger.h backend/backend.cpp backend/backend.h diff --git a/src/backend/importdummy.qml b/src/backend/importdummy.qml deleted file mode 100644 index f6836ef26b46f663c209318b670c7f5157e52c1d..0000000000000000000000000000000000000000 --- a/src/backend/importdummy.qml +++ /dev/null @@ -1,45 +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.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 QtQuick.Timeline -import QtQuick.Timeline.BlendTrees - -import QtQuickUltralite.Extras -import QtQuickUltralite.Layers - -import QtCharts - -import FlowView -import Qt.labs.folderlistmodel - -import QtWebSockets - -ApplicationWindow { - visible: true - width: 640 - height: 480 -}