Skip to content

Commit

Permalink
Migrate to Conan (#3)
Browse files Browse the repository at this point in the history
* update readme

* add conan, remove submodules

* fix android workflow

* fix macos

* fix workflow
  • Loading branch information
rainyl authored Mar 16, 2024
1 parent 3e5323e commit a54b877
Show file tree
Hide file tree
Showing 54 changed files with 8,247 additions and 732 deletions.
243 changes: 243 additions & 0 deletions .github/workflows/test_conan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
name: build test release

on:
push:
branches: ["conan"]
tags:
- "v*.*.*"
# pull_request:
# branches: [ "main" ]

env:
ANDROID_NDK_VERSION: r26c
OPENCV_VERSION: 4.9.0
LIB_NAME: libopencv_dart

jobs:
build-android:
name: build-android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: setup
run: |
sudo apt-get update
sudo apt-get install -y build-essential libgtk-3-dev ffmpeg libavcodec-dev \
cmake ninja-build ccache nasm libavformat-dev libavutil-dev libswscale-dev \
libgflags-dev python3 unzip tree python3-pip
python3 -m pip install conan
conan profile detect -f
cd ${{github.workspace}}
mkdir -p build/android
wget -q -O build/android-ndk-$ANDROID_NDK_VERSION-linux.zip \
https://dl.google.com/android/repository/android-ndk-$ANDROID_NDK_VERSION-linux.zip
unzip -q -o build/android-ndk-$ANDROID_NDK_VERSION-linux.zip -d build/
- name: build-android
run: |
conan build . -b missing -pr:h profiles/android-x86_64 \
-c tools.android:ndk_path="`pwd`/build/android-ndk-$ANDROID_NDK_VERSION"
conan build . -b missing -pr:h profiles/android-armv8 \
-c tools.android:ndk_path="`pwd`/build/android-ndk-$ANDROID_NDK_VERSION"
conan build . -b missing -pr:h profiles/android-armv7 \
-c tools.android:ndk_path="`pwd`/build/android-ndk-$ANDROID_NDK_VERSION"
- uses: actions/upload-artifact@v4
name: upload-android-x86_64
with:
path: build/publish/libopencv_dart-android-x86_64.tar.gz
name: libopencv_dart-android-x86_64.tar.gz

- uses: actions/upload-artifact@v4
name: upload-android-arm64-v8a
with:
path: build/publish/libopencv_dart-android-arm64-v8a.tar.gz
name: libopencv_dart-android-arm64-v8a.tar.gz

- uses: actions/upload-artifact@v4
name: upload-android-armeabi-v7a
with:
path: build/publish/libopencv_dart-android-armeabi-v7a.tar.gz
name: libopencv_dart-android-armeabi-v7a.tar.gz
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
prerelease: false
files: |
build/publish/libopencv_dart-android-arm64-v8a.tar.gz
build/publish/libopencv_dart-android-armeabi-v7a.tar.gz
build/publish/libopencv_dart-android-x86_64.tar.gz
build-ubuntu:
name: build-ubuntu
runs-on: ubuntu-latest

steps:
- name: setup
run: |
sudo apt-get update
sudo apt-get install -y curl git wget python3 unzip build-essential \
libgtk-3-dev ffmpeg libavcodec-dev \
cmake ninja-build ccache nasm libavformat-dev libavutil-dev \
libswscale-dev libgflags-dev \
libjpeg-dev libpng-dev libtiff-dev python3-pip
python3 -m pip install conan
conan profile detect -f
- uses: actions/checkout@v4
with:
submodules: true
- name: build-opencv-dart
run: |
conan build . -b missing -c tools.cmake.cmaketoolchain:generator=Ninja
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- uses: actions/upload-artifact@v4
name: upload-linux-x64
with:
path: build/publish/libopencv_dart-linux-x64.tar.gz
name: libopencv_dart-linux-x64.tar.gz
- name: Run Test
run: |
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/linux:$LD_LIBRARY_PATH
flutter pub get
flutter test -x skip-workflow,no-local-files
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
prerelease: false
files: |
build/publish/libopencv_dart-linux-x64.tar.gz
build-windows:
name: build-windows
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: build-opencv-dart
run: |
python3 -m pip install conan
conan profile detect -f
conan build . -b missing -s compiler.cppstd=20
- uses: actions/upload-artifact@v4
name: upload-windows-x64
with:
path: build/publish/libopencv_dart-windows-x64.tar.gz
name: libopencv_dart-windows-x64.tar.gz
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- name: Run Test
run: |
$env:PATH = "${{github.workspace}}\windows;${env:PATH}"
flutter pub get
flutter test -x no-local-files
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
prerelease: false
files: |
build/publish/libopencv_dart-windows-x64.tar.gz
build-macos:
name: build-macos
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: setup
run: |
brew install --force --overwrite ninja ccache ffmpeg nasm
python3 -m pip install conan
conan profile detect -f
cd ${{github.workspace}}
- name: build
run: |
conan build . -b missing
- uses: actions/upload-artifact@v4
name: upload-macos-x64
with:
path: build/publish/libopencv_dart-macos-x64.tar.gz
name: libopencv_dart-macos-x64.tar.gz
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- name: Run Test
run: |
ls -alh $GITHUB_WORKSPACE/macos
export DYLD_LIBRARY_PATH=$GITHUB_WORKSPACE/macos:$DYLD_LIBRARY_PATH
flutter pub get
flutter test -x no-local-files
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
prerelease: false
files: |
build/publish/libopencv_dart-macos-x64.tar.gz
build-macos-arm64:
name: build-macos-arm64
runs-on: macos-14
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: setup
run: |
# brew update
brew install --force --overwrite ninja ccache ffmpeg nasm
python3 -m pip install conan
conan profile detect -f
cd ${{github.workspace}}
- name: build
run: |
conan build . -b missing
ls -alh build/Macos
- uses: actions/upload-artifact@v4
name: upload-macos-arm64
with:
path: build/publish/libopencv_dart-macos-arm64.tar.gz
name: libopencv_dart-macos-arm64.tar.gz
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- name: Run Test
run: |
ls -alh $GITHUB_WORKSPACE/macos
export DYLD_LIBRARY_PATH=$GITHUB_WORKSPACE/macos:$DYLD_LIBRARY_PATH
flutter pub get
flutter test -x no-local-files
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
prerelease: false
files: |
build/publish/libopencv_dart-macos-arm64.tar.gz
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ __pycache__
small2.mp4
test/models/
*.dylib
CMakeUserPresets*

# Files and directories created by pub
.dart_tool/
Expand Down
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
[submodule "src/gocv"]
path = src/gocv
url = https://github.com/rainyl/gocv.git
[submodule "src/opencv"]
path = src/opencv
url = https://github.com/opencv/opencv.git
[submodule "src/opencv_contrib"]
path = src/opencv_contrib
url = https://github.com/opencv/opencv_contrib.git
87 changes: 87 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
cmake_minimum_required(VERSION 3.15)

project(opencv_dart_library VERSION 0.0.1 LANGUAGES C CXX)
set(library_name "opencv_dart")

set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

find_package(OpenCV REQUIRED)

set(OpenCV_LIBS
opencv_aruco opencv_core opencv_calib3d opencv_dnn opencv_highgui
opencv_features2d opencv_photo opencv_imgproc
opencv_objdetect opencv_video opencv_videoio opencv_stitching
)

if(ANDROID)
list(APPEND OpenCV_LIBS camera2ndk mediandk -landroid)
endif(ANDROID)

message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

file(GLOB GOCV_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"

# "${CMAKE_CURRENT_SOURCE_DIR}/gocv/contrib/*.cpp"
)
file(GLOB GOCV_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"

# "${CMAKE_CURRENT_SOURCE_DIR}/gocv/contrib/*.cpp"
)

add_library(${library_name} SHARED
${GOCV_FILES}
)
target_include_directories(${library_name} SYSTEM PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src"
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(${library_name} PRIVATE ${OpenCV_LIBS})
set_target_properties(${library_name} PROPERTIES

# PUBLIC_HEADER ${GOCV_HEADERS}
OUTPUT_NAME ${library_name}
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
LINK_FLAGS_RELEASE -s
)

if(WIN32)
set_target_properties(${library_name} PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
endif(WIN32)

target_compile_definitions(${library_name} PUBLIC DART_SHARED_LIB)

if(WITH_OPENCV_DART_DEMO)
add_executable(
demo
"demo.c"
)
target_link_libraries(
demo
PUBLIC
${OpenCV_LIBS}
${library_name}
)
endif()

# ## install
install(TARGETS ${library_name}
DESTINATION ${CMAKE_INSTALL_PREFIX})

if(WIN32)
file(GLOB CV_DEPENDENCIES "${CMAKE_BINARY_DIR}/*.dll")
elseif(APPLE)
file(GLOB CV_DEPENDENCIES "${CMAKE_BINARY_DIR}/*.dylib")
elseif(LINUX)
file(GLOB CV_DEPENDENCIES "${CMAKE_BINARY_DIR}/*.so")
endif()

install(FILES ${CV_DEPENDENCIES} DESTINATION ${CMAKE_INSTALL_PREFIX})
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ More examples are on the way...
- [ ] modify C wrapper to catch exceptions
- [ ] Native Assets
- [ ] async?
- [ ] directly include opencv source code, refactor cmakelists.txt

## For Developers

Expand Down
Loading

0 comments on commit a54b877

Please sign in to comment.