Build-Windows.ps1 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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:TWITCH_CLIENTID -ne '' ) -and ( $env:TWITCH_HASH -ne '' ) ) {
  52. $CmakeArgs += @(
  53. "-DTWITCH_CLIENTID:STRING=${env:TWITCH_CLIENTID}"
  54. "-DTWITCH_HASH:STRING=${env:TWITCH_HASH}"
  55. )
  56. }
  57. if ( ( $env:RESTREAM_CLIENTID -ne '' ) -and ( $env:RESTREAM_HASH -ne '' ) ) {
  58. $CmakeArgs += @(
  59. "-DRESTREAM_CLIENTID:STRING=${env:RESTREAM_CLIENTID}"
  60. "-DRESTREAM_HASH:STRING=${env:RESTREAM_HASH}"
  61. )
  62. }
  63. if ( ( $env:YOUTUBE_CLIENTID -ne '' ) -and ( $env:YOUTUBE_CLIENTID_HASH -ne '' ) -and
  64. ( $env:YOUTUBE_SECRET -ne '' ) -and ( $env:YOUTUBE_SECRET_HASH-ne '' ) ) {
  65. $CmakeArgs += @(
  66. "-DYOUTUBE_CLIENTID:STRING=${env:YOUTUBE_CLIENTID}"
  67. "-DYOUTUBE_CLIENTID_HASH:STRING=${env:YOUTUBE_CLIENTID_HASH}"
  68. "-DYOUTUBE_SECRET:STRING=${env:YOUTUBE_SECRET}"
  69. "-DYOUTUBE_SECRET_HASH:STRING=${env:YOUTUBE_SECRET_HASH}"
  70. )
  71. }
  72. if ( $env:GPU_PRIORITY_VAL -ne '' ) {
  73. $CmakeArgs += @(
  74. "-DGPU_PRIORITY_VAL:STRING=${env:GPU_PRIORITY_VAL}"
  75. )
  76. }
  77. if ( ( $env:CI -ne $null ) -and ( $env:CCACHE_CONFIGPATH -ne $null ) ) {
  78. $CmakeArgs += @(
  79. "-DENABLE_CCACHE:BOOL=TRUE"
  80. )
  81. }
  82. if ( $VerbosePreference -eq 'Continue' ) {
  83. $CmakeBuildArgs += ('--verbose')
  84. $CmakeInstallArgs += ('--verbose')
  85. }
  86. if ( $DebugPreference -eq 'Continue' ) {
  87. $CmakeArgs += ('--debug-output')
  88. }
  89. $CmakeBuildArgs += @(
  90. '--preset', "windows-${Target}"
  91. '--config', $Configuration
  92. '--parallel'
  93. '--', '/consoleLoggerParameters:Summary', '/noLogo'
  94. )
  95. $CmakeInstallArgs += @(
  96. '--install', "build_${Target}"
  97. '--prefix', "${ProjectRoot}/build_${Target}/install"
  98. '--config', $Configuration
  99. )
  100. Log-Group "Configuring obs-studio..."
  101. Invoke-External cmake @CmakeArgs
  102. Log-Group "Building obs-studio..."
  103. Invoke-External cmake @CmakeBuildArgs
  104. }
  105. Log-Group "Installing obs-studio..."
  106. Invoke-External cmake @CmakeInstallArgs
  107. Pop-Location -Stack BuildTemp
  108. Log-Group
  109. }
  110. Build