Przeglądaj źródła

CI: Update Windows build scripts

Uses identical modular structure as macOS and Linux and rewritten
entirely for PowerShell.
PatTheMav 4 lat temu
rodzic
commit
ee94f89963

+ 132 - 0
CI/build-windows.ps1

@@ -0,0 +1,132 @@
+Param(
+    [Switch]$Help,
+    [Switch]$Quiet,
+    [Switch]$Verbose,
+    [Switch]$NoChoco,
+    [Switch]$SkipDependencyChecks,
+    [Switch]$BuildInstaller,
+    [Switch]$CombinedArchs,
+    [String]$BuildDirectory = "build",
+    [String]$BuildArch = (Get-CimInstance CIM_OperatingSystem).OSArchitecture,
+    [String]$BuildConfiguration = "RelWithDebInfo"
+)
+
+##############################################################################
+# Windows plugin build script
+##############################################################################
+#
+# This script contains all steps necessary to:
+#
+#   * Build libobs and obs-frontend-api with all required dependencies
+#   * Build your plugin
+#   * Create 64-bit or 32-bit packages
+#   * Create 64-bit or 32-bit installation packages
+#   * Create combined installation packages
+#
+# Parameters:
+#   -Help                   : Print usage help
+#   -NoChco                 : Skip automatic dependency installation
+#                             via Chocolatey
+#   -SkipDependencyChecks   : Skips dependency checks
+#   -BuildDirectory         : Directory to use for builds
+#                             Default: Win64 on 64-bit systems
+#                                      Win32 on 32-bit systems
+#  -BuildArch               : Build architecture to use (32bit or 64bit)
+#  -BuildConfiguration      : Build configuration to use
+#                             Default: RelWithDebInfo
+#  -BuildInstaller          : Build InnoSetup installer - Default: off"
+#  -CombinedArchs           : Create combined packages and installer
+#                             (64-bit and 32-bit) - Default: off"
+#
+# Environment Variables (optional):
+#  WindowsDepsVersion       : Pre-compiled Windows dependencies version
+#  WindowsQtVersion         : Pre-compiled Qt version
+#  ObsVersion               : OBS Version
+#
+##############################################################################
+
+$ErrorActionPreference = "Stop"
+
+$_RunObsBuildScript = $true
+
+$CheckoutDir = git rev-parse --show-toplevel
+
+$DepsBuildDir = "${CheckoutDir}/../obs-build-dependencies"
+$ObsBuildDir = "${CheckoutDir}/../obs-studio"
+
+if (Test-Path ${CheckoutDir}/CI/include/build_environment.ps1) {
+    . ${CheckoutDir}/CI/include/build_environment.ps1
+}
+
+. ${CheckoutDir}/CI/include/build_support_windows.ps1
+
+## DEPENDENCY INSTALLATION ##
+. ${CheckoutDir}/CI/windows/01_install_dependencies.ps1
+
+## OBS LIBRARY BUILD ##
+. ${CheckoutDir}/CI/windows/02_build_obs_libs.ps1
+
+## PLUGIN BUILD ##
+. ${CheckoutDir}/CI/windows/03_build_plugin.ps1
+
+## PLUGIN PACKAGE AND NOTARIZE ##
+. ${CheckoutDir}/CI/windows/04_package_plugin.ps1
+
+## MAIN SCRIPT FUNCTIONS ##
+function Build-Obs-Plugin-Main {
+    Ensure-Directory ${CheckoutDir}
+    Write-Step "Fetching version tags..."
+    & git fetch origin --tags
+    $GitBranch = git rev-parse --abbrev-ref HEAD
+    $GitHash = git rev-parse --short HEAD
+    $ErrorActionPreference = "SilentlyContiue"
+    $GitTag = git describe --tags --abbrev=0
+    $ErrorActionPreference = "Stop"
+
+    if ($GitTag -eq $null) {
+        $GitTag=$ProductVersion
+    }
+
+    $FileName = "${ProductName}-${GitTag}-${GitHash}"
+
+    if(!($SkipDependencyChecks.isPresent)) {
+        Install-Dependencies -NoChoco:$NoChoco
+    }
+
+    if($CombinedArchs.isPresent) {
+        Build-OBS-Libs -BuildArch 64-bit
+        Build-OBS-Libs -BuildArch 32-bit
+        Build-OBS-Plugin -BuildArch 64-bit
+        Build-OBS-Plugin -BuildArch 32-bit
+    } else {
+        Build-OBS-Libs
+        Build-OBS-Plugin
+    }
+
+    Package-OBS-Plugin
+}
+
+function Print-Usage {
+    Write-Host "build-windows.ps1 - Build script for ${ProductName}"
+    $Lines = @(
+        "Usage: ${MyInvocation.MyCommand.Name}",
+        "-Help                    : Print this help",
+        "-Quiet                   : Suppress most build process output"
+        "-Verbose                 : Enable more verbose build process output"
+        "-NoChoco                 : Skip automatic dependency installation via Chocolatey - Default: on",
+        "-SkipDependencyChecks    : Skips dependency checks - Default: off",
+        "-BuildDirectory          : Directory to use for builds - Default: build64 on 64-bit systems, build32 on 32-bit systems",
+        "-BuildArch               : Build architecture to use (32bit or 64bit) - Default: local architecture",
+        "-BuildConfiguration      : Build configuration to use - Default: RelWithDebInfo",
+        "-BuildInstaller          : Build InnoSetup installer - Default: off",
+        "-CombinedArchs           : Create combined packages and installer (64-bit and 32-bit) - Default: off"
+    )
+    $Lines | Write-Host
+}
+
+if($Help.isPresent) {
+    Print-Usage
+    exit 0
+}
+
+Build-Obs-Plugin-Main

+ 2 - 0
CI/include/build_environment.ps1.in

@@ -0,0 +1,2 @@
+$ProductName = "@CMAKE_PROJECT_NAME@"
+$ProductVersion = "@CMAKE_PROJECT_VERSION@"

+ 139 - 0
CI/include/build_support_windows.ps1

@@ -0,0 +1,139 @@
+$CIWorkflow = "${CheckoutDir}/.github/workflows/main.yml"
+
+$CIDepsVersion = Get-Content ${CIWorkflow} | Select-String "[ ]+DEPS_VERSION_WIN: '([0-9\-]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
+$CIQtVersion = Get-Content ${CIWorkflow} | Select-String "[ ]+QT_VERSION_WIN: '([0-9\.]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
+$CIObsVersion = Get-Content ${CIWorkflow} | Select-String "[ ]+OBS_VERSION: '([0-9\.]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
+
+function Write-Status {
+    param(
+        [parameter(Mandatory=$true)]
+        [string] $output
+    )
+
+    if (!($Quiet.isPresent)) {
+        if (Test-Path env:CI) {
+            Write-Host "[${ProductName}] ${output}"
+        } else {
+            Write-Host -ForegroundColor blue "[${ProductName}] ${output}"
+        }
+    }
+}
+
+function Write-Info {
+    param(
+        [parameter(Mandatory=$true)]
+        [string] $output
+    )
+
+    if (!($Quiet.isPresent)) {
+        if (Test-Path env:CI) {
+            Write-Host " + ${output}"
+        } else {
+            Write-Host -ForegroundColor DarkYellow " + ${output}"
+        }
+    }
+}
+
+function Write-Step {
+    param(
+        [parameter(Mandatory=$true)]
+        [string] $output
+    )
+
+    if (!($Quiet.isPresent)) {
+        if (Test-Path env:CI) {
+            Write-Host " + ${output}"
+        } else {
+            Write-Host -ForegroundColor green " + ${output}"
+        }
+    }
+}
+
+function Write-Error {
+    param(
+        [parameter(Mandatory=$true)]
+        [string] $output
+    )
+
+    if (Test-Path env:CI) {
+        Write-Host " + ${output}"
+    } else {
+        Write-Host -ForegroundColor red " + ${output}"
+    }
+}
+
+function Test-CommandExists {
+    param(
+        [parameter(Mandatory=$true)]
+        [string] $Command
+    )
+
+    $CommandExists = $false
+    $OldActionPref = $ErrorActionPreference
+    $ErrorActionPreference = "stop"
+
+    try {
+        if (Get-Command $Command) {
+            $CommandExists = $true
+        }
+    } Catch {
+        $CommandExists = $false
+    } Finally {
+        $ErrorActionPreference = $OldActionPref
+    }
+
+    return $CommandExists
+}
+
+function Ensure-Directory {
+    param(
+        [parameter(Mandatory=$true)]
+        [string] $Directory
+    )
+
+    if (!(Test-Path $Directory)) {
+        $null = New-Item -ItemType Directory -Force -Path $Directory
+    }
+
+    Set-Location -Path $Directory
+}
+
+$BuildDirectory = "$(if (Test-Path Env:BuildDirectory) { $env:BuildDirectory } else { $BuildDirectory })"
+$BuildConfiguration = "$(if (Test-Path Env:BuildConfiguration) { $env:BuildConfiguration } else { $BuildConfiguration })"
+$BuildArch = "$(if (Test-Path Env:BuildArch) { $env:BuildArch } else { $BuildArch })"
+$OBSBranch = "$(if (Test-Path Env:OBSBranch) { $env:OBSBranch } else { $OBSBranch })"
+$WindowsDepsVersion = "$(if (Test-Path Env:WindowsDepsVersion ) { $env:WindowsDepsVersion } else { $CIDepsVersion })"
+$WindowsQtVersion = "$(if (Test-Path Env:WindowsQtVersion ) { $env:WindowsQtVersion } else { $CIQtVersion }")
+$CmakeSystemVersion = "$(if (Test-Path Env:CMAKE_SYSTEM_VERSION) { $Env:CMAKE_SYSTEM_VERSION } else { "10.0.18363.657" })"
+$OBSVersion = "$(if ( Test-Path Env:OBSVersion ) { $env:ObsVersion } else { $CIObsVersion })"
+
+function Install-Windows-Dependencies {
+    Write-Status "Checking Windows build dependencies"
+
+    $ObsBuildDependencies = @(
+        @("7z", "7zip"),
+        @("cmake", "cmake --install-arguments 'ADD_CMAKE_TO_PATH=System'"),
+        @("iscc", "innosetup")
+    )
+
+    if(!(Test-CommandExists "choco")) {
+        Set-ExecutionPolicy AllSigned
+        Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
+    }
+
+    Foreach($Dependency in $ObsBuildDependencies) {
+        if($Dependency -is [system.array]) {
+            $Command = $Dependency[0]
+            $ChocoName = $Dependency[1]
+        } else {
+            $Command = $Dependency
+            $ChocoName = $Dependency
+        }
+
+        if(!(Test-CommandExists "${Command}")) {
+            Invoke-Expression "choco install -y ${ChocoName}"
+        }
+    }
+
+    $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
+}

+ 158 - 0
CI/windows/01_install_dependencies.ps1

@@ -0,0 +1,158 @@
+Param(
+    [Switch]$Help = $(if (Test-Path variable:Help) { $Help }),
+    [Switch]$Quiet = $(if (Test-Path variable:Quiet) { $Quiet }),
+    [Switch]$Verbose = $(if (Test-Path variable:Verbose) { $Verbose }),
+    [Switch]$NoChoco = $(if (Test-Path variable:NoChoco) { $true } else { $false }),
+    [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" } else { (Get-CimInstance CIM_OperatingSystem).OSArchitecture }),
+    [String]$ProductName = $(if (Test-Path variable:ProductName) { "${ProductName}" } else { "obs-plugin" })
+)
+
+##############################################################################
+# Windows dependency management function
+##############################################################################
+#
+# This script file can be included in build scripts for Windows or run
+# directly
+#
+##############################################################################
+
+$ErrorActionPreference = "Stop"
+
+Function Install-obs-deps {
+    Param(
+        [Parameter(Mandatory=$true)]
+        [String]$Version
+    )
+
+    Write-Status "Setup for pre-built Windows OBS dependencies v${Version}"
+    Ensure-Directory $DepsBuildDir
+
+    if (!(Test-Path $DepsBuildDir/dependencies${Version})) {
+        Write-Status "Setting up pre-built Windows OBS dependencies v${Version}"
+
+        Write-Step "Download..."
+        $ProgressPreference = $(if ($Quiet.isPresent) { "SilentlyContinue" } else { "Continue" })
+        Invoke-WebRequest -Uri "https://cdn-fastly.obsproject.com/downloads/dependencies${Version}.zip" -UseBasicParsing -OutFile "dependencies${Version}.zip"
+        $ProgressPreference = 'Continue'
+
+        Write-Step "Unpack..."
+
+        Expand-Archive -Path "dependencies${Version}.zip"
+    } else {
+        Write-Step "Found existing pre-built dependencies..."
+
+    }
+}
+
+function Install-qt-deps {
+    Param(
+        [Parameter(Mandatory=$true)]
+        [String]$Version
+    )
+
+    Write-Status "Setup for pre-built dependency Qt v${Version}"
+    Ensure-Directory $DepsBuildDir
+
+    if (!(Test-Path $DepsBuildDir/Qt_${Version})) {
+        Write-Status "Setting up OBS dependency Qt v${Version}"
+
+        Write-Step "Download..."
+        $ProgressPreference = $(if ($Quiet.isPresent) { 'SilentlyContinue' } else { 'Continue' })
+        Invoke-WebRequest -Uri "https://cdn-fastly.obsproject.com/downloads/Qt_${Version}.7z" -UseBasicParsing -OutFile "Qt_${Version}.7z"
+        $ProgressPreference = 'Continue'
+        
+        Write-Step "Unpack..."
+
+        # TODO: Replace with zip and properly package Qt to share directory with other deps
+        & 7z x Qt_${Version}.7z
+        & mv ${Version} "Qt_${Version}"
+    } else {
+        Write-Step "Found existing pre-built Qt..."
+    }
+}
+
+function Install-obs-studio {
+    Param(
+        [parameter(Mandatory=$true)]
+        [string]$Version
+    )
+
+    $CheckoutRef = "$(if (!(Test-Path variable:OBSBranch)) { ${OBSBranch} } else { "tags/${OBSVersion}" })"
+
+    Write-Status "Setup for OBS Studio v${CheckoutRef}"
+    Ensure-Directory ${ObsBuildDir}
+
+    if (!(Test-Path "${ObsBuildDir}/.git")) {
+        & git clone --recursive https://github.com/obsproject/obs-studio "${pwd}"
+        & git fetch origin --tags
+        & git checkout ${CheckoutRef} -b obs-plugin-build
+    } else {
+        $BranchExists = &git show-ref --verify --quiet refs/heads/obs-plugin-build
+
+        if ($BranchExists -Eq $false) {
+            & git checkout ${CheckoutRef} -b obs-plugin-build
+        } else {
+            & git checkout obs-plugin-build
+        }
+    }
+}
+
+function Install-Dependencies {
+    if(!($NoChoco.isPresent)) {
+        Install-Windows-Dependencies
+    }
+
+    $BuildDependencies = @(
+        @('obs-deps', $WindowsDepsVersion),
+        @('qt-deps', $WindowsQtVersion),
+        @('obs-studio', $OBSVersion)
+    )
+
+    Foreach($Dependency in ${BuildDependencies}) {
+        $DependencyName = $Dependency[0]
+        $DependencyVersion = $Dependency[1]
+
+        $FunctionName = "Install-${DependencyName}"
+        & $FunctionName -Version $DependencyVersion
+    }
+
+    Ensure-Directory ${CheckoutDir}
+}
+
+function Install-Dependencies-Standalone {
+    $CheckoutDir = git rev-parse --show-toplevel
+
+    if (Test-Path ${CheckoutDir}/CI/include/build_environment.ps1) {
+        . ${CheckoutDir}/CI/include/build_environment.ps1
+    }
+
+    $DepsBuildDir = "${CheckoutDir}/../obs-build-dependencies"
+    $ObsBuildDir = "${CheckoutDir}/../obs-studio"
+
+    . ${CheckoutDir}/CI/include/build_support_windows.ps1
+
+    Write-Status "Setting up plugin build dependencies"
+    Install-Dependencies
+}
+
+function Print-Usage {
+    $Lines = @(
+        "Usage: ${MyInvocation.MyCommand.Name}",
+        "-Help                    : Print this help",
+        "-Quiet                   : Suppress most build process output",
+        "-Verbose                 : Enable more verbose build process output",
+        "-NoChoco                 : Skip automatic dependency installation via Chocolatey - Default: on"
+        "-BuildArch               : Build architecture to use (32bit or 64bit) - Default: local architecture"
+    )
+
+    $Lines | Write-Host
+}
+
+if(!(Test-Path variable:_RunObsBuildScript)) {
+    if ($Help.isPresent) {
+        Print-Usage
+        exit 0
+    }
+
+    Install-Dependencies-Standalone
+}

+ 102 - 0
CI/windows/02_build_obs_libs.ps1

@@ -0,0 +1,102 @@
+Param(
+    [Switch]$Help = $(if (Test-Path variable:Help) { $Help }),
+    [Switch]$Quiet = $(if (Test-Path variable:Quiet) { $Quiet }),
+    [Switch]$Verbose = $(if (Test-Path variable:Verbose) { $Verbose }),
+    [String]$ProductName = $(if (Test-Path variable:ProductName) { "${ProductName}" } else { "obs-plugin" }),
+    [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" } else { "build" }),
+    [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" } else { (Get-WmiObject Win32_OperatingSystem).OSArchitecture}),
+    [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" } else { "RelWithDebInfo" })
+)
+
+##############################################################################
+# Windows libobs library build function
+##############################################################################
+#
+# This script file can be included in build scripts for Windows or run
+# directly
+#
+##############################################################################
+
+$ErrorActionPreference = "Stop"
+
+function Build-OBS-Libs {
+    Param(
+        [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" }),
+        [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" }),
+        [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" })
+    )
+
+    Write-Status "Build libobs and obs-frontend-api"
+
+    Ensure-Directory ${ObsBuildDir}
+
+    if ($BuildArch -eq "64-bit") {
+        $QtDirectory = "${CheckoutDir}/../obs-build-dependencies/Qt_${WindowsQtVersion}/msvc2019_64"
+        $DepsDirectory = "${CheckoutDir}/../obs-build-dependencies/dependencies${WindowsDepsVersion}/win64"
+        $Env:CMAKE_PREFIX_PATH="${QtDirectory};${DepsDirectory}/bin;${DepsDirectory}"
+
+        cmake -S . -B "plugin_${BuildDirectory}64" -G "Visual Studio 16 2019" `
+            -DCMAKE_SYSTEM_VERSION="${CmakeSystemVersion}" `
+            -DCMAKE_GENERATOR_PLATFORM=x64 `
+            -DENABLE_PLUGINS=OFF `
+            -DENABLE_UI=ON `
+            -DENABLE_SCRIPTING=OFF `
+            "$(if (Test-Path Variable:$Quiet) { "-Wno-deprecated -Wno-dev --log-level=ERROR" })"
+
+        cmake --build "plugin_${BuildDirectory}64" -t obs-frontend-api --config ${BuildConfiguration}
+    } else {
+        $QtDirectory = "${CheckoutDir}/../obs-build-dependencies/Qt_${WindowsQtVersion}/msvc2019"
+        $DepsDirectory = "${CheckoutDir}/../obs-build-dependencies/dependencies${WindowsDepsVersion}/win32"
+        $Env:CMAKE_PREFIX_PATH="${QtDirectory};${DepsDirectory}/bin;${DepsDirectory}"
+
+        cmake -S . -B "plugin_${BuildDirectory}32" -G "Visual Studio 16 2019" `
+            -DCMAKE_SYSTEM_VERSION="${CmakeSystemVersion}" `
+            -DCMAKE_GENERATOR_PLATFORM=Win32 `
+            -DENABLE_PLUGINS=OFF `
+            -DENABLE_UI=ON `
+            -DENABLE_SCRIPTING=OFF `
+            "$(if (Test-Path Variable:$Quiet) { "-Wno-deprecated -Wno-dev --log-level=ERROR" })"
+
+        cmake --build "plugin_${BuildDirectory}32" -t obs-frontend-api --config ${BuildConfiguration}
+    }
+
+    Ensure-Directory ${CheckoutDir}
+}
+
+
+function Build-OBS-Libs-Standalone {
+    $CheckoutDir = git rev-parse --show-toplevel
+
+    if (Test-Path ${CheckoutDir}/CI/include/build_environment.ps1) {
+        . ${CheckoutDir}/CI/include/build_environment.ps1
+    }
+
+    $ObsBuildDir = "${CheckoutDir}/../obs-studio"
+
+    . ${CheckoutDir}/CI/include/build_support_windows.ps1
+
+    Build-OBS-Libs
+}
+
+function Print-Usage {
+    $Lines = @(
+        "Usage: ${MyInvocation.MyCommand.Name}",
+        "-Help                    : Print this help",
+        "-Quiet                   : Suppress most build process output",
+        "-Verbose                 : Enable more verbose build process output",
+        "-BuildDirectory          : Directory to use for builds - Default: build64 on 64-bit systems, build32 on 32-bit systems",
+        "-BuildArch               : Build architecture to use (32bit or 64bit) - Default: local architecture",
+        "-BuildConfiguration      : Build configuration to use - Default: RelWithDebInfo"
+    )
+
+    $Lines | Write-Host
+}
+
+if(!(Test-Path variable:_RunObsBuildScript)) {
+    if($Help.isPresent) {
+        Print-Usage
+        exit 0
+    }
+
+    Build-OBS-Libs-Standalone
+}

+ 92 - 0
CI/windows/03_build_plugin.ps1

@@ -0,0 +1,92 @@
+Param(
+    [Switch]$Help = $(if (Test-Path variable:Help) { $Help }),
+    [Switch]$Quiet = $(if (Test-Path variable:Quiet) { $Quiet }),
+    [Switch]$Verbose = $(if (Test-Path variable:Verbose) { $Verbose }),
+    [String]$ProductName = $(if (Test-Path variable:ProductName) { "${ProductName}" } else { "obs-plugin" }),
+    [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" } else { "build" }),
+    [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" } else { (Get-WmiObject Win32_OperatingSystem).OSArchitecture}),
+    [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" } else { "RelWithDebInfo" })
+)
+
+##############################################################################
+# Windows libobs plugin build function
+##############################################################################
+#
+# This script file can be included in build scripts for Windows or run
+# directly
+#
+##############################################################################
+
+$ErrorActionPreference = "Stop"
+
+function Build-OBS-Plugin {
+    Param(
+        [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" }),
+        [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" }),
+        [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" })
+    )
+
+    Write-Status "Build plugin ${ProductName}"
+    Ensure-Directory ${CheckoutDir}
+
+    if ($BuildArch -eq "64-bit") {
+        $QtFolder = "${CheckoutDir}/../obs-build-dependencies/Qt_${WindowsQtVersion}/msvc2019_64"
+        $DepsFolder = "${CheckoutDir}/../obs-build-dependencies/dependencies${WindowsDepsVersion}/win64"
+        $Env:CMAKE_PREFIX_PATH="${QtFolder};${DepsFolder}/bin;${DepsFolder}"
+
+        cmake -S . -B "${BuildDirectory}64" -G "Visual Studio 16 2019" `
+            -DCMAKE_GENERATOR_PLATFORM=x64 `
+            -DCMAKE_SYSTEM_VERSION="${CmakeSystemVersion}" `
+            "$(if (Test-Path Variable:$Quiet) { "-Wno-deprecated -Wno-dev --log-level=ERROR" })"
+
+        cmake --build "${BuildDirectory}64" --config ${BuildConfiguration}
+    } else {
+        $QtFolder = "${CheckoutDir}/../obs-build-dependencies/Qt_${WindowsQtVersion}/msvc2019"
+        $DepsFolder = "${CheckoutDir}/../obs-build-dependencies/dependencies${WindowsDepsVersion}/win32"
+        $Env:CMAKE_PREFIX_PATH="${QtFolder};${DepsFolder}/bin;${DepsFolder}"
+
+        cmake -S . -B "${BuildDirectory}32" -G "Visual Studio 16 2019" `
+            -DCMAKE_GENERATOR_PLATFORM=Win32 `
+            -DCMAKE_SYSTEM_VERSION="${CmakeSystemVersion}" `
+            "$(if (Test-Path Variable:$Quiet) { "-Wno-deprecated -Wno-dev --log-level=ERROR" })"
+
+        cmake --build "${BuildDirectory}32" --config ${BuildConfiguration}
+    }
+
+    Ensure-Directory ${CheckoutDir}
+}
+
+function Build-Plugin-Standalone {
+    $CheckoutDir = git rev-parse --show-toplevel
+
+    if (Test-Path ${CheckoutDir}/CI/include/build_environment.ps1) {
+        . ${CheckoutDir}/CI/include/build_environment.ps1
+    }
+
+    . ${CheckoutDir}/CI/include/build_support_windows.ps1
+
+    Build-OBS-Plugin
+}
+
+function Print-Usage {
+    $Lines = @(
+        "Usage: ${MyInvocation.MyCommand.Name}",
+        "-Help                    : Print this help",
+        "-Quiet                   : Suppress most build process output",
+        "-Verbose                 : Enable more verbose build process output",
+        "-BuildDirectory          : Directory to use for builds - Default: build64 on 64-bit systems, build32 on 32-bit systems",
+        "-BuildArch               : Build architecture to use (32bit or 64bit) - Default: local architecture",
+        "-BuildConfiguration      : Build configuration to use - Default: RelWithDebInfo"
+    )
+
+    $Lines | Write-Host
+}
+
+if(!(Test-Path variable:_RunObsBuildScript)) {
+    if($Help.isPresent) {
+        Print-Usage
+        exit 0
+    }
+
+    Build-Plugin-Standalone
+ }

+ 141 - 0
CI/windows/04_package_plugin.ps1

@@ -0,0 +1,141 @@
+Param(
+    [Switch]$Help = $(if (Test-Path variable:Help) { $Help }),
+    [Switch]$Quiet = $(if (Test-Path variable:Quiet) { $Quiet }),
+    [Switch]$Verbose = $(if (Test-Path variable:Verbose) { $Verbose }),
+    [Switch]$BuildInstaller = $(if ($BuildInstaller.isPresent) { $true }),
+    [String]$ProductName = $(if (Test-Path variable:ProductName) { "${ProductName}" } else { "obs-plugin" }),
+    [Switch]$CombinedArchs = $(if ($CombinedArchs.isPresent) { $true }),
+    [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" } else { "build" }),
+    [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" } else { (Get-WmiObject Win32_OperatingSystem).OSArchitecture}),
+    [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" } else { "RelWithDebInfo" })
+)
+
+##############################################################################
+# Windows libobs plugin package function
+##############################################################################
+#
+# This script file can be included in build scripts for Windows or run
+# directly with the -Standalone switch
+#
+##############################################################################
+
+$ErrorActionPreference = "Stop"
+
+function Package-OBS-Plugin {
+    Param(
+        [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" }),
+        [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" }),
+        [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" })
+    )
+
+    Write-Status "Package plugin ${ProductName}"
+    Ensure-Directory ${CheckoutDir}
+
+    if ($CombinedArchs.isPresent) {
+        if (!(Test-Path ${CheckoutDir}/release/obs-plugins/64bit)) {
+            cmake --build ${BuildDirectory}64 --config ${BuildConfiguration} -t install
+        }
+
+        if (!(Test-Path ${CheckoutDir}/release/obs-plugins/32bit)) {
+            cmake --build ${BuildDirectory}32 --config ${BuildConfiguration} -t install
+        }
+
+        $CompressVars = @{
+            Path = "${CheckoutDir}/release/*"
+            CompressionLevel = "Optimal"
+            DestinationPath = "${FileName}-Windows.zip"
+        }
+
+        Write-Step "Creating zip archive..."
+
+        Compress-Archive -Force @CompressVars
+        if(($BuildInstaller.isPresent) -And (Test-CommandExists "iscc")) {
+            Write-Step "Creating installer..."
+            & iscc ${CheckoutDir}/installer/installer-Windows.generated.iss /O. /F"${FileName}-Windows-Installer"
+        }
+    } elseif ($BuildArch -eq "64-bit") {
+        cmake --build ${BuildDirectory}64 --config ${BuildConfiguration} -t install
+
+        $CompressVars = @{
+            Path = "${CheckoutDir}/release/*"
+            CompressionLevel = "Optimal"
+            DestinationPath = "${FileName}-Win64.zip"
+        }
+
+        Write-Step "Creating zip archive..."
+
+        Compress-Archive -Force @CompressVars
+
+        if(($BuildInstaller.isPresent) -And (Test-CommandExists "iscc")) {
+            Write-Step "Creating installer..."
+            & iscc ${CheckoutDir}/installer/installer-Windows.generated.iss /O. /F"${FileName}-Win64-Installer"
+        }
+    } elseif ($BuildArch -eq "32-bit") {
+        cmake --build ${BuildDirectory}32 --config ${BuildConfiguration} -t install
+
+        $CompressVars = @{
+            Path = "${CheckoutDir}/release/*"
+            CompressionLevel = "Optimal"
+            DestinationPath = "${FileName}-Win32.zip"
+        }
+
+        Write-Step "Creating zip archive..."
+
+        Compress-Archive -Force @CompressVars
+
+        if(($BuildInstaller.isPresent) -And (Test-CommandExists "iscc")) {
+            Write-Step "Creating installer..."
+            & iscc ${CheckoutDir}/installer/installer-Windows.generated.iss /O. /F"${FileName}-Win32-Installer"
+        }
+    }
+}
+
+function Package-Plugin-Standalone {
+    $CheckoutDir = git rev-parse --show-toplevel
+
+    if (Test-Path ${CheckoutDir}/CI/include/build_environment.ps1) {
+        . ${CheckoutDir}/CI/include/build_environment.ps1
+    }
+
+    . ${CheckoutDir}/CI/include/build_support_windows.ps1
+
+    Ensure-Directory ${CheckoutDir}
+    $GitBranch = git rev-parse --abbrev-ref HEAD
+    $GitHash = git rev-parse --short HEAD
+    $ErrorActionPreference = "SilentlyContiue"
+    $GitTag = git describe --tags --abbrev=0
+    $ErrorActionPreference = "Stop"
+
+    if ($GitTag -eq $null) {
+        $GitTag=$ProductVersion
+    }
+
+    $FileName = "${ProductName}-${GitTag}-${GitHash}"
+
+    Package-OBS-Plugin
+}
+
+function Print-Usage {
+    $Lines = @(
+        "Usage: ${MyInvocation.MyCommand.Name}",
+        "-Help                    : Print this help",
+        "-Quiet                   : Suppress most build process output",
+        "-Verbose                 : Enable more verbose build process output",
+        "-CombinedArchs           : Create combined architecture package",
+        "-BuildDirectory          : Directory to use for builds - Default: build64 on 64-bit systems, build32 on 32-bit systems",
+        "-BuildArch               : Build architecture to use (32bit or 64bit) - Default: local architecture",
+        "-BuildConfiguration      : Build configuration to use - Default: RelWithDebInfo"
+    )
+
+    $Lines | Write-Host
+}
+
+
+if(!(Test-Path variable:_RunObsBuildScript)) {
+    if($Help.isPresent) {
+        Print-Usage
+        exit 0
+    }
+
+    Package-Plugin-Standalone
+}

+ 0 - 2
ci/ci_includes.cmd.in

@@ -1,2 +0,0 @@
-set PluginName=@CMAKE_PROJECT_NAME@
-set PluginVersion=@CMAKE_PROJECT_VERSION@

+ 0 - 6
ci/windows/download-obs-deps.cmd

@@ -1,6 +0,0 @@
-if not exist %DepsBasePath% (
-    curl -o %DepsBasePath%.zip -kLO https://obsproject.com/downloads/dependencies2017.zip -f --retry 5 -C -
-    7z x %DepsBasePath%.zip -o%DepsBasePath%
-) else (
-    echo "OBS dependencies are already there. Download skipped."
-)

+ 0 - 8
ci/windows/install-qt-win.cmd

@@ -1,8 +0,0 @@
-if not exist %QtBaseDir% (
-	curl -kLO https://cdn-fastly.obsproject.com/downloads/Qt_5.10.1.7z -f --retry 5 -z Qt_5.10.1.7z
-    7z x Qt_5.10.1.7z -o%QtBaseDir%
-) else (
-	echo "Qt is already installed. Download skipped."
-)
-
-dir %QtBaseDir%

+ 0 - 14
ci/windows/package-windows.cmd

@@ -1,14 +0,0 @@
-call "%~dp0..\ci_includes.generated.cmd"
-
-mkdir package
-cd package
-
-git rev-parse --short HEAD > package-version.txt
-set /p PackageVersion=<package-version.txt
-del package-version.txt
-
-REM Package ZIP archive
-7z a "%PluginName%-%PackageVersion%-Windows.zip" "..\release\*"
-
-REM Build installer
-iscc ..\installer\installer-Windows.generated.iss /O. /F"%PluginName%-%PackageVersion%-Windows-Installer"

+ 0 - 36
ci/windows/prepare-obs-windows.cmd

@@ -1,36 +0,0 @@
-@echo off
-SETLOCAL EnableDelayedExpansion
-
-REM If obs-studio directory does not exist, clone the git repo
-if not exist %OBSPath% (
-	echo obs-studio directory does not exist
-	git clone https://github.com/obsproject/obs-studio %OBSPath%
-	cd /D %OBSPath%\
-	git describe --tags --abbrev=0 --exclude="*-rc*" > "%OBSPath%\obs-studio-latest-tag.txt"
-    set /p OBSLatestTag=<"%OBSPath%\obs-studio-latest-tag.txt"
-)
-
-REM Prepare OBS Studio builds
-
-echo Running CMake...
-cd /D %OBSPath%
-echo   git checkout %OBSLatestTag%
-git checkout %OBSLatestTag%
-echo:
-
-if not exist build32 mkdir build32
-if not exist build64 mkdir build64
-
-echo   Running cmake for obs-studio %OBSLatestTag% 32-bit...
-cd build32
-cmake -G "Visual Studio 16 2019" -A Win32 -DCMAKE_SYSTEM_VERSION=10.0 -DQTDIR="%QTDIR32%" -DDepsPath="%DepsPath32%" -DBUILD_CAPTIONS=true -DDISABLE_PLUGINS=true -DCOPIED_DEPENDENCIES=false -DCOPY_DEPENDENCIES=true ..
-echo:
-echo:
-
-echo   Running cmake for obs-studio %OBSLatestTag% 64-bit...
-cd ..\build64
-cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_SYSTEM_VERSION=10.0 -DQTDIR="%QTDIR64%" -DDepsPath="%DepsPath64%" -DBUILD_CAPTIONS=true -DDISABLE_PLUGINS=true -DCOPIED_DEPENDENCIES=false -DCOPY_DEPENDENCIES=true ..
-echo:
-echo:
-
-dir "%OBSPath%\libobs"

+ 0 - 15
ci/windows/prepare-windows.cmd

@@ -1,15 +0,0 @@
-mkdir build32
-mkdir build64
-
-cd build32
-cmake -G "Visual Studio 16 2019" -A Win32 -DCMAKE_SYSTEM_VERSION=10.0 -DQTDIR="%QTDIR32%" -DLibObs_DIR="%OBSPath%\build32\libobs" -DLIBOBS_INCLUDE_DIR="%OBSPath%\libobs" -DLIBOBS_LIB="%OBSPath%\build32\libobs\%build_config%\obs.lib" -DOBS_FRONTEND_LIB="%OBSPath%\build32\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib" ..
-cd ..\build64
-cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_SYSTEM_VERSION=10.0 -DQTDIR="%QTDIR64%" -DLibObs_DIR="%OBSPath%\build64\libobs" -DLIBOBS_INCLUDE_DIR="%OBSPath%\libobs" -DLIBOBS_LIB="%OBSPath%\build64\libobs\%build_config%\obs.lib" -DOBS_FRONTEND_LIB="%OBSPath%\build64\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib" ..
-
-REM Import the generated includes to get the plugin's name
-call "%~dp0..\ci_includes.generated.cmd"
-
-REM Rename the solution files to something CI can pick up 
-cd ..
-ren "build32\%PluginName%.sln" "main.sln"
-ren "build64\%PluginName%.sln" "main.sln"

+ 1 - 1
installer/installer-Windows.iss.in

@@ -55,7 +55,7 @@ var
 begin
   // initialize default path, which will be returned when the following registry
   // key queries fail due to missing keys or for some different reason
-  Result := '{pf}\obs-studio';
+  Result := '{autopf}\obs-studio';
   // query the first registry value; if this succeeds, return the obtained value
   if RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', InstallPath) then
     Result := InstallPath