Skip to content

Commit

Permalink
Build for headless qt5 and qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaarrfk committed Mar 13, 2024
1 parent 328ac16 commit 813fd05
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 20 deletions.
6 changes: 5 additions & 1 deletion recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if "%PY3K%" == "0" (
mkdir build
cd build

if "%qt_version%"=="5" set WITH_QT="-DWITH_QT=5"
if "%qt_version%"=="6" set WITH_QT="-DWITH_QT=6"
if "%qt_version%"=="none" set WITH_QT="-DWITH_QT=0"

for /F "tokens=1,2 delims=. " %%a in ("%PY_VER%") do (
set "PY_MAJOR=%%a"
set "PY_MINOR=%%b"
Expand Down Expand Up @@ -85,7 +89,7 @@ cmake -LAH -G "Ninja"
-DWITH_TESSERACT=0 ^
-DWITH_VTK=0 ^
-DWITH_WIN32UI=0 ^
-DWITH_QT=5 ^
%WITH_QT% ^
-DINSTALL_C_EXAMPLES=0 ^
-DOPENCV_EXTRA_MODULES_PATH=%UNIX_SRC_DIR%/opencv_contrib/modules ^
-DPYTHON_EXECUTABLE="" ^
Expand Down
12 changes: 9 additions & 3 deletions recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -ex
# https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindPNG.cmake#L55
ln -s $PREFIX/include/libpng16 $PREFIX/include/libpng

QT="5"
V4L="1"
OPENVINO="1"

Expand All @@ -16,17 +15,24 @@ if [[ "${target_platform}" == linux-* ]]; then
OPENMP="-DWITH_OPENMP=1"
fi

if [[ "${target_platform}" == osx-* ]]; then
if [[ "$qt_version" == "5" ]]; then
QT="5"
elif [[ "$qt_version" == "6" ]]; then
QT="6"
else
QT="0"
fi

if [[ "${target_platform}" == osx-* ]]; then
V4L="0"
elif [[ "${target_platform}" == linux-ppc64le ]]; then
QT="0"
OPENVINO="0"
fi


if [[ "${target_platform}" != "${build_platform}" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DProtobuf_PROTOC_EXECUTABLE=$BUILD_PREFIX/bin/protoc"
CMAKE_ARGS="${CMAKE_ARGS} -DQT_HOST_PATH=${BUILD_PREFIX}"
fi


Expand Down
20 changes: 16 additions & 4 deletions recipe/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
MACOSX_SDK_VERSION: # [osx and x86_64]
- "10.13" # [osx and x86_64]
MACOSX_DEPLOYMENT_TARGET: # [osx and x86_64]
- "10.13" # [osx and x86_64]
MACOSX_SDK_VERSION: # [osx and x86_64 and qt_version!=6]
- "10.13" # [osx and x86_64 and qt_version!=6]
MACOSX_DEPLOYMENT_TARGET: # [osx and x86_64 and qt_version!=6]
- "10.13" # [osx and x86_64 and qt_version==none]
- "10.13" # [osx and x86_64 and qt_version==5]

# https://doc.qt.io/qt-6/macos.html
MACOSX_DEPLOYMENT_TARGET: # [osx and qt_version == 6]
- '11.0' # [osx and qt_version == 6]
MACOSX_SDK_VERSION: # [osx and qt_version == 6]
- '12.3' # [osx and qt_version == 6]

qt_version:
- none
- 5 # [not ppc64le]
- 6 # [not ppc64le]
46 changes: 34 additions & 12 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
{% set PY_VER_MAJOR = PY_VER.split('.')[0] %}
{% set PY_VER_MINOR = PY_VER.split('.')[1] %}

{% set build = 10 %}

{% if qt_version == "5" %}
{% set build = build + 200 %}
{% endif %}

{% if qt_version == "6" %}
{% set build = build + 400 %}
{% endif %}

package:
name: libopencv
version: {{ version }}
Expand All @@ -35,6 +45,7 @@ source:
patches:
# backport https://github.com/opencv/opencv/pull/21611 (unmerged as of 06/2023)
- patches_opencv/0001-Add-installation-of-pip-metadata-from-cmake.patch
- patches_opencv/0001-Also-install-metadata-for-opencv-python-headless.patch
- patches_opencv/0002-delete-lines-that-download-opencv.patch
- patches_opencv/0003-find-pkgconfig-on-windows.patch
- patches_opencv/0004-fix-detection-for-protobuf-23.x.patch
Expand All @@ -50,21 +61,24 @@ source:
sha256: 78884f64b564a3b06dc6ee731ed33b60c6d8cd864cea07f21d94ba0f90c7b310

build:
number: 9
string: py{{ PY_VER_MAJOR }}{{ PY_VER_MINOR }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
number: {{ build }}
string: qt{{ qt_version }}_py{{ PY_VER_MAJOR }}{{ PY_VER_MINOR }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
run_exports:
# https://abi-laboratory.pro/index.php?view=timeline&l=opencv
# Things seem to change every patch versions, mostly the dnn module
- {{ pin_subpackage('libopencv', max_pin='x.x.x') }}
ignore_run_exports_from:
- python
# Skip for now. remove me later
skip: true # [py!=310]

requirements:
build:
- python # [build_platform != target_platform]
- cross-python_{{ target_platform }} # [build_platform != target_platform]
- numpy # [build_platform != target_platform]
- libprotobuf # [build_platform != target_platform]
- qt6-main # [build_platform != target_platform and qt_version == 6]
# pkg-config is required to find ffpmeg
- pkg-config
- cmake
Expand All @@ -91,8 +105,9 @@ requirements:
# binary
- ffmpeg {{ ffmpeg }}=lgpl_*
- freetype
- glib # [unix]
# harfbuzz and glib are both needed for freetype support
- harfbuzz
- glib
- hdf5
- jasper
- libcblas
Expand All @@ -105,7 +120,8 @@ requirements:
- libtiff
- libwebp
- openexr
- qt-main # [not osx and not ppc64le]
- qt-main # [qt_version == 5]
- qt6-main # [qt_version == 6]
- zlib
- libopenvino-dev # [not ppc64le]

Expand Down Expand Up @@ -181,15 +197,16 @@ test:
{{ opencv_libs.append("xobjdetect") or "" }}
{{ opencv_libs.append("xphoto") or "" }}
{{ opencv_libs.append("freetype") or "" }}
- export MACOSX_DEPLOYMENT_TARGET={{ MACOSX_DEPLOYMENT_TARGET }} # [osx]
- export CONDA_BUILD_SYSROOT={{ CONDA_BUILD_SYSROOT }} # [osx]
- OPENCV_FLAGS=`pkg-config --cflags opencv4` # [unix]
- $CXX -std=c++11 $RECIPE_DIR/test.cpp ${OPENCV_FLAGS} -o test # [unix]
- export MACOSX_DEPLOYMENT_TARGET={{ MACOSX_DEPLOYMENT_TARGET }} # [osx]
- export CONDA_BUILD_SYSROOT={{ CONDA_BUILD_SYSROOT }} # [osx]
- OPENCV_FLAGS=`pkg-config --cflags opencv4` # [unix]
- $CXX -std=c++11 $RECIPE_DIR/test.cpp ${OPENCV_FLAGS} -o test # [unix]
- if [[ $(./test) != $PKG_VERSION ]]; then exit 1 ; fi # [unix]
{% for each_opencv_lib in opencv_libs %}
- echo Testing for presence of {{ each_opencv_lib }}
- test -f $PREFIX/lib/libopencv_{{ each_opencv_lib }}${SHLIB_EXT} # [unix]
- test -f $PREFIX/lib/libopencv_{{ each_opencv_lib }}${SHLIB_EXT} # [unix]
- if not exist %PREFIX%\\Library\\bin\\opencv_{{ each_opencv_lib }}{{ win_ver_lib }}.dll exit 1 # [win]
- echo Found {{ each_opencv_lib }}
{% endfor %}
- test -f $PREFIX/lib/libopencv_bioinspired${SHLIB_EXT} # [unix]
- test -f $PREFIX/lib/libopencv_hdf${SHLIB_EXT} # [unix]
Expand All @@ -202,7 +219,9 @@ outputs:
- name: libopencv
- name: opencv
build:
string: py{{ PY_VER_MAJOR }}{{ PY_VER_MINOR }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
string: qt{{ qt_version }}_py{{ PY_VER_MAJOR }}{{ PY_VER_MINOR }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
# Skip for now. remove me later
skip: true # [py!=310]
requirements:
host:
# Explicitely add a python requirement so that the hash changes between
Expand All @@ -220,7 +239,9 @@ outputs:

- name: py-opencv
build:
string: py{{ PY_VER_MAJOR }}{{ PY_VER_MINOR }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
# Skip for now. remove me later
skip: true # [py!=310]
string: qt{{ qt_version }}_py{{ PY_VER_MAJOR }}{{ PY_VER_MINOR }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}
run_exports:
# Should we even have this???
# don't pin the python version so hard.
Expand Down Expand Up @@ -262,7 +283,8 @@ outputs:
- python -c "import cv2, re; assert re.search('Lapack:\s+YES', cv2.getBuildInformation())"
- pip check
- pip list
- test $(pip list | grep opencv-python | wc -l) -eq 1 # [unix]
- test $(pip list | grep opencv-python | wc -l) -eq 2 # [unix]
- test $(pip list | grep opencv-python-headless | wc -l) -eq 1 # [unix]
requires:
- pip

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From bab68f46520a60ed4fa6b384fe36d7174183e983 Mon Sep 17 00:00:00 2001
From: Mark Harfouche <mark.harfouche@gmail.com>
Date: Mon, 11 Mar 2024 22:40:08 -0400
Subject: [PATCH] Also install metadata for opencv-python-headless

---
modules/python/common.cmake | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/modules/python/common.cmake b/modules/python/common.cmake
index 88f4189206..f4c8ec7258 100644
--- a/modules/python/common.cmake
+++ b/modules/python/common.cmake
@@ -252,6 +252,17 @@ if (OPENCV_PYTHON_PIP_METADATA_INSTALL)
FILES "${CMAKE_CURRENT_BINARY_DIR}/METADATA" "${CMAKE_CURRENT_BINARY_DIR}/INSTALLER"
DESTINATION ${OPENCV_PYTHON_INSTALL_PATH}/opencv_python-${OPENCV_VERSION}.dist-info
COMPONENT python)
+
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info")
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info/METADATA "")
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info/METADATA "Metadata-Version: 2.1\n")
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info/METADATA "Name: opencv-python-headless\n")
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info/METADATA "Version: ${OPENCV_VERSION}\n")
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info/INSTALLER "${OPENCV_PYTHON_PIP_METADATA_INSTALLER}\n")
+ install(
+ FILES "${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info/METADATA" "${CMAKE_CURRENT_BINARY_DIR}/ocvph.dist-info/INSTALLER"
+ DESTINATION ${OPENCV_PYTHON_INSTALL_PATH}/opencv_python_headless-${OPENCV_VERSION}.dist-info
+ COMPONENT python)
endif()

unset(PYTHON_SRC_DIR)
--
2.43.2

3 changes: 3 additions & 0 deletions recipe/yum_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
mesa-libGL
mesa-libEGL
libglvnd-glx
libglvnd-opengl

0 comments on commit 813fd05

Please sign in to comment.