Build.ps1 (3391B)
1 # Copyright (c) Microsoft Corporation. 2 # Licensed under the MIT License. 3 4 <# 5 .SYNOPSIS 6 Simplifies build commands for the SFS Client. 7 8 .PARAMETER Clean 9 Use this to clean the build folder before building. 10 11 .PARAMETER BuildType 12 Use this to define the build type between "Debug" and "Release". The default is "Debug". 13 14 .PARAMETER EnableTestOverrides 15 Use this to enable test overrides. 16 17 .PARAMETER BuildTests 18 Use this to enable building tests. On by default. 19 20 .PARAMETER BuildSamples 21 Use this to enable building samples. On by default. 22 23 .DESCRIPTION 24 This script will contain the build commands for the SFS Client. The default build folder will be "<git_root>/build". 25 Use this on Windows platforms in a PowerShell session. 26 27 .EXAMPLE 28 PS> ./scripts/Build.ps1 29 #> 30 param ( 31 [switch] $Clean = $false, 32 # BuildType is a build time parameter for Visual Studio generator in CMake 33 [ValidateSet("Debug", "Release")] 34 [string] $BuildType = "Debug", 35 # Make sure when adding a new switch below to check if it requires CMake regeneration 36 [switch] $EnableTestOverrides = $false, 37 [bool] $BuildTests = $true, 38 [bool] $BuildSamples = $true 39 ) 40 41 $GitRoot = (Resolve-Path (&git -C $PSScriptRoot rev-parse --show-toplevel)).Path 42 if (!(Test-Path "$GitRoot\vcpkg")) 43 { 44 throw "vcpkg not found at $GitRoot\vcpkg. Run the Setup.ps1 script first." 45 } 46 47 $BuildFolder = "$GitRoot/build" 48 if ($Clean -and (Test-Path $BuildFolder)) 49 { 50 Write-Host -ForegroundColor Yellow "Cleaning build folder before build..." 51 Remove-Item -Recurse -Force $BuildFolder 52 } 53 54 $Regenerate = $false 55 $CMakeCacheFile = "$BuildFolder\CMakeCache.txt" 56 $EnableTestOverridesStr = if ($EnableTestOverrides) {"ON"} else {"OFF"} 57 $BuildTestsOverridesStr = if ($BuildTests) {"ON"} else {"OFF"} 58 $BuildSamplesOverridesStr = if ($BuildSamples) {"ON"} else {"OFF"} 59 60 function Test-CMakeCacheValueNoMatch($CMakeCacheFile, $Pattern, $ExpectedValue) 61 { 62 $Match = Select-String -Path $CMakeCacheFile -Pattern $Pattern 63 if ($null -ne $Match -and $null -ne $Match.Matches.Groups[1]) 64 { 65 return $ExpectedValue -ne $Match.Matches.Groups[1].Value 66 } 67 return $true 68 } 69 70 if (Test-Path $CMakeCacheFile) 71 { 72 # Regenerate if one of the build options is set to a different value than the one passed in 73 $Regenerate = Test-CMakeCacheValueNoMatch $CMakeCacheFile "^SFS_ENABLE_TEST_OVERRIDES:BOOL=(.*)$" $EnableTestOverridesStr 74 $Regenerate = Test-CMakeCacheValueNoMatch $CMakeCacheFile "^SFS_BUILD_TESTS:BOOL=(.*)$" $BuildTestsOverridesStr 75 $Regenerate = Test-CMakeCacheValueNoMatch $CMakeCacheFile "^SFS_BUILD_SAMPLES:BOOL=(.*)$" $BuildSamplesOverridesStr 76 } 77 78 # Configure cmake if build folder doesn't exist or if the build must be regenerated. 79 # This creates build targets that will be used by the build command 80 if (!(Test-Path $BuildFolder) -or $Regenerate) 81 { 82 $Options = "-DSFS_ENABLE_TEST_OVERRIDES=$EnableTestOverridesStr"; 83 $Options += " -DSFS_BUILD_TESTS=$BuildTestsOverridesStr"; 84 $Options += " -DSFS_BUILD_SAMPLES=$BuildSamplesOverridesStr"; 85 $Options += " -DSFS_WINDOWS_STATIC_ONLY=ON"; 86 Invoke-Expression "cmake -S $GitRoot -B $BuildFolder $Options" 87 } 88 89 # This is the build command. If any CMakeLists.txt files change, this will also reconfigure before building 90 cmake --build $BuildFolder --config $BuildType