forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.ps1
More file actions
90 lines (75 loc) · 3.31 KB
/
Copy pathBuild.ps1
File metadata and controls
90 lines (75 loc) · 3.31 KB
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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
<#
.SYNOPSIS
Simplifies build commands for the SFS Client.
.PARAMETER Clean
Use this to clean the build folder before building.
.PARAMETER BuildType
Use this to define the build type between "Debug" and "Release". The default is "Debug".
.PARAMETER EnableTestOverrides
Use this to enable test overrides.
.PARAMETER BuildTests
Use this to enable building tests. On by default.
.PARAMETER BuildSamples
Use this to enable building samples. On by default.
.DESCRIPTION
This script will contain the build commands for the SFS Client. The default build folder will be "<git_root>/build".
Use this on Windows platforms in a PowerShell session.
.EXAMPLE
PS> ./scripts/Build.ps1
#>
param (
[switch] $Clean = $false,
# BuildType is a build time parameter for Visual Studio generator in CMake
[ValidateSet("Debug", "Release")]
[string] $BuildType = "Debug",
# Make sure when adding a new switch below to check if it requires CMake regeneration
[switch] $EnableTestOverrides = $false,
[bool] $BuildTests = $true,
[bool] $BuildSamples = $true
)
$GitRoot = (Resolve-Path (&git -C $PSScriptRoot rev-parse --show-toplevel)).Path
if (!(Test-Path "$GitRoot\vcpkg"))
{
throw "vcpkg not found at $GitRoot\vcpkg. Run the Setup.ps1 script first."
}
$BuildFolder = "$GitRoot/build"
if ($Clean -and (Test-Path $BuildFolder))
{
Write-Host -ForegroundColor Yellow "Cleaning build folder before build..."
Remove-Item -Recurse -Force $BuildFolder
}
$Regenerate = $false
$CMakeCacheFile = "$BuildFolder\CMakeCache.txt"
$EnableTestOverridesStr = if ($EnableTestOverrides) {"ON"} else {"OFF"}
$BuildTestsOverridesStr = if ($BuildTests) {"ON"} else {"OFF"}
$BuildSamplesOverridesStr = if ($BuildSamples) {"ON"} else {"OFF"}
function Test-CMakeCacheValueNoMatch($CMakeCacheFile, $Pattern, $ExpectedValue)
{
$Match = Select-String -Path $CMakeCacheFile -Pattern $Pattern
if ($null -ne $Match -and $null -ne $Match.Matches.Groups[1])
{
return $ExpectedValue -ne $Match.Matches.Groups[1].Value
}
return $true
}
if (Test-Path $CMakeCacheFile)
{
# Regenerate if one of the build options is set to a different value than the one passed in
$Regenerate = Test-CMakeCacheValueNoMatch $CMakeCacheFile "^SFS_ENABLE_TEST_OVERRIDES:BOOL=(.*)$" $EnableTestOverridesStr
$Regenerate = Test-CMakeCacheValueNoMatch $CMakeCacheFile "^SFS_BUILD_TESTS:BOOL=(.*)$" $BuildTestsOverridesStr
$Regenerate = Test-CMakeCacheValueNoMatch $CMakeCacheFile "^SFS_BUILD_SAMPLES:BOOL=(.*)$" $BuildSamplesOverridesStr
}
# Configure cmake if build folder doesn't exist or if the build must be regenerated.
# This creates build targets that will be used by the build command
if (!(Test-Path $BuildFolder) -or $Regenerate)
{
$Options = "-DSFS_ENABLE_TEST_OVERRIDES=$EnableTestOverridesStr";
$Options += " -DSFS_BUILD_TESTS=$BuildTestsOverridesStr";
$Options += " -DSFS_BUILD_SAMPLES=$BuildSamplesOverridesStr";
$Options += " -DSFS_WINDOWS_STATIC_ONLY=ON";
Invoke-Expression "cmake -S $GitRoot -B $BuildFolder $Options"
}
# This is the build command. If any CMakeLists.txt files change, this will also reconfigure before building
cmake --build $BuildFolder --config $BuildType