Build-Windows.ps1 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. [CmdletBinding()]
  2. param(
  3. [ValidateSet('x64')]
  4. [string] $Target = 'x64',
  5. [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')]
  6. [string] $Configuration = 'RelWithDebInfo',
  7. [switch] $SkipAll,
  8. [switch] $SkipBuild,
  9. [switch] $SkipDeps
  10. )
  11. $ErrorActionPreference = 'Stop'
  12. if ( $DebugPreference -eq 'Continue' ) {
  13. $VerbosePreference = 'Continue'
  14. $InformationPreference = 'Continue'
  15. }
  16. if ( ! ( [System.Environment]::Is64BitOperatingSystem ) ) {
  17. throw "A 64-bit system is required to build the project."
  18. }
  19. if ( $PSVersionTable.PSVersion -lt '7.0.0' ) {
  20. Write-Warning 'The obs-deps PowerShell build script requires PowerShell Core 7. Install or upgrade your PowerShell version: https://aka.ms/pscore6'
  21. exit 2
  22. }
  23. function Build {
  24. trap {
  25. Pop-Location -Stack BuildTemp -ErrorAction 'SilentlyContinue'
  26. Write-Error $_
  27. Log-Group
  28. exit 2
  29. }
  30. $ScriptHome = $PSScriptRoot
  31. $ProjectRoot = Resolve-Path -Path "$PSScriptRoot/../.."
  32. $BuildSpecFile = "${ProjectRoot}/buildspec.json"
  33. $UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse
  34. foreach($Utility in $UtilityFunctions) {
  35. Write-Debug "Loading $($Utility.FullName)"
  36. . $Utility.FullName
  37. }
  38. $BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json
  39. $ProductName = $BuildSpec.name
  40. $ProductVersion = $BuildSpec.version
  41. if ( ! $SkipDeps ) {
  42. Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"
  43. }
  44. Push-Location -Stack BuildTemp
  45. if ( ! ( ( $SkipAll ) -or ( $SkipBuild ) ) ) {
  46. Ensure-Location $ProjectRoot
  47. $CmakeArgs = @()
  48. $CmakeBuildArgs = @()
  49. $CmakeInstallArgs = @()
  50. if ( $VerbosePreference -eq 'Continue' ) {
  51. $CmakeBuildArgs += ('--verbose')
  52. $CmakeInstallArgs += ('--verbose')
  53. }
  54. if ( $DebugPreference -eq 'Continue' ) {
  55. $CmakeArgs += ('--debug-output')
  56. }
  57. $Preset = "windows-$(if ( $Env:CI -ne $null ) { 'ci-' })${Target}"
  58. $CmakeArgs += @(
  59. '--preset', $Preset
  60. )
  61. $CmakeBuildArgs += @(
  62. '--build'
  63. '--preset', $Preset
  64. '--config', $Configuration
  65. '--parallel'
  66. '--', '/consoleLoggerParameters:Summary', '/noLogo'
  67. )
  68. $CmakeInstallArgs += @(
  69. '--install', "build_${Target}"
  70. '--prefix', "${ProjectRoot}/release/${Configuration}"
  71. '--config', $Configuration
  72. )
  73. Log-Group "Configuring ${ProductName}..."
  74. Invoke-External cmake @CmakeArgs
  75. Log-Group "Building ${ProductName}..."
  76. Invoke-External cmake @CmakeBuildArgs
  77. }
  78. Log-Group "Install ${ProductName}..."
  79. Invoke-External cmake @CmakeInstallArgs
  80. Pop-Location -Stack BuildTemp
  81. Log-Group
  82. }
  83. Build