Build-Windows.ps1 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "obs-studio requires a 64-bit system to build and run."
  18. }
  19. if ( $PSVersionTable.PSVersion -lt '7.2.0' ) {
  20. Write-Warning 'The obs-studio 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. if ( ! $SkipDeps ) {
  40. Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"
  41. }
  42. Push-Location -Stack BuildTemp
  43. if ( ! ( ( $SkipAll ) -or ( $SkipBuild ) ) ) {
  44. Ensure-Location $ProjectRoot
  45. $Preset = "windows-$(if ( $env:CI -ne $null ) { 'ci-' })${Target}"
  46. $CmakeArgs = @(
  47. '--preset', $Preset
  48. )
  49. $CmakeBuildArgs = @('--build')
  50. $CmakeInstallArgs = @()
  51. if ( ( $env:CI -ne $null ) -and ( $env:CCACHE_CONFIGPATH -ne $null ) ) {
  52. $CmakeArgs += @(
  53. "-DENABLE_CCACHE:BOOL=TRUE"
  54. )
  55. }
  56. if ( $VerbosePreference -eq 'Continue' ) {
  57. $CmakeBuildArgs += ('--verbose')
  58. $CmakeInstallArgs += ('--verbose')
  59. }
  60. if ( $DebugPreference -eq 'Continue' ) {
  61. $CmakeArgs += ('--debug-output')
  62. }
  63. $CmakeBuildArgs += @(
  64. '--preset', "windows-${Target}"
  65. '--config', $Configuration
  66. '--parallel'
  67. '--', '/consoleLoggerParameters:Summary', '/noLogo'
  68. )
  69. $CmakeInstallArgs += @(
  70. '--install', "build_${Target}"
  71. '--prefix', "${ProjectRoot}/build_${Target}/install"
  72. '--config', $Configuration
  73. )
  74. Log-Group "Configuring obs-studio..."
  75. Invoke-External cmake @CmakeArgs
  76. Log-Group "Building obs-studio..."
  77. Invoke-External cmake @CmakeBuildArgs
  78. }
  79. Log-Group "Installing obs-studio..."
  80. Invoke-External cmake @CmakeInstallArgs
  81. Pop-Location -Stack BuildTemp
  82. Log-Group
  83. }
  84. Build