Last active
April 29, 2021 10:02
-
-
Save yipo/e70638aae454d95377cc96f936ba0840 to your computer and use it in GitHub Desktop.
Update the source file list of CMakeLists.txt under one directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = 'Stop' | |
function Get-SourceFiles ([String]$Dir) { | |
Push-Location $Dir | |
try { | |
Get-ChildItem . -File -Recurse | Where-Object { $_.Extension -match '^\.(c|cpp|h|hpp)$' } | Resolve-Path -Relative | ForEach-Object { $_.TrimStart('.\').Replace('\', '/') } | Sort-Object | |
} | |
finally { | |
Pop-Location | |
} | |
} | |
function Update-SourceFileList { | |
param ( | |
[Parameter(ValueFromPipeline)] | |
[String]$Line, | |
[String]$Dir = $PWD | |
) | |
begin { | |
$take = $true | |
} | |
process { | |
if ($take) { | |
$Line | |
$take = $Line -ne 'set(SOURCES' | |
} | |
elseif ($Line -eq ')') { | |
Get-SourceFiles $Dir | ForEach-Object { " $_" } | |
')' | |
$take = $true | |
} | |
} | |
} | |
function Update-CMakeLists ([String]$Dir) { | |
$file = Join-Path $Dir -ChildPath 'CMakeLists.txt' -Resolve | |
$content = Get-Content $file | Update-SourceFileList -Dir $Dir | |
Set-Content $file -Value $content | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment