blob: 1e4c3545be815e8961e7e07d81db8064c555bce5 [file] [log] [blame]
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001SUMMARY = "Opencv : The Open Computer Vision Library"
2HOMEPAGE = "http://opencv.org/"
3SECTION = "libs"
4
5LICENSE = "Apache-2.0"
6LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57"
7
8ARM_INSTRUCTION_SET:armv4 = "arm"
9ARM_INSTRUCTION_SET:armv5 = "arm"
10
11DEPENDS = "libtool swig-native bzip2 zlib glib-2.0 libwebp"
12
Andrew Geissler615f2f12022-07-15 14:00:58 -050013SRCREV_opencv = "b0dc474160e389b9c9045da5db49d03ae17c6a6b"
14SRCREV_contrib = "7b77c355a8fdc97667b3fa1e7a0d37e4973fc868"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000015SRCREV_boostdesc = "34e4206aef44d50e6bbcd0ab06354b52e7466d26"
16SRCREV_vgg = "fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d"
17SRCREV_face = "8afa57abc8229d611c4937165d20e2a2d9fc5a12"
18SRCREV_wechat-qrcode = "a8b69ccc738421293254aec5ddb38bd523503252"
19
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000020
21SRCREV_FORMAT = "opencv_contrib_ipp_boostdesc_vgg"
22SRC_URI = "git://github.com/opencv/opencv.git;name=opencv;branch=master;protocol=https \
Patrick Williams2194f502022-10-16 14:26:09 -050023 git://github.com/opencv/opencv_contrib.git;destsuffix=git/contrib;name=contrib;branch=master;protocol=https \
Patrick Williams2194f502022-10-16 14:26:09 -050024 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_xfeatures2d_boostdesc_20161012;destsuffix=git/boostdesc;name=boostdesc;protocol=https \
25 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_xfeatures2d_vgg_20160317;destsuffix=git/vgg;name=vgg;protocol=https \
26 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_face_alignment_20170818;destsuffix=git/face;name=face;protocol=https \
27 git://github.com/WeChatCV/opencv_3rdparty.git;branch=wechat_qrcode;destsuffix=git/wechat_qrcode;name=wechat-qrcode;protocol=https \
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000028 file://0003-To-fix-errors-as-following.patch \
29 file://0001-Temporarliy-work-around-deprecated-ffmpeg-RAW-functi.patch \
30 file://0001-Dont-use-isystem.patch \
31 file://download.patch \
32 file://0001-Make-ts-module-external.patch \
Andrew Geissler517393d2023-01-13 08:55:19 -060033 file://0001-Add-missing-header-for-LIBAVCODEC_VERSION_INT.patch \
Andrew Geisslerc5535c92023-01-27 16:10:19 -060034 file://0008-Do-not-embed-build-directory-in-binaries.patch \
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000035 "
Patrick Williams2194f502022-10-16 14:26:09 -050036SRC_URI:append:riscv64 = " file://0001-Use-Os-to-compile-tinyxml2.cpp.patch;patchdir=contrib"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000037
38S = "${WORKDIR}/git"
39
40# OpenCV wants to download more files during configure. We download these in
41# do_fetch and construct a source cache in the format it expects
42OPENCV_DLDIR = "${WORKDIR}/downloads"
43
44do_unpack_extra() {
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000045
46 md5() {
47 # Return the MD5 of $1
48 echo $(md5sum $1 | cut -d' ' -f1)
49 }
50 cache() {
51 TAG=$1
52 shift
53 mkdir --parents ${OPENCV_DLDIR}/$TAG
54 for F in $*; do
55 DEST=${OPENCV_DLDIR}/$TAG/$(md5 $F)-$(basename $F)
56 test -e $DEST || ln -s $F $DEST
57 done
58 }
Patrick Williams2194f502022-10-16 14:26:09 -050059 cache xfeatures2d/boostdesc ${S}/boostdesc/*.i
60 cache xfeatures2d/vgg ${S}/vgg/*.i
61 cache data ${S}/face/*.dat
62 cache wechat_qrcode ${S}/wechat_qrcode/*.caffemodel
63 cache wechat_qrcode ${S}/wechat_qrcode/*.prototxt
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000064}
65addtask unpack_extra after do_unpack before do_patch
66
67CMAKE_VERBOSE = "VERBOSE=1"
68
Patrick Williams2194f502022-10-16 14:26:09 -050069EXTRA_OECMAKE = "-DOPENCV_EXTRA_MODULES_PATH=${S}/contrib/modules \
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000070 -DWITH_1394=OFF \
71 -DENABLE_PRECOMPILED_HEADERS=OFF \
72 -DCMAKE_SKIP_RPATH=ON \
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060073 -DWITH_IPP=OFF \
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000074 -DOPENCV_GENERATE_PKGCONFIG=ON \
75 -DOPENCV_DOWNLOAD_PATH=${OPENCV_DLDIR} \
76 -DOPENCV_ALLOW_DOWNLOADS=OFF \
77 ${@bb.utils.contains("TARGET_CC_ARCH", "-msse3", "-DENABLE_SSE=1 -DENABLE_SSE2=1 -DENABLE_SSE3=1 -DENABLE_SSSE3=1", "", d)} \
78 ${@bb.utils.contains("TARGET_CC_ARCH", "-msse4.1", "-DENABLE_SSE=1 -DENABLE_SSE2=1 -DENABLE_SSE3=1 -DENABLE_SSSE3=1 -DENABLE_SSE41=1", "", d)} \
79 ${@bb.utils.contains("TARGET_CC_ARCH", "-msse4.2", "-DENABLE_SSE=1 -DENABLE_SSE2=1 -DENABLE_SSE3=1 -DENABLE_SSSE3=1 -DENABLE_SSE41=1 -DENABLE_SSE42=1", "", d)} \
80"
Andrew Geissler615f2f12022-07-15 14:00:58 -050081LDFLAGS:append:mips = " -Wl,--no-as-needed -latomic -Wl,--as-needed"
82LDFLAGS:append:riscv32 = " -Wl,--no-as-needed -latomic -Wl,--as-needed"
83
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000084EXTRA_OECMAKE:append:x86 = " -DX86=ON"
85# disable sse4.1 and sse4.2 to fix 32bit build failure
86# https://github.com/opencv/opencv/issues/21597
87EXTRA_OECMAKE:remove:x86 = " -DENABLE_SSE41=1 -DENABLE_SSE42=1"
88
89PACKAGECONFIG ??= "gapi python3 eigen jpeg png tiff v4l libv4l gstreamer samples tbb gphoto2 \
90 ${@bb.utils.contains("DISTRO_FEATURES", "x11", "gtk", "", d)} \
Andrew Geissler517393d2023-01-13 08:55:19 -060091 ${@bb.utils.contains_any("LICENSE_FLAGS_ACCEPTED", "commercial_ffmpeg commercial", "libav", "", d)}"
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000092
93# TBB does not build for powerpc so disable that package config
94PACKAGECONFIG:remove:powerpc = "tbb"
95# tbb now needs getcontect/setcontext which is not there for all arches on musl
96PACKAGECONFIG:remove:libc-musl:riscv64 = "tbb"
97PACKAGECONFIG:remove:libc-musl:riscv32 = "tbb"
98
99PACKAGECONFIG[gapi] = "-DWITH_ADE=ON -Dade_DIR=${STAGING_LIBDIR},-DWITH_ADE=OFF,ade"
100PACKAGECONFIG[amdblas] = "-DWITH_OPENCLAMDBLAS=ON,-DWITH_OPENCLAMDBLAS=OFF,libclamdblas,"
101PACKAGECONFIG[amdfft] = "-DWITH_OPENCLAMDFFT=ON,-DWITH_OPENCLAMDFFT=OFF,libclamdfft,"
102PACKAGECONFIG[dnn] = "-DBUILD_opencv_dnn=ON -DPROTOBUF_UPDATE_FILES=ON -DBUILD_PROTOBUF=OFF,-DBUILD_opencv_dnn=OFF,protobuf protobuf-native,"
103PACKAGECONFIG[eigen] = "-DWITH_EIGEN=ON,-DWITH_EIGEN=OFF,libeigen gflags glog,"
104PACKAGECONFIG[freetype] = "-DBUILD_opencv_freetype=ON,-DBUILD_opencv_freetype=OFF,freetype,"
105PACKAGECONFIG[gphoto2] = "-DWITH_GPHOTO2=ON,-DWITH_GPHOTO2=OFF,libgphoto2,"
106PACKAGECONFIG[gstreamer] = "-DWITH_GSTREAMER=ON,-DWITH_GSTREAMER=OFF,gstreamer1.0 gstreamer1.0-plugins-base,"
107PACKAGECONFIG[gtk] = "-DWITH_GTK=ON,-DWITH_GTK=OFF,gtk+3,"
108PACKAGECONFIG[jasper] = "-DWITH_JASPER=ON,-DWITH_JASPER=OFF,jasper,"
109PACKAGECONFIG[java] = "-DJAVA_INCLUDE_PATH=${JAVA_HOME}/include -DJAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux -DJAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include -DJAVA_AWT_LIBRARY=${JAVA_HOME}/lib/amd64/libjawt.so -DJAVA_JVM_LIBRARY=${JAVA_HOME}/lib/amd64/server/libjvm.so,,ant-native fastjar-native openjdk-8-native,"
110PACKAGECONFIG[jpeg] = "-DWITH_JPEG=ON,-DWITH_JPEG=OFF,jpeg,"
111PACKAGECONFIG[libav] = "-DWITH_FFMPEG=ON,-DWITH_FFMPEG=OFF,libav,"
112PACKAGECONFIG[libv4l] = "-DWITH_LIBV4L=ON,-DWITH_LIBV4L=OFF,v4l-utils,"
113PACKAGECONFIG[opencl] = "-DWITH_OPENCL=ON,-DWITH_OPENCL=OFF,opencl-headers virtual/opencl-icd,"
114PACKAGECONFIG[oracle-java] = "-DJAVA_INCLUDE_PATH=${ORACLE_JAVA_HOME}/include -DJAVA_INCLUDE_PATH2=${ORACLE_JAVA_HOME}/include/linux -DJAVA_AWT_INCLUDE_PATH=${ORACLE_JAVA_HOME}/include -DJAVA_AWT_LIBRARY=${ORACLE_JAVA_HOME}/lib/amd64/libjawt.so -DJAVA_JVM_LIBRARY=${ORACLE_JAVA_HOME}/lib/amd64/server/libjvm.so,,ant-native oracle-jse-jdk oracle-jse-jdk-native,"
115PACKAGECONFIG[png] = "-DWITH_PNG=ON,-DWITH_PNG=OFF,libpng,"
116PACKAGECONFIG[python2] = "-DPYTHON2_NUMPY_INCLUDE_DIRS:PATH=${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include,,python-numpy,"
117PACKAGECONFIG[python3] = "-DPYTHON3_NUMPY_INCLUDE_DIRS:PATH=${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include,,python3-numpy,"
118PACKAGECONFIG[samples] = "-DBUILD_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON,-DBUILD_EXAMPLES=OFF,,"
119PACKAGECONFIG[tbb] = "-DWITH_TBB=ON,-DWITH_TBB=OFF,tbb,"
120PACKAGECONFIG[tests] = "-DBUILD_TESTS=ON,-DBUILD_TESTS=OFF,,"
121PACKAGECONFIG[text] = "-DBUILD_opencv_text=ON,-DBUILD_opencv_text=OFF,tesseract,"
122PACKAGECONFIG[tiff] = "-DWITH_TIFF=ON,-DWITH_TIFF=OFF,tiff,"
123PACKAGECONFIG[v4l] = "-DWITH_V4L=ON,-DWITH_V4L=OFF,v4l-utils,"
124
125inherit pkgconfig cmake
126
127inherit ${@bb.utils.contains('PACKAGECONFIG', 'python3', 'setuptools3-base', '', d)}
128inherit ${@bb.utils.contains('PACKAGECONFIG', 'python2', 'distutils-base', '', d)}
129
130export PYTHON_CSPEC="-I${STAGING_INCDIR}/${PYTHON_DIR}"
131export PYTHON="${STAGING_BINDIR_NATIVE}/${@bb.utils.contains('PACKAGECONFIG', 'python3', 'python3', 'python', d)}"
132export ORACLE_JAVA_HOME="${STAGING_DIR_NATIVE}/usr/bin/java"
133export JAVA_HOME="${STAGING_DIR_NATIVE}/usr/lib/jvm/openjdk-8-native"
134export ANT_DIR="${STAGING_DIR_NATIVE}/usr/share/ant/"
135
136TARGET_CC_ARCH += "-I${S}/include "
137
138PACKAGES += "${@bb.utils.contains('PACKAGECONFIG', 'samples', '${PN}-samples', '', d)} \
139 ${@bb.utils.contains('PACKAGECONFIG', 'oracle-java', '${PN}-java', '', d)} \
140 ${@bb.utils.contains('PACKAGECONFIG', 'java', '${PN}-java', '', d)} \
141 ${@bb.utils.contains('PACKAGECONFIG', 'python2', 'python-${BPN}', '', d)} \
142 ${@bb.utils.contains('PACKAGECONFIG', 'python3', 'python3-${BPN}', '', d)} \
143 ${PN}-apps"
144
145python populate_packages:prepend () {
146 cv_libdir = d.expand('${libdir}')
147 do_split_packages(d, cv_libdir, r'^lib(.*)\.so$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev', allow_links=True)
148 do_split_packages(d, cv_libdir, r'^lib(.*)\.la$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev')
149 do_split_packages(d, cv_libdir, r'^lib(.*)\.a$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev')
150 do_split_packages(d, cv_libdir, r'^lib(.*)\.so\.*', 'lib%s', 'OpenCV %s library', extra_depends='', allow_links=True)
151
152 pn = d.getVar('PN')
153 metapkg = pn + '-dev'
154 d.setVar('ALLOW_EMPTY:' + metapkg, "1")
155 blacklist = [ metapkg ]
156 metapkg_rdepends = [ ]
157 packages = d.getVar('PACKAGES').split()
158 for pkg in packages[1:]:
159 if not pkg in blacklist and not pkg in metapkg_rdepends and pkg.endswith('-dev'):
160 metapkg_rdepends.append(pkg)
161 d.setVar('RRECOMMENDS:' + metapkg, ' '.join(metapkg_rdepends))
162
163 metapkg = pn
164 d.setVar('ALLOW_EMPTY:' + metapkg, "1")
165 blacklist = [ metapkg, "libopencv-ts" ]
166 metapkg_rdepends = [ ]
167 for pkg in packages[1:]:
168 if not pkg in blacklist and not pkg in metapkg_rdepends and not pkg.endswith('-dev') and not pkg.endswith('-dbg') and not pkg.endswith('-doc') and not pkg.endswith('-locale') and not pkg.endswith('-staticdev'):
169 metapkg_rdepends.append(pkg)
170 d.setVar('RDEPENDS:' + metapkg, ' '.join(metapkg_rdepends))
171}
172
173PACKAGES_DYNAMIC += "^libopencv-.*"
174
175FILES:${PN} = ""
176FILES:${PN}-dbg += "${datadir}/OpenCV/java/.debug/* ${datadir}/OpenCV/samples/bin/.debug/*"
177FILES:${PN}-dev = "${includedir} ${libdir}/pkgconfig ${libdir}/cmake/opencv4/*.cmake"
178FILES:${PN}-staticdev += "${libdir}/opencv4/3rdparty/*.a"
179FILES:${PN}-apps = "${bindir}/* ${datadir}/opencv4 ${datadir}/licenses"
180FILES:${PN}-java = "${datadir}/OpenCV/java"
181FILES:${PN}-samples = "${datadir}/opencv4/samples/"
182
183INSANE_SKIP:${PN}-java = "libdir"
184INSANE_SKIP:${PN}-dbg = "libdir"
185
186ALLOW_EMPTY:${PN} = "1"
187
188SUMMARY:python-opencv = "Python bindings to opencv"
189FILES:python-opencv = "${PYTHON_SITEPACKAGES_DIR}/*"
190RDEPENDS:python-opencv = "python-core python-numpy"
191
192SUMMARY:python3-opencv = "Python bindings to opencv"
193FILES:python3-opencv = "${PYTHON_SITEPACKAGES_DIR}/*"
194RDEPENDS:python3-opencv = "python3-core python3-numpy"
195
196RDEPENDS:${PN}-apps = "bash"
197
198do_compile:prepend() {
199 # remove the build host info to improve reproducibility
200 if [ -f ${WORKDIR}/build/modules/core/version_string.inc ]; then
201 sed -i "s#${WORKDIR}#/workdir#g" ${WORKDIR}/build/modules/core/version_string.inc
202 fi
203}
204
205do_install:append() {
206 # Move Python files into correct library folder (for multilib build)
207 if [ "$libdir" != "/usr/lib" -a -d ${D}/usr/lib ]; then
208 mv ${D}/usr/lib/* ${D}/${libdir}/
209 rm -rf ${D}/usr/lib
210 fi
211 # remove build host path to improve reproducibility
212 if [ -f ${D}${libdir}/cmake/opencv4/OpenCVModules.cmake ]; then
213 sed -e 's@${STAGING_DIR_HOST}@@g' \
214 -i ${D}${libdir}/cmake/opencv4/OpenCVModules.cmake
215 fi
216 # remove setup_vars_opencv4.sh as its content is confusing and useless
217 if [ -f ${D}${bindir}/setup_vars_opencv4.sh ]; then
218 rm -rf ${D}${bindir}/setup_vars_opencv4.sh
219 fi
220}