-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.ps1
executable file
·224 lines (206 loc) · 8.07 KB
/
build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env pwsh
$number_of_build_workers=8
$use_vcpkg=$true
$use_ninja=$false
$force_cpp_build=$false
function getProgramFiles32bit() {
$out = ${env:PROGRAMFILES(X86)}
if ($null -eq $out) {
$out = ${env:PROGRAMFILES}
}
if ($null -eq $out) {
throw "Could not find [Program Files 32-bit]"
}
return $out
}
function getLatestVisualStudioWithDesktopWorkloadPath() {
$programFiles = getProgramFiles32bit
$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhereExe) {
$output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
}
if (!$installationPath) {
Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow
$output = & $vswhereExe -products * -latest -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
}
}
if (!$installationPath) {
Throw "Could not locate any installation of Visual Studio"
}
}
else {
Throw "Could not locate vswhere at $vswhereExe"
}
return $installationPath
}
function getLatestVisualStudioWithDesktopWorkloadVersion() {
$programFiles = getProgramFiles32bit
$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhereExe) {
$output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationVersion = $instance.InstallationVersion
}
if (!$installationVersion) {
Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow
$output = & $vswhereExe -products * -latest -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance) {
$installationVersion = $instance.installationVersion
}
}
if (!$installationVersion) {
Throw "Could not locate any installation of Visual Studio"
}
}
else {
Throw "Could not locate vswhere at $vswhereExe"
}
return $installationVersion
}
if ((Test-Path env:VCPKG_ROOT) -and $use_vcpkg) {
$vcpkg_path = "$env:VCPKG_ROOT"
Write-Host "Found vcpkg in VCPKG_ROOT: $vcpkg_path"
}
elseif ((Test-Path "${env:WORKSPACE}\vcpkg") -and $use_vcpkg) {
$vcpkg_path = "${env:WORKSPACE}\vcpkg"
Write-Host "Found vcpkg in WORKSPACE\vcpkg: $vcpkg_path"
}
else {
Write-Host "Skipping vcpkg-enabled builds because the VCPKG_ROOT environment variable is not defined or you requested to avoid VCPKG, using self-distributed libs`n" -ForegroundColor Yellow
}
if ($null -eq $env:VCPKG_DEFAULT_TRIPLET -and $use_vcpkg) {
Write-Host "No default triplet has been set-up for vcpkg. Defaulting to x64-windows" -ForegroundColor Yellow
$vcpkg_triplet = "x64-windows"
}
elseif ($use_vcpkg) {
$vcpkg_triplet = $env:VCPKG_DEFAULT_TRIPLET
}
if ($vcpkg_triplet -Match "x86" -and $use_vcpkg) {
Throw "darknet is supported only in x64 builds!"
}
if ($null -eq (Get-Command "cl.exe" -ErrorAction SilentlyContinue)) {
$vsfound = getLatestVisualStudioWithDesktopWorkloadPath
Write-Host "Found VS in ${vsfound}"
Push-Location "${vsfound}\Common7\Tools"
cmd.exe /c "VsDevCmd.bat -arch=x64 & set" |
ForEach-Object {
if ($_ -match "=") {
$v = $_.split("="); Set-Item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
Pop-Location
Write-Host "Visual Studio Command Prompt variables set" -ForegroundColor Yellow
}
$tokens = getLatestVisualStudioWithDesktopWorkloadVersion
$tokens = $tokens.split('.')
if($use_ninja) {
$generator = "Ninja"
}
else {
if ($tokens[0] -eq "14") {
$generator = "Visual Studio 14 2015"
}
elseif ($tokens[0] -eq "15") {
$generator = "Visual Studio 15 2017"
}
elseif ($tokens[0] -eq "16") {
$generator = "Visual Studio 16 2019"
}
else {
throw "Unknown Visual Studio version, unsupported configuration"
}
}
Write-Host "Setting up environment to use CMake generator: $generator" -ForegroundColor Yellow
if ($null -eq (Get-Command "nvcc.exe" -ErrorAction SilentlyContinue)) {
if (Test-Path env:CUDA_PATH) {
$env:PATH += ";${env:CUDA_PATH}\bin"
Write-Host "Found cuda in ${env:CUDA_PATH}" -ForegroundColor Yellow
}
else {
Write-Host "Unable to find CUDA, if necessary please install it or define a CUDA_PATH env variable pointing to the install folder" -ForegroundColor Yellow
}
}
if (Test-Path env:CUDA_PATH) {
if (-Not(Test-Path env:CUDA_TOOLKIT_ROOT_DIR)) {
$env:CUDA_TOOLKIT_ROOT_DIR = "${env:CUDA_PATH}"
Write-Host "Added missing env variable CUDA_TOOLKIT_ROOT_DIR" -ForegroundColor Yellow
}
}
if($force_cpp_build) {
$additional_build_setup="-DBUILD_AS_CPP:BOOL=TRUE"
}
if ($use_vcpkg) {
## DEBUG
#New-Item -Path .\build_win_debug -ItemType directory -Force
#Set-Location build_win_debug
#if ($use_ninja) {
#cmake -G "$generator" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" #"-DCMAKE_BUILD_TYPE=Debug" $additional_build_setup ..
#$dllfolder = "."
#}
#else {
#cmake -G "$generator" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" "-DCMAKE_BUILD_TYPE=Debug" $additional_build_setup ..
#$dllfolder = "Debug"
#}
#cmake --build . --config Debug --target install
##cmake --build . --config Debug --parallel ${number_of_build_workers} --target install #valid only for CMake 3.12+
#Remove-Item DarknetConfig.cmake
#Remove-Item DarknetConfigVersion.cmake
#$dllfiles = Get-ChildItem ${dllfolder}\*.dll
#if ($dllfiles) {
# Copy-Item $dllfiles ..
#}
#Set-Location ..
#Copy-Item cmake\Modules\*.cmake share\darknet\
# RELEASE
New-Item -Path .\build_win_release -ItemType directory -Force
Set-Location build_win_release
if($use_ninja) {
cmake -G "$generator" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" "-DCMAKE_BUILD_TYPE=Release" $additional_build_setup ..
$dllfolder = "."
}
else {
cmake -G "$generator" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" "-DCMAKE_BUILD_TYPE=Release" $additional_build_setup ..
$dllfolder = "Release"
}
cmake --build . --config Release --target install
#cmake --build . --config Release --parallel ${number_of_build_workers} --target install #valid only for CMake 3.12+
Remove-Item DarknetConfig.cmake
Remove-Item DarknetConfigVersion.cmake
$dllfiles = Get-ChildItem ${dllfolder}\*.dll
if ($dllfiles) {
Copy-Item $dllfiles ..
}
Set-Location ..
Copy-Item cmake\Modules\*.cmake share\darknet\
}
else {
# USE LOCAL PTHREAD LIB AND LOCAL STB HEADER, NO VCPKG, ONLY RELEASE MODE SUPPORTED
# if you want to manually force this case, remove VCPKG_ROOT env variable and remember to use "vcpkg integrate remove" in case you had enabled user-wide vcpkg integration
New-Item -Path .\build_win_release_novcpkg -ItemType directory -Force
Set-Location build_win_release_novcpkg
if($use_ninja) {
cmake -G "$generator" $additional_build_setup ..
}
else {
cmake -G "$generator" -T "host=x64" -A "x64" $additional_build_setup ..
}
cmake --build . --config Release --target install
#cmake --build . --config Release --parallel ${number_of_build_workers} --target install #valid only for CMake 3.12+
Remove-Item DarknetConfig.cmake
Remove-Item DarknetConfigVersion.cmake
$dllfolder = "..\3rdparty\pthreads\bin"
$dllfiles = Get-ChildItem ${dllfolder}\*.dll
if ($dllfiles) {
Copy-Item $dllfiles ..
}
Set-Location ..
Copy-Item cmake\Modules\*.cmake share\darknet\
}