qmake: Provide feature for windeployqt

windeployqt is a tool that aids in the deployment of Qt libraries and
other files on Windows. This feature (CONFIG+=windeployqt) adds
automatic invocation of windeployqt for qmake projects as a post-link
action. For Visual Studio projects, windeployqt is added as a custom
target which runs after linking, automatically adding the output as
deployment items.

Task-number: QTBUG-35630

Change-Id: I4cdcb1a7f70cedccb4a4e17be5eb9f5de35a4d66
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
bb10
Andrew Knight 2014-02-11 13:49:18 +02:00 committed by The Qt Project
parent 49df5fc3d2
commit b4fe9ce225
7 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,19 @@
# Extra target for running windeployqt
qtPrepareTool(QMAKE_WINDEPLOYQT, windeployqt)
build_pass {
load(resolve_target)
isEmpty(WINDEPLOYQT_OPTIONS): WINDEPLOYQT_OPTIONS = -qmldir $$shell_quote($$shell_path($$_PRO_FILE_PWD_))
WINDEPLOYQT_TARGET = $$shell_quote($$shell_path($$QMAKE_RESOLVED_TARGET))
WINDEPLOYQT_OUTPUT = $$shell_quote($$shell_path($$dirname(QMAKE_RESOLVED_TARGET)/$$basename(TARGET).windeployqt))
windeployqt.target = windeployqt
windeployqt.commands = $$QMAKE_WINDEPLOYQT $$WINDEPLOYQT_OPTIONS -list target $$WINDEPLOYQT_TARGET > $$WINDEPLOYQT_OUTPUT
windeployqt_clean.commands = if exist $$WINDEPLOYQT_OUTPUT for /f %i in ($$WINDEPLOYQT_OUTPUT) do $$QMAKE_DEL_FILE %~fi && $$QMAKE_DEL_DIR %~pi
QMAKE_EXTRA_TARGETS += windeployqt_clean
DISTCLEAN_DEPS += windeployqt_clean
QMAKE_DISTCLEAN += $$WINDEPLOYQT_OUTPUT
} else {
windeployqt.CONFIG += recursive
}
QMAKE_EXTRA_TARGETS += windeployqt

View File

@ -774,6 +774,10 @@ void VCXProjectWriter::write(XmlOutput &xml, VCProject &tool)
write(xml, config.preLink);
xml << closetag();
// windeployqt
if (!config.windeployqt.ExcludedFromBuild)
write(xml, config.windeployqt);
}
// The file filters are added in a separate file for MSBUILD.
@ -1720,6 +1724,42 @@ void VCXProjectWriter::write(XmlOutput &xml, const VCDeploymentTool &tool)
// SmartDevice deployment not supported in VS 2010
}
void VCXProjectWriter::write(XmlOutput &xml, const VCWinDeployQtTool &tool)
{
const QString name = QStringLiteral("WinDeployQt_") + tool.config->Name;
xml << tag("Target")
<< attrTag(_Name, name)
<< attrTag("Condition", generateCondition(*tool.config))
<< attrTag("Inputs", "$(OutDir)\\$(TargetName).exe")
<< attrTag("Outputs", tool.Record)
<< tag(_Message)
<< attrTag("Text", tool.CommandLine)
<< closetag()
<< tag("Exec")
<< attrTag("Command", tool.CommandLine)
<< closetag()
<< closetag()
<< tag("Target")
<< attrTag(_Name, QStringLiteral("PopulateWinDeployQtItems_") + tool.config->Name)
<< attrTag("Condition", generateCondition(*tool.config))
<< attrTag("AfterTargets", "Link")
<< attrTag("DependsOnTargets", name)
<< tag("ReadLinesFromFile")
<< attrTag("File", tool.Record)
<< tag("Output")
<< attrTag("TaskParameter", "Lines")
<< attrTag("ItemName", "DeploymentItems")
<< closetag()
<< closetag()
<< tag(_ItemGroup)
<< tag("None")
<< attrTag("Include", "@(DeploymentItems)")
<< attrTagT("DeploymentContent", _True)
<< closetag()
<< closetag()
<< closetag();
}
void VCXProjectWriter::write(XmlOutput &xml, const VCConfiguration &tool)
{
xml << tag("PropertyGroup")

View File

@ -174,6 +174,7 @@ public:
void write(XmlOutput &, const VCResourceCompilerTool &);
void write(XmlOutput &, const VCEventTool &);
void write(XmlOutput &, const VCDeploymentTool &);
void write(XmlOutput &, const VCWinDeployQtTool &);
void write(XmlOutput &, const VCConfiguration &);
void write(XmlOutput &, VCFilter &);

View File

@ -2794,6 +2794,12 @@ void VCProjectWriter::write(XmlOutput &xml, const VCDeploymentTool &tool)
<< closetag(tool.DeploymentTag);
}
void VCProjectWriter::write(XmlOutput &xml, const VCWinDeployQtTool &tool)
{
Q_UNUSED(xml);
Q_UNUSED(tool);
}
void VCProjectWriter::write(XmlOutput &xml, const VCConfiguration &tool)
{
xml << tag(_Configuration)

View File

@ -860,6 +860,24 @@ public:
~VCPreLinkEventTool(){}
};
class VCWinDeployQtTool : public VCToolBase
{
public:
VCWinDeployQtTool() {}
~VCWinDeployQtTool() {}
protected:
bool parseOption(const char *) { return false; }
public:
// Variables
QString Record;
QString CommandLine;
bool ExcludedFromBuild;
VCConfiguration * config;
};
class VCConfiguration
{
public:
@ -900,6 +918,7 @@ public:
VCDeploymentTool deployment;
VCPreLinkEventTool preLink;
VCResourceCompilerTool resource;
VCWinDeployQtTool windeployqt;
};
struct VCFilterFile
@ -1156,6 +1175,7 @@ public:
virtual void write(XmlOutput &, const VCResourceCompilerTool &);
virtual void write(XmlOutput &, const VCEventTool &);
virtual void write(XmlOutput &, const VCDeploymentTool &);
virtual void write(XmlOutput &, const VCWinDeployQtTool &);
virtual void write(XmlOutput &, const VCConfiguration &);
virtual void write(XmlOutput &, VCFilter &);

View File

@ -1021,6 +1021,7 @@ void VcprojGenerator::initConfiguration()
if ((!project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
|| conf.WinRT)
initDeploymentTool();
initWinDeployQtTool();
initPreLinkEventTools();
if (!isDebug)
@ -1323,6 +1324,22 @@ void VcprojGenerator::initDeploymentTool()
}
}
void VcprojGenerator::initWinDeployQtTool()
{
VCConfiguration &conf = vcProject.Configuration;
conf.windeployqt.ExcludedFromBuild = true;
if (project->isActiveConfig("windeployqt")) {
conf.windeployqt.Record = QStringLiteral("$(TargetName).windeployqt.$(Platform).$(Configuration)");
conf.windeployqt.CommandLine =
MakefileGenerator::shellQuote(QDir::toNativeSeparators(project->first("QMAKE_WINDEPLOYQT").toQString()))
+ QLatin1Char(' ') + project->values("WINDEPLOYQT_OPTIONS").join(QLatin1Char(' '))
+ QStringLiteral(" -list relative -dir \"$(MSBuildProjectDirectory)\" \"$(OutDir)\\$(TargetName).exe\" > ")
+ MakefileGenerator::shellQuote(conf.windeployqt.Record);
conf.windeployqt.config = &vcProject.Configuration;
conf.windeployqt.ExcludedFromBuild = false;
}
}
void VcprojGenerator::initPreLinkEventTools()
{
VCConfiguration &conf = vcProject.Configuration;

View File

@ -109,6 +109,7 @@ protected:
void initPreBuildEventTools();
void initPostBuildEventTools();
void initDeploymentTool();
void initWinDeployQtTool();
void initPreLinkEventTools();
void initRootFiles();
void initSourceFiles();