vcpkg/scripts/getWindowsSDK.ps1

102 lines
2.7 KiB
PowerShell
Raw Normal View History

[CmdletBinding()]
param(
2017-02-25 00:27:53 +00:00
[Parameter(Mandatory=$False)]
[switch]$DisableWin10SDK = $False,
2017-02-25 00:27:53 +00:00
[Parameter(Mandatory=$False)]
[switch]$DisableWin81SDK = $False
)
2017-02-25 00:27:53 +00:00
if ($DisableWin10SDK -and $DisableWin81SDK)
{
throw "Both Win10SDK and Win81SDK were disabled."
}
Write-Verbose "Executing $($MyInvocation.MyCommand.Name)"
$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition
2017-02-25 00:27:53 +00:00
$validInstances = New-Object System.Collections.ArrayList
2017-02-24 23:17:18 +00:00
$CandidateProgramFiles = $(& $scriptsDir\getProgramFiles32bit.ps1), $(& $scriptsDir\getProgramFilesPlatformBitness.ps1)
2017-02-25 00:27:53 +00:00
Write-Verbose "Program Files Candidate locations: $([system.String]::Join(',', $CandidateProgramFiles))"
# Windows 10 SDK
2017-02-25 00:27:53 +00:00
Write-Verbose "`n"
Write-Verbose "Looking for Windows 10 SDK"
foreach ($ProgramFiles in $CandidateProgramFiles)
{
$folder = "$ProgramFiles\Windows Kits\10\Include"
if (!(Test-Path $folder))
{
2017-02-25 00:27:53 +00:00
Write-Verbose "$folder - Not Found"
continue
}
2017-02-25 00:27:53 +00:00
Write-Verbose "$folder - Found"
2017-02-09 23:26:40 +00:00
$win10sdkVersions = @(Get-ChildItem $folder | Where-Object {$_.Name -match "^10"} | Sort-Object)
[array]::Reverse($win10sdkVersions) # Newest SDK first
2017-02-09 23:26:40 +00:00
foreach ($win10sdkV in $win10sdkVersions)
{
2017-02-25 00:27:53 +00:00
$windowsheader = "$folder\$win10sdkV\um\windows.h"
if (!(Test-Path $windowsheader))
2017-02-09 23:26:40 +00:00
{
2017-02-25 00:27:53 +00:00
Write-Verbose "$windowsheader - Not Found"
continue
2017-02-09 23:26:40 +00:00
}
2017-02-25 00:27:53 +00:00
Write-Verbose "$windowsheader - Found"
$ddkheader = "$folder\$win10sdkV\shared\sdkddkver.h"
if (!(Test-Path $ddkheader))
{
Write-Verbose "$ddkheader - Not Found"
continue
}
Write-Verbose "$ddkheader - Found"
2017-02-25 00:27:53 +00:00
$win10sdkVersionString = $win10sdkV.ToString()
Write-Verbose "Found $win10sdkVersionString"
$validInstances.Add($win10sdkVersionString) > $null
}
}
# Windows 8.1 SDK
2017-02-25 00:27:53 +00:00
Write-Verbose "`n"
Write-Verbose "Looking for Windows 8.1 SDK"
foreach ($ProgramFiles in $CandidateProgramFiles)
{
$folder = "$ProgramFiles\Windows Kits\8.1\Include"
2017-02-25 00:27:53 +00:00
if (!(Test-Path $folder))
{
Write-Verbose "$folder - Not Found"
continue
}
Write-Verbose "$folder - Found"
$win81sdkVersionString = "8.1"
Write-Verbose "Found $win81sdkVersionString"
$validInstances.Add($win81sdkVersionString) > $null
}
Write-Verbose "`n`n`n"
Write-Verbose "The following Windows SDKs were found:"
foreach ($instance in $validInstances)
{
Write-Verbose $instance
}
# Selecting
foreach ($instance in $validInstances)
{
if (!$DisableWin10SDK -and $instance -match "10.")
{
return $instance
}
if (!$DisableWin81SDK -and $instance -match "8.1")
{
2017-02-25 00:27:53 +00:00
return $instance
}
}
throw "Could not detect a Windows SDK / TargetPlatformVersion"