diff --git a/buildwin.ps1 b/buildwin.ps1 index 8eb398131..d75039bf9 100644 --- a/buildwin.ps1 +++ b/buildwin.ps1 @@ -4,8 +4,7 @@ # Usage: # ------ # buildwin.ps1 [-poco_base dir] -# [-vs_version 150 | 140] -# [-vs_flavor Community | Professional | Enterprise] +# [-vs 140 | 150 | 160] # [-action build | rebuild | clean] # [-linkmode shared | static_mt | static_md | all] # [-config release | debug | both] @@ -14,6 +13,8 @@ # [-tests] # [-omit "Lib1X;LibY;LibZ;..."] # [-tool msbuild | devenv] +# [-useenv env | noenv] +# [-verbosity m[inimal] | q[uiet] | n[ormal] | d[etailed] | diag[nostic]] # [-openssl_base dir] # [-mysql_base dir] @@ -24,12 +25,8 @@ Param [string] $poco_base, [Parameter()] - [ValidateSet(140, 150)] - [int] $vs_version, - - [Parameter()] - [ValidateSet('Community' , 'Professional' , 'Enterprise')] - [string] $vs_flavor = 'Community', + [ValidateSet(140, 150, 160)] + [int] $vs = 140, [Parameter()] [ValidateSet('build', 'rebuild', 'clean')] @@ -55,6 +52,14 @@ Param [ValidateSet('msbuild', 'devenv')] [string] $tool = 'msbuild', + [Parameter()] + [ValidateSet('env', 'noenv')] + [string] $useenv = 'env', + + [Parameter()] + [ValidateSet('quiet', 'm[inimal]', 'n[ormal]', 'd[etailed]', 'diag[nostic]')] + [string] $verbosity = 'minimal', + [Parameter()] [string] $openssl_base, @@ -64,6 +69,42 @@ Param [switch] $help ) +function Add-VSCOMNTOOLS([int] $vsver) +{ + if ($vsver -ge 150) + { + $vssetup= $([Environment]::GetFolderPath("MyDocuments")) + $vssetup= Join-Path $vssetup "WindowsPowerShell" + $vssetup= Join-Path $vssetup "Modules" + $vssetup= Join-Path $vssetup "VSSetup" + if (-not (Test-Path $vssetup)) + { + Install-Module VSSetup -Scope CurrentUser -Force + } + if ($vsver -eq 150) + { + $range='[15.0,16.0)' + } + if ($vsver -eq 160) + { + $range='[16.0,17.0)' + } + + $installationPath = Get-VSSetupInstance | Select-VSSetupInstance -Version $range -Latest -Require Microsoft.VisualStudio.Component.VC.Tools.x86.x64 | select InstallationPath + $vscomntools = $installationPath.psobject.properties.Value; + if ($vsver -eq 150) + { + set-item -force -path "ENV:VS150COMNTOOLS" -value "$vscomntools\Common7\Tools\" + Write-Host "`nVS150COMNTOOLS=$env:VS150COMNTOOLS" -ForegroundColor Yellow + } + if ($vsver -eq 160) + { + set-item -force -path "ENV:VS160COMNTOOLS" -value "$vscomntools\Common7\Tools\" + Write-Host "`nVS160COMNTOOLS=$env:VS160COMNTOOLS" -ForegroundColor Yellow + } + + } +} function Add-Env-Var([string] $lib, [string] $var) { @@ -81,15 +122,10 @@ function Set-Environment { if ($poco_base -eq '') { $script:poco_base = Get-Location } - if ($vs_version -eq 0) + switch ( $vs ) { - if ($Env:VS150COMNTOOLS -ne '') { $script:vs_version = 150 } - elseif ($Env:VS140COMNTOOLS -ne '') { $script:vs_version = 140 } - else - { - Write-Host 'Visual Studio not found, exiting.' - Exit 1 - } + 140 { } + default { Add-VSCOMNTOOLS $vs } } if (-Not $Env:PATH.Contains("$Env:POCO_BASE\bin64;$Env:POCO_BASE\bin;")) @@ -115,27 +151,28 @@ function Set-Environment Add-Env-Var "MYSQL" "LIB" } - $vsct = "VS$($vs_version)COMNTOOLS" + $vsct = "VS$($vs)COMNTOOLS" $vsdir = '' - if ($vs_version -eq 150) - { - if (-not (Test-Path Env:$vsct)) { Set-Item -path Env:$vsct -value "C:\Program Files (x86)\Microsoft Visual Studio\2017\$($vs_flavor)\Common7\Tools" } - } $vsdir = (Get-Item Env:$vsct).Value $Command = '' $CommandArg = '' if ($platform -eq 'x64') { $CommandArg = "amd64" } else { $CommandArg = "x86" } - if ($vs_version -ge 150) + if ($vs -eq 150) { $Command = Resolve-Path "$($vsdir)\..\..\VC\Auxiliary\Build\vcvarsall.bat" $script:msbuild_exe = Resolve-Path "$($vsdir)\..\..\MSBuild\15.0\Bin\MSBuild.exe" + } else { + if ($vs -eq 160) + { + $Command = Resolve-Path "$($vsdir)\..\..\VC\Auxiliary\Build\vcvarsall.bat" + $script:msbuild_exe = Resolve-Path "$($vsdir)\..\..\MSBuild\Current\Bin\MSBuild.exe" } else { $Command = Resolve-Path "$($vsdir)\..\..\VC\vcvarsall.bat" $script:msbuild_exe = "MSBuild.exe" - } + }} $tempFile = [IO.Path]::GetTempFileName() cmd /c " `"$Command`" $CommandArg && set > `"$tempFile`" " @@ -155,9 +192,8 @@ function Process-Input { Write-Host 'Usage:' Write-Host '------' - Write-Host 'buildwin.ps1 [-poco_base dir]' - Write-Host ' [-vs_version 150 | 140]' - Write-Host ' [-vs_flavor Community | Professional | Enterprise]' + Write-Host 'buildwin.ps1 [-poco_base