aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-09-24 14:09:33 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-09-30 22:24:01 +0200
commit1248d4a65b3748e97c188c5e23a2b80cefdf1fc7 (patch)
treed88983c769d33593aa2d6b7d4db22d2cd4dc340a /examples/quick
parentb04c0790687bd6bcc5165d94ee2b89a934fad491 (diff)
CMake: Refactor bundle_shared into a more reusable function
Refactor the logic of bundle_shared into a more reusable add_qml_module_to_macos_app_bundle function that can be used in QtQuick examples that need to bundle the qml plugin on macOS, but don't use the 'shared' qml module plugin. The new function is placed in a QtBundleQmlModuleForMacOS.cmake file which can be included separately from the shared/CMakeLists.txt project. Amends 633a85cd39cdd294283439972cffebcff32ac0cb Task-number: QTBUG-96805 Change-Id: Iebb3f4734b9a6bd8a8316bf5ae01d9740c442645 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 7ab424a5cd7790dd87eabd68c294d38662aca8fe)
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/shared/CMakeLists.txt33
-rw-r--r--examples/quick/shared/QtBundleQmlModuleForMacOS.cmake29
2 files changed, 37 insertions, 25 deletions
diff --git a/examples/quick/shared/CMakeLists.txt b/examples/quick/shared/CMakeLists.txt
index 6d93a10010..ad3e89f6ff 100644
--- a/examples/quick/shared/CMakeLists.txt
+++ b/examples/quick/shared/CMakeLists.txt
@@ -35,31 +35,14 @@ qt_add_qml_module(${PROJECT_NAME}_shared
"images/tab.png"
)
-# put the shared module into the macOS bundle directory.
-# Only call this function if your main project is has the MACOSX_BUNDLE option set.
-function(bundle_shared example)
- if(QT6_IS_SHARED_LIBS_BUILD AND APPLE)
- # The application's main.cpp adds an explicit QML import path to look for qml modules under
- # a PlugIns subdirectory in a macOS bundle.
- # Copy the qmldir and shared library qml plugin.
-
- # Ensure the executable depends on the plugin so the plugin is copied
- # only after it was built.
- add_dependencies(${example} ${PROJECT_NAME}_shared)
-
- set(shared_dir "$<TARGET_FILE_DIR:${PROJECT_NAME}_shared>")
- set(shared_qmldir_file "${shared_dir}/qmldir")
- set(app_dir "$<TARGET_FILE_DIR:${example}>")
- set(bundle_shared_dir "${app_dir}/../PlugIns/shared")
-
- add_custom_command(TARGET ${example} POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory ${bundle_shared_dir}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- $<TARGET_FILE:${PROJECT_NAME}_shared> ${bundle_shared_dir}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- ${shared_qmldir_file} ${bundle_shared_dir}
- )
- endif()
+include(QtBundleQmlModuleForMacOS.cmake)
+# Puts the shared qml module plugin and qmldir into the macOS app bundle directory.
+# Only call this function if your main project has the MACOSX_BUNDLE option set.
+function(bundle_shared app_target)
+ set(qml_plugin_target "${PROJECT_NAME}_shared")
+ set(qml_module_uri "shared")
+ add_qml_module_to_macos_app_bundle(
+ "${app_target}" "${qml_plugin_target}" "${qml_module_uri}")
endfunction()
set(INSTALL_SHAREDDIR "${INSTALL_EXAMPLESDIR}/quick/${PROJECT_NAME}/shared")
diff --git a/examples/quick/shared/QtBundleQmlModuleForMacOS.cmake b/examples/quick/shared/QtBundleQmlModuleForMacOS.cmake
new file mode 100644
index 0000000000..86edd352eb
--- /dev/null
+++ b/examples/quick/shared/QtBundleQmlModuleForMacOS.cmake
@@ -0,0 +1,29 @@
+function(add_qml_module_to_macos_app_bundle app_target qml_plugin_target qml_module_uri)
+ 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.
+
+ # 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}")
+
+ set(qml_plugin_dir "$<TARGET_FILE_DIR:${qml_plugin_target}>")
+ set(qmldir_file "${qml_plugin_dir}/qmldir")
+
+ 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()
+