46 lines
3.0 KiB
PowerShell
46 lines
3.0 KiB
PowerShell
|
|
param(
|
||
|
|
[Parameter(Mandatory=$true)][string]$BuildRoot,
|
||
|
|
[Parameter(Mandatory=$true)][string]$OpenCVDir,
|
||
|
|
[string]$OpenCVRuntimeDir = '',
|
||
|
|
[string]$Generator = 'Visual Studio 17 2022'
|
||
|
|
)
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
$projectRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||
|
|
$buildPath = [System.IO.Path]::GetFullPath($BuildRoot)
|
||
|
|
if ($buildPath.StartsWith($projectRoot + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase) -or $buildPath -eq $projectRoot) {
|
||
|
|
throw 'Use a build directory outside the source tree.'
|
||
|
|
}
|
||
|
|
New-Item -ItemType Directory -Force -Path $buildPath | Out-Null
|
||
|
|
$opencvConfigDir = $OpenCVDir
|
||
|
|
# The OpenCV 4.7 Windows-pack dispatcher does not recognize newer MSVC versions.
|
||
|
|
# Select its existing x64 binary package directly; do not alter/install dependencies.
|
||
|
|
$windowsPackConfig = Join-Path $OpenCVDir 'x64/vc16/lib/OpenCVConfig.cmake'
|
||
|
|
if (Test-Path -LiteralPath $windowsPackConfig) { $opencvConfigDir = Split-Path $windowsPackConfig -Parent }
|
||
|
|
if (-not $OpenCVRuntimeDir) { $OpenCVRuntimeDir = Join-Path (Split-Path $opencvConfigDir -Parent) 'bin' }
|
||
|
|
if (-not (Test-Path -LiteralPath $OpenCVRuntimeDir -PathType Container)) { throw "Missing OpenCV runtime directory: $OpenCVRuntimeDir" }
|
||
|
|
$savedPath = $env:PATH
|
||
|
|
$env:PATH = "$OpenCVRuntimeDir;$savedPath"
|
||
|
|
function Invoke-Checked([string]$Executable, [string[]]$Arguments) {
|
||
|
|
Write-Host "$Executable $($Arguments -join ' ')"
|
||
|
|
# Route native output through the host so the transcript includes real build/test output.
|
||
|
|
& $Executable @Arguments 2>&1 | ForEach-Object { Write-Host $_ }
|
||
|
|
if ($LASTEXITCODE -ne 0) { throw "$Executable failed with exit code $LASTEXITCODE" }
|
||
|
|
}
|
||
|
|
Start-Transcript -Path (Join-Path $buildPath 'verification.log') -Force | Out-Null
|
||
|
|
try {
|
||
|
|
$libraryBuild = Join-Path $buildPath 'library'
|
||
|
|
$installPath = Join-Path $buildPath 'install'
|
||
|
|
$consumerBuild = Join-Path $buildPath 'consumer'
|
||
|
|
Invoke-Checked 'cmake' @('-S', $projectRoot, '-B', $libraryBuild, '-G', $Generator, '-A', 'x64', "-DOpenCV_DIR=$opencvConfigDir", '-DTEC_BUILD_TESTS=ON', '-DTEC_BUILD_EXAMPLES=ON')
|
||
|
|
Invoke-Checked 'cmake' @('--build', $libraryBuild, '--config', 'Release', '--parallel')
|
||
|
|
Invoke-Checked 'ctest' @('--test-dir', $libraryBuild, '-C', 'Release', '--output-on-failure', '--verbose')
|
||
|
|
Invoke-Checked 'cmake' @('--install', $libraryBuild, '--config', 'Release', '--prefix', $installPath)
|
||
|
|
Invoke-Checked 'cmake' @('-S', (Join-Path $projectRoot 'tests/installed_consumer'), '-B', $consumerBuild, '-G', $Generator, '-A', 'x64', "-DCMAKE_PREFIX_PATH=$installPath", "-DOpenCV_DIR=$opencvConfigDir")
|
||
|
|
Invoke-Checked 'cmake' @('--build', $consumerBuild, '--config', 'Release', '--parallel')
|
||
|
|
Invoke-Checked 'ctest' @('--test-dir', $consumerBuild, '-C', 'Release', '--output-on-failure', '--verbose')
|
||
|
|
Write-Host 'VERIFICATION PASSED: Release library, automated tests, example, installation and independent consumer.'
|
||
|
|
} finally {
|
||
|
|
Stop-Transcript | Out-Null
|
||
|
|
$env:PATH = $savedPath
|
||
|
|
}
|