build-scripts/winrtbuild.ps1
author Sam Lantinga
Thu, 01 Sep 2016 01:26:56 -0700
changeset 10304 ee83e0b4a36f
parent 9942 e82bfd942409
child 10911 1863707d9df8
permissions -rw-r--r--
wayland: Add support for relative mouse mode, by Jonas Ã…dahl <jadahl@gmail.com>

Generate the C protocol files from the protocol XML files installed by
wayland-protocols, and use them to implement support for relative pointer
motions and pointer locking.

Note that at the time, the protocol is unstable and may change in the future.
Any future breaking changes will, however, fail gracefully and result in no
regressions compared to before this patch.
dludwig@9216
     1
#
dludwig@9217
     2
# winrtbuild.ps1 -- A Powershell script to build all SDL/WinRT variants,
dludwig@9216
     3
#    across all WinRT platforms, in all of their supported, CPU architectures.
dludwig@9216
     4
#
dludwig@9216
     5
# Initial version written by David Ludwig <dludwig@pobox.com>
dludwig@9216
     6
#
dludwig@9216
     7
# This script can be launched from Windows Explorer by double-clicking
dludwig@9217
     8
# on winrtbuild.bat
dludwig@9216
     9
#
dludwig@9216
    10
# Output will be placed in the following subdirectories of the SDL source
dludwig@9216
    11
# tree:
dludwig@9216
    12
#   * VisualC-WinRT\lib\  -- final .dll, .lib, and .pdb files
dludwig@9216
    13
#   * VisualC-WinRT\obj\  -- intermediate build files
dludwig@9216
    14
#
dludwig@9216
    15
# Recommended Dependencies:
dludwig@9216
    16
#   * Windows 8.1 or higher
dludwig@9216
    17
#   * Powershell 4.0 or higher (included as part of Windows 8.1)
dludwig@9216
    18
#   * Visual C++ 2012, for building Windows 8.0 and Windows Phone 8.0 binaries.
dludwig@9216
    19
#   * Visual C++ 2013, for building Windows 8.1 and Windows Phone 8.1 binaries
dludwig@9216
    20
#   * SDKs for Windows 8.0, Windows 8.1, Windows Phone 8.0, and
dludwig@9216
    21
#     Windows Phone 8.1, as needed
dludwig@9216
    22
#
dludwig@9216
    23
# Commom parameters/variables may include, but aren't strictly limited to:
dludwig@9216
    24
#   * PlatformToolset: the name of one of Visual Studio's build platforms.
dludwig@9216
    25
#     Different PlatformToolsets output different binaries.  One
dludwig@9216
    26
#     PlatformToolset exists for each WinRT platform.  Possible values
dludwig@9216
    27
#     may include:
dludwig@9216
    28
#       - "v110": Visual Studio 2012 build tools, plus the Windows 8.0 SDK
dludwig@9216
    29
#       - "v110_wp80": Visual Studio 2012 build tools, plus the Windows Phone 8.0 SDK
dludwig@9216
    30
#       - "v120": Visual Studio 2013 build tools, plus the Windows 8.1 SDK
dludwig@9216
    31
#       - "v120_wp81": Visual Studio 2013 build tools, plus the Windows Phone 8.1 SDK
dludwig@9216
    32
#   * VSProjectPath: the full path to a Visual Studio or Visual C++ project file
dludwig@9216
    33
#   * VSProjectName: the internal name of a Visual Studio or Visual C++ project
dludwig@9216
    34
#     file.  Some of Visual Studio's own build tools use this name when
dludwig@9216
    35
#     calculating paths for build-output.
dludwig@9216
    36
#   * Platform: a Visual Studio platform name, which often maps to a CPU
dludwig@9216
    37
#     CPU architecture.  Possible values may include: "Win32" (for 32-bit x86),
dludwig@9216
    38
#     "ARM", or "x64" (for 64-bit x86).
dludwig@9216
    39
#
dludwig@9216
    40
dludwig@9940
    41
# Base version of SDL, used for packaging purposes
dludwig@9940
    42
$SDLVersion = "2.0.4"
dludwig@9216
    43
dludwig@9216
    44
# Gets the .bat file that sets up an MSBuild environment, given one of
dludwig@9216
    45
# Visual Studio's, "PlatformToolset"s.
dludwig@9216
    46
function Get-MSBuild-Env-Launcher
dludwig@9216
    47
{
dludwig@9216
    48
    param(
dludwig@9216
    49
        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
dludwig@9216
    50
    )
dludwig@9216
    51
dludwig@9216
    52
    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012
dludwig@9216
    53
        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
dludwig@9216
    54
    }
dludwig@9216
    55
    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
dludwig@9216
    56
        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
dludwig@9216
    57
    }
dludwig@9216
    58
    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013
dludwig@9216
    59
        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
dludwig@9216
    60
    }
dludwig@9216
    61
    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
dludwig@9216
    62
        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
dludwig@9216
    63
    }
dludwig@9935
    64
    if ($PlatformToolset -eq "v140") {      # Windows 10, via VS 2015
dludwig@9935
    65
        return "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
dludwig@9935
    66
    }
dludwig@9216
    67
    return ""
dludwig@9216
    68
}
dludwig@9216
    69
dludwig@9216
    70
# Gets a string that identifies the build-variant of SDL/WinRT that is specific
dludwig@9216
    71
# to a particular Visual Studio PlatformToolset.
dludwig@9216
    72
function Get-SDL-WinRT-Variant-Name
dludwig@9216
    73
{
dludwig@9216
    74
    param(
dludwig@9216
    75
        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
dludwig@9216
    76
dludwig@9216
    77
        # If true, append a string to this function's output, identifying the
dludwig@9216
    78
        # build-variant's minimum-supported version of Visual Studio.
dludwig@9216
    79
        [switch]$IncludeVSSuffix = $false
dludwig@9216
    80
    )
dludwig@9216
    81
dludwig@9216
    82
    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012 project files
dludwig@9216
    83
        if ($IncludeVSSuffix) {
dludwig@9216
    84
            return "WinRT80_VS2012"
dludwig@9216
    85
        } else {
dludwig@9216
    86
            return "WinRT80"
dludwig@9216
    87
        }
dludwig@9216
    88
    }
dludwig@9216
    89
    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
dludwig@9216
    90
        if ($IncludeVSSuffix) {
dludwig@9216
    91
            return "WinPhone80_VS2012"
dludwig@9216
    92
        } else {
dludwig@9216
    93
            return "WinPhone80"
dludwig@9216
    94
        }
dludwig@9216
    95
    }
dludwig@9216
    96
    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013 project files
dludwig@9216
    97
        if ($IncludeVSSuffix) {
dludwig@9216
    98
            return "WinRT81_VS2013"
dludwig@9216
    99
        } else {
dludwig@9216
   100
            return "WinRT81"
dludwig@9216
   101
        }
dludwig@9216
   102
    }
dludwig@9216
   103
    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
dludwig@9216
   104
        if ($IncludeVSSuffix) {
dludwig@9216
   105
            return "WinPhone81_VS2013"
dludwig@9216
   106
        } else {
dludwig@9216
   107
            return "WinPhone81"
dludwig@9216
   108
        }
dludwig@9216
   109
    }
dludwig@9935
   110
    if ($PlatformToolset -eq "v140") {      # Windows 10, via VS 2015 project files
dludwig@9935
   111
        if ($IncludeVSSuffix) {
dludwig@9935
   112
            return "UWP_VS2015"
dludwig@9935
   113
        } else {
dludwig@9935
   114
            return "UWP"
dludwig@9935
   115
        }
dludwig@9935
   116
    }
dludwig@9216
   117
    return ""
dludwig@9216
   118
}
dludwig@9216
   119
dludwig@9216
   120
# Returns the internal name of a Visual Studio Project.
dludwig@9216
   121
#
dludwig@9216
   122
# The internal name of a VS Project is encoded inside the project file
dludwig@9216
   123
# itself, inside a set of <ProjectName></ProjectName> XML tags.
dludwig@9216
   124
function Get-VS-ProjectName
dludwig@9216
   125
{
dludwig@9216
   126
    param(
dludwig@9216
   127
        [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
dludwig@9216
   128
    )
dludwig@9216
   129
dludwig@9216
   130
    # For now, just do a regex for the project name:
dludwig@9216
   131
    $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
dludwig@9216
   132
    foreach ($match in $matches) {
dludwig@9216
   133
        if ($match.Groups.Count -ge 1) {
dludwig@9216
   134
            return $match.Groups[1].Value
dludwig@9216
   135
        }
dludwig@9216
   136
    }
dludwig@9216
   137
    return $null
dludwig@9216
   138
}
dludwig@9216
   139
dludwig@9216
   140
# Build a specific variant of SDL/WinRT
dludwig@9216
   141
function Build-SDL-WinRT-Variant
dludwig@9216
   142
{
dludwig@9216
   143
    #
dludwig@9216
   144
    # Read in arguments:
dludwig@9216
   145
    #
dludwig@9216
   146
    param (
dludwig@9216
   147
        # name of an SDL project file, minus extensions and
dludwig@9216
   148
        # platform-identifying suffixes
dludwig@9216
   149
        [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
dludwig@9216
   150
dludwig@9216
   151
        [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
dludwig@9216
   152
dludwig@9216
   153
        [Parameter(Mandatory=$true,Position=3)][string]$Platform
dludwig@9216
   154
    )
dludwig@9216
   155
dludwig@9216
   156
    #
dludwig@9216
   157
    # Derive other properties from read-in arguments:
dludwig@9216
   158
    #
dludwig@9216
   159
dludwig@9216
   160
    # The .bat file to setup a platform-appropriate MSBuild environment:
dludwig@9216
   161
    $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
dludwig@9216
   162
dludwig@9216
   163
    # The full path to the VS Project that'll be built:
dludwig@9216
   164
    $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
dludwig@9216
   165
dludwig@9216
   166
    # The internal name of the VS Project, used in some post-build steps:
dludwig@9216
   167
    $VSProjectName = Get-VS-ProjectName $VSProjectPath
dludwig@9216
   168
dludwig@9216
   169
    # Where to place output binaries (.dll, .lib, and .pdb files):
dludwig@9940
   170
    $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
dludwig@9216
   171
dludwig@9216
   172
    # Where to place intermediate build files:
dludwig@9216
   173
    $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
dludwig@9216
   174
dludwig@9216
   175
    #
dludwig@9216
   176
    # Build the VS Project:
dludwig@9216
   177
    #
dludwig@9735
   178
    cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Configuration=Release /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
dludwig@9216
   179
    $BuildResult = $?
dludwig@9216
   180
dludwig@9216
   181
    #
dludwig@9216
   182
    # Move .dll files into place.  This fixes a problem whereby MSBuild may
dludwig@9216
   183
    # put output files into a sub-directory of $OutDir, rather than $OutDir
dludwig@9216
   184
    # itself.
dludwig@9216
   185
    #
dludwig@9216
   186
    if (Test-Path "$OutDir\$VSProjectName\") {
dludwig@9216
   187
        Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
dludwig@9216
   188
    }
dludwig@9216
   189
dludwig@9216
   190
    #
dludwig@9216
   191
    # Clean up unneeded files in $OutDir:
dludwig@9216
   192
    #
dludwig@9216
   193
    if (Test-Path "$OutDir\$VSProjectName\") {
dludwig@9216
   194
        Remove-Item -Recurse "$OutDir\$VSProjectName"
dludwig@9216
   195
    }
dludwig@9216
   196
    Remove-Item "$OutDir\*.exp"
dludwig@9216
   197
    Remove-Item "$OutDir\*.ilk"
dludwig@9216
   198
    Remove-Item "$OutDir\*.pri"
dludwig@9216
   199
dludwig@9216
   200
    #
dludwig@9216
   201
    # All done.  Indicate success, or failure, to the caller:
dludwig@9216
   202
    #
dludwig@9216
   203
    #echo "RESULT: $BuildResult" | Out-Host
dludwig@9216
   204
    return $BuildResult
dludwig@9216
   205
}
dludwig@9216
   206
dludwig@9216
   207
dludwig@9216
   208
#
dludwig@9216
   209
# Build each variant, with corresponding .dll, .lib, and .pdb files:
dludwig@9216
   210
#
dludwig@9940
   211
$DidAnyDLLBuildFail = $false
dludwig@9940
   212
$DidAnyNugetBuildFail = $false
dludwig@9216
   213
dludwig@9216
   214
# Build for Windows Phone 8.0, via VC++ 2012:
dludwig@9940
   215
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyDLLBuildFail = $true }
dludwig@9940
   216
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyDLLBuildFail = $true }
dludwig@9216
   217
dludwig@9216
   218
# Build for Windows Phone 8.1, via VC++ 2013:
dludwig@9940
   219
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyDLLBuildFail = $true }
dludwig@9940
   220
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyDLLBuildFail = $true }
dludwig@9216
   221
dludwig@9216
   222
# Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
dludwig@9940
   223
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyDLLBuildFail = $true }
dludwig@9940
   224
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyDLLBuildFail = $true }
dludwig@9940
   225
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyDLLBuildFail = $true }
dludwig@9216
   226
dludwig@9216
   227
# Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
dludwig@9940
   228
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyDLLBuildFail = $true }
dludwig@9940
   229
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyDLLBuildFail = $true }
dludwig@9940
   230
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyDLLBuildFail = $true }
dludwig@9216
   231
dludwig@9935
   232
# Build for Windows 10, via VC++ 2015
dludwig@9940
   233
if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "ARM"))        { $DidAnyDLLBuildFail = $true }
dludwig@9940
   234
if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "Win32"))      { $DidAnyDLLBuildFail = $true }
dludwig@9940
   235
if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "x64"))        { $DidAnyDLLBuildFail = $true }
dludwig@9940
   236
dludwig@9940
   237
# Build NuGet packages, if possible
dludwig@9940
   238
if ($DidAnyDLLBuildFail -eq $true) {
dludwig@9940
   239
    Write-Warning -Message "Unable to build all variants.  NuGet packages will not be built."
dludwig@9940
   240
    $DidAnyNugetBuildFail = $true
dludwig@9940
   241
} else {
dludwig@9940
   242
    $NugetPath = (Get-Command -CommandType Application nuget.exe | %{$_.Path}) 2> $null
dludwig@9940
   243
    if ("$NugetPath" -eq "") {
dludwig@9940
   244
        Write-Warning -Message "Unable to find nuget.exe.  NuGet packages will not be built."
dludwig@9940
   245
        $DidAnyNugetBuildFail = $true
dludwig@9940
   246
    } else {
dludwig@9940
   247
        Write-Host -ForegroundColor Cyan "Building SDL2 NuGet packages..."
dludwig@9940
   248
        Write-Host -ForegroundColor Cyan "... via NuGet install: $NugetPath"
dludwig@9940
   249
        $NugetOutputDir = "$PSScriptRoot\..\VisualC-WinRT\lib\nuget"
dludwig@9940
   250
        Write-Host -ForegroundColor Cyan "...  output directory: $NugetOutputDir"
dludwig@9941
   251
        $SDLHGRevision = $($(hg log -l 1 --repository "$PSScriptRoot\.." | select-string "changeset") -Replace "changeset:\W*(\d+).*",'$1') 2>$null
dludwig@9940
   252
        Write-Host -ForegroundColor Cyan "...       HG Revision: $SDLHGRevision"
dludwig@9940
   253
dludwig@9940
   254
        # Base options to nuget.exe
dludwig@9940
   255
        $NugetOptions = @("pack", "PACKAGE_NAME_WILL_GO_HERE", "-Output", "$NugetOutputDir")
dludwig@9940
   256
dludwig@9940
   257
        # Try attaching hg revision to NuGet package:
dludwig@9940
   258
        $NugetOptions += "-Version"
dludwig@9940
   259
        if ("$SDLHGRevision" -eq "") {
dludwig@9940
   260
            Write-Warning -Message "Unable to find the Mercurial revision (maybe hg.exe can't be found?).  NuGet packages will not have this attached to their name."
dludwig@9940
   261
            $NugetOptions += "$SDLVersion-Unofficial"
dludwig@9940
   262
        } else {
dludwig@9940
   263
            $NugetOptions += "$SDLVersion.$SDLHGRevision-Unofficial"
dludwig@9940
   264
        }
dludwig@9940
   265
dludwig@9940
   266
        # Create NuGet output dir, if not yet created:
dludwig@9940
   267
        if ($(Test-Path "$NugetOutputDir") -eq $false) {
dludwig@9940
   268
            New-Item "$NugetOutputDir" -type directory
dludwig@9940
   269
        }
dludwig@9940
   270
dludwig@9940
   271
        # Package SDL2:
dludwig@9940
   272
        $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2-WinRT.nuspec"
dludwig@9940
   273
        &"$NugetPath" $NugetOptions -Symbols
dludwig@9940
   274
        if ( ! $? ) { $DidAnyNugetBuildFail = $true }
dludwig@9940
   275
dludwig@9940
   276
        # Package SDL2main:
dludwig@9942
   277
        $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2main-WinRT-NonXAML.nuspec"
dludwig@9940
   278
        &"$NugetPath" $NugetOptions
dludwig@9940
   279
        if ( ! $? ) { $DidAnyNugetBuildFail = $true }
dludwig@9940
   280
    }
dludwig@9940
   281
}
dludwig@9940
   282
dludwig@9935
   283
dludwig@9216
   284
# Let the script's caller know whether or not any errors occurred.
dludwig@9216
   285
# Exit codes compatible with Buildbot are used (1 for error, 0 for success).
dludwig@9940
   286
if ($DidAnyDLLBuildFail -eq $true) {
dludwig@9940
   287
    Write-Error -Message "Unable to build all known variants of SDL2 for WinRT"
dludwig@9216
   288
    exit 1
dludwig@9940
   289
} elseif ($DidAnyNugetBuildFail -eq $true) {
dludwig@9940
   290
    Write-Warning -Message "Unable to build NuGet packages"
dludwig@9940
   291
    exit 0  # Should NuGet package build failure lead to a non-failing result code instead?
dludwig@9216
   292
} else {
dludwig@9216
   293
    exit 0
dludwig@9216
   294
}