PowerShell script to deploy Qt Standalone Windows App

qt-logoUse this script with QtCreator (Option, External Tools):

Executable: powershell

Arguments: deployWindowsApp.ps1 %{CurrentProject:Name} %{CurrentProject:NativePath} %{CurrentProject:BuildPath} %{CurrentProject:QT_INSTALL_BINS} c:\Developer\Deploy

 

MingW compiler path is hardcoded (need by winDeployQt)
I used 7-zip command line tool to create the final Zip archive.

 

My Directory tree:

[code]
Developer
+—Build
+—MyApp-Built-with-Qt-MingW
+—release
+—debug
+—Code
+—MyApp
+—Deploy (some deployable stuff)
+—Deploy
+—MyApp-Windows-x32
+—Tools
+—Qt
[/code]

Here is the script deployWindowsApp.ps1:

[code lang=”PowerShell” wraplines=”false”]
param(
[string]$appName,
[string]$appSource,
[string]$appBuild,
[string]$qtBin,
[string]$dest
)

function fix([string]$path) {
return $path.Replace("/","\")
}

#***************** M A I N **************
$scriptName = $MyInvocation.MyCommand.Name
Write-Host "<$scriptName>"
$appSource= fix($appSource)
$appBuild= fix($appBuild)
$qtBin= fix($qtBin)
$dest= fix($dest)

Write-Host "APP-NAME=$appName"
Write-Host "APP-SOURCE-DIR=$appSource"
Write-Host "APP-BUILD-DIR=$appBuild"
Write-Host "QT-BIN-DIR=$qtBin"
Write-Host "DESTINATION-DIR=$dest"
Write-Host "———————–"
$deploy="$appSource\Deploy\"
Write-Host "embed this stuff=$deploy"

if (Test-Path -Path "$appSource\VERSION.pri") {
$text = Get-Content "$appSource\VERSION.pri" -Raw
$appVer=$text.Trim().Remove(0,4)
Write-Host "APP-VERSION=$appVer"
}

$destName = "$appName-$appVer-Windows-x32"
$destPath = "$dest\$destName\"
Write-Host "*** CREATING: $destName"

if (Test-Path -Path $destPath) {
Write-Host "Path exists: $destPath"
} else {
Write-Host "Creating path: $destPath"
New-Item -ItemType directory -Path $destPath | Out-Null
}
# COPY EXE
Write-Host "*** COPY BINARY"
Copy-Item "$appBuild\release\$appName.exe" -Destination $destPath -Force
# COPY Deploy STUFF
Write-Host "*** COPY DEPLOYABLE STUFF"
Copy-Item "$appSource\Deploy\*" -Destination $destPath -Force
# WinDeployQt
cd $dest
# qtBin -> "C:\Developer\Tools\Qt\5.5\mingw492_32\bin"
$gccBin = "C:\Developer\Tools\Qt\Tools\mingw492_32\bin"
$zipBin = "C:\Program Files\7-Zip"
$env:Path += ";$qtBin;$gccBin;$zipBin"

#C:\Qt\5.5\mingw492_32\bin\windeployqt.exe –release "$destName"
Write-Host "*** WINDEPLOYQT"
windeployqt.exe –release "$destName"

#Copy MISSING
Write-Host "*** COPY MISSING"
Copy-Item "$qtBin\Qt5Quick.dll" -Destination $destPath -Force
Copy-Item "$qtBin\..\qml" -Destination $destPath -Recurse -Force

Write-Host "*** ZIPPPING"
7z.exe a -r "$dest\$destName.zip" "$dest\$destName"
Write-Host "</$scriptName>"
[/code]

NJoY 🙂