build-scripts/winrtbuild.ps1
author David Ludwig <dludwig@pobox.com>
Mon, 30 Nov 2015 21:11:33 -0500
changeset 9935 93fd2ca0ed98
parent 9735 35d8f8976d32
child 9940 f2d5ed0d9686
permissions -rw-r--r--
WinRT: made WinRT build script create Win10/UWP .dll files
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@9216
    41
dludwig@9216
    42
# Gets the .bat file that sets up an MSBuild environment, given one of
dludwig@9216
    43
# Visual Studio's, "PlatformToolset"s.
dludwig@9216
    44
function Get-MSBuild-Env-Launcher
dludwig@9216
    45
{
dludwig@9216
    46
    param(
dludwig@9216
    47
        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
dludwig@9216
    48
    )
dludwig@9216
    49
dludwig@9216
    50
    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012
dludwig@9216
    51
        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
dludwig@9216
    52
    }
dludwig@9216
    53
    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
dludwig@9216
    54
        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
dludwig@9216
    55
    }
dludwig@9216
    56
    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013
dludwig@9216
    57
        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
dludwig@9216
    58
    }
dludwig@9216
    59
    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
dludwig@9216
    60
        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
dludwig@9216
    61
    }
dludwig@9935
    62
    if ($PlatformToolset -eq "v140") {      # Windows 10, via VS 2015
dludwig@9935
    63
        return "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
dludwig@9935
    64
    }
dludwig@9216
    65
    return ""
dludwig@9216
    66
}
dludwig@9216
    67
dludwig@9216
    68
# Gets a string that identifies the build-variant of SDL/WinRT that is specific
dludwig@9216
    69
# to a particular Visual Studio PlatformToolset.
dludwig@9216
    70
function Get-SDL-WinRT-Variant-Name
dludwig@9216
    71
{
dludwig@9216
    72
    param(
dludwig@9216
    73
        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
dludwig@9216
    74
dludwig@9216
    75
        # If true, append a string to this function's output, identifying the
dludwig@9216
    76
        # build-variant's minimum-supported version of Visual Studio.
dludwig@9216
    77
        [switch]$IncludeVSSuffix = $false
dludwig@9216
    78
    )
dludwig@9216
    79
dludwig@9216
    80
    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012 project files
dludwig@9216
    81
        if ($IncludeVSSuffix) {
dludwig@9216
    82
            return "WinRT80_VS2012"
dludwig@9216
    83
        } else {
dludwig@9216
    84
            return "WinRT80"
dludwig@9216
    85
        }
dludwig@9216
    86
    }
dludwig@9216
    87
    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
dludwig@9216
    88
        if ($IncludeVSSuffix) {
dludwig@9216
    89
            return "WinPhone80_VS2012"
dludwig@9216
    90
        } else {
dludwig@9216
    91
            return "WinPhone80"
dludwig@9216
    92
        }
dludwig@9216
    93
    }
dludwig@9216
    94
    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013 project files
dludwig@9216
    95
        if ($IncludeVSSuffix) {
dludwig@9216
    96
            return "WinRT81_VS2013"
dludwig@9216
    97
        } else {
dludwig@9216
    98
            return "WinRT81"
dludwig@9216
    99
        }
dludwig@9216
   100
    }
dludwig@9216
   101
    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
dludwig@9216
   102
        if ($IncludeVSSuffix) {
dludwig@9216
   103
            return "WinPhone81_VS2013"
dludwig@9216
   104
        } else {
dludwig@9216
   105
            return "WinPhone81"
dludwig@9216
   106
        }
dludwig@9216
   107
    }
dludwig@9935
   108
    if ($PlatformToolset -eq "v140") {      # Windows 10, via VS 2015 project files
dludwig@9935
   109
        if ($IncludeVSSuffix) {
dludwig@9935
   110
            return "UWP_VS2015"
dludwig@9935
   111
        } else {
dludwig@9935
   112
            return "UWP"
dludwig@9935
   113
        }
dludwig@9935
   114
    }
dludwig@9216
   115
    return ""
dludwig@9216
   116
}
dludwig@9216
   117
dludwig@9216
   118
# Returns the internal name of a Visual Studio Project.
dludwig@9216
   119
#
dludwig@9216
   120
# The internal name of a VS Project is encoded inside the project file
dludwig@9216
   121
# itself, inside a set of <ProjectName></ProjectName> XML tags.
dludwig@9216
   122
function Get-VS-ProjectName
dludwig@9216
   123
{
dludwig@9216
   124
    param(
dludwig@9216
   125
        [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
dludwig@9216
   126
    )
dludwig@9216
   127
dludwig@9216
   128
    # For now, just do a regex for the project name:
dludwig@9216
   129
    $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
dludwig@9216
   130
    foreach ($match in $matches) {
dludwig@9216
   131
        if ($match.Groups.Count -ge 1) {
dludwig@9216
   132
            return $match.Groups[1].Value
dludwig@9216
   133
        }
dludwig@9216
   134
    }
dludwig@9216
   135
    return $null
dludwig@9216
   136
}
dludwig@9216
   137
dludwig@9216
   138
# Build a specific variant of SDL/WinRT
dludwig@9216
   139
function Build-SDL-WinRT-Variant
dludwig@9216
   140
{
dludwig@9216
   141
    #
dludwig@9216
   142
    # Read in arguments:
dludwig@9216
   143
    #
dludwig@9216
   144
    param (
dludwig@9216
   145
        # name of an SDL project file, minus extensions and
dludwig@9216
   146
        # platform-identifying suffixes
dludwig@9216
   147
        [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
dludwig@9216
   148
dludwig@9216
   149
        [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
dludwig@9216
   150
dludwig@9216
   151
        [Parameter(Mandatory=$true,Position=3)][string]$Platform
dludwig@9216
   152
    )
dludwig@9216
   153
dludwig@9216
   154
    #
dludwig@9216
   155
    # Derive other properties from read-in arguments:
dludwig@9216
   156
    #
dludwig@9216
   157
dludwig@9216
   158
    # The .bat file to setup a platform-appropriate MSBuild environment:
dludwig@9216
   159
    $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
dludwig@9216
   160
dludwig@9216
   161
    # The full path to the VS Project that'll be built:
dludwig@9216
   162
    $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
dludwig@9216
   163
dludwig@9216
   164
    # The internal name of the VS Project, used in some post-build steps:
dludwig@9216
   165
    $VSProjectName = Get-VS-ProjectName $VSProjectPath
dludwig@9216
   166
dludwig@9216
   167
    # Where to place output binaries (.dll, .lib, and .pdb files):
dludwig@9216
   168
    $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$PlatformToolset\$Platform"
dludwig@9216
   169
dludwig@9216
   170
    # Where to place intermediate build files:
dludwig@9216
   171
    $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
dludwig@9216
   172
dludwig@9216
   173
    #
dludwig@9216
   174
    # Build the VS Project:
dludwig@9216
   175
    #
dludwig@9735
   176
    cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Configuration=Release /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
dludwig@9216
   177
    $BuildResult = $?
dludwig@9216
   178
dludwig@9216
   179
    #
dludwig@9216
   180
    # Move .dll files into place.  This fixes a problem whereby MSBuild may
dludwig@9216
   181
    # put output files into a sub-directory of $OutDir, rather than $OutDir
dludwig@9216
   182
    # itself.
dludwig@9216
   183
    #
dludwig@9216
   184
    if (Test-Path "$OutDir\$VSProjectName\") {
dludwig@9216
   185
        Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
dludwig@9216
   186
    }
dludwig@9216
   187
dludwig@9216
   188
    #
dludwig@9216
   189
    # Clean up unneeded files in $OutDir:
dludwig@9216
   190
    #
dludwig@9216
   191
    if (Test-Path "$OutDir\$VSProjectName\") {
dludwig@9216
   192
        Remove-Item -Recurse "$OutDir\$VSProjectName"
dludwig@9216
   193
    }
dludwig@9216
   194
    Remove-Item "$OutDir\*.exp"
dludwig@9216
   195
    Remove-Item "$OutDir\*.ilk"
dludwig@9216
   196
    Remove-Item "$OutDir\*.pri"
dludwig@9216
   197
dludwig@9216
   198
    #
dludwig@9216
   199
    # All done.  Indicate success, or failure, to the caller:
dludwig@9216
   200
    #
dludwig@9216
   201
    #echo "RESULT: $BuildResult" | Out-Host
dludwig@9216
   202
    return $BuildResult
dludwig@9216
   203
}
dludwig@9216
   204
dludwig@9216
   205
dludwig@9216
   206
#
dludwig@9216
   207
# Build each variant, with corresponding .dll, .lib, and .pdb files:
dludwig@9216
   208
#
dludwig@9216
   209
$DidAnyFail = $false
dludwig@9216
   210
dludwig@9216
   211
# Build for Windows Phone 8.0, via VC++ 2012:
dludwig@9216
   212
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyFail = $true }
dludwig@9216
   213
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyFail = $true }
dludwig@9216
   214
dludwig@9216
   215
# Build for Windows Phone 8.1, via VC++ 2013:
dludwig@9216
   216
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyFail = $true }
dludwig@9216
   217
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyFail = $true }
dludwig@9216
   218
dludwig@9216
   219
# Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
dludwig@9216
   220
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyFail = $true }
dludwig@9216
   221
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyFail = $true }
dludwig@9216
   222
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyFail = $true }
dludwig@9216
   223
dludwig@9216
   224
# Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
dludwig@9216
   225
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyFail = $true }
dludwig@9216
   226
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyFail = $true }
dludwig@9216
   227
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyFail = $true }
dludwig@9216
   228
dludwig@9935
   229
# Build for Windows 10, via VC++ 2015
dludwig@9935
   230
if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "ARM"))        { $DidAnyFail = $true }
dludwig@9935
   231
if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "Win32"))      { $DidAnyFail = $true }
dludwig@9935
   232
if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "x64"))        { $DidAnyFail = $true }
dludwig@9935
   233
dludwig@9216
   234
# Let the script's caller know whether or not any errors occurred.
dludwig@9216
   235
# Exit codes compatible with Buildbot are used (1 for error, 0 for success).
dludwig@9216
   236
if ($DidAnyFail -eq $true) {
dludwig@9216
   237
    exit 1
dludwig@9216
   238
} else {
dludwig@9216
   239
    exit 0
dludwig@9216
   240
}