[CmdletBinding()] param ( [ValidateSet('Debug', 'Release')] [string]$Configuration = 'Debug', [switch]$RegenerateProject ) $ErrorActionPreference = 'Stop' $sourceRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..\..\scummvm')) $buildDirectory = Join-Path $sourceRoot 'build-msvc' $generatorProject = Join-Path $sourceRoot 'devtools\create_project\msvc\create_project.vcxproj' $generatorExecutable = Join-Path $sourceRoot 'dists\msvc\create_project.exe' $solution = Join-Path $buildDirectory 'scummvm.sln' if (-not (Test-Path -LiteralPath (Join-Path $sourceRoot 'configure') -PathType Leaf)) { throw "ScummVM source checkout was not found at '$sourceRoot'." } $msbuildPath = $env:MSBUILD_EXE if ([string]::IsNullOrWhiteSpace($msbuildPath) -or -not (Test-Path -LiteralPath $msbuildPath -PathType Leaf)) { $msbuildCommand = Get-Command MSBuild.exe -ErrorAction SilentlyContinue if ($null -ne $msbuildCommand) { $msbuildPath = $msbuildCommand.Source } } if ([string]::IsNullOrWhiteSpace($msbuildPath) -or -not (Test-Path -LiteralPath $msbuildPath -PathType Leaf)) { throw 'MSBuild was not found. Run this script from a Visual Studio Developer PowerShell or set MSBUILD_EXE.' } New-Item -ItemType Directory -Path $buildDirectory -Force | Out-Null $vcpkgRootOutput = & $msbuildPath $generatorProject '-getProperty:VcpkgRoot' '/p:Configuration=Release' '/p:Platform=Win32' if ($LASTEXITCODE -ne 0) { throw "Could not query the vcpkg root from MSBuild (exit code $LASTEXITCODE)." } $vcpkgRoot = ($vcpkgRootOutput | Out-String).Trim() if ([string]::IsNullOrWhiteSpace($vcpkgRoot) -or -not (Test-Path -LiteralPath (Join-Path $vcpkgRoot 'vcpkg.exe') -PathType Leaf)) { throw 'The vcpkg MSBuild integration was not found. Run vcpkg integrate install, then retry.' } $localManifest = Join-Path $buildDirectory 'vcpkg.json' if (-not (Test-Path -LiteralPath $localManifest -PathType Leaf)) { $manifest = Get-Content -LiteralPath (Join-Path $sourceRoot 'vcpkg.json') -Raw | ConvertFrom-Json $manifest.name = 'scummvm-local-build' $manifest | ConvertTo-Json -Depth 100 | Set-Content -LiteralPath $localManifest -Encoding UTF8 } $registryConfiguration = Join-Path $buildDirectory 'vcpkg-configuration.json' if (-not (Test-Path -LiteralPath $registryConfiguration -PathType Leaf)) { $baseline = '' $bundleManifest = Join-Path $vcpkgRoot 'vcpkg-bundle.json' if (Test-Path -LiteralPath $bundleManifest -PathType Leaf) { $baseline = (Get-Content -LiteralPath $bundleManifest -Raw | ConvertFrom-Json).embeddedsha } else { $gitCommand = Get-Command git -ErrorAction SilentlyContinue if ($null -ne $gitCommand) { $baselineOutput = & $gitCommand.Source -C $vcpkgRoot rev-parse HEAD if ($LASTEXITCODE -eq 0) { $baseline = ($baselineOutput | Out-String).Trim() } } } if ($baseline -notmatch '^[0-9a-fA-F]{40}$') { throw "Could not find a 40-character registry baseline in '$vcpkgRoot'." } $configurationData = [ordered]@{ 'default-registry' = [ordered]@{ kind = 'builtin' baseline = $baseline } } $configurationData | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $registryConfiguration -Encoding UTF8 } $buildProperties = Join-Path $buildDirectory 'Directory.Build.props' if (-not (Test-Path -LiteralPath $buildProperties -PathType Leaf)) { @' $(MSBuildThisFileDirectory) $(MSBuildThisFileDirectory)vcpkg_installed '@ | Set-Content -LiteralPath $buildProperties -Encoding UTF8 } if ($RegenerateProject -or -not (Test-Path -LiteralPath $solution -PathType Leaf)) { & $msbuildPath $generatorProject '/m' '/p:Configuration=Release' '/p:Platform=Win32' '/verbosity:minimal' if ($LASTEXITCODE -ne 0) { throw "Building create_project failed (exit code $LASTEXITCODE)." } if (-not (Test-Path -LiteralPath $generatorExecutable -PathType Leaf)) { throw "The project generator was not produced at '$generatorExecutable'." } Push-Location $buildDirectory try { & $generatorExecutable '..' '--msvc' '--vcpkg' '--disable-all-engines' '--enable-engine=ultima' '--enable-engine=ultima8' if ($LASTEXITCODE -ne 0) { throw "Generating the ScummVM solution failed (exit code $LASTEXITCODE)." } } finally { Pop-Location } } & $msbuildPath $solution '/m' "/p:Configuration=$Configuration" '/p:Platform=x64' '/verbosity:minimal' if ($LASTEXITCODE -ne 0) { throw "The $Configuration x64 ScummVM build failed (exit code $LASTEXITCODE)." }