@@ -1815,10 +1815,21 @@ function Build-CMakeProject {
1815
1815
# Single token value, no need to quote spaces, the splat operator does the right thing.
1816
1816
$Value = $Define.Value.Replace (" \" , " /" )
1817
1817
} 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
-
1821
1818
# 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)
1822
1833
$Value = if ($IsLinkerFlag ) {
1823
1834
if ($CMakeSupportsCMP0181 ) { " LINKER:" } elseif ($PrefixLinkerFlags ) { " -Xlinker " } else { " " }
1824
1835
} else {
@@ -1830,26 +1841,8 @@ function Build-CMakeProject {
1830
1841
" "
1831
1842
}
1832
1843
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
1851
1845
}
1852
-
1853
1846
$cmakeGenerateArgs += @ (" -D" , " $ ( $Define.Key ) =$Value " )
1854
1847
}
1855
1848
0 commit comments