-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-srt.ps1
206 lines (180 loc) · 6.98 KB
/
build-srt.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#-----------------------------------------------------------------------------
#
# SRT library build procedures for Windows
# Copyright (c) 2020, Thierry Lelegard
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
#-----------------------------------------------------------------------------
<#
.SYNOPSIS
Build the SRT library for Windows.
.PARAMETER BareVersion
Use the "bare version" number from libsrt (in file version.h). This is the
most recent official version number. Since there are likely some commits
in the libsrt repository since the last commit, this may not be the most
appropriate version number. By default, use a detailed version number
(most recent version, number of commits since then, short commit SHA).
.PARAMETER NoPause
Do not wait for the user to press <enter> at end of execution. By default,
execute a "pause" instruction at the end of execution, which is useful
when the script was run from Windows Explorer.
.PARAMETER Tag
Specify the got tag or commit to build. By default, use the latest repo
state.
#>
[CmdletBinding()]
param(
[switch]$BareVersion = $false,
[switch]$NoPause = $false,
[string]$Tag = ""
)
Write-Output "SRT build procedure"
$RepoUrl = "https://github.com/Haivision/srt.git"
# A function to exit this script.
function Exit-Script([string]$Message = "")
{
$Code = 0
if ($Message -ne "") {
Write-Output "ERROR: $Message"
$Code = 1
}
if (-not $NoPause) {
pause
}
exit $Code
}
# Local file names.
$RootDir = $PSScriptRoot
$ExtDir = "$RootDir\external"
$RepoDir = "$ExtDir\srt"
# Create the directory for external products when necessary.
[void](New-Item -Path $ExtDir -ItemType Directory -Force)
# Locate OpenSSL root from local installation.
$SslRoot = @{
"x64" = "C:\Program Files\OpenSSL-Win64";
"Win32" = "C:\Program Files (x86)\OpenSSL-Win32"
}
# Verify a few files.
$Missing = 0
foreach ($file in @($SslRoot["x64"], $SslRoot["Win32"])) {
if (-not (Test-Path $file)) {
Write-Output "**** Missing $file"
$Missing = $Missing + 1
}
}
if ($Missing -gt 0) {
Exit-Script "Missing $Missing files"
}
# Clone repository or update it.
# Note that git outputs its log on stderr, so use --quiet.
if (Test-Path "$RepoDir\.git") {
# The repo is already cloned, just update it.
Write-Output "Updating repository ..."
Push-Location $RepoDir
git checkout master --quiet
git pull origin master
Pop-Location
}
else {
# Clone the repo.
Write-Output "Cloning $RepoUrl ..."
git clone --quiet $RepoUrl $RepoDir
if (-not (Test-Path "$RepoDir\.git")) {
Exit-Script "Failed to clone $RepoUrl"
}
}
# Checkout the required tag.
if ($Tag.Length -gt 0) {
Write-Output "Checking out $Tag ..."
Push-Location $RepoDir
git checkout --quiet $Tag
Pop-Location
# Cleanup build areas to force a fresh cmake config.
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "$RepoDir.build.x64"
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "$RepoDir.build.Win32"
}
# Build the version number.
$Version = (& "$PSScriptRoot\get-srt-version.ps1" -BareVersion:$BareVersion)
Write-Output "==> SRT version is $Version"
# Locate MSBuild and CMake, regardless of Visual Studio version.
Write-Output "Searching MSBuild and CMake ..."
$MSRoots = @("C:\Program Files*\MSBuild", "C:\Program Files*\Microsoft Visual Studio", "C:\Program Files*\CMake*")
$MSBuild = Get-ChildItem -Recurse -Path $MSRoots -Include MSBuild.exe -ErrorAction Ignore |
ForEach-Object { (Get-Command $_).FileVersionInfo } |
Sort-Object -Unique -Property FileVersion |
ForEach-Object { $_.FileName} |
Select-Object -Last 1
if (-not $MSBuild) {
Exit-Script "MSBuild not found"
}
$CMake = Get-ChildItem -Recurse -Path $MSRoots -Include cmake.exe -ErrorAction Ignore |
ForEach-Object { (Get-Command $_).FileVersionInfo } |
Sort-Object -Unique -Property FileVersion |
ForEach-Object { $_.FileName} |
Select-Object -Last 1
if (-not $CMake) {
Exit-Script "CMake not found"
}
# Configure and build SRT library using CMake on two architectures.
foreach ($Platform in @("x64", "Win32")) {
# Build directory:
$SrtBuildDir = "$RepoDir.build.$Platform"
[void](New-Item -Path $SrtBuildDir -ItemType Directory -Force)
Write-Output "Configuring build for platform $Platform ..."
$SRoot = $SslRoot[$Platform]
& $CMake -S $RepoDir -B $SrtBuildDir -A $Platform `
-DENABLE_STDCXX_SYNC=ON `
-DOPENSSL_ROOT_DIR="$SRoot" `
-DOPENSSL_LIBRARIES="$SRoot\lib\libssl_static.lib;$SRoot\lib\libcrypto_static.lib" `
-DOPENSSL_INCLUDE_DIR="$SRoot\include"
# Patch version string in version.h
if (-not $BareVersion) {
Get-Content "$SrtBuildDir\version.h" |
ForEach-Object {
$_ -replace "#define *SRT_VERSION_STRING .*","#define SRT_VERSION_STRING `"$Version`""
} |
Out-File "$SrtBuildDir\version.new" -Encoding ascii
Move-Item "$SrtBuildDir\version.new" "$SrtBuildDir\version.h" -Force
}
Write-Output "Building for platform $Platform ..."
foreach ($Conf in @("Release", "Debug")) {
& $MSBuild "$SrtBuildDir\SRT.sln" /nologo /maxcpucount /property:Configuration=$Conf /property:Platform=$Platform /target:srt_static
}
}
# Verify the presence of compiled libraries.
Write-Output "Checking compiled libraries ..."
$Missing = 0
foreach ($Conf in @("Release", "Debug")) {
foreach ($Platform in @("x64", "Win32")) {
$Path = "$RepoDir.build.$Platform\$Conf\srt_static.lib"
if (-not (Test-Path $Path)) {
Write-Output "**** Missing $Path"
$Missing = $Missing + 1
}
}
}
if ($Missing -gt 0) {
Exit-Script "Missing $Missing files"
}
Exit-Script