winrtbuild.ps1 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. return ""
  60. }
  61. # Gets a string that identifies the build-variant of SDL/WinRT that is specific
  62. # to a particular Visual Studio PlatformToolset.
  63. function Get-SDL-WinRT-Variant-Name
  64. {
  65. param(
  66. [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
  67. # If true, append a string to this function's output, identifying the
  68. # build-variant's minimum-supported version of Visual Studio.
  69. [switch]$IncludeVSSuffix = $false
  70. )
  71. if ($PlatformToolset -eq "v110") { # Windows 8.0 (not Windows Phone), via VS 2012 project files
  72. if ($IncludeVSSuffix) {
  73. return "WinRT80_VS2012"
  74. } else {
  75. return "WinRT80"
  76. }
  77. }
  78. if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
  79. if ($IncludeVSSuffix) {
  80. return "WinPhone80_VS2012"
  81. } else {
  82. return "WinPhone80"
  83. }
  84. }
  85. if ($PlatformToolset -eq "v120") { # Windows 8.1 (not Windows Phone), via VS 2013 project files
  86. if ($IncludeVSSuffix) {
  87. return "WinRT81_VS2013"
  88. } else {
  89. return "WinRT81"
  90. }
  91. }
  92. if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
  93. if ($IncludeVSSuffix) {
  94. return "WinPhone81_VS2013"
  95. } else {
  96. return "WinPhone81"
  97. }
  98. }
  99. return ""
  100. }
  101. # Returns the internal name of a Visual Studio Project.
  102. #
  103. # The internal name of a VS Project is encoded inside the project file
  104. # itself, inside a set of <ProjectName></ProjectName> XML tags.
  105. function Get-VS-ProjectName
  106. {
  107. param(
  108. [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
  109. )
  110. # For now, just do a regex for the project name:
  111. $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
  112. foreach ($match in $matches) {
  113. if ($match.Groups.Count -ge 1) {
  114. return $match.Groups[1].Value
  115. }
  116. }
  117. return $null
  118. }
  119. # Build a specific variant of SDL/WinRT
  120. function Build-SDL-WinRT-Variant
  121. {
  122. #
  123. # Read in arguments:
  124. #
  125. param (
  126. # name of an SDL project file, minus extensions and
  127. # platform-identifying suffixes
  128. [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
  129. [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
  130. [Parameter(Mandatory=$true,Position=3)][string]$Platform
  131. )
  132. #
  133. # Derive other properties from read-in arguments:
  134. #
  135. # The .bat file to setup a platform-appropriate MSBuild environment:
  136. $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
  137. # The full path to the VS Project that'll be built:
  138. $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
  139. # The internal name of the VS Project, used in some post-build steps:
  140. $VSProjectName = Get-VS-ProjectName $VSProjectPath
  141. # Where to place output binaries (.dll, .lib, and .pdb files):
  142. $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$PlatformToolset\$Platform"
  143. # Where to place intermediate build files:
  144. $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
  145. #
  146. # Build the VS Project:
  147. #
  148. cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
  149. $BuildResult = $?
  150. #
  151. # Move .dll files into place. This fixes a problem whereby MSBuild may
  152. # put output files into a sub-directory of $OutDir, rather than $OutDir
  153. # itself.
  154. #
  155. if (Test-Path "$OutDir\$VSProjectName\") {
  156. Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
  157. }
  158. #
  159. # Clean up unneeded files in $OutDir:
  160. #
  161. if (Test-Path "$OutDir\$VSProjectName\") {
  162. Remove-Item -Recurse "$OutDir\$VSProjectName"
  163. }
  164. Remove-Item "$OutDir\*.exp"
  165. Remove-Item "$OutDir\*.ilk"
  166. Remove-Item "$OutDir\*.pri"
  167. #
  168. # All done. Indicate success, or failure, to the caller:
  169. #
  170. #echo "RESULT: $BuildResult" | Out-Host
  171. return $BuildResult
  172. }
  173. #
  174. # Build each variant, with corresponding .dll, .lib, and .pdb files:
  175. #
  176. $DidAnyFail = $false
  177. # Build for Windows Phone 8.0, via VC++ 2012:
  178. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM")) { $DidAnyFail = $true }
  179. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyFail = $true }
  180. # Build for Windows Phone 8.1, via VC++ 2013:
  181. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM")) { $DidAnyFail = $true }
  182. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyFail = $true }
  183. # Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
  184. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM")) { $DidAnyFail = $true }
  185. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32")) { $DidAnyFail = $true }
  186. if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64")) { $DidAnyFail = $true }
  187. # Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
  188. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM")) { $DidAnyFail = $true }
  189. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32")) { $DidAnyFail = $true }
  190. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64")) { $DidAnyFail = $true }
  191. # Let the script's caller know whether or not any errors occurred.
  192. # Exit codes compatible with Buildbot are used (1 for error, 0 for success).
  193. if ($DidAnyFail -eq $true) {
  194. exit 1
  195. } else {
  196. exit 0
  197. }