-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathwindows-build.ps1
More file actions
388 lines (338 loc) · 15.8 KB
/
windows-build.ps1
File metadata and controls
388 lines (338 loc) · 15.8 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
Write-Host "Starting build script..." -ForegroundColor Cyan
Start-Sleep -Seconds 1
try {
$ErrorActionPreference = "Stop"
Write-Host "USDTweak Automated Build Script" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Prerequisites:" -ForegroundColor White
Write-Host " - Git https://git-scm.com/download/win" -ForegroundColor White
Write-Host " - CMake 3.14+ https://cmake.org/download/" -ForegroundColor White
Write-Host " - Visual Studio 2022 with C++ desktop workload" -ForegroundColor White
Write-Host " - ~3 GB free disk space" -ForegroundColor White
Write-Host ""
# Function to check if a command exists
function Test-Command($cmdname) {
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
# Check git
if (-not (Test-Command "git")) {
Write-Host "Error: Git is not installed or not in PATH." -ForegroundColor Red
Write-Host "Download from: https://git-scm.com/download/win" -ForegroundColor Yellow
pause
exit 1
}
# Check cmake
if (-not (Test-Command "cmake")) {
Write-Host "Error: CMake is not installed or not in PATH." -ForegroundColor Red
Write-Host "Download from: https://cmake.org/download/" -ForegroundColor Yellow
pause
exit 1
}
# Check cmake version
$cmakeVersionOutput = & cmake --version 2>&1 | Select-Object -First 1
if ($cmakeVersionOutput -match "(\d+\.\d+)") {
$cmakeVer = [version]$Matches[1]
if ($cmakeVer -lt [version]"3.14") {
Write-Host "Error: CMake 3.14 or higher is required (found $cmakeVersionOutput)." -ForegroundColor Red
Write-Host "Download from: https://cmake.org/download/" -ForegroundColor Yellow
pause
exit 1
}
Write-Host "Found CMake $($Matches[1])" -ForegroundColor Green
}
# Check Visual Studio 2022 with C++ workload
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $vswhere)) {
Write-Host "Error: Visual Studio Installer not found. Visual Studio 2022 is required." -ForegroundColor Red
Write-Host "Download from: https://visualstudio.microsoft.com/downloads/" -ForegroundColor Yellow
pause
exit 1
}
$vsInstall = & $vswhere -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath 2>$null
if (-not $vsInstall) {
$vsAny = & $vswhere -latest -property installationPath 2>$null
if ($vsAny) {
Write-Host "Error: Visual Studio found at '$vsAny' but the C++ desktop development workload is not installed." -ForegroundColor Red
Write-Host "Open Visual Studio Installer and add 'Desktop development with C++'." -ForegroundColor Yellow
} else {
Write-Host "Error: Visual Studio 2022 is not installed." -ForegroundColor Red
Write-Host "Download from: https://visualstudio.microsoft.com/downloads/" -ForegroundColor Yellow
}
pause
exit 1
}
$vsVersion = & $vswhere -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property catalog_productLineVersion 2>$null
if ($vsVersion -ne "2022") {
Write-Host "Error: Visual Studio 2022 is required (found VS $vsVersion)." -ForegroundColor Red
Write-Host "Download from: https://visualstudio.microsoft.com/downloads/" -ForegroundColor Yellow
pause
exit 1
}
Write-Host "Found Visual Studio 2022 with C++ workload" -ForegroundColor Green
# Check disk space (~3 GB needed)
$scriptDrive = (Resolve-Path $PSScriptRoot).Drive
$freeGB = [math]::Round((Get-PSDrive $scriptDrive.Name).Free / 1GB, 1)
if ($freeGB -lt 3) {
Write-Host "Error: Insufficient disk space. Need ~3 GB free, only $freeGB GB available on drive $($scriptDrive.Name):." -ForegroundColor Red
pause
exit 1
}
Write-Host "Disk space: $freeGB GB free" -ForegroundColor Green
Write-Host "`nAll prerequisites satisfied." -ForegroundColor Green
# Create build directory
$buildDir = Join-Path $PSScriptRoot "build"
New-Item -ItemType Directory -Force -Path $buildDir | Out-Null
# Define USD directory path
$usdDir = Join-Path $buildDir "usd"
# USD 25.08 with Python 3.12 from NVIDIA
$usdVersion = "25.08"
$pythonVersion = "3.12"
$pythonLibVersion = "312"
$usdUrl = "https://developer.nvidia.com/downloads/usd/usd_binaries/25.08/usd.py312.windows-x86_64.usdview.release-v25.08.71e038c1.zip"
# Check if USD directory exists with the correct version
$usdPresent = $false
if (Test-Path $usdDir) {
$pxrConfig = Join-Path $usdDir "pxrConfig.cmake"
$pythonLib = Join-Path $usdDir "python\libs\python${pythonLibVersion}.lib"
if ((Test-Path $pxrConfig) -and (Test-Path $pythonLib)) {
# Verify the USD version matches what we expect
$pxrContent = Get-Content $pxrConfig -Raw
if ($pxrContent -match 'set\(PXR_VERSION\s+"(\d+)"\)') {
$installedVersion = $Matches[1]
$expectedVersion = $usdVersion -replace '\.', '' # "25.08" -> "2508"
if ($installedVersion -eq $expectedVersion) {
Write-Host "`nFound existing USD $usdVersion installation in build/usd" -ForegroundColor Green
$usdPresent = $true
} else {
Write-Host "`nExisting USD is version $installedVersion but $expectedVersion is required, re-downloading..." -ForegroundColor Yellow
Remove-Item -Path $usdDir -Recurse -Force
}
} else {
Write-Host "`nCould not determine USD version, re-downloading..." -ForegroundColor Yellow
Remove-Item -Path $usdDir -Recurse -Force
}
} else {
Write-Host "`nUSD directory exists but appears incomplete, re-downloading..." -ForegroundColor Yellow
Remove-Item -Path $usdDir -Recurse -Force
}
}
if (-not $usdPresent) {
New-Item -ItemType Directory -Force -Path $usdDir | Out-Null
$usdZip = Join-Path $buildDir "usd.zip"
Write-Host "`nDownloading USD $usdVersion from NVIDIA (~464 MB)..." -ForegroundColor Yellow
Write-Host "This may take several minutes depending on your connection." -ForegroundColor DarkGray
try {
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $usdUrl -OutFile $usdZip
$ProgressPreference = 'Continue'
} catch {
Write-Host "Error: Failed to download USD. Please check your internet connection or download manually from:" -ForegroundColor Red
Write-Host $usdUrl -ForegroundColor Yellow
pause
exit 1
}
# Verify the download isn't empty or truncated
if (-not (Test-Path $usdZip) -or (Get-Item $usdZip).Length -lt 100000000) {
Write-Host "Error: Downloaded file appears to be incomplete or corrupted. Please try again." -ForegroundColor Red
if (Test-Path $usdZip) { Remove-Item -Path $usdZip -Force }
pause
exit 1
}
# Extract USD
Write-Host "Extracting USD..." -ForegroundColor Yellow
$sevenZip = "${env:ProgramFiles}\7-Zip\7z.exe"
if (Test-Path $sevenZip) {
Write-Host "Using 7-Zip for extraction..." -ForegroundColor Green
$extractProcess = Start-Process -FilePath $sevenZip -ArgumentList "x", "`"$usdZip`"", "-o`"$usdDir`"", "-y" -NoNewWindow -Wait -PassThru
if ($extractProcess.ExitCode -ne 0) {
Write-Host "7-Zip extraction failed, falling back to PowerShell extraction..." -ForegroundColor Yellow
Expand-Archive -Path $usdZip -DestinationPath $usdDir -Force
}
} else {
Write-Host "7-Zip not found, using PowerShell extraction (this may be slow for large archives)..." -ForegroundColor Yellow
Expand-Archive -Path $usdZip -DestinationPath $usdDir -Force
}
# Remove the zip file after extraction
if (Test-Path $usdZip) {
Remove-Item -Path $usdZip -Force
}
# Verify extraction succeeded
if (-not (Test-Path (Join-Path $usdDir "pxrConfig.cmake"))) {
Write-Host "Error: USD extraction failed - pxrConfig.cmake not found in build/usd." -ForegroundColor Red
Write-Host "Try deleting the build/usd directory and running this script again." -ForegroundColor Yellow
pause
exit 1
}
Write-Host "USD $usdVersion extracted successfully" -ForegroundColor Green
} else {
Write-Host "Using existing USD installation in build/usd" -ForegroundColor Green
}
# ----------------------------------------------------------------
# The NVIDIA USD package ships TBB, OpenSubdiv, and Imath libraries
# but does not include CMake config files for them. The pxrConfig.cmake
# expects to find these via find_dependency(), so we create minimal
# config files that define the required imported targets.
# ----------------------------------------------------------------
# Create TBB CMake config
$tbbCmakeDir = Join-Path $usdDir "lib\cmake\TBB"
if (-not (Test-Path (Join-Path $tbbCmakeDir "TBBConfig.cmake"))) {
Write-Host "Creating TBB CMake config..." -ForegroundColor Yellow
New-Item -ItemType Directory -Force -Path $tbbCmakeDir | Out-Null
@'
get_filename_component(_TBB_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
if(NOT TARGET TBB::tbb)
add_library(TBB::tbb SHARED IMPORTED)
set_target_properties(TBB::tbb PROPERTIES
IMPORTED_IMPLIB "${_TBB_ROOT}/lib/tbb.lib"
IMPORTED_LOCATION "${_TBB_ROOT}/bin/tbb.dll"
INTERFACE_INCLUDE_DIRECTORIES "${_TBB_ROOT}/include"
)
endif()
set(TBB_FOUND TRUE)
set(TBB_VERSION "2020.3")
'@ | Set-Content (Join-Path $tbbCmakeDir "TBBConfig.cmake") -Encoding UTF8
@'
set(PACKAGE_VERSION "2020.3")
if("${PACKAGE_FIND_VERSION}" VERSION_GREATER "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
'@ | Set-Content (Join-Path $tbbCmakeDir "TBBConfigVersion.cmake") -Encoding UTF8
}
# Create OpenSubdiv CMake config
$osdCmakeDir = Join-Path $usdDir "lib\cmake\OpenSubdiv"
if (-not (Test-Path (Join-Path $osdCmakeDir "OpenSubdivConfig.cmake"))) {
Write-Host "Creating OpenSubdiv CMake config..." -ForegroundColor Yellow
New-Item -ItemType Directory -Force -Path $osdCmakeDir | Out-Null
@'
get_filename_component(_OSD_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
if(NOT TARGET opensubdiv::opensubdiv)
add_library(opensubdiv::opensubdiv INTERFACE IMPORTED)
add_library(opensubdiv::osdCPU STATIC IMPORTED)
set_target_properties(opensubdiv::osdCPU PROPERTIES
IMPORTED_LOCATION "${_OSD_ROOT}/lib/osdCPU.lib"
)
add_library(opensubdiv::osdGPU STATIC IMPORTED)
set_target_properties(opensubdiv::osdGPU PROPERTIES
IMPORTED_LOCATION "${_OSD_ROOT}/lib/osdGPU.lib"
)
set_target_properties(opensubdiv::opensubdiv PROPERTIES
INTERFACE_LINK_LIBRARIES "opensubdiv::osdCPU;opensubdiv::osdGPU"
INTERFACE_INCLUDE_DIRECTORIES "${_OSD_ROOT}/include"
)
endif()
set(OpenSubdiv_FOUND TRUE)
set(OpenSubdiv_VERSION "3.6.0")
'@ | Set-Content (Join-Path $osdCmakeDir "OpenSubdivConfig.cmake") -Encoding UTF8
@'
set(PACKAGE_VERSION "3.6.0")
if("${PACKAGE_FIND_VERSION}" VERSION_GREATER "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
'@ | Set-Content (Join-Path $osdCmakeDir "OpenSubdivConfigVersion.cmake") -Encoding UTF8
}
# Create Imath CMake config
$imathCmakeDir = Join-Path $usdDir "lib\cmake\Imath"
if (-not (Test-Path (Join-Path $imathCmakeDir "ImathConfig.cmake"))) {
Write-Host "Creating Imath CMake config..." -ForegroundColor Yellow
New-Item -ItemType Directory -Force -Path $imathCmakeDir | Out-Null
@'
get_filename_component(_IMATH_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
if(NOT TARGET Imath::Imath)
add_library(Imath::Imath SHARED IMPORTED)
set_target_properties(Imath::Imath PROPERTIES
IMPORTED_IMPLIB "${_IMATH_ROOT}/lib/Imath-3_1.lib"
IMPORTED_LOCATION "${_IMATH_ROOT}/bin/Imath-3_1.dll"
INTERFACE_INCLUDE_DIRECTORIES "${_IMATH_ROOT}/include;${_IMATH_ROOT}/include/Imath"
)
endif()
if(NOT TARGET Imath::ImathConfig)
add_library(Imath::ImathConfig INTERFACE IMPORTED)
set_target_properties(Imath::ImathConfig PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMATH_ROOT}/include;${_IMATH_ROOT}/include/Imath"
)
endif()
set(Imath_FOUND TRUE)
set(Imath_VERSION "3.1.12")
'@ | Set-Content (Join-Path $imathCmakeDir "ImathConfig.cmake") -Encoding UTF8
@'
set(PACKAGE_VERSION "3.1.12")
if("${PACKAGE_FIND_VERSION}" VERSION_GREATER "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
'@ | Set-Content (Join-Path $imathCmakeDir "ImathConfigVersion.cmake") -Encoding UTF8
}
# Move to build directory
Push-Location $buildDir
# Configure with CMake
Write-Host "`nConfiguring with CMake..." -ForegroundColor Yellow
& cmake `
-G "Visual Studio 17 2022" `
-A x64 `
"-DCMAKE_PREFIX_PATH=$usdDir\lib\cmake" `
"-Dpxr_DIR=$usdDir" `
"-DMaterialX_DIR=$usdDir\lib\cmake\MaterialX" `
"-DImath_DIR=$usdDir\lib\cmake\Imath" `
"-DPython3_EXECUTABLE=$usdDir\python\python.exe" `
"-DPython3_LIBRARY=$usdDir\python\libs\python${pythonLibVersion}.lib" `
"-DPython3_INCLUDE_DIR=$usdDir\python\include" `
"-DPython3_VERSION=$pythonVersion" `
..
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: CMake configuration failed." -ForegroundColor Red
Write-Host "Check the output above for details." -ForegroundColor Yellow
pause
exit 1
}
# Build the project
Write-Host "`nBuilding project..." -ForegroundColor Yellow
& cmake --build . --config RelWithDebInfo --parallel
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Build failed." -ForegroundColor Red
Write-Host "Check the compiler output above for details." -ForegroundColor Yellow
pause
exit 1
}
# Return to original directory
Pop-Location
# Verify the executable was produced
$exePath = Join-Path $buildDir "RelWithDebInfo\usdtweak.exe"
if (-not (Test-Path $exePath)) {
Write-Host "Error: Build reported success but usdtweak.exe was not found at:" -ForegroundColor Red
Write-Host " $exePath" -ForegroundColor Yellow
pause
exit 1
}
Write-Host "`nBuild completed successfully!" -ForegroundColor Green
Write-Host "Executable: $exePath" -ForegroundColor Green
Write-Host "Run usdtweak with: .\windows-start.bat" -ForegroundColor Green
} catch {
Write-Host "`nError occurred:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host "`nStack trace:" -ForegroundColor Red
Write-Host $_.ScriptStackTrace -ForegroundColor Red
pause
exit 1
} finally {
if ($buildDir -and (Get-Location).Path -eq $buildDir) {
Pop-Location
}
}
Write-Host "`nPress any key to exit..." -ForegroundColor Cyan
pause