[CmdletBinding()] param( [ValidateSet('Debug', 'Release')] [string]$Configuration = 'Debug' ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $projectRoot = Split-Path -Parent $PSScriptRoot $qtRoot = 'D:\Qt5.15.2\5.15.2\mingw81_64' $minGwBin = 'D:\Qt5.15.2\Tools\mingw810_64\bin' $qmakePath = Join-Path $qtRoot 'bin\qmake.exe' $makePath = Join-Path $minGwBin 'mingw32-make.exe' $projectFile = Join-Path $projectRoot 'app\integrated_platform.pro' $configurationName = $Configuration.ToLowerInvariant() $buildDirectory = Join-Path $projectRoot "build\$configurationName" $executablePath = Join-Path $buildDirectory "$configurationName\integrated_platform.exe" foreach ($requiredPath in @($qmakePath, $makePath, $projectFile)) { if (-not (Test-Path -LiteralPath $requiredPath)) { throw "未找到必要文件:$requiredPath" } } New-Item -ItemType Directory -Path $buildDirectory -Force | Out-Null $originalPath = $env:Path $env:Path = "$qtRoot\bin;$minGwBin;$env:Path" Push-Location $buildDirectory try { & $qmakePath $projectFile "CONFIG+=$configurationName" "CONFIG-=$(if ($configurationName -eq 'debug') { 'release' } else { 'debug' })" if ($LASTEXITCODE -ne 0) { throw "qmake 执行失败,退出码:$LASTEXITCODE" } & $makePath -j2 if ($LASTEXITCODE -ne 0) { throw "mingw32-make 执行失败,退出码:$LASTEXITCODE" } if (-not (Test-Path -LiteralPath $executablePath)) { throw "未生成可执行文件:$executablePath" } Write-Host "构建完成,正在启动:$executablePath" & $executablePath if ($LASTEXITCODE -ne 0) { throw "程序退出异常,退出码:$LASTEXITCODE" } } finally { Pop-Location $env:Path = $originalPath }