20 lines
1.7 KiB
PowerShell
20 lines
1.7 KiB
PowerShell
param([ValidateSet('Release','Debug')][string]$Configuration='Release',[string]$QmakePath)
|
|
$ErrorActionPreference='Stop'
|
|
$packageRoot=[IO.Path]::GetFullPath($PSScriptRoot)
|
|
if(-not $QmakePath){$QmakePath=Join-Path $packageRoot 'third_party\Qt\bin\qmake.exe'}
|
|
$qmake=(Resolve-Path -LiteralPath $QmakePath).Path
|
|
$vswhere=Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
|
|
if(-not(Test-Path -LiteralPath $vswhere)){throw 'MSVC build tools are required. Install the Desktop development with C++ component on this computer.'}
|
|
$vsPath=& $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
|
if(-not $vsPath){throw 'No MSVC x64 compiler was found on this computer.'}
|
|
$vcvars=Join-Path $vsPath 'VC\Auxiliary\Build\vcvarsall.bat'
|
|
$buildPath=Join-Path $packageRoot ('build\qtcreator-'+$Configuration.ToLowerInvariant())
|
|
New-Item -ItemType Directory -Force -Path $buildPath | Out-Null
|
|
$config=$Configuration.ToLowerInvariant();$otherConfig=if($config -eq 'release'){'debug'}else{'release'}
|
|
$commandFile=Join-Path $buildPath 'Invoke-QtBuild.cmd'
|
|
$commands=@('@echo off',('call "{0}" x64' -f $vcvars),'if errorlevel 1 exit /b 1',('cd /d "{0}"' -f $buildPath),('"{0}" "{1}" -spec win32-msvc "CONFIG+={2}" "CONFIG-={3}"' -f $qmake,(Join-Path $packageRoot 'source\VisionGuide.pro'),$config,$otherConfig),'if errorlevel 1 exit /b 1','nmake /NOLOGO /f Makefile','exit /b %errorlevel%')
|
|
[IO.File]::WriteAllLines($commandFile,$commands,[Text.Encoding]::Default)
|
|
& $env:ComSpec /d /c "`"$commandFile`""
|
|
if($LASTEXITCODE -ne 0){throw "qmake build failed with exit code $LASTEXITCODE"}
|
|
Write-Host "Executable: $(Join-Path $buildPath 'bin\VisionGuide.exe')"
|