winrtbuild.ps1 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #
  2. # winrtbuild.ps1 -- A Powershell script to build all SDL/WinRT variants,
  3. # across all WinRT platforms, in all of their supported, CPU architectures.
  4. #
  5. # Initial version written by David Ludwig <[email protected]>
  6. #
  7. # This script can be launched from Windows Explorer by double-clicking
  8. # on winrtbuild.bat
  9. #
  10. # Output will be placed in the following subdirectories of the SDL source
  11. # tree:
  12. # * VisualC-WinRT\lib\ -- final .dll, .lib, and .pdb files
  13. # * VisualC-WinRT\obj\ -- intermediate build files
  14. #
  15. # Recommended Dependencies:
  16. # * Windows 8.1 or higher
  17. # * Powershell 4.0 or higher (included as part of Windows 8.1)
  18. # * Visual C++ 2012, for building Windows 8.0 and Windows Phone 8.0 binaries.
  19. # * Visual C++ 2013, for building Windows 8.1 and Windows Phone 8.1 binaries
  20. # * SDKs for Windows 8.0, Windows 8.1, Windows Phone 8.0, and
  21. # Windows Phone 8.1, as needed
  22. #
  23. # Commom parameters/variables may include, but aren't strictly limited to:
  24. # * PlatformToolset: the name of one of Visual Studio's build platforms.
  25. # Different PlatformToolsets output different binaries. One
  26. # PlatformToolset exists for each WinRT platform. Possible values
  27. # may include:
  28. # - "v110": Visual Studio 2012 build tools, plus the Windows 8.0 SDK
  29. # - "v110_wp80": Visual Studio 2012 build tools, plus the Windows Phone 8.0 SDK
  30. # - "v120": Visual Studio 2013 build tools, plus the Windows 8.1 SDK
  31. # - "v120_wp81": Visual Studio 2013 build tools, plus the Windows Phone 8.1 SDK
  32. # * VSProjectPath: the full path to a Visual Studio or Visual C++ project file
  33. # * VSProjectName: the internal name of a Visual Studio or Visual C++ project
  34. # file. Some of Visual Studio's own build tools use this name when
  35. # calculating paths for build-output.
  36. # * Platform: a Visual Studio platform name, which often maps to a CPU
  37. # CPU architecture. Possible values may include: "Win32" (for 32-bit x86),
  38. # "ARM", or "x64" (for 64-bit x86).
  39. #
  40. # Gets the .bat file that sets up an MSBuild environment, given one of
  41. # Visual Studio's, "PlatformToolset"s.
  42. function Get-MSBuild-Env-Launcher
  43. {
  44. param(
  45. [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
  46. )
  47. if ($PlatformToolset -eq "v110") { # Windows 8.0 (not Windows Phone), via VS 2012
  48. return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
  49. }
  50. if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
  51. return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
  52. }
  53. if ($PlatformToolset -eq "v120") { # Windows 8.1 (not Windows Phone), via VS 2013
  54. return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
  55. }
  56. if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
  57. return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
  58. }
  59. if ($PlatformToolset -eq "v140") { # Windows 10, via VS 2015
  60. return "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
  61. }
  62. return ""
  63. }
  64. # Gets a string that identifies the build-variant of SDL/WinRT that is specific
  65. # to a particular Visual Studio PlatformToolset.
  66. function Get-SDL-WinRT-Variant-Name
  67. {
  68. param(
  69. [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
  70. # If true, append a string to this function's output, identifying the
  71. # build-variant's minimum-supported version of Visual Studio.
  72. [switch]$IncludeVSSuffix = $false
  73. )
  74. if ($PlatformToolset -eq "v110") { # Windows 8.0 (not Windows Phone), via VS 2012 project files
  75. if ($IncludeVSSuffix) {
  76. return "WinRT80_VS2012"
  77. } else {
  78. return "WinRT80"
  79. }
  80. }
  81. if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
  82. if ($IncludeVSSuffix) {
  83. return "WinPhone80_VS2012"
  84. } else {
  85. return "WinPhone80"
  86. }
  87. }
  88. if ($PlatformToolset -eq "v120") { # Windows 8.1 (not Windows Phone), via VS 2013 project files
  89. if ($IncludeVSSuffix) {
  90. return "WinRT81_VS2013"
  91. } else {
  92. return "WinRT81"
  93. }
  94. }
  95. if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
  96. if ($IncludeVSSuffix) {
  97. return "WinPhone81_VS2013"
  98. } else {
  99. return "WinPhone81"
  100. }
  101. }
  102. if ($PlatformToolset -eq "v140") { # Windows 10, via VS 2015 project files
  103. if ($IncludeVSSuffix) {
  104. return "UWP_VS2015"
  105. } else {
  106. return "UWP"
  107. }
  108. }
  109. return ""
  110. }
  111. # Returns the internal name of a Visual Studio Project.
  112. #
  113. # The internal name of a VS Project is encoded inside the project file
  114. # itself, inside a set of <ProjectName></ProjectName> XML tags.
  115. function Get-VS-ProjectName
  116. {
  117. param(
  118. [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
  119. )
  120. # For now, just do a regex for the project name:
  121. $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
  122. foreach ($match in $matches) {
  123. if ($match.Groups.Count -ge 1) {
  124. return $match.Groups[1].Value
  125. }
  126. }
  127. return $null
  128. }
  129. # Build a specific variant of SDL/WinRT
  130. function Build-SDL-WinRT-Variant
  131. {
  132. #
  133. # Read in arguments:
  134. #
  135. param (
  136. # name of an SDL project file, minus extensions and
  137. # platform-identifying suffixes
  138. [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
  139. [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
  140. [Parameter(Mandatory=$true,Position=3)][string]$Platform
  141. )
  142. #
  143. # Derive other properties from read-in arguments:
  144. #
  145. # The .bat file to setup a platform-appropriate MSBuild environment:
  146. $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
  147. # The full path to the VS Project that'll be built:
  148. $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
  149. # The internal name of the VS Project, used in some post-build steps:
  150. $VSProjectName = Get-VS-ProjectName $VSProjectPath
  151. # Where to place output binaries (.dll, .lib, and .pdb files):
  152. $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$PlatformToolset\$Platform"
  153. # Where to place intermediate build files:
  154. $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
  155. #
  156. # Build the VS Project:
  157. #
  158. cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Configuration=Release /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
  159. $BuildResult = $?
  160. #
  161. # Move .dll files into place. This fixes a problem whereby MSBuild may
  162. # put output files into a sub-directory of $OutDir, rather than $OutDir
  163. # itself.
  164. #
  165. if (Test-Path "$OutDir\$VSProjectName\") {
  166. Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
  167. }
  168. #
  169. # Clean up unneeded files in $OutDir:
  170. #
  171. if (Test-Path "$OutDir\$VSProjectName\") {
  172. Remove-Item -Recurse "$OutDir\$VSProjectName"
  173. }
  174. Remove-Item "$OutDir\*.exp"
  175. Remove-Item "$OutDir\*.ilk"
  176. Remove-Item "$OutDir\*.pri"
  177. #
  178. # All done. Indicate success, or failure, to the caller:
  179. #
  180. #echo "RESULT: $BuildResult" | Out-Host
  181. return $BuildResult
  182. }
  183. #
  184. # Build each variant, with corresponding .dll, .lib, and .pdb files:
  185. #
  186. $DidAnyFail = $false
  187. # Build for Windows Phone 8.0, via VC++ 2012:
  188. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM")) { $DidAnyFail = $true }
  189. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyFail = $true }
  190. # Build for Windows Phone 8.1, via VC++ 2013:
  191. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM")) { $DidAnyFail = $true }
  192. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyFail = $true }
  193. # Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
  194. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM")) { $DidAnyFail = $true }
  195. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32")) { $DidAnyFail = $true }
  196. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64")) { $DidAnyFail = $true }
  197. # Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
  198. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM")) { $DidAnyFail = $true }
  199. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32")) { $DidAnyFail = $true }
  200. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64")) { $DidAnyFail = $true }
  201. # Build for Windows 10, via VC++ 2015
  202. if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "ARM")) { $DidAnyFail = $true }
  203. if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "Win32")) { $DidAnyFail = $true }
  204. if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "x64")) { $DidAnyFail = $true }
  205. # Let the script's caller know whether or not any errors occurred.
  206. # Exit codes compatible with Buildbot are used (1 for error, 0 for success).
  207. if ($DidAnyFail -eq $true) {
  208. exit 1
  209. } else {
  210. exit 0
  211. }