Skip to content

Commit 9dbf81a

Browse files
committed
Join flags arguments
1 parent 36eee08 commit 9dbf81a

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

utils/build.ps1

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,10 +1815,21 @@ function Build-CMakeProject {
18151815
# Single token value, no need to quote spaces, the splat operator does the right thing.
18161816
$Value = $Define.Value.Replace("\", "/")
18171817
} else {
1818-
# Linker flags are escaped differently, depending on the CMake version.
1819-
$IsLinkerFlag = $Define.Key -match "_LINKER_FLAGS" -and ($Platform.OS -ne [OS]::Android)
1820-
18211818
# Flags array, multiple tokens, quoting needed for tokens containing spaces
1819+
$EscapedArgs = $Define.Value | ForEach-Object {
1820+
$Arg = $_.Replace("\", "/")
1821+
if ($Arg.Contains(" ")) {
1822+
# Escape the quote so it makes it through. PowerShell 5 and Core
1823+
# handle quotes differently, so we need to check the version.
1824+
$quote = if ($PSEdition -eq "Core") { '"' } else { '\"' }
1825+
"$quote$Arg$quote"
1826+
} else {
1827+
$Arg
1828+
}
1829+
}
1830+
1831+
# Linker flags are handled differently depending on the CMake version.
1832+
$IsLinkerFlag = $Define.Key -match "_LINKER_FLAGS" -and ($Platform.OS -ne [OS]::Android)
18221833
$Value = if ($IsLinkerFlag) {
18231834
if ($CMakeSupportsCMP0181) { "LINKER:" } elseif ($PrefixLinkerFlags) { "-Xlinker " } else { "" }
18241835
} else {
@@ -1830,26 +1841,8 @@ function Build-CMakeProject {
18301841
" "
18311842
}
18321843

1833-
$FirstArg = $true
1834-
foreach ($Arg in $Define.Value) {
1835-
if ($FirstArg) {
1836-
$FirstArg = $false
1837-
} else {
1838-
$Value += $Separator
1839-
}
1840-
1841-
$ArgWithForwardSlashes = $Arg.Replace("\", "/")
1842-
if ($ArgWithForwardSlashes.Contains(" ")) {
1843-
# Escape the quote so it makes it through. PowerShell 5 and Core
1844-
# handle quotes differently, so we need to check the version.
1845-
$quote = if ($PSEdition -eq "Core") { '"' } else { '\"' }
1846-
$Value += "$quote$ArgWithForwardSlashes$quote"
1847-
} else {
1848-
$Value += $ArgWithForwardSlashes
1849-
}
1850-
}
1844+
$Value += $EscapedArgs -join $Separator
18511845
}
1852-
18531846
$cmakeGenerateArgs += @("-D", "$($Define.Key)=$Value")
18541847
}
18551848

0 commit comments

Comments
 (0)