-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathllaunch.ps1
65 lines (57 loc) · 1.72 KB
/
llaunch.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
#
# generate, compile and run exe files
#
function getExePathFromCMakeLists()
{
$content = Get-Content -Path "./CMakeLists.txt"
$lastLine = ""
$contentContainedExeName = ""
foreach($line in $content)
{
if ($line.StartsWith("add_executable"))
{
$index = $line.IndexOf("(")
$contentContainedExeName = $line.Substring($index + 1)
if ([string]::IsNullOrEmpty($contentContainedExeName))
{
$lastLine = $line
continue
}
break
} elseif ($lastLine.StartsWith("add_executable"))
{
$contentContainedExeName = $line
break
}
$lastLine = $line
}
$result = -split $contentContainedExeName
$exePath = "./build/DEBUG/" + $result[0] + ".exe"
return $exePath
}
$currentDirectory = Get-Location
$cmakeListsPath = Join-Path -Path $currentDirectory -ChildPath "CMakeLists.txt"
if (-not (Test-Path $cmakeListsPath))
{
Write-Host("No CMakeLists.txt in current directory, please check.")
return
}
Write-Host "Start generating and compiling..."
$buildFolderPath = ".\build"
if (-not (Test-Path $buildFolderPath))
{
New-Item -ItemType Directory -Path $buildFolderPath | Out-Null
Write-Host "build folder created."
}
cmake -G "Visual Studio 17 2022" -A x64 -S . -B ./build/
if ($LASTEXITCODE -eq 0)
{
cmake --build ./build/ --config DEBUG
if ($LASTEXITCODE -eq 0)
{
$exePath = getExePathFromCMakeLists
Write-Host "start running as follows..."
Write-Host "=================================================="
Invoke-Expression $exePath
}
}