fix: build error

This commit is contained in:
Furqan-14
2026-05-26 16:13:11 +05:30
parent 81ba95ed88
commit 5e5404c330
2 changed files with 80 additions and 5 deletions
+53 -5
View File
@@ -1,8 +1,46 @@
param (
[string]$Preset = "win-local-pdfium"
)
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# --- Auto-generate CMakeUserPresets.json if missing ---
$UserPresetsPath = Join-Path $ScriptDir "..\CMakeUserPresets.json"
if (-not (Test-Path $UserPresetsPath)) {
$TemplatePath = Join-Path $ScriptDir "..\CMakeUserPresets.json.template"
if (Test-Path $TemplatePath) {
Write-Host "CMakeUserPresets.json not found. Auto-generating it from template for user: $env:USERNAME..." -ForegroundColor Cyan
$content = Get-Content $TemplatePath -Raw
$content = $content -replace "@USERNAME@", $env:USERNAME
[System.IO.File]::WriteAllText($UserPresetsPath, $content)
Write-Host "Generated CMakeUserPresets.json successfully." -ForegroundColor Green
}
}
# --- Resolve vcpkg root ---
$vcpkgRoot = $env:VCPKG_ROOT
if (-not $vcpkgRoot) {
$vcpkgRoot = "C:\Users\furqa\vcpkg"
$candidates = @(
"C:\vcpkg",
"C:\src\vcpkg",
"C:\Users\$env:USERNAME\vcpkg",
"C:\Users\furqa\vcpkg"
)
foreach ($cand in $candidates) {
if (Test-Path $cand) {
$vcpkgRoot = $cand
break
}
}
if (-not $vcpkgRoot) {
Write-Error "VCPKG_ROOT was not set and vcpkg could not be found at standard locations. Please set the VCPKG_ROOT environment variable."
exit 1
}
$env:VCPKG_ROOT = $vcpkgRoot
Write-Host "VCPKG_ROOT was not set. Defaulting to $vcpkgRoot" -ForegroundColor Yellow
Write-Host "VCPKG_ROOT defaulted to: $vcpkgRoot" -ForegroundColor Yellow
}
$vcvars = "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
@@ -10,6 +48,16 @@ if (-not (Test-Path $vcvars)) {
$vcvars = "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
}
if (-not (Test-Path $vcvars)) {
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
if (Test-Path $vswhere) {
$vsPath = (& $vswhere -latest -prerelease -products * -property installationPath | Select-Object -First 1)
if ($vsPath) {
$vcvars = Join-Path $vsPath "VC\Auxiliary\Build\vcvars64.bat"
}
}
}
if (-not (Test-Path $vcvars)) {
Write-Error "Could not find vcvars64.bat. Please ensure Visual Studio or Build Tools is installed."
exit 1
@@ -21,15 +69,15 @@ cmd /c "`"$vcvars`" && set" | Where-Object { $_ -match '=' } | ForEach-Object {
[System.Environment]::SetEnvironmentVariable($name, $value, 'Process')
}
Write-Host "Configuring CMake preset 'win-local-pdfium'..." -ForegroundColor Cyan
cmake --preset win-local-pdfium
Write-Host "Configuring CMake preset '$Preset'..." -ForegroundColor Cyan
cmake --preset $Preset
if ($LASTEXITCODE -ne 0) {
Write-Error "CMake configuration failed."
exit $LASTEXITCODE
}
Write-Host "Building all targets..." -ForegroundColor Cyan
cmake --build --preset win-local-pdfium
cmake --build --preset $Preset
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed."
exit $LASTEXITCODE