This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathprepare.ps1
106 lines (86 loc) · 4.37 KB
/
prepare.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
. "$PSScriptRoot\helpers.ps1"
# 切换目录
Set-Location $projectDir
Write-Host "当前工程目录:$projectDir"
# 检查是否预编译依赖
if (Test-VcpkgIsPrebuilt $vcpkgRoot)
{
Write-Failure "已经安装了预编译依赖,请不要混合使用 prepare.ps1 和 prepare_prebuilt.ps1"
SafeExit 1
}
# 检查必要命令
if (-not (Get-Command -Name git -ErrorAction SilentlyContinue))
{
Write-Failure "请先安装 Git,并确保 git 命令已添加到 PATH 环境变量"
SafeExit 1
}
# 检查 vcpkg
if (-not (Test-Path $vcpkgCmd))
{
Write-Host "Vcpkg 未安装,即将安装……"
Remove-Item -Recurse -Force $vcpkgRoot -ErrorAction SilentlyContinue
Write-Host "正在克隆 vcpkg 仓库……"
git clone https://github.com/Microsoft/vcpkg.git "$vcpkgRoot"
Write-Host "正在构建 vcpkg……"
& "$vcpkgRoot\bootstrap-vcpkg.bat"
if ($?)
{
Write-Success "Vcpkg 构建成功"
}
else
{
Write-Failure "Vcpkg 构建失败"
SafeExit 1
}
}
else
{
Write-Success "Vcpkg 已安装"
}
$vcpkgTripletPath = "$vcpkgRoot\triplets\$vcpkgTriplet.cmake"
if (-not (Test-Path $vcpkgTripletPath))
{
Write-Host "正在创建 vcpkg triplet……"
Copy-Item "$projectDir\cmake\$vcpkgTriplet.cmake" $vcpkgTripletPath
}
Write-Success "Vcpkg triplet 已创建"
# 检查依赖
Write-Host "正在检查依赖……"
$vcpkgCommit = Get-Content "$projectDir\vcpkg-commit.txt" -ErrorAction SilentlyContinue
if ($vcpkgCommit)
{
git -C $vcpkgRoot fetch --depth=1 origin $vcpkgCommit
git -C $vcpkgRoot checkout $vcpkgCommit -- ports
if ($?)
{
Write-Success "Vcpkg 包版本已固定到 $vcpkgCommit"
}
else
{
Write-Failure "固定 vcpkg 包版本失败"
SafeExit 1
}
}
& "$vcpkgCmd" --vcpkg-root "$vcpkgRoot" remove --outdated
if ($?) { Write-Success "已移除过时的依赖" }
foreach ($package in Get-Content "$projectDir\vcpkg-requirements.txt")
{
$package = $package.trim()
if ($package)
{
Write-Host "正在安装依赖 $package……"
& "$vcpkgCmd" --vcpkg-root "$vcpkgRoot" --triplet $vcpkgTriplet install $package
if ($?)
{
Write-Success "依赖 $package 已安装"
}
else
{
Write-Failure "依赖 $package 安装失败"
SafeExit 1
}
}
}
Write-Success "构建环境准备完成"
# 退出
SafeExit 0