Enhance vcpkg integration in project generation script

- Improved the vcpkg path checking mechanism to include additional common installation locations and check for global installations.
- Added support for manifest mode by detecting the presence of a vcpkg.json file, allowing automatic dependency management.
- Enhanced output messages to provide clearer feedback on vcpkg usage and installation status, improving user experience.
This commit is contained in:
scawful
2025-09-28 11:18:56 -04:00
parent d69609abec
commit dfc5b329af

View File

@@ -142,14 +142,18 @@ if (-not (Test-Path $BuildDir)) {
$VcpkgPath = Join-Path $SourceDir "vcpkg\scripts\buildsystems\vcpkg.cmake" $VcpkgPath = Join-Path $SourceDir "vcpkg\scripts\buildsystems\vcpkg.cmake"
$VcpkgInstalled = Join-Path $SourceDir "vcpkg\installed" $VcpkgInstalled = Join-Path $SourceDir "vcpkg\installed"
# Check for vcpkg in common locations # Check for vcpkg in common locations (including global installations)
$VcpkgPaths = @( $VcpkgPaths = @(
(Join-Path $SourceDir "vcpkg\scripts\buildsystems\vcpkg.cmake"), (Join-Path $SourceDir "vcpkg\scripts\buildsystems\vcpkg.cmake"),
"$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake", "$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake",
"$env:ProgramFiles\vcpkg\scripts\buildsystems\vcpkg.cmake", "$env:ProgramFiles\vcpkg\scripts\buildsystems\vcpkg.cmake",
"$env:ProgramFiles(x86)\vcpkg\scripts\buildsystems\vcpkg.cmake" "$env:ProgramFiles(x86)\vcpkg\scripts\buildsystems\vcpkg.cmake",
"$env:LOCALAPPDATA\vcpkg\scripts\buildsystems\vcpkg.cmake"
) )
# Also check if vcpkg is available in PATH (for global installations)
$VcpkgExe = Get-Command vcpkg -ErrorAction SilentlyContinue
$UseVcpkg = $false $UseVcpkg = $false
foreach ($path in $VcpkgPaths) { foreach ($path in $VcpkgPaths) {
if (Test-Path $path) { if (Test-Path $path) {
@@ -159,7 +163,33 @@ foreach ($path in $VcpkgPaths) {
} }
} }
# If no local vcpkg found but vcpkg.exe is in PATH, check for manifest mode
if (-not $UseVcpkg -and $VcpkgExe) {
# Check if we have a vcpkg.json manifest file (indicates manifest mode)
$VcpkgManifest = Join-Path $SourceDir "vcpkg.json"
if (Test-Path $VcpkgManifest) {
Write-Host "Found vcpkg.json manifest file, using vcpkg in manifest mode" -ForegroundColor Green
$UseVcpkg = $true
# For manifest mode, we don't need to specify the toolchain file explicitly
# CMake will automatically detect and use vcpkg
}
}
if ($UseVcpkg) { if ($UseVcpkg) {
# Check if we're using manifest mode
$VcpkgManifest = Join-Path $SourceDir "vcpkg.json"
if (Test-Path $VcpkgManifest) {
Write-Host "Using vcpkg in manifest mode" -ForegroundColor Green
Write-Host "vcpkg will automatically install dependencies from vcpkg.json" -ForegroundColor Green
# Check if vcpkg is available in PATH
if ($VcpkgExe) {
Write-Host "vcpkg executable found: $($VcpkgExe.Source)" -ForegroundColor Green
} else {
Write-Host "vcpkg not found in PATH. Please ensure vcpkg is installed and available." -ForegroundColor Yellow
Write-Host "You can install vcpkg from: https://github.com/Microsoft/vcpkg" -ForegroundColor Yellow
}
} else {
Write-Host "Using vcpkg toolchain: $VcpkgPath" -ForegroundColor Green Write-Host "Using vcpkg toolchain: $VcpkgPath" -ForegroundColor Green
# Check if vcpkg is properly installed with required packages # Check if vcpkg is properly installed with required packages
@@ -181,6 +211,7 @@ if ($UseVcpkg) {
Write-Host "vcpkg.exe not found. Please install dependencies manually." -ForegroundColor Yellow Write-Host "vcpkg.exe not found. Please install dependencies manually." -ForegroundColor Yellow
} }
} }
}
} else { } else {
Write-Host "vcpkg not found, using system libraries" -ForegroundColor Yellow Write-Host "vcpkg not found, using system libraries" -ForegroundColor Yellow
Write-Host "Note: This may cause missing dependency issues. Consider installing vcpkg." -ForegroundColor Yellow Write-Host "Note: This may cause missing dependency issues. Consider installing vcpkg." -ForegroundColor Yellow
@@ -215,11 +246,23 @@ $CmakeArgs = @(
) )
if ($UseVcpkg) { if ($UseVcpkg) {
# Check if we're using manifest mode (vcpkg.json present)
$VcpkgManifest = Join-Path $SourceDir "vcpkg.json"
if (Test-Path $VcpkgManifest) {
# Manifest mode - CMake will automatically detect vcpkg
Write-Host "Using vcpkg in manifest mode" -ForegroundColor Green
$CmakeArgs += @( $CmakeArgs += @(
"-DCMAKE_TOOLCHAIN_FILE=`"$VcpkgPath`"",
"-DVCPKG_TARGET_TRIPLET=$Architecture-windows", "-DVCPKG_TARGET_TRIPLET=$Architecture-windows",
"-DVCPKG_MANIFEST_MODE=ON" "-DVCPKG_MANIFEST_MODE=ON"
) )
} else {
# Classic mode - specify toolchain file
Write-Host "Using vcpkg in classic mode with toolchain: $VcpkgPath" -ForegroundColor Green
$CmakeArgs += @(
"-DCMAKE_TOOLCHAIN_FILE=`"$VcpkgPath`"",
"-DVCPKG_TARGET_TRIPLET=$Architecture-windows"
)
}
} }
# Configure CMake to generate Visual Studio project files # Configure CMake to generate Visual Studio project files