Enable shared library build of Qt for iOS

As of f68e2c92cc, 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 <volker.hilsheimer@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Tor Arne Vestbø 2022-12-16 16:34:31 +01:00
parent c0967bd288
commit adb91d6afb
6 changed files with 17 additions and 5 deletions

View File

@ -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

View File

@ -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}")

View File

@ -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

View File

@ -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)")

View File

@ -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
)

View File

@ -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