-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathwindows-build.ps1
199 lines (173 loc) · 7.67 KB
/
windows-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
# Ensure the window stays open
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
Write-Host "Starting build script..." -ForegroundColor Cyan
Start-Sleep -Seconds 1
try {
# Ensure we stop on any errors
$ErrorActionPreference = "Stop"
Write-Host "USDTweak Automated Build Script" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Cyan
# Function to check if a command exists
function Test-Command($cmdname) {
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
# Check prerequisites
$prerequisites = @{
"git" = "Git is required. Download from: https://git-scm.com/download/win"
"cmake" = "CMake is required. Download from: https://cmake.org/download/"
}
foreach ($cmd in $prerequisites.Keys) {
if (-not (Test-Command $cmd)) {
Write-Host "Error: $($prerequisites[$cmd])" -ForegroundColor Red
pause
exit 1
}
}
# 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"
# Check if USD directory exists first
$usdPresent = Test-Path $usdDir
if ($usdPresent) {
# Only verify files if directory exists
$usdValidationPaths = @(
(Join-Path $usdDir "pxrConfig.cmake"), # Corrected path for pxrConfig.cmake
(Join-Path $usdDir "lib\cmake\MaterialX\MaterialXConfig.cmake"), # Corrected path for MaterialXConfig.cmake
(Join-Path $usdDir "python\python.exe")
)
$missingFiles = @()
foreach ($path in $usdValidationPaths) {
if (-not (Test-Path $path)) {
$missingFiles += $path
}
}
if ($missingFiles.Count -gt 0) {
Write-Host "Warning: USD directory exists but missing required files:" -ForegroundColor Yellow
foreach ($file in $missingFiles) {
Write-Host " - $file" -ForegroundColor Yellow
}
# Removed the deletion of the USD directory
# $usdPresent = $false
# Remove-Item -Path $usdDir -Recurse -Force
}
}
if (-not $usdPresent) {
# Create USD directory only if we need to download
New-Item -ItemType Directory -Force -Path $usdDir | Out-Null
# Download USD from NVIDIA
$usdUrl = "https://developer.nvidia.com/downloads/USD/usd_binaries/24.11/usd.py311.windows-x86_64.usdview.release-0.24.11-4d81dd85.zip"
$usdZip = Join-Path $buildDir "usd.zip"
Write-Host "`nDownloading USD from NVIDIA..." -ForegroundColor Yellow
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
}
# Extract USD - Try to use 7-Zip if available
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..." -ForegroundColor Yellow
Expand-Archive -Path $usdZip -DestinationPath $usdDir -Force
}
# Remove the zip file after extraction
Remove-Item -Path $usdZip -Force
# Diagnostic: Check what's in the extracted directory
Write-Host "Checking USD directory structure..." -ForegroundColor Yellow
Write-Host "Contents of ${usdDir}:" -ForegroundColor Yellow
Get-ChildItem -Path ${usdDir} | ForEach-Object {
Write-Host " - $($_.Name)"
}
# Search for pxrConfig.cmake
Write-Host "`nSearching for pxrConfig.cmake..." -ForegroundColor Yellow
$pxrConfigFiles = Get-ChildItem -Path $usdDir -Recurse -Filter "pxrConfig.cmake"
if ($pxrConfigFiles) {
foreach ($file in $pxrConfigFiles) {
Write-Host " Found at: $($file.FullName)"
}
} else {
Write-Host " No pxrConfig.cmake found!"
}
} else {
Write-Host "`nUsing existing USD installation in build/usd" -ForegroundColor Green
}
# Move to build directory
Push-Location $buildDir
# Configure with CMake
Write-Host "`nConfiguring with CMake..." -ForegroundColor Yellow
$cmakeArgs = @(
"-G`"Visual Studio 17 2022`"",
"-A", "x64",
"-Dpxr_DIR=`"$usdDir`"",
"-DMaterialX_DIR=`"$usdDir\lib\cmake\MaterialX`"",
"-DPython3_EXECUTABLE=`"$usdDir\python\python.exe`"",
"-DPython3_LIBRARY=`"$usdDir\python\libs\python311.lib`"",
"-DPython3_INCLUDE_DIR=`"$usdDir\python\include`"",
"-DPython3_VERSION=`"3.11`"",
"-DImath_DIR=`"$usdDir\lib\cmake\Imath`"",
".."
)
$cmakeProcess = Start-Process cmake -ArgumentList ($cmakeArgs -join ' ') -NoNewWindow -Wait -PassThru
if ($cmakeProcess.ExitCode -ne 0) {
Write-Host "Error: CMake configuration failed" -ForegroundColor Red
pause
exit 1
}
# Fix the osdGPU.lib and osdCPU.lib issue in pxrTargets.cmake
$pxrTargetsPath = Join-Path $usdDir "cmake\pxrTargets.cmake"
if (Test-Path $pxrTargetsPath) {
$content = Get-Content $pxrTargetsPath
$content = $content -replace '\$\{_IMPORT_PREFIX\}/lib/osdGPU\.lib;', ''
$content = $content -replace '\$\{_IMPORT_PREFIX\}/lib/osdCPU\.lib;', ''
Set-Content $pxrTargetsPath $content
}
# Build the project
Write-Host "`nBuilding project..." -ForegroundColor Yellow
$buildProcess = Start-Process cmake -ArgumentList "--build", ".", "--config", "RelWithDebInfo", "--parallel" -NoNewWindow -Wait -PassThru
if ($buildProcess.ExitCode -ne 0) {
Write-Host "Error: Build failed" -ForegroundColor Red
pause
exit 1
}
# Install
Write-Host "`nInstalling..." -ForegroundColor Yellow
$installProcess = Start-Process cmake -ArgumentList "--install", ".", "--prefix", "./install", "--config", "RelWithDebInfo" -NoNewWindow -Wait -PassThru
if ($installProcess.ExitCode -ne 0) {
Write-Host "Error: Installation failed" -ForegroundColor Red
pause
exit 1
}
# Return to original directory
Pop-Location
Write-Host "`nBuild completed successfully!" -ForegroundColor Green
Write-Host "The built files can be found in: $buildDir\install" -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 {
# Make sure we're back in the original directory
if ($buildDir -and (Get-Location).Path -eq $buildDir) {
Pop-Location
}
}
# Move pause outside of try-catch so it always executes
Write-Host "`nPress any key to exit..." -ForegroundColor Cyan
pause