@@ -905,6 +905,7 @@ function Build-CMakeProject {
905905 [string []] $UsePinnedCompilers = @ (), # ASM,C,CXX,Swift
906906 [switch ] $UseSwiftSwiftDriver = $false ,
907907 [switch ] $AddAndroidCMakeEnv = $false ,
908+ [switch ] $UseGNUDriver = $false ,
908909 [string ] $SwiftSDK = " " ,
909910 [hashtable ] $Defines = @ {}, # Values are either single strings or arrays of flags
910911 [string []] $BuildTargets = @ ()
@@ -992,15 +993,19 @@ function Build-CMakeProject {
992993 $CFlags = @ ()
993994 switch ($Platform ) {
994995 Windows {
995- $CFlags = @ (" /GS-" , " /Gw" , " /Gy" , " /Oi" , " /Oy" , " /Zc:inline" )
996+ $CFlags = if ($UseGNUDriver ) {
997+ @ (" -fno-stack-protector" , " -ffunction-sections" , " -fdata-sections" , " -fomit-frame-pointer" )
998+ } else {
999+ @ (" /GS-" , " /Gw" , " /Gy" , " /Oi" , " /Oy" , " /Zc:inline" )
1000+ }
9961001 }
9971002 Android {
9981003 $CFlags = @ (" --sysroot=$ ( Get-AndroidNDKPath ) \toolchains\llvm\prebuilt\windows-x86_64\sysroot" )
9991004 }
10001005 }
10011006
10021007 $CXXFlags = @ ()
1003- if ($Platform -eq " Windows" ) {
1008+ if ($Platform -eq " Windows" -and -not $UseGNUDriver ) {
10041009 $CXXFlags += $CFlags.Clone () + @ (" /Zc:__cplusplus" )
10051010 }
10061011
@@ -1011,8 +1016,13 @@ function Build-CMakeProject {
10111016 Append- FlagsDefine $Defines CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded
10121017 Append- FlagsDefine $Defines CMAKE_POLICY_CMP0141 NEW
10131018 # Add additional linker flags for generating the debug info.
1014- Append- FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS " /debug"
1015- Append- FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS " /debug"
1019+ if ($UseGNUDriver ) {
1020+ Append- FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS " -Xlinker -debug"
1021+ Append- FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS " -Xlinker -debug"
1022+ } else {
1023+ Append- FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS " /debug"
1024+ Append- FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS " /debug"
1025+ }
10161026 } elseif ($Platform -eq " Android" ) {
10171027 # Use a built lld linker as the Android's NDK linker might be too
10181028 # old and not support all required relocations needed by the Swift
@@ -1050,7 +1060,7 @@ function Build-CMakeProject {
10501060 }
10511061 }
10521062 if ($UsePinnedCompilers.Contains (" C" ) -Or $UseBuiltCompilers.Contains (" C" )) {
1053- $Driver = if ($Platform -eq " Windows" ) { " clang-cl.exe" } else { " clang.exe" }
1063+ $Driver = if ($Platform -eq " Windows" -and -not $UseGNUDriver ) { " clang-cl.exe" } else { " clang.exe" }
10541064 if ($UseBuiltCompilers.Contains (" C" )) {
10551065 TryAdd- KeyValue $Defines CMAKE_C_COMPILER ([IO.Path ]::Combine($CompilersBinaryCache , " bin" , $Driver ))
10561066 } else {
@@ -1064,7 +1074,7 @@ function Build-CMakeProject {
10641074 Append- FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
10651075 }
10661076 if ($UsePinnedCompilers.Contains (" CXX" ) -Or $UseBuiltCompilers.Contains (" CXX" )) {
1067- $Driver = if ($Platform -eq " Windows" ) { " clang-cl.exe" } else { " clang++.exe" }
1077+ $Driver = if ($Platform -eq " Windows" -and -not $UseGNUDriver ) { " clang-cl.exe" } else { " clang++.exe" }
10681078 if ($UseBuiltCompilers.Contains (" CXX" )) {
10691079 TryAdd- KeyValue $Defines CMAKE_CXX_COMPILER ([IO.Path ]::Combine($CompilersBinaryCache , " bin" , $Driver ))
10701080 } else {
0 commit comments