From adb91d6afb9e25ffb180de53afff3de443696e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 16 Dec 2022 16:34:31 +0100 Subject: [PATCH] Enable shared library build of Qt for iOS As of f68e2c92cc0ed2c1929140402c061359bc2363a5, and its follow up changes, we can now link individual plugins statically, even if the Qt build is generally a shared build. This allows us to build Qt for iOS as shared libraries, while still keeping the platform plugin as a static library, since this is harder to port over to a shared library. This gives the benefit of faster turnaround during development, as well as binary compatibility promises for the main Qt libraries, without having to go fully shared for all of Qt. Static builds are still the default, due to the downsides of larger application bundles and slower load times for shared builds. For now the user has to manually tick the "Embed & Sign" check box in Xcode for each Qt library, which is only available with Xcode projects generated by the qmake Xcode generator. Task-number: QTBUG-85974 Change-Id: Id2b7bd2823c8e7c79068dda95295b574ada8d7f2 Reviewed-by: Volker Hilsheimer Reviewed-by: Alexey Edelev --- cmake/QtAutoDetect.cmake | 4 +++- cmake/QtFrameworkHelpers.cmake | 9 +++++++-- cmake/QtModuleHelpers.cmake | 5 ++++- configure.cmake | 1 - src/plugins/platforms/ios/CMakeLists.txt | 2 ++ .../ios/optional/nsphotolibrarysupport/CMakeLists.txt | 1 + 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cmake/QtAutoDetect.cmake b/cmake/QtAutoDetect.cmake index 07afc1a8962..a994fc5e55f 100644 --- a/cmake/QtAutoDetect.cmake +++ b/cmake/QtAutoDetect.cmake @@ -229,7 +229,9 @@ function(qt_auto_detect_ios) endif() set(CMAKE_OSX_ARCHITECTURES "${osx_architectures}" CACHE STRING "") - qt_internal_ensure_static_qt_config() + if(NOT DEFINED BUILD_SHARED_LIBS) + qt_internal_ensure_static_qt_config() + endif() # Disable qt rpaths for iOS, just like mkspecs/common/uikit.conf does, due to those # bundles not being able to use paths outside the app bundle. Not sure this is strictly diff --git a/cmake/QtFrameworkHelpers.cmake b/cmake/QtFrameworkHelpers.cmake index e4e2a1373fc..e97c30956ee 100644 --- a/cmake/QtFrameworkHelpers.cmake +++ b/cmake/QtFrameworkHelpers.cmake @@ -57,7 +57,7 @@ function(qt_internal_find_apple_system_framework out_var framework_name) endif() endfunction() -# Copy header files to QtXYZ.framework/Versions/A/Headers/ +# Copy header files to the framework's Headers directory # Use this function for header files that # - are not added as source files to the target # - are not marked as PUBLIC_HEADER @@ -163,7 +163,12 @@ function(qt_internal_get_framework_info out_var target) set(${out_var}_name "${module}") set(${out_var}_dir "${${out_var}_name}.framework") set(${out_var}_header_dir "${${out_var}_dir}/Headers") - set(${out_var}_versioned_header_dir "${${out_var}_dir}/Versions/${${out_var}_version}/Headers") + if(UIKIT) + # iOS frameworks do not version their headers + set(${out_var}_versioned_header_dir "${${out_var}_header_dir}") + else() + set(${out_var}_versioned_header_dir "${${out_var}_dir}/Versions/${${out_var}_version}/Headers") + endif() set(${out_var}_private_header_dir "${${out_var}_header_dir}/${${out_var}_bundle_version}") set(${out_var}_private_module_header_dir "${${out_var}_private_header_dir}/${module}") diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index bc98e77c7d9..819ea1b3345 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -327,7 +327,10 @@ function(qt_internal_add_module target) EXPORT_PROPERTIES "${export_properties}") endif() - if(WASM AND BUILD_SHARED_LIBS) + # FIXME: This workaround is needed because the deployment logic + # for iOS and WASM just copies/embeds the directly linked library, + # which will just be a versioned symlink to the actual library. + if((UIKIT OR WASM) AND BUILD_SHARED_LIBS) set(version_args "") else() set(version_args diff --git a/configure.cmake b/configure.cmake index b15661bf280..32974bbe909 100644 --- a/configure.cmake +++ b/configure.cmake @@ -477,7 +477,6 @@ qt_feature("android-style-assets" PRIVATE ) qt_feature("shared" PUBLIC LABEL "Building shared libraries" - AUTODETECT NOT UIKIT CONDITION BUILD_SHARED_LIBS ) qt_feature_definition("shared" "QT_STATIC" NEGATE PREREQUISITE "!defined(QT_SHARED) && !defined(QT_STATIC)") diff --git a/src/plugins/platforms/ios/CMakeLists.txt b/src/plugins/platforms/ios/CMakeLists.txt index 7b654af2a49..a822005b94e 100644 --- a/src/plugins/platforms/ios/CMakeLists.txt +++ b/src/plugins/platforms/ios/CMakeLists.txt @@ -9,6 +9,7 @@ qt_internal_add_plugin(QIOSIntegrationPlugin OUTPUT_NAME qios + STATIC # Force static, even in shared builds DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES ios # special case PLUGIN_TYPE platforms SOURCES @@ -36,6 +37,7 @@ qt_internal_add_plugin(QIOSIntegrationPlugin ${FWMetal} ${FWQuartzCore} ${FWUIKit} + ${FWCoreGraphics} Qt::CorePrivate Qt::GuiPrivate ) diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/CMakeLists.txt b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/CMakeLists.txt index 093e74c3e96..ab1e5b6c4a1 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/CMakeLists.txt +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/CMakeLists.txt @@ -9,6 +9,7 @@ qt_internal_add_plugin(QIosOptionalPlugin_NSPhotoLibraryPlugin OUTPUT_NAME qiosnsphotolibrarysupport + STATIC # Force static, even in shared builds PLUGIN_TYPE platforms/darwin CLASS_NAME QIosOptionalPlugin_NSPhotoLibrary DEFAULT_IF FALSE