summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2022-06-29 14:19:07 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-30 20:52:59 +0000
commita26f5d83c4a079207f0d3cbe4b78507fc2ddf437 (patch)
tree2510311d5ce7220b4d7990473e797ba37c1b33cc
parentc344046075fa3359dd4c70e92253f2edc5368579 (diff)
Prevent linking of AppMan modules into user plugins
As the AppMan modules are static libraries, linking any of them into a QML plugin (that later gets loaded into the system-ui) will lead to a bunch of problems: 1) due to symbol duplication and duplicate static data, a lot of singletons may exist twice 2) all static constructors (logging, crash-handling, etc.) are run a second time, overriding any custom configuration that was applied after config parsing. If you are legitimately building a custom appman binary, a custom launcher or a native app using launcher-lib, you need to flag this via compile-time defines now: Either AM_COMPILING_APPMAN or AM_COMPILING_LAUNCHER AM_COMPILING_LAUNCHER is also used for native apps using launcher-lib. Change-Id: I0c1a3fb7e0c7121f92d44c764c2c1eeb720e7041 Reviewed-by: Dominik Holland <dominik.holland@qt.io> (cherry picked from commit a1c90ed4605b08c39d380d2605d26b684d340c64) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/applicationmanager/application-features/doc/src/application-features.qdoc8
-rw-r--r--examples/applicationmanager/application-features/native/widgets/CMakeLists.txt4
-rw-r--r--examples/applicationmanager/application-features/native/widgets/widgets.pro3
-rw-r--r--examples/applicationmanager/custom-appman/CMakeLists.txt4
-rw-r--r--examples/applicationmanager/custom-appman/custom-appman.pro3
-rw-r--r--examples/applicationmanager/custom-appman/doc/src/custom-appman.qdoc8
-rw-r--r--examples/applicationmanager/softwarecontainer-plugin/softwarecontainer.cpp2
-rw-r--r--examples/applicationmanager/startup-plugin/startup-plugin.h1
-rw-r--r--src/application-lib/CMakeLists.txt2
-rw-r--r--src/common-lib/CMakeLists.txt2
-rw-r--r--src/common-lib/global.h7
-rw-r--r--src/crypto-lib/CMakeLists.txt2
-rw-r--r--src/dbus-lib/CMakeLists.txt2
-rw-r--r--src/intent-client-lib/CMakeLists.txt2
-rw-r--r--src/intent-server-lib/CMakeLists.txt2
-rw-r--r--src/launcher-lib/CMakeLists.txt2
-rw-r--r--src/main-lib/CMakeLists.txt2
-rw-r--r--src/manager-lib/CMakeLists.txt2
-rw-r--r--src/monitor-lib/CMakeLists.txt2
-rw-r--r--src/notification-lib/CMakeLists.txt2
-rw-r--r--src/package-lib/CMakeLists.txt2
-rw-r--r--src/shared-main-lib/CMakeLists.txt2
-rw-r--r--src/tools/appman/CMakeLists.txt2
-rw-r--r--src/tools/controller/CMakeLists.txt2
-rw-r--r--src/tools/dumpqmltypes/CMakeLists.txt2
-rw-r--r--src/tools/launcher-qml/CMakeLists.txt2
-rw-r--r--src/tools/packager/CMakeLists.txt2
-rw-r--r--src/tools/testrunner/CMakeLists.txt1
-rw-r--r--src/tools/uploader/CMakeLists.txt2
-rw-r--r--src/window-lib/CMakeLists.txt2
30 files changed, 78 insertions, 3 deletions
diff --git a/examples/applicationmanager/application-features/doc/src/application-features.qdoc b/examples/applicationmanager/application-features/doc/src/application-features.qdoc
index a2ccb99b..ed9afad1 100644
--- a/examples/applicationmanager/application-features/doc/src/application-features.qdoc
+++ b/examples/applicationmanager/application-features/doc/src/application-features.qdoc
@@ -93,6 +93,14 @@ needs a \c type window property to differentiate between normal windows and popu
This application only works in multi-process mode, as application processes cannot be started in
single-process mode.
+Linking against the private application manager modules is prohibited by default to prevent
+potential problems with duplicate symbols coming from QML plugins. However here building against
+them is both intended and required, so we need to set the define \c AM_COMPILING_LAUNCHER:
+
+\quotefromfile applicationmanager/application-features/native/widgets/CMakeLists.txt
+\skipuntil /allows us to link against/
+\printuntil /AM_COMPILING_LAUNCHER/
+
The C++ code for the native widgets application is as follows:
\quotefromfile applicationmanager/application-features/native/widgets/main.cpp
diff --git a/examples/applicationmanager/application-features/native/widgets/CMakeLists.txt b/examples/applicationmanager/application-features/native/widgets/CMakeLists.txt
index b4c977da..52de895e 100644
--- a/examples/applicationmanager/application-features/native/widgets/CMakeLists.txt
+++ b/examples/applicationmanager/application-features/native/widgets/CMakeLists.txt
@@ -22,6 +22,10 @@ find_package(Qt6 COMPONENTS AppManLauncherPrivate)
qt_add_executable(widgets
main.cpp
)
+
+# This define flags us as a "launcher" and allows us to link against the AppMan's private libraries
+target_compile_definitions(widgets PRIVATE AM_COMPILING_LAUNCHER)
+
set_target_properties(widgets PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
diff --git a/examples/applicationmanager/application-features/native/widgets/widgets.pro b/examples/applicationmanager/application-features/native/widgets/widgets.pro
index 9a93277d..784f63cf 100644
--- a/examples/applicationmanager/application-features/native/widgets/widgets.pro
+++ b/examples/applicationmanager/application-features/native/widgets/widgets.pro
@@ -4,6 +4,9 @@ QT += widgets appman_launcher-private
SOURCES = main.cpp
+# This define flags us as a "launcher" and allows us to link against the AppMan's private libraries
+DEFINES *= AM_COMPILING_LAUNCHER
+
DESTDIR = $$OUT_PWD/../../apps/widgets
target.path = $$[QT_INSTALL_EXAMPLES]/applicationmanager/application-features/apps/widgets
diff --git a/examples/applicationmanager/custom-appman/CMakeLists.txt b/examples/applicationmanager/custom-appman/CMakeLists.txt
index c3627257..972295d4 100644
--- a/examples/applicationmanager/custom-appman/CMakeLists.txt
+++ b/examples/applicationmanager/custom-appman/CMakeLists.txt
@@ -20,6 +20,10 @@ find_package(Qt6 COMPONENTS AppManMainPrivate)
qt_add_executable(custom-appman
custom-appman.cpp
)
+
+# This define flags us as an "appman" and allows us to link against the AppMan's private libraries
+target_compile_definitions(custom-appman PRIVATE AM_COMPILING_APPMAN)
+
set_target_properties(custom-appman PROPERTIES
WIN32_EXECUTABLE FALSE
MACOSX_BUNDLE FALSE
diff --git a/examples/applicationmanager/custom-appman/custom-appman.pro b/examples/applicationmanager/custom-appman/custom-appman.pro
index e1ebab9e..f6f4e294 100644
--- a/examples/applicationmanager/custom-appman/custom-appman.pro
+++ b/examples/applicationmanager/custom-appman/custom-appman.pro
@@ -6,6 +6,9 @@ CONFIG -= app_bundle qml_debug
DEFINES += QT_MESSAGELOGCONTEXT
+# This define flags us as an "appman" and allows us to link against the AppMan's private libraries
+DEFINES *= AM_COMPILING_APPMAN
+
QT = appman_main-private
SOURCES = custom-appman.cpp
diff --git a/examples/applicationmanager/custom-appman/doc/src/custom-appman.qdoc b/examples/applicationmanager/custom-appman/doc/src/custom-appman.qdoc
index 0b74c1c9..dc16c90e 100644
--- a/examples/applicationmanager/custom-appman/doc/src/custom-appman.qdoc
+++ b/examples/applicationmanager/custom-appman/doc/src/custom-appman.qdoc
@@ -25,6 +25,14 @@ If you still require this behavior, this example provides a starting point that
custom implementation upon. Keep in mind, that this custom application manager executable needs a
System UI to display something on the screen, just like the standard \c appman executable.
+Linking against those application manager modules is prohibited by default to prevent
+potential problems with duplicate symbols coming from QML plugins. However here building against
+them is both intended and required, so we need to set the define \c AM_COMPILING_APPMAN:
+
+\quotefromfile applicationmanager/custom-appman/CMakeLists.txt
+\skipuntil /allows us to link against/
+\printuntil /AM_COMPILING_APPMAN/
+
The following is a breakdown of the minimal code necessary:
\quotefromfile applicationmanager/custom-appman/custom-appman.cpp
diff --git a/examples/applicationmanager/softwarecontainer-plugin/softwarecontainer.cpp b/examples/applicationmanager/softwarecontainer-plugin/softwarecontainer.cpp
index 4fcdb23d..a9c8ebe0 100644
--- a/examples/applicationmanager/softwarecontainer-plugin/softwarecontainer.cpp
+++ b/examples/applicationmanager/softwarecontainer-plugin/softwarecontainer.cpp
@@ -6,7 +6,6 @@
#include <tuple>
#include <QtDBus/QtDBus>
-#include <QtAppManCommon/global.h>
#include <QJsonDocument>
#include <QSocketNotifier>
#include <QMetaObject>
@@ -52,7 +51,6 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, QMap<QString,QStr
QT_END_NAMESPACE
-QT_USE_NAMESPACE_AM
// unfortunately, this is a copy of the code from debugwrapper.cpp
static QStringList substituteCommand(const QStringList &debugWrapperCommand, const QString &program,
diff --git a/examples/applicationmanager/startup-plugin/startup-plugin.h b/examples/applicationmanager/startup-plugin/startup-plugin.h
index e5d073ce..f917c3dd 100644
--- a/examples/applicationmanager/startup-plugin/startup-plugin.h
+++ b/examples/applicationmanager/startup-plugin/startup-plugin.h
@@ -5,7 +5,6 @@
#include <QLoggingCategory>
#include <QtAppManPluginInterfaces/startupinterface.h>
-#include <QtAppManCommon/global.h>
Q_DECLARE_LOGGING_CATEGORY(LogMe)
diff --git a/src/application-lib/CMakeLists.txt b/src/application-lib/CMakeLists.txt
index 30e64b42..087fe417 100644
--- a/src/application-lib/CMakeLists.txt
+++ b/src/application-lib/CMakeLists.txt
@@ -21,4 +21,6 @@ qt_internal_add_module(AppManApplicationPrivate
PUBLIC_LIBRARIES
Qt::Core
Qt::Network
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/common-lib/CMakeLists.txt b/src/common-lib/CMakeLists.txt
index e9a77790..89454d29 100644
--- a/src/common-lib/CMakeLists.txt
+++ b/src/common-lib/CMakeLists.txt
@@ -31,6 +31,8 @@ qt_internal_add_module(AppManCommonPrivate
Qt::Network
Qt::Qml
Qt::QmlPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
qt_internal_extend_target(AppManCommonPrivate CONDITION TARGET Qt::DltLogging
diff --git a/src/common-lib/global.h b/src/common-lib/global.h
index 99697e10..b22edf28 100644
--- a/src/common-lib/global.h
+++ b/src/common-lib/global.h
@@ -21,3 +21,10 @@ QT_END_NAMESPACE_AM
#define qL1C(x) QLatin1Char(x)
#define qSL(x) QStringLiteral(x)
+#if !defined(AM_COMPILING_APPMAN) && !defined(AM_COMPILING_LAUNCHER) && !defined(QT_TESTCASE_BUILDDIR)
+# if defined(AM_FORCE_COMPILING_AGAINST_MODULES)
+# warning "You have forced compiling against AppMan modules outside of a (custom) appman binary or launcher build."
+# else
+# error "You are including headers from AppMan modules outside of a (custom) appman binary or launcher build. If you are aware of the implications of AppMan's modules being static libraries, you can #define AM_FORCE_COMPILING_AGAINST_MODULES"
+# endif
+#endif
diff --git a/src/crypto-lib/CMakeLists.txt b/src/crypto-lib/CMakeLists.txt
index fe2138fa..72fbe95e 100644
--- a/src/crypto-lib/CMakeLists.txt
+++ b/src/crypto-lib/CMakeLists.txt
@@ -14,6 +14,8 @@ qt_internal_add_module(AppManCryptoPrivate
Qt::AppManCommonPrivate
PUBLIC_LIBRARIES
Qt::Core
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/dbus-lib/CMakeLists.txt b/src/dbus-lib/CMakeLists.txt
index 183eb0f5..df7a19d4 100644
--- a/src/dbus-lib/CMakeLists.txt
+++ b/src/dbus-lib/CMakeLists.txt
@@ -21,6 +21,8 @@ qt_internal_add_module(AppManDBusPrivate
PUBLIC_LIBRARIES
Qt::Core
Qt::DBus
+ DEFINES
+ AM_COMPILING_APPMAN
)
# QMAKE_EXTRA_TARGETS = "recreate-dbus-xml" "recreate-applicationmanager-dbus-xml" "recreate-packagemanager-dbus-xml" "recreate-windowmanager-dbus-xml"
diff --git a/src/intent-client-lib/CMakeLists.txt b/src/intent-client-lib/CMakeLists.txt
index 3decb8dd..abb8c127 100644
--- a/src/intent-client-lib/CMakeLists.txt
+++ b/src/intent-client-lib/CMakeLists.txt
@@ -18,4 +18,6 @@ qt_internal_add_module(AppManIntentClientPrivate
Qt::Core
Qt::Network
Qt::Qml
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/intent-server-lib/CMakeLists.txt b/src/intent-server-lib/CMakeLists.txt
index 8973f00a..7782527b 100644
--- a/src/intent-server-lib/CMakeLists.txt
+++ b/src/intent-server-lib/CMakeLists.txt
@@ -19,4 +19,6 @@ qt_internal_add_module(AppManIntentServerPrivate
Qt::Core
Qt::Network
Qt::Qml
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/launcher-lib/CMakeLists.txt b/src/launcher-lib/CMakeLists.txt
index c2c97757..1d293725 100644
--- a/src/launcher-lib/CMakeLists.txt
+++ b/src/launcher-lib/CMakeLists.txt
@@ -29,6 +29,8 @@ qt_internal_add_module(AppManLauncherPrivate
Qt::Qml
Qt::Quick
Qt::QuickPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
qt_internal_extend_target(AppManLauncherPrivate CONDITION QT_FEATURE_am_widgets_support AND TARGET Qt::Widgets
diff --git a/src/main-lib/CMakeLists.txt b/src/main-lib/CMakeLists.txt
index d58173d6..a9a40ab6 100644
--- a/src/main-lib/CMakeLists.txt
+++ b/src/main-lib/CMakeLists.txt
@@ -33,6 +33,8 @@ qt_internal_add_module(AppManMainPrivate
EXTRA_CMAKE_FILES
wrapper.cpp.in
Qt6AppManMainPrivateMacros.cmake
+ DEFINES
+ AM_COMPILING_APPMAN
)
qt_internal_extend_target(AppManMainPrivate CONDITION QT_FEATURE_am_widgets_support AND TARGET Qt::Widgets
diff --git a/src/manager-lib/CMakeLists.txt b/src/manager-lib/CMakeLists.txt
index 117005f9..2e4f3481 100644
--- a/src/manager-lib/CMakeLists.txt
+++ b/src/manager-lib/CMakeLists.txt
@@ -49,6 +49,8 @@ qt_internal_add_module(AppManManagerPrivate
Qt::QmlPrivate
Qt::Quick
Qt::QuickPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
qt_internal_extend_target(AppManManagerPrivate CONDITION QT_FEATURE_am_multi_process
diff --git a/src/monitor-lib/CMakeLists.txt b/src/monitor-lib/CMakeLists.txt
index 212bf1c1..f884cec0 100644
--- a/src/monitor-lib/CMakeLists.txt
+++ b/src/monitor-lib/CMakeLists.txt
@@ -15,6 +15,8 @@ qt_internal_add_module(AppManMonitorPrivate
PUBLIC_LIBRARIES
Qt::Core
Qt::Gui
+ DEFINES
+ AM_COMPILING_APPMAN
)
qt_internal_extend_target(AppManMonitorPrivate CONDITION LINUX
diff --git a/src/notification-lib/CMakeLists.txt b/src/notification-lib/CMakeLists.txt
index 7a15ff52..e337ac21 100644
--- a/src/notification-lib/CMakeLists.txt
+++ b/src/notification-lib/CMakeLists.txt
@@ -14,4 +14,6 @@ qt_internal_add_module(AppManNotificationPrivate
PUBLIC_LIBRARIES
Qt::Core
Qt::Qml
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/package-lib/CMakeLists.txt b/src/package-lib/CMakeLists.txt
index 3180bf23..f1d03d0e 100644
--- a/src/package-lib/CMakeLists.txt
+++ b/src/package-lib/CMakeLists.txt
@@ -19,6 +19,8 @@ qt_internal_add_module(AppManPackagePrivate
PUBLIC_LIBRARIES
Qt::Core
Qt::Network
+ DEFINES
+ AM_COMPILING_APPMAN
)
qt_internal_extend_target(AppManPackagePrivate CONDITION QT_FEATURE_am_system_libarchive
diff --git a/src/shared-main-lib/CMakeLists.txt b/src/shared-main-lib/CMakeLists.txt
index 57ee84c4..ec1d76ab 100644
--- a/src/shared-main-lib/CMakeLists.txt
+++ b/src/shared-main-lib/CMakeLists.txt
@@ -25,4 +25,6 @@ qt_internal_add_module(AppManSharedMainPrivate
Qt::Quick
Qt::AppManCommonPrivate
Qt::AppManMonitorPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/tools/appman/CMakeLists.txt b/src/tools/appman/CMakeLists.txt
index b58d0406..3794d7c5 100644
--- a/src/tools/appman/CMakeLists.txt
+++ b/src/tools/appman/CMakeLists.txt
@@ -8,6 +8,8 @@ qt_internal_add_tool(${target_name}
appman.cpp
PUBLIC_LIBRARIES
Qt::AppManMainPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
if (TARGET ${target_name})
diff --git a/src/tools/controller/CMakeLists.txt b/src/tools/controller/CMakeLists.txt
index 644ec9c5..c4e5e375 100644
--- a/src/tools/controller/CMakeLists.txt
+++ b/src/tools/controller/CMakeLists.txt
@@ -11,6 +11,8 @@ qt_internal_add_tool(${target_name}
Qt::DBus
Qt::Network
Qt::AppManCommonPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
if (TARGET ${target_name})
diff --git a/src/tools/dumpqmltypes/CMakeLists.txt b/src/tools/dumpqmltypes/CMakeLists.txt
index b76c763f..b7ef9b31 100644
--- a/src/tools/dumpqmltypes/CMakeLists.txt
+++ b/src/tools/dumpqmltypes/CMakeLists.txt
@@ -17,6 +17,8 @@ qt_internal_add_tool(${target_name}
Qt::AppManNotificationPrivate
Qt::AppManSharedMainPrivate
Qt::AppManWindowPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
set(qml_install_dir "${INSTALL_QMLDIR}")
diff --git a/src/tools/launcher-qml/CMakeLists.txt b/src/tools/launcher-qml/CMakeLists.txt
index f29f60ec..99bc41ca 100644
--- a/src/tools/launcher-qml/CMakeLists.txt
+++ b/src/tools/launcher-qml/CMakeLists.txt
@@ -20,4 +20,6 @@ qt_internal_add_tool(${target_name}
Qt::AppManNotificationPrivate
Qt::AppManPluginInterfacesPrivate
Qt::AppManSharedMainPrivate
+ DEFINES
+ AM_COMPILING_LAUNCHER
)
diff --git a/src/tools/packager/CMakeLists.txt b/src/tools/packager/CMakeLists.txt
index 2e206932..7651d90a 100644
--- a/src/tools/packager/CMakeLists.txt
+++ b/src/tools/packager/CMakeLists.txt
@@ -13,4 +13,6 @@ qt_internal_add_tool(${target_name}
Qt::AppManCommonPrivate
Qt::AppManCryptoPrivate
Qt::AppManPackagePrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/tools/testrunner/CMakeLists.txt b/src/tools/testrunner/CMakeLists.txt
index e893b00a..34bc6229 100644
--- a/src/tools/testrunner/CMakeLists.txt
+++ b/src/tools/testrunner/CMakeLists.txt
@@ -9,6 +9,7 @@ qt_internal_add_tool(${target_name}
testrunner.cpp testrunner.h
DEFINES
AM_TESTRUNNER
+ AM_COMPILING_APPMAN
PUBLIC_LIBRARIES
Qt::QuickTest
Qt::QuickTestPrivate
diff --git a/src/tools/uploader/CMakeLists.txt b/src/tools/uploader/CMakeLists.txt
index e95cfd69..f21a4949 100644
--- a/src/tools/uploader/CMakeLists.txt
+++ b/src/tools/uploader/CMakeLists.txt
@@ -9,4 +9,6 @@ qt_internal_add_tool(${target_name}
PUBLIC_LIBRARIES
Qt::Network
Qt::AppManCommonPrivate
+ DEFINES
+ AM_COMPILING_APPMAN
)
diff --git a/src/window-lib/CMakeLists.txt b/src/window-lib/CMakeLists.txt
index 48901d3c..ab60bf26 100644
--- a/src/window-lib/CMakeLists.txt
+++ b/src/window-lib/CMakeLists.txt
@@ -24,6 +24,8 @@ qt_internal_add_module(AppManWindowPrivate
Qt::Network
Qt::Qml
Qt::Quick
+ DEFINES
+ AM_COMPILING_APPMAN
)
if(QT_FEATURE_am_multi_process)