diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-03-09 14:48:15 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-03-09 14:53:36 +0800 |
| commit | 239cd62103d617f0b2a9d58527843417a0db6ab4 (patch) | |
| tree | 2566d5ce8a5bfae7b92e7c83c011655753b83a0e /gui/win32/scripts | |
| parent | e02921ae75d41253406834bd7e214c3c8dec6f9b (diff) | |
Add Win32 GUI for butck_gui.exe
Diffstat (limited to 'gui/win32/scripts')
| -rw-r--r-- | gui/win32/scripts/_entry.ps1 | 91 | ||||
| -rw-r--r-- | gui/win32/scripts/build.ps1 | 87 | ||||
| -rw-r--r-- | gui/win32/scripts/clean.ps1 | 15 | ||||
| -rw-r--r-- | gui/win32/scripts/run.ps1 | 10 |
4 files changed, 203 insertions, 0 deletions
diff --git a/gui/win32/scripts/_entry.ps1 b/gui/win32/scripts/_entry.ps1 new file mode 100644 index 0000000..1d49e46 --- /dev/null +++ b/gui/win32/scripts/_entry.ps1 @@ -0,0 +1,91 @@ +$pathsToPreserve = @() +$originalPath = $env:PATH -split ';' +foreach ($pathEntry in $originalPath) { + if ($pathEntry -match 'CMake|Python|Git|System32|WindowsApps') { + $pathsToPreserve += $pathEntry + } +} + +Get-ChildItem env: | Where-Object { $_.Name -match "^INCLUDE$|^LIB$|^LIBPATH$" } | ForEach-Object { + Remove-Item "env:\$($_.Name)" +} + +$env:Path = $pathsToPreserve -join ';' + +$vcTools = "C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717" +$vcHost = "Hostx64\x64" + +$clPath = "$vcTools\bin\$vcHost" +$env:Path = "$clPath;$env:Path" + +$sdkBase = "C:\Program Files (x86)\Windows Kits\10" +$sdkVersions = Get-ChildItem "$sdkBase\Include" -Directory | + Where-Object { $_.Name -match "^\d+\.\d+" } | + Sort-Object Name -Descending + +if ($sdkVersions) { + $latestSdk = $sdkVersions[0].Name + + $sdkBin = "$sdkBase\bin\$latestSdk\x64" + $env:Path = "$sdkBin;$env:Path" + + $includePaths = @( + "$vcTools\include", + "$sdkBase\Include\$latestSdk\um", + "$sdkBase\Include\$latestSdk\shared", + "$sdkBase\Include\$latestSdk\ucrt" + ) + $env:INCLUDE = ($includePaths -join ';') + + $libPaths = @( + "$vcTools\lib\x64", + "$sdkBase\Lib\$latestSdk\um\x64", + "$sdkBase\Lib\$latestSdk\ucrt\x64" + ) + $env:LIB = ($libPaths -join ';') + + $env:LIBPATH = "$vcTools\lib\x64;$sdkBase\Lib\$latestSdk\um\x64" +} else { + Write-Host "Warning: Using generic SDK path" -ForegroundColor Yellow + $env:Path = "$sdkBase\bin\x64;$env:Path" + $env:INCLUDE = "$vcTools\include" + $env:LIB = "$vcTools\lib\x64" +} + +$libFiles = @( + "$vcTools\lib\x64\MSVCRTD.lib", + "$vcTools\lib\x64\MSVCRT.lib" +) + +foreach ($lib in $libFiles) { + if (-not (Test-Path $lib)) { + Write-Host "$(Split-Path $lib -Leaf)" -ForegroundColor Red + } +} + +# Generate .clangd configuration file +$clangdContent = @" +CompileFlags: + CompilationDatabase: build/ + Add: + - -I$sdkBase\Include\$latestSdk\um + - -I$sdkBase\Include\$latestSdk\shared + - -I$sdkBase\Include\$latestSdk\ucrt + - -I$vcTools\include + - -I`${workspaceFolder}/include + Remove: [] + +Diagnostics: + ClangTidy: + Add: + - "*" + Remove: + - modernize-use-trailing-return-type + UnusedIncludes: Strict + +Index: + Background: Build +"@ + +$clangdPath = "..\.clangd" +$clangdContent | Out-File -FilePath $clangdPath -Encoding UTF8 diff --git a/gui/win32/scripts/build.ps1 b/gui/win32/scripts/build.ps1 new file mode 100644 index 0000000..a5c01e5 --- /dev/null +++ b/gui/win32/scripts/build.ps1 @@ -0,0 +1,87 @@ +$originalLocation = Get-Location +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $scriptPath + +. $scriptPath\_entry.ps1 + +$generator = "" +$arch = "x64" + +$vsPaths = @( + "C:\Program Files\Microsoft Visual Studio\2022\Community", + "C:\Program Files\Microsoft Visual Studio\2022\Professional", + "C:\Program Files\Microsoft Visual Studio\2022\Enterprise", + "C:\Program Files\Microsoft Visual Studio\2022\BuildTools", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" +) + +foreach ($path in $vsPaths) { + if (Test-Path $path) { + if ($path -match "2022") { + $generator = "Visual Studio 17 2022" + } elseif ($path -match "2019") { + $generator = "Visual Studio 16 2019" + } elseif ($path -match "2017") { + $generator = "Visual Studio 15 2017" + } + break + } +} + +if ([string]::IsNullOrEmpty($generator)) { + if (Get-Command ninja -ErrorAction SilentlyContinue) { + $generator = "Ninja" + } + elseif (Get-Command nmake -ErrorAction SilentlyContinue) { + $generator = "NMake Makefiles" + } + elseif (Get-Command mingw32-make -ErrorAction SilentlyContinue) { + $generator = "MinGW Makefiles" + } + else { + Write-Host "No suitable generator found. Please install Visual Studio or another build system." -ForegroundColor Red + exit 1 + } +} + +if (!(Test-Path -Path "..\build")) { + New-Item -ItemType Directory -Path "..\build" | Out-Null +} +Set-Location "..\build" + +if ($generator -match "Visual Studio") { + if ($generator -match "Visual Studio 15 2017") { + cmake .. -G "$generator" -A $arch + } else { + cmake .. -G "$generator" -A $arch + } +} else { + cmake .. -G "$generator" +} + +if ($LASTEXITCODE -ne 0) { + Write-Host "CMake configuration failed!" -ForegroundColor Red + Set-Location $originalLocation + exit 1 +} + +if ($generator -match "Visual Studio") { + cmake --build . --config Release +} else { + cmake --build . +} + +if ($LASTEXITCODE -ne 0) { + Write-Host "Build failed!" -ForegroundColor Red + Set-Location $originalLocation + exit 1 +} + +Set-Location $originalLocation diff --git a/gui/win32/scripts/clean.ps1 b/gui/win32/scripts/clean.ps1 new file mode 100644 index 0000000..59d9593 --- /dev/null +++ b/gui/win32/scripts/clean.ps1 @@ -0,0 +1,15 @@ +$originalLocation = Get-Location +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $scriptPath + +if (!(Test-Path -Path "..\build")) { + Set-Location $originalLocation + exit +} + +Remove-Item "..\build" -Recurse -Force -ErrorAction SilentlyContinue +if (Test-Path -Path "..\.clangd") { + Remove-Item "..\.clangd" -Recurse -Force -ErrorAction SilentlyContinue +} + +Set-Location $originalLocation diff --git a/gui/win32/scripts/run.ps1 b/gui/win32/scripts/run.ps1 new file mode 100644 index 0000000..a8f50e8 --- /dev/null +++ b/gui/win32/scripts/run.ps1 @@ -0,0 +1,10 @@ +$originalLocation = Get-Location +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $scriptPath + +$exePath = "..\build\bin\butck_gui.exe" +if (Test-Path $exePath) { + & $exePath +} + +Set-Location $originalLocation |
