31 lines
741 B
PowerShell
31 lines
741 B
PowerShell
# 定义项目和构建目录的变量
|
|
$projectDir = "$PSScriptRoot"
|
|
echo $projectDir
|
|
$buildDir = "$projectDir\build"
|
|
|
|
# 创建构建目录
|
|
if (-Not (Test-Path -Path $buildDir)) {
|
|
New-Item -ItemType Directory -Path $buildDir
|
|
}
|
|
|
|
# 进入构建目录
|
|
Set-Location -Path $buildDir
|
|
|
|
# 运行CMake生成构建系统
|
|
cmake -G "Visual Studio 17 2022" -T host=x64 ..
|
|
|
|
# 编译项目
|
|
cmake --build . --config Release
|
|
|
|
# 检查编译命令的退出代码
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "CMake build failed with exit code $LASTEXITCODE. Exiting script." -ForegroundColor Red
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
# 返回项目目录
|
|
Set-Location -Path $projectDir
|
|
|
|
# 打印构建完成的消息
|
|
Write-Host "build done." -ForegroundColor Darkgreen
|