Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3#include <QCoreApplication>
4#include <QDir>
5#include <QLibraryInfo>
6
7#include "../shared/shared.h"
8
9int main(int argc, char **argv)
10{
11 QCoreApplication app(argc, argv);
12
13 QString appBundlePath;
14 if (argc > 1)
15 appBundlePath = QString::fromLocal8Bit(argv[1]);
16
17 if (argc < 2 || appBundlePath.startsWith("-")) {
18 qDebug() << "Usage: macdeployqt app-bundle [options]";
19 qDebug() << "";
20 qDebug() << "Options:";
21 qDebug() << " -verbose=<0-3> : 0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug";
22 qDebug() << " -no-plugins : Skip plugin deployment";
23 qDebug() << " -dmg : Create a .dmg disk image";
24 qDebug() << " -no-strip : Don't run 'strip' on the binaries";
25 qDebug() << " -use-debug-libs : Deploy with debug versions of frameworks and plugins (implies -no-strip)";
26 qDebug() << " -executable=<path> : Let the given executable use the deployed frameworks too";
27 qDebug() << " -qmldir=<path> : Scan for QML imports in the given path";
28 qDebug() << " -qmlimport=<path> : Add the given path to the QML module search locations";
29 qDebug() << " -always-overwrite : Copy files even if the target file exists";
30 qDebug() << " -codesign=<ident> : Run codesign with the given identity on all executables";
31 qDebug() << " -hardened-runtime : Enable Hardened Runtime when code signing";
32 qDebug() << " -timestamp : Include a secure timestamp when code signing (requires internet connection)";
33 qDebug() << " -sign-for-notarization=<ident>: Activate the necessary options for notarization (requires internet connection)";
34 qDebug() << " -appstore-compliant : Skip deployment of components that use private API";
35 qDebug() << " -libpath=<path> : Add the given path to the library search path";
36 qDebug() << " -fs=<filesystem> : Set the filesystem used for the .dmg disk image (defaults to HFS+)";
37 qDebug() << "";
38 qDebug() << "macdeployqt takes an application bundle as input and makes it";
39 qDebug() << "self-contained by copying in the Qt frameworks and plugins that";
40 qDebug() << "the application uses.";
41 qDebug() << "";
42 qDebug() << "Plugins related to a framework are copied in with the";
43 qDebug() << "framework. The accessibility, image formats, and text codec";
44 qDebug() << "plugins are always copied, unless \"-no-plugins\" is specified.";
45 qDebug() << "";
46 qDebug() << "Qt plugins may use private API and will cause the app to be";
47 qDebug() << "rejected from the Mac App store. MacDeployQt will print a warning";
48 qDebug() << "when known incompatible plugins are deployed. Use -appstore-compliant ";
49 qDebug() << "to skip these plugins. Currently two SQL plugins are known to";
50 qDebug() << "be incompatible: qsqlodbc and qsqlpsql.";
51 qDebug() << "";
52 qDebug() << "See the \"Deploying Applications on OS X\" topic in the";
53 qDebug() << "documentation for more information about deployment on OS X.";
54
55 return 1;
56 }
57
58 appBundlePath = QDir::cleanPath(appBundlePath);
59
60 if (!QDir(appBundlePath).exists()) {
61 qDebug() << "Error: Could not find app bundle" << appBundlePath;
62 return 1;
63 }
64
65 bool plugins = true;
66 bool dmg = false;
67 QByteArray filesystem("HFS+");
68 bool useDebugLibs = false;
69 extern bool runStripEnabled;
70 extern bool alwaysOwerwriteEnabled;
72 QStringList additionalExecutables;
73 bool qmldirArgumentUsed = false;
74 QStringList qmlDirs;
75 QStringList qmlImportPaths;
76 extern bool runCodesign;
78 extern bool hardenedRuntime;
79 extern bool appstoreCompliant;
80 extern bool deployFramework;
81 extern bool secureTimestamp;
82
83 for (int i = 2; i < argc; ++i) {
85 if (argument == QByteArray("-no-plugins")) {
86 LogDebug() << "Argument found:" << argument;
87 plugins = false;
88 } else if (argument == QByteArray("-dmg")) {
89 LogDebug() << "Argument found:" << argument;
90 dmg = true;
91 } else if (argument == QByteArray("-no-strip")) {
92 LogDebug() << "Argument found:" << argument;
93 runStripEnabled = false;
94 } else if (argument == QByteArray("-use-debug-libs")) {
95 LogDebug() << "Argument found:" << argument;
96 useDebugLibs = true;
97 runStripEnabled = false;
98 } else if (argument.startsWith(QByteArray("-verbose"))) {
99 LogDebug() << "Argument found:" << argument;
100 int index = argument.indexOf("=");
101 bool ok = false;
102 int number = argument.mid(index+1).toInt(&ok);
103 if (!ok)
104 LogError() << "Could not parse verbose level";
105 else
107 } else if (argument.startsWith(QByteArray("-executable"))) {
108 LogDebug() << "Argument found:" << argument;
109 int index = argument.indexOf('=');
110 if (index == -1)
111 LogError() << "Missing executable path";
112 else
113 additionalExecutables << argument.mid(index+1);
114 } else if (argument.startsWith(QByteArray("-qmldir"))) {
115 LogDebug() << "Argument found:" << argument;
116 qmldirArgumentUsed = true;
117 int index = argument.indexOf('=');
118 if (index == -1)
119 LogError() << "Missing qml directory path";
120 else
121 qmlDirs << argument.mid(index+1);
122 } else if (argument.startsWith(QByteArray("-qmlimport"))) {
123 LogDebug() << "Argument found:" << argument;
124 int index = argument.indexOf('=');
125 if (index == -1)
126 LogError() << "Missing qml import path";
127 else
128 qmlImportPaths << argument.mid(index+1);
129 } else if (argument.startsWith(QByteArray("-libpath"))) {
130 LogDebug() << "Argument found:" << argument;
131 int index = argument.indexOf('=');
132 if (index == -1)
133 LogError() << "Missing library search path";
134 else
136 } else if (argument == QByteArray("-always-overwrite")) {
137 LogDebug() << "Argument found:" << argument;
139 } else if (argument.startsWith(QByteArray("-codesign"))) {
140 LogDebug() << "Argument found:" << argument;
141 int index = argument.indexOf("=");
142 if (index < 0 || index >= argument.size()) {
143 LogError() << "Missing code signing identity";
144 } else {
145 runCodesign = true;
147 }
148 } else if (argument.startsWith(QByteArray("-sign-for-notarization"))) {
149 LogDebug() << "Argument found:" << argument;
150 int index = argument.indexOf("=");
151 if (index < 0 || index >= argument.size()) {
152 LogError() << "Missing code signing identity";
153 } else {
154 runCodesign = true;
155 hardenedRuntime = true;
156 secureTimestamp = true;
158 }
159 } else if (argument.startsWith(QByteArray("-hardened-runtime"))) {
160 LogDebug() << "Argument found:" << argument;
161 hardenedRuntime = true;
162 } else if (argument.startsWith(QByteArray("-timestamp"))) {
163 LogDebug() << "Argument found:" << argument;
164 secureTimestamp = true;
165 } else if (argument == QByteArray("-appstore-compliant")) {
166 LogDebug() << "Argument found:" << argument;
167 appstoreCompliant = true;
168
169 // Undocumented option, may not work as intended
170 } else if (argument == QByteArray("-deploy-framework")) {
171 LogDebug() << "Argument found:" << argument;
172 deployFramework = true;
173
174 } else if (argument.startsWith(QByteArray("-fs"))) {
175 LogDebug() << "Argument found:" << argument;
176 int index = argument.indexOf('=');
177 if (index == -1)
178 LogError() << "Missing filesystem type";
179 else
180 filesystem = argument.mid(index+1);
181 } else if (argument.startsWith("-")) {
182 LogError() << "Unknown argument" << argument << "\n";
183 return 1;
184 }
185 }
186
187 DeploymentInfo deploymentInfo = deployQtFrameworks(appBundlePath, additionalExecutables, useDebugLibs);
188
189 if (deploymentInfo.isDebug)
190 useDebugLibs = true;
191
192 if (deployFramework && deploymentInfo.isFramework)
193 fixupFramework(appBundlePath);
194
195 // Convenience: Look for .qml files in the current directory if no -qmldir specified.
196 if (qmlDirs.isEmpty()) {
197 QDir dir;
198 if (!dir.entryList(QStringList() << QStringLiteral("*.qml")).isEmpty()) {
199 qmlDirs += QStringLiteral(".");
200 }
201 }
202
203 if (!qmlDirs.isEmpty()) {
204 bool ok = deployQmlImports(appBundlePath, deploymentInfo, qmlDirs, qmlImportPaths);
205 if (!ok && qmldirArgumentUsed)
206 return 1; // exit if the user explicitly asked for qml import deployment
207
208 // Update deploymentInfo.deployedFrameworks - the QML imports
209 // may have brought in extra frameworks as dependencies.
210 deploymentInfo.deployedFrameworks += findAppFrameworkNames(appBundlePath);
211 deploymentInfo.deployedFrameworks =
212 QSet<QString>(deploymentInfo.deployedFrameworks.begin(),
213 deploymentInfo.deployedFrameworks.end()).values();
214 }
215
216 // Handle plugins
217 if (plugins) {
218 // Set the plugins search directory
219 deploymentInfo.pluginPath = QLibraryInfo::path(QLibraryInfo::PluginsPath);
220
221 // Sanity checks
222 if (deploymentInfo.pluginPath.isEmpty()) {
223 LogError() << "Missing Qt plugins path\n";
224 return 1;
225 }
226
227 if (!QDir(deploymentInfo.pluginPath).exists()) {
228 LogError() << "Plugins path does not exist" << deploymentInfo.pluginPath << "\n";
229 return 1;
230 }
231
232 // Deploy plugins
233 Q_ASSERT(!deploymentInfo.pluginPath.isEmpty());
234 if (!deploymentInfo.pluginPath.isEmpty()) {
235 LogNormal();
236 deployPlugins(appBundlePath, deploymentInfo, useDebugLibs);
237 createQtConf(appBundlePath);
238 }
239 }
240
241 if (runStripEnabled)
242 stripAppBinary(appBundlePath);
243
244 if (runCodesign)
245 codesign(codesignIdentiy, appBundlePath);
246
247 if (dmg) {
248 LogNormal();
249 createDiskImage(appBundlePath, filesystem);
250 }
251
252 return 0;
253}
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inmodule QtCore
Definition qdir.h:20
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qdir.cpp:1715
static QString cleanPath(const QString &path)
Returns path with directory separators normalized (that is, platform-native separators converted to "...
Definition qdir.cpp:2398
static QString path(LibraryPath p)
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5949
int main()
[0]
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define qDebug
[1]
Definition qlogging.h:164
GLuint index
[2]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
bool runCodesign
Definition shared.cpp:30
bool deployQmlImports(const QString &appBundlePath, DeploymentInfo deploymentInfo, QStringList &qmlDirs, QStringList &qmlImportPaths)
Definition shared.cpp:1267
QStringList librarySearchPath
Definition shared.cpp:31
void createQtConf(const QString &appBundlePath)
Definition shared.cpp:1204
bool deployFramework
Definition shared.cpp:38
void fixupFramework(const QString &frameworkName)
Definition shared.cpp:1586
void createDiskImage(const QString &appBundlePath, const QString &filesystemType)
Definition shared.cpp:1550
bool appstoreCompliant
Definition shared.cpp:36
bool runStripEnabled
Definition shared.cpp:28
void stripAppBinary(const QString &bundlePath)
Definition shared.cpp:936
QString codesignIdentiy
Definition shared.cpp:32
bool alwaysOwerwriteEnabled
Definition shared.cpp:29
void deployPlugins(const ApplicationBundleInfo &appBundleInfo, const QString &pluginSourcePath, const QString pluginDestinationPath, DeploymentInfo deploymentInfo, bool useDebugLibs)
Definition shared.cpp:1079
DeploymentInfo deployQtFrameworks(QList< FrameworkInfo > frameworks, const QString &bundlePath, const QStringList &binaryPaths, bool useDebugLibs, bool useLoaderPath)
Definition shared.cpp:961
QStringList findAppFrameworkNames(const QString &appBundlePath)
Definition shared.cpp:403
bool hardenedRuntime
Definition shared.cpp:34
void codesign(const QString &identity, const QString &appBundlePath)
Definition shared.cpp:1546
bool secureTimestamp
Definition shared.cpp:35
int logLevel
Definition shared.cpp:37
#define LogError()
Definition shared.h:13
#define LogDebug()
Definition shared.h:16
#define LogNormal()
Definition shared.h:15
QString dir
[11]
QApplication app(argc, argv)
[0]
QDBusArgument argument