summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2024-01-30 13:05:59 +0200
committerJuha Vuolle <juha.vuolle@qt.io>2024-02-07 11:10:43 +0200
commitad5c428718405ff4ca0c2938943e7cc8fb82d35f (patch)
treea431acec4f7060df62cd5689bdeb23f2adb17b35
parent7a62659880d5cc56316ccf1129e2c694bb138bd7 (diff)
Make colorpalette's qtexamplestyle qml module accessible on macOS
... by making sure it's properly part of the app bundle. Task-number: QTBUG-115085 Change-Id: I196d309c9400acb897950dbfb5fe99d9d7f13756 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--examples/demos/colorpaletteclient/CMakeLists.txt3
-rw-r--r--examples/demos/colorpaletteclient/main.cpp3
-rw-r--r--examples/demos/shared/QtBundleQmlModuleForMacOS.cmake35
3 files changed, 41 insertions, 0 deletions
diff --git a/examples/demos/colorpaletteclient/CMakeLists.txt b/examples/demos/colorpaletteclient/CMakeLists.txt
index 02bb9aff7..6b668c0d7 100644
--- a/examples/demos/colorpaletteclient/CMakeLists.txt
+++ b/examples/demos/colorpaletteclient/CMakeLists.txt
@@ -68,3 +68,6 @@ install(TARGETS colorpaletteclient
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
+
+include(../shared/QtBundleQmlModuleForMacOS.cmake)
+add_qml_module_to_macos_app_bundle("colorpaletteclient" "qtexamplestyle")
diff --git a/examples/demos/colorpaletteclient/main.cpp b/examples/demos/colorpaletteclient/main.cpp
index 18fc44bbc..c9f5ddc3f 100644
--- a/examples/demos/colorpaletteclient/main.cpp
+++ b/examples/demos/colorpaletteclient/main.cpp
@@ -12,6 +12,9 @@ int main(int argc, char *argv[])
QIcon::setThemeName("colorpaletteclient");
QQmlApplicationEngine engine;
+#ifdef Q_OS_MACOS
+ engine.addImportPath(app.applicationDirPath() + "/../PlugIns");
+#endif
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
[](){ QCoreApplication::exit(EXIT_FAILURE);}, Qt::QueuedConnection);
engine.loadFromModule("ColorPalette", "Main");
diff --git a/examples/demos/shared/QtBundleQmlModuleForMacOS.cmake b/examples/demos/shared/QtBundleQmlModuleForMacOS.cmake
new file mode 100644
index 000000000..6f2fbc25a
--- /dev/null
+++ b/examples/demos/shared/QtBundleQmlModuleForMacOS.cmake
@@ -0,0 +1,35 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+function(add_qml_module_to_macos_app_bundle app_target qml_module)
+ if(QT6_IS_SHARED_LIBS_BUILD AND APPLE)
+ # The application's main.cpp adds an explicit QML import path to look for qml module plugins
+ # under a PlugIns subdirectory of a macOS app bundle.
+ # Copy the qmldir and shared library qml plugin.
+
+ qt6_query_qml_module(${qml_module}
+ QMLDIR qmldir_file
+ PLUGIN_TARGET qml_plugin_target
+ URI qml_module_uri
+ )
+
+ # Ensure the executable depends on the plugin so the plugin is copied
+ # only after it was built.
+ add_dependencies(${app_target} ${qml_plugin_target})
+
+ set(app_dir "$<TARGET_FILE_DIR:${app_target}>")
+
+ string(REGEX REPLACE "[^A-Za-z0-9]" "_" escaped_uri "${qml_module_uri}")
+
+ set(dest_module_dir_in_app_bundle "${app_dir}/../PlugIns/${escaped_uri}")
+
+ add_custom_command(TARGET ${app_target} POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${dest_module_dir_in_app_bundle}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ $<TARGET_FILE:${qml_plugin_target}> ${dest_module_dir_in_app_bundle}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${qmldir_file} ${dest_module_dir_in_app_bundle}
+ )
+ endif()
+endfunction()
+