-
Notifications
You must be signed in to change notification settings - Fork 0
/
env-msvc.ps1
83 lines (74 loc) · 2.68 KB
/
env-msvc.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
param (
[Parameter(Mandatory=$true)][string]$TARGET_PLATFORM,
[Parameter(Mandatory=$true)][string]$TARGET_ARCH
)
${env:PARALLEL_JOBS} = ${env:NUMBER_OF_PROCESSORS}
${env:CCACHE_SRC} = ""
$ccache = Get-Command -Name ccache.exe -CommandType Application -ErrorAction SilentlyContinue
if ($ccache -ne $null) {
${env:CCACHE_SRC} = "$($ccache.Source)"
# https://github.com/ccache/ccache/discussions/978
${env:CMAKE_EXTRA} = "${env:CMAKE_EXTRA} -D CMAKE_C_COMPILER_LAUNCHER=`"${env:CCACHE_SRC}`""
${env:CMAKE_EXTRA} = "${env:CMAKE_EXTRA} -D CMAKE_CXX_COMPILER_LAUNCHER=`"${env:CCACHE_SRC}`""
}
# >>> VS DevShell >>>
# Only supports access to the VS DevShell from PowerShell
# see https://learn.microsoft.com/visualstudio/ide/reference/command-prompt-powershell#developer-powershell
$HOST_ARCH = ${env:PROCESSOR_ARCHITECTURE}.ToLower()
# Alreay accessed the VS DevShell
$VSCMD_ARG_TGT_ARCH = ${env:VSCMD_ARG_TGT_ARCH}
if ($VSCMD_ARG_TGT_ARCH -ne $null) {
if ($VSCMD_ARG_TGT_ARCH -ieq "x64") {
$VSCMD_ARG_TGT_ARCH = "amd64"
}
if ($VSCMD_ARG_TGT_ARCH -ieq $TARGET_ARCH) {
exit 0
}
}
$VS_DEVCMD_ARGS = "-host_arch=${HOST_ARCH} -arch=${TARGET_ARCH}"
function vsdevsh {
param (
[Parameter(Mandatory=$true)][string]$VS_PATH
)
$VS_PS1 = "${VS_PATH}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
if (-not (Test-Path -PathType Leaf -Path "${VS_PS1}")) {
return $false
}
Write-Host -ForegroundColor Green "Enter VS DevShell via PS1"
Import-Module "${VS_PS1}"
Enter-VsDevShell -VsInstallPath "${VS_PATH}" -SkipAutomaticLocation -DevCmdArguments "${VS_DEVCMD_ARGS}"
return $true
}
# Set VS search path
$MSVC_INSTALL_DIR = ${env:MSVC_INSTALL_DIR}
if ($MSVC_INSTALL_DIR -eq $null) {
$MSVC_INSTALL_DIR = "C:\Program Files (x86)\Microsoft Visual Studio"
if (-not (Test-Path -PathType Container -Path "${MSVC_INSTALL_DIR}")) {
$MSVC_INSTALL_DIR = "C:\Program Files\Microsoft Visual Studio"
}
}
$MSVC_SKIP_AUTO_SEARCH = ${env:MSVC_SKIP_AUTO_SEARCH}
if ($MSVC_SKIP_AUTO_SEARCH -eq $null) {
$MSVC_SKIP_AUTO_SEARCH = "0"
}
if ($MSVC_SKIP_AUTO_SEARCH -ieq "0") {
$VS_SEARCH_PATH = @(
"${MSVC_INSTALL_DIR}\2022\BuildTools",
"${MSVC_INSTALL_DIR}\2022\Community",
"${MSVC_INSTALL_DIR}\2022\Professional",
"${MSVC_INSTALL_DIR}\2022\Enterprise",
"${MSVC_INSTALL_DIR}\2019\BuildTools",
"${MSVC_INSTALL_DIR}\2019\Community",
"${MSVC_INSTALL_DIR}\2019\Professional",
"${MSVC_INSTALL_DIR}\2019\Enterprise"
)
} else {
$VS_SEARCH_PATH = @( "${MSVC_INSTALL_DIR}" )
}
$vs_devshell_ok = $false
foreach ($VS_PATH in $VS_SEARCH_PATH) {
$vs_devshell_ok = vsdevsh "$VS_PATH"
if ($vs_devshell_ok) { break }
}
if (-not $vs_devshell_ok) { exit 1 }
# <<< VS DevShell <<<