Skip to content

Commit

Permalink
Merge pull request #26 from mscottford/arm64-support-improvements
Browse files Browse the repository at this point in the history
GitHub Actions Support for Building arm64
  • Loading branch information
shimat authored Oct 5, 2024
2 parents 0751f18 + bf9f24f commit 0caaff1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ jobs:
build:

strategy:
fail-fast: false
matrix:
platform: ["win"]
#platform: ["win", "uwp"]
arch: ["x86", "x64", "ARM"]
arch: ["x86", "x64", "ARM", "arm64"]
exclude:
- platform: win
arch: ARM
Expand All @@ -36,6 +37,9 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2

- name: Install NASM to support SIMD optimizations
uses: ilammy/setup-nasm@v1

- name: Setup vcpkg
uses: lukka/[email protected]
if: ${{ matrix.platform == 'win' }}
Expand All @@ -59,6 +63,7 @@ jobs:
- name: Build OpenCV
shell: powershell
run: |
Set-PSDebug -Trace 1
if ("${{matrix.platform}}" -eq 'win'){
. ".\build_windows.ps1"
BuildForWindows ${{matrix.arch}} "${env:VCPKG_ROOT}" $TRUE
Expand Down
55 changes: 45 additions & 10 deletions build_windows.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
function BuildForWindows($platform, $vcpkgPath, $runMsbuild) {
function BuildForWindows($targetPlatform, $vcpkgPath, $runMsbuild, $hostPlatform) {
if (-not $hostPlatform) {
$hostPlatform = "x64"
}

#$ErrorActionPreference = "Stop"

$buildDirectory = "build_win_${platform}"
$buildDirectory = "build_win_${targetPlatform}"
mkdir $buildDirectory -Force -ErrorAction Stop | Out-Null
cd $buildDirectory
pwd

if ($platform -eq "x64") {
if ($targetPlatform -eq "x64") {
$targetProcessor = "AMD64"
$msbuildPlatform = "x64"
$msmfFlag = "ON"
$caroteneFlag = "ON"
}
elseif ($targetPlatform -eq "arm64") {
$targetProcessor = "ARM64"
$msbuildPlatform = "ARM64"
$msmfFlag = "ON"
$caroteneFlag = "OFF"
}
else {
$targetProcessor = "x86"
$msbuildPlatform = "Win32"
$msmfFlag = "OFF" # opencv_videoio430.lib(cap_msmf.obj) : error LNK2001: unresolved external symbol _MFVideoFormat_H263
$msmfFlag = "OFF" # opencv_videoio430.lib(cap_msmf.obj) : error LNK2001: unresolved external symbol _MFVideoFormat_H263
$caroteneFlag = "ON"
}

if ($hostPlatform -eq "x64") {
$hostProcessor = "AMD64"
} elseif ($hostPlatform -eq "arm64") {
$hostProcessor = "ARM64"
} else {
$hostProcessor = "x86"
}

$crossCompileOptions = ""
if ($hostPlatform -ne $targetPlatform) {
# Based on https://github.com/opencv/opencv/issues/24235#issuecomment-1713781654 and https://github.com/opencv/opencv/issues/24235#issuecomment-1719639169

$crossCompileOptions = "-D CMAKE_CROSSCOMPILING=1"
}

cmake -G "Visual Studio 17 2022" `
-A $msbuildPlatform `
$crossCompileOptions `
-D CMAKE_SYSTEM_HOST_PROCESSOR=$hostProcessor `
-D CMAKE_SYSTEM_PROCESSOR=$targetProcessor `
-D CMAKE_SYSTEM_NAME=Windows `
-D CMAKE_SYSTEM_VERSION=10.0 `
-D CMAKE_BUILD_TYPE=Release `
-D CMAKE_INSTALL_PREFIX=install `
-D INSTALL_C_EXAMPLES=OFF `
Expand Down Expand Up @@ -46,17 +79,18 @@ function BuildForWindows($platform, $vcpkgPath, $runMsbuild) {
-D WITH_QT=OFF `
-D WITH_FREETYPE=OFF `
-D WITH_TESSERACT=ON `
-D Tesseract_INCLUDE_DIR="${vcpkgPath}/installed/${platform}-windows-static/include" `
-D Tesseract_LIBRARY="${vcpkgPath}/installed/${platform}-windows-static/lib/tesseract41.lib" `
-D Lept_LIBRARY="${vcpkgPath}/installed/${platform}-windows-static/lib/leptonica-1.81.0.lib" `
-D WITH_CAROTENE=${caroteneFlag} `
-D Tesseract_INCLUDE_DIR="${vcpkgPath}/installed/${targetPlatform}-windows-static/include" `
-D Tesseract_LIBRARY="${vcpkgPath}/installed/${targetPlatform}-windows-static/lib/tesseract41.lib" `
-D Lept_LIBRARY="${vcpkgPath}/installed/${targetPlatform}-windows-static/lib/leptonica-1.81.0.lib" `
-D ENABLE_CXX11=1 `
-D OPENCV_ENABLE_NONFREE=ON `
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules `
-D BUILD_SHARED_LIBS=OFF ../opencv
-D BUILD_SHARED_LIBS=OFF ../opencv
# ENABLE_CXX11 is for Tesseract (https://github.com/opencv/opencv_contrib/blob/a26f71313009c93d105151094436eecd4a0990ed/modules/text/cmake/init.cmake#L19)

if ($runMsbuild) {
# Developer Powershell for VS 2019
# Developer Powershell for VS 2019
# Path: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell cebe9bd5}"
# WorkDir: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\

Expand All @@ -75,9 +109,10 @@ If ((Resolve-Path -Path $MyInvocation.InvocationName).ProviderPath -eq $MyInvoca
$vcpkgPath = "C:\Projects\vcpkg"
$platform = "x64"
#$platform = "x86"
#$platform = "arm64"

Invoke-Expression "${vcpkgPath}\vcpkg.exe install tesseract:${platform}-windows-static" -ErrorAction Stop
#Invoke-Expression "${vcpkgPath}\vcpkg.exe integrate install" -ErrorAction Stop

BuildForWindows $platform $vcpkgPath $FALSE
}
}

0 comments on commit 0caaff1

Please sign in to comment.