Skip to content

Commit 87e1963

Browse files
committed
add windows-2022 into github CI matrix
1 parent 3371174 commit 87e1963

3 files changed

Lines changed: 102 additions & 5 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path
4+
$DepsRoot = Join-Path $RepoRoot ".deps"
5+
$OcvVer = "4.11.0"
6+
7+
$ZipPath = Join-Path $DepsRoot "opencv-$OcvVer.zip"
8+
$SrcDir = Join-Path $DepsRoot "opencv-$OcvVer"
9+
$BuildDir = Join-Path $DepsRoot "opencv-build-$OcvVer"
10+
$InstDir = Join-Path $DepsRoot "opencv-install-$OcvVer"
11+
12+
New-Item -ItemType Directory -Force -Path $DepsRoot | Out-Null
13+
14+
# Download OpenCV sources
15+
if (-not (Test-Path $ZipPath)) {
16+
Write-Host "Downloading OpenCV $OcvVer..."
17+
Invoke-WebRequest -Uri "https://github.com/opencv/opencv/archive/$OcvVer.zip" -OutFile $ZipPath
18+
}
19+
20+
# Extract
21+
if (-not (Test-Path $SrcDir)) {
22+
Write-Host "Extracting..."
23+
Expand-Archive -Path $ZipPath -DestinationPath $DepsRoot -Force
24+
}
25+
26+
New-Item -ItemType Directory -Force -Path $BuildDir | Out-Null
27+
New-Item -ItemType Directory -Force -Path $InstDir | Out-Null
28+
29+
# Configure (VS2022)
30+
Write-Host "Configuring OpenCV..."
31+
& cmake -S $SrcDir -B $BuildDir -G "Visual Studio 17 2022" -A x64 `
32+
-DCMAKE_INSTALL_PREFIX="$InstDir" `
33+
-DCMAKE_CONFIGURATION_TYPES="Debug;RelWithDebInfo" `
34+
-DINSTALL_CREATE_DISTRIB=ON `
35+
-DBUILD_LIST=features2d,highgui,flann,calib3d,imgcodecs `
36+
-DWITH_OPENEXR=ON `
37+
-DBUILD_EXAMPLES=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF `
38+
-DWITH_CUDA=OFF
39+
40+
# Build + install both configs (your project uses RelWithDebInfo in CI)
41+
Write-Host "Building+Installing OpenCV RelWithDebInfo..."
42+
& cmake --build $BuildDir --config RelWithDebInfo --target INSTALL
43+
44+
Write-Host "Building+Installing OpenCV Debug..."
45+
& cmake --build $BuildDir --config Debug --target INSTALL
46+
47+
# Find OpenCVConfig.cmake and write OpenCV_DIR
48+
$cfg = Get-ChildItem -Path $InstDir -Recurse -Filter OpenCVConfig.cmake | Select-Object -First 1
49+
if ($null -eq $cfg) { throw "OpenCVConfig.cmake not found under $InstDir" }
50+
51+
$OpenCV_DIR = $cfg.Directory.FullName
52+
Set-Content -Path (Join-Path $DepsRoot "opencv_dir.txt") -Value $OpenCV_DIR -Encoding ASCII
53+
54+
# Also store bin path for runtime (opencv_world*.dll)
55+
$dll = Get-ChildItem -Path $InstDir -Recurse -Filter "opencv_world*.dll" | Select-Object -First 1
56+
if ($dll) {
57+
Set-Content -Path (Join-Path $DepsRoot "opencv_bin.txt") -Value $dll.Directory.FullName -Encoding ASCII
58+
}
59+
60+
Write-Host "OpenCV_DIR = $OpenCV_DIR"

.github/workflows/cmake.yml

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
os: [ubuntu-24.04, macos-14]
13+
os: [ubuntu-24.04, macos-14, windows-2022]
1414
runs-on: ${{ matrix.os }}
1515

1616
steps:
@@ -29,6 +29,11 @@ jobs:
2929
bash .github/scripts/macos/install_openmp.sh
3030
bash .github/scripts/macos/install_opencv.sh
3131
32+
- name: Build and install OpenCV (Windows)
33+
if: runner.os == 'Windows'
34+
shell: pwsh
35+
run: .github/scripts/windows/install_opencv.ps1
36+
3237
- name: Configure CMake (Linux)
3338
if: runner.os == 'Linux'
3439
run: |
@@ -44,9 +49,36 @@ jobs:
4449
-DOpenCV_DIR="/opt/opencv-4.11.0/lib/cmake/opencv4" \
4550
-DOpenMP_ROOT="$(brew --prefix libomp)"
4651
47-
- name: Build
52+
- name: Configure CMake (Windows)
53+
if: runner.os == 'Windows'
54+
shell: pwsh
55+
run: |
56+
$OpenCV_DIR = Get-Content .deps/opencv_dir.txt
57+
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DOpenCV_DIR="$OpenCV_DIR"
58+
59+
- name: Build (any OS)
4860
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
4961

50-
- name: test_sift
51-
working-directory: ${{github.workspace}}
62+
- name: Run test_sift (Linux/macOS)
63+
if: runner.os != 'Windows'
5264
run: ./build/test_sift
65+
66+
- name: Copy OpenCV/gtest DLLs (Windows)
67+
if: runner.os == 'Windows'
68+
shell: pwsh
69+
run: |
70+
$cfg = "${{ env.BUILD_TYPE }}"
71+
$exeDir = Join-Path $pwd "build\$cfg"
72+
73+
# OpenCV DLLs (from your install script output)
74+
$ocvBin = Get-Content .deps/opencv_bin.txt
75+
Copy-Item "$ocvBin\opencv_world*.dll" $exeDir -Force
76+
77+
# gtest DLLs (built inside your build tree, location varies -> search)
78+
Get-ChildItem -Path build -Recurse -Filter "gtest*.dll" |
79+
ForEach-Object { Copy-Item $_.FullName $exeDir -Force }
80+
81+
- name: Run test_sift (Windows)
82+
if: runner.os == 'Windows'
83+
shell: pwsh
84+
run: .\build\${{ env.BUILD_TYPE }}\test_sift.exe

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ else()
1616
endif()
1717

1818
find_package(OpenCV 4.11.0 REQUIRED)
19+
# в целом "как выполнить сборку OpenCV и проекта" можно узнать посмотрев на GitHub CI,
20+
# который выполняет сборку и исполнение на linux/windows/macos
21+
# описание шагов - в .github/workflows/cmake.yml
22+
#
1923
# Linux:
2024
# sudo .github/scripts/install_opencv_linux.sh
2125
# укажите для CMake путь к OpenCV:
2226
# в CLion это делается через File->Settings->Build, Execution, Deployment->CMake->CMake options: -DOpenCV_DIR=/opt/opencv-4.11.0/lib/cmake/opencv4
2327
# там же сразу стоит добавить в дополнению к Debug сборке - сборку с включенными оптимизациями и отладочными символами - RelWithDebInfo
2428
#
2529
# Windows: (но рекомендуется использовать Linux)
26-
# Скачайте этот скрипт и следуйте инструкции - https://gist.github.com/PolarNick239/18036d942ae4b9aad9f1da756ce6c845#file-buildocv-sh-L10-L33
30+
# выполните в powershell .github/scripts/windows/install_opencv.ps1
31+
# альтернативно вы можете следовать инструкции - https://gist.github.com/PolarNick239/18036d942ae4b9aad9f1da756ce6c845#file-buildocv-sh-L10-L33
2732
#
2833
# MacOS: (но рекомендуется использовать Linux, MacOS не тестировался, только на github CI, а инструкция является галлюцинацией LLM)
2934
# sudo bash .github/scripts/macos/install_openmp.sh

0 commit comments

Comments
 (0)