diff options
author | Robert Griebl <robert.griebl@qt.io> | 2022-06-29 14:19:07 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2022-06-30 12:26:04 +0000 |
commit | a1c90ed4605b08c39d380d2605d26b684d340c64 (patch) | |
tree | 8b76a66bd594abb02e9801858d0168f90efcbdef /examples | |
parent | 0b895aa93688926781e30fa5400832396e9c8bef (diff) | |
download | qtapplicationmanager-a1c90ed4605b08c39d380d2605d26b684d340c64.tar.gz |
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
Pick-to: 6.4
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Diffstat (limited to 'examples')
8 files changed, 30 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) |