From 944110089d4cb1c229dba422989e154db65a67fd Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Fri, 27 Jan 2017 11:34:17 -0800 Subject: [PATCH] Build Qt libraries with -fapplication-extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures at compile-time that Qt libraries do not use any APIs that are not safe for use in application extensions, and fixes warning messages that appear when linking to Qt libraries that are not built with this flag, when used in an application extension. This is especially important on watchOS where *all* "applications" are actually application extensions, and on other Apple platforms if application extensions are developed using Qt. Task-number: QTBUG-40101 Change-Id: I022046f2584e0222253d33052b0abc221d7c93d6 Reviewed-by: Tor Arne Vestbø --- mkspecs/features/mac/default_post.prf | 7 +++++++ mkspecs/features/qml_plugin.prf | 3 +++ mkspecs/features/qt_module.prf | 3 +++ mkspecs/features/qt_plugin.prf | 3 +++ qmake/generators/mac/pbuilder_pbx.cpp | 1 + src/corelib/kernel/qeventdispatcher_cf.mm | 3 ++- src/plugins/platforms/cocoa/cocoa.pro | 2 ++ src/plugins/platforms/ios/kernel.pro | 2 ++ 8 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mkspecs/features/mac/default_post.prf b/mkspecs/features/mac/default_post.prf index 1b2e5d5db4a..4a30a8a652e 100644 --- a/mkspecs/features/mac/default_post.prf +++ b/mkspecs/features/mac/default_post.prf @@ -38,6 +38,13 @@ qt { !bitcode: QMAKE_LFLAGS += $$QMAKE_LFLAGS_HEADERPAD +app_extension_api_only { + QMAKE_CFLAGS += -fapplication-extension + QMAKE_CXXFLAGS += -fapplication-extension + QMAKE_CXXFLAGS_PRECOMPILE += -fapplication-extension + QMAKE_LFLAGS += -fapplication-extension +} + macx-xcode { !isEmpty(QMAKE_XCODE_DEBUG_INFORMATION_FORMAT) { debug_information_format.name = DEBUG_INFORMATION_FORMAT diff --git a/mkspecs/features/qml_plugin.prf b/mkspecs/features/qml_plugin.prf index 7e12626db37..de036c129e7 100644 --- a/mkspecs/features/qml_plugin.prf +++ b/mkspecs/features/qml_plugin.prf @@ -21,6 +21,9 @@ if(win32|mac):!macx-xcode { CONFIG += relative_qt_rpath # Qt's QML plugins should be relocatable +# Qt libraries should only use Application Extension safe APIs +darwin:!no_app_extension_api_only: CONFIG += app_extension_api_only + !no_cxx_module:isEmpty(CXX_MODULE) { CXX_MODULE = $$TARGET TARGET = declarative_$${TARGET} diff --git a/mkspecs/features/qt_module.prf b/mkspecs/features/qt_module.prf index 23d75182d0e..7ba81c93b17 100644 --- a/mkspecs/features/qt_module.prf +++ b/mkspecs/features/qt_module.prf @@ -46,6 +46,9 @@ CONFIG(shared, static|shared):qtConfig(framework): \ CONFIG += relative_qt_rpath # Qt libraries should be relocatable +# Qt libraries should only use Application Extension safe APIs +darwin:!no_app_extension_api_only: CONFIG += app_extension_api_only + ucmodule = $$upper($$MODULE) isEmpty(MODULE_INCNAME): MODULE_INCNAME = $$TARGET diff --git a/mkspecs/features/qt_plugin.prf b/mkspecs/features/qt_plugin.prf index 265b4ea8a21..31079f1e12f 100644 --- a/mkspecs/features/qt_plugin.prf +++ b/mkspecs/features/qt_plugin.prf @@ -32,6 +32,9 @@ tool_plugin { CONFIG += relative_qt_rpath # Qt's plugins should be relocatable +# Qt libraries should only use Application Extension safe APIs +darwin:!no_app_extension_api_only: CONFIG += app_extension_api_only + CONFIG(static, static|shared)|prefix_build { isEmpty(MODULE): MODULE = $$basename(TARGET) diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp index f42b3021f12..728e654be8b 100644 --- a/qmake/generators/mac/pbuilder_pbx.cpp +++ b/qmake/generators/mac/pbuilder_pbx.cpp @@ -1485,6 +1485,7 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t) } } settings.insert("COPY_PHASE_STRIP", (as_release ? "YES" : "NO")); + settings.insert("APPLICATION_EXTENSION_API_ONLY", project->isActiveConfig("app_extension_api_only") ? "YES" : "NO"); // required for tvOS (and watchos), optional on iOS (deployment target >= iOS 6.0) settings.insert("ENABLE_BITCODE", project->isActiveConfig("bitcode") ? "YES" : "NO"); settings.insert("GCC_GENERATE_DEBUGGING_SYMBOLS", as_release ? "NO" : "YES"); diff --git a/src/corelib/kernel/qeventdispatcher_cf.mm b/src/corelib/kernel/qeventdispatcher_cf.mm index 9ac48f144d2..27eb3d03370 100644 --- a/src/corelib/kernel/qeventdispatcher_cf.mm +++ b/src/corelib/kernel/qeventdispatcher_cf.mm @@ -80,7 +80,8 @@ QT_USE_NAMESPACE #elif defined(Q_OS_WATCHOS) object:[WKExtension sharedExtension]]; #else - object:[UIApplication sharedApplication]]; + // Use performSelector so this can work in an App Extension + object:[[UIApplication class] performSelector:@selector(sharedApplication)]]; #endif } diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 0664841c2d5..62935210be7 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -86,6 +86,8 @@ QT += \ accessibility_support-private clipboard_support-private theme_support-private \ fontdatabase_support-private graphics_support-private cgl_support-private +CONFIG += no_app_extension_api_only + qtHaveModule(widgets) { OBJECTIVE_SOURCES += \ qpaintengine_mac.mm \ diff --git a/src/plugins/platforms/ios/kernel.pro b/src/plugins/platforms/ios/kernel.pro index 71257d09f73..6eb9f2c5345 100644 --- a/src/plugins/platforms/ios/kernel.pro +++ b/src/plugins/platforms/ios/kernel.pro @@ -5,6 +5,8 @@ TARGET = qios # application's main() when the plugin is a shared library. qtConfig(shared): CONFIG += static +CONFIG += no_app_extension_api_only + QT += \ core-private gui-private \ clipboard_support-private fontdatabase_support-private graphics_support-private