blob: e4fb676f7e1585ed91e8fa494fd2bdf719d2d8fc [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
13SRCREV_opencv = "dad26339a975b49cfb6c7dbe4bd5276c9dcb36e2"
14SRCREV_contrib = "49e8f123ca08e76891856a1ecce491b62d08ba20"
15SRCREV_ipp = "a56b6ac6f030c312b2dce17430eef13aed9af274"
16SRCREV_boostdesc = "34e4206aef44d50e6bbcd0ab06354b52e7466d26"
17SRCREV_vgg = "fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d"
18SRCREV_face = "8afa57abc8229d611c4937165d20e2a2d9fc5a12"
19SRCREV_wechat-qrcode = "a8b69ccc738421293254aec5ddb38bd523503252"
20
21def ipp_filename(d):
22 import re
23 arch = d.getVar('TARGET_ARCH')
24 if re.match("i.86$", arch):
25 return "ippicv_2020_lnx_ia32_20191018_general.tgz"
26 else:
27 return "ippicv_2020_lnx_intel64_20191018_general.tgz"
28
29def ipp_md5sum(d):
30 import re
31 arch = d.getVar('TARGET_ARCH')
32 if re.match("i.86$", arch):
33 return "ad189a940fb60eb71f291321322fe3e8"
34 else:
35 return "7421de0095c7a39162ae13a6098782f9"
36
37IPP_FILENAME = "${@ipp_filename(d)}"
38IPP_MD5 = "${@ipp_md5sum(d)}"
39
40SRCREV_FORMAT = "opencv_contrib_ipp_boostdesc_vgg"
41SRC_URI = "git://github.com/opencv/opencv.git;name=opencv;branch=master;protocol=https \
42 git://github.com/opencv/opencv_contrib.git;destsuffix=contrib;name=contrib;branch=master;protocol=https \
43 git://github.com/opencv/opencv_3rdparty.git;branch=ippicv/master_20191018;destsuffix=ipp;name=ipp;protocol=https \
44 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_xfeatures2d_boostdesc_20161012;destsuffix=boostdesc;name=boostdesc;protocol=https \
45 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_xfeatures2d_vgg_20160317;destsuffix=vgg;name=vgg;protocol=https \
46 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_face_alignment_20170818;destsuffix=face;name=face;protocol=https \
47 git://github.com/WeChatCV/opencv_3rdparty.git;branch=wechat_qrcode;destsuffix=wechat_qrcode;name=wechat-qrcode;protocol=https \
48 file://0001-3rdparty-ippicv-Use-pre-downloaded-ipp.patch \
49 file://0003-To-fix-errors-as-following.patch \
50 file://0001-Temporarliy-work-around-deprecated-ffmpeg-RAW-functi.patch \
51 file://0001-Dont-use-isystem.patch \
52 file://download.patch \
53 file://0001-Make-ts-module-external.patch \
Patrick Williams03907ee2022-05-01 06:28:52 -050054 file://0001-core-vsx-update-vec_absd-workaround-condition.patch \
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000055 "
56SRC_URI:append:riscv64 = " file://0001-Use-Os-to-compile-tinyxml2.cpp.patch;patchdir=../contrib"
57
58S = "${WORKDIR}/git"
59
60# OpenCV wants to download more files during configure. We download these in
61# do_fetch and construct a source cache in the format it expects
62OPENCV_DLDIR = "${WORKDIR}/downloads"
63
64do_unpack_extra() {
65 tar xzf ${WORKDIR}/ipp/ippicv/${IPP_FILENAME} -C ${WORKDIR}
66
67 md5() {
68 # Return the MD5 of $1
69 echo $(md5sum $1 | cut -d' ' -f1)
70 }
71 cache() {
72 TAG=$1
73 shift
74 mkdir --parents ${OPENCV_DLDIR}/$TAG
75 for F in $*; do
76 DEST=${OPENCV_DLDIR}/$TAG/$(md5 $F)-$(basename $F)
77 test -e $DEST || ln -s $F $DEST
78 done
79 }
80 cache xfeatures2d/boostdesc ${WORKDIR}/boostdesc/*.i
81 cache xfeatures2d/vgg ${WORKDIR}/vgg/*.i
82 cache data ${WORKDIR}/face/*.dat
83 cache wechat_qrcode ${WORKDIR}/wechat_qrcode/*.caffemodel
84 cache wechat_qrcode ${WORKDIR}/wechat_qrcode/*.prototxt
85}
86addtask unpack_extra after do_unpack before do_patch
87
88CMAKE_VERBOSE = "VERBOSE=1"
89
90EXTRA_OECMAKE = "-DOPENCV_EXTRA_MODULES_PATH=${WORKDIR}/contrib/modules \
91 -DWITH_1394=OFF \
92 -DENABLE_PRECOMPILED_HEADERS=OFF \
93 -DCMAKE_SKIP_RPATH=ON \
94 -DOPENCV_ICV_HASH=${IPP_MD5} \
95 -DIPPROOT=${WORKDIR}/ippicv_lnx \
96 -DOPENCV_GENERATE_PKGCONFIG=ON \
97 -DOPENCV_DOWNLOAD_PATH=${OPENCV_DLDIR} \
98 -DOPENCV_ALLOW_DOWNLOADS=OFF \
99 ${@bb.utils.contains("TARGET_CC_ARCH", "-msse3", "-DENABLE_SSE=1 -DENABLE_SSE2=1 -DENABLE_SSE3=1 -DENABLE_SSSE3=1", "", d)} \
100 ${@bb.utils.contains("TARGET_CC_ARCH", "-msse4.1", "-DENABLE_SSE=1 -DENABLE_SSE2=1 -DENABLE_SSE3=1 -DENABLE_SSSE3=1 -DENABLE_SSE41=1", "", d)} \
101 ${@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)} \
102"
103EXTRA_OECMAKE:append:x86 = " -DX86=ON"
104# disable sse4.1 and sse4.2 to fix 32bit build failure
105# https://github.com/opencv/opencv/issues/21597
106EXTRA_OECMAKE:remove:x86 = " -DENABLE_SSE41=1 -DENABLE_SSE42=1"
107
108PACKAGECONFIG ??= "gapi python3 eigen jpeg png tiff v4l libv4l gstreamer samples tbb gphoto2 \
109 ${@bb.utils.contains("DISTRO_FEATURES", "x11", "gtk", "", d)} \
110 "
111
112# TBB does not build for powerpc so disable that package config
113PACKAGECONFIG:remove:powerpc = "tbb"
114# tbb now needs getcontect/setcontext which is not there for all arches on musl
115PACKAGECONFIG:remove:libc-musl:riscv64 = "tbb"
116PACKAGECONFIG:remove:libc-musl:riscv32 = "tbb"
117
118PACKAGECONFIG[gapi] = "-DWITH_ADE=ON -Dade_DIR=${STAGING_LIBDIR},-DWITH_ADE=OFF,ade"
119PACKAGECONFIG[amdblas] = "-DWITH_OPENCLAMDBLAS=ON,-DWITH_OPENCLAMDBLAS=OFF,libclamdblas,"
120PACKAGECONFIG[amdfft] = "-DWITH_OPENCLAMDFFT=ON,-DWITH_OPENCLAMDFFT=OFF,libclamdfft,"
121PACKAGECONFIG[dnn] = "-DBUILD_opencv_dnn=ON -DPROTOBUF_UPDATE_FILES=ON -DBUILD_PROTOBUF=OFF,-DBUILD_opencv_dnn=OFF,protobuf protobuf-native,"
122PACKAGECONFIG[eigen] = "-DWITH_EIGEN=ON,-DWITH_EIGEN=OFF,libeigen gflags glog,"
123PACKAGECONFIG[freetype] = "-DBUILD_opencv_freetype=ON,-DBUILD_opencv_freetype=OFF,freetype,"
124PACKAGECONFIG[gphoto2] = "-DWITH_GPHOTO2=ON,-DWITH_GPHOTO2=OFF,libgphoto2,"
125PACKAGECONFIG[gstreamer] = "-DWITH_GSTREAMER=ON,-DWITH_GSTREAMER=OFF,gstreamer1.0 gstreamer1.0-plugins-base,"
126PACKAGECONFIG[gtk] = "-DWITH_GTK=ON,-DWITH_GTK=OFF,gtk+3,"
127PACKAGECONFIG[jasper] = "-DWITH_JASPER=ON,-DWITH_JASPER=OFF,jasper,"
128PACKAGECONFIG[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,"
129PACKAGECONFIG[jpeg] = "-DWITH_JPEG=ON,-DWITH_JPEG=OFF,jpeg,"
130PACKAGECONFIG[libav] = "-DWITH_FFMPEG=ON,-DWITH_FFMPEG=OFF,libav,"
131PACKAGECONFIG[libv4l] = "-DWITH_LIBV4L=ON,-DWITH_LIBV4L=OFF,v4l-utils,"
132PACKAGECONFIG[opencl] = "-DWITH_OPENCL=ON,-DWITH_OPENCL=OFF,opencl-headers virtual/opencl-icd,"
133PACKAGECONFIG[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,"
134PACKAGECONFIG[png] = "-DWITH_PNG=ON,-DWITH_PNG=OFF,libpng,"
135PACKAGECONFIG[python2] = "-DPYTHON2_NUMPY_INCLUDE_DIRS:PATH=${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include,,python-numpy,"
136PACKAGECONFIG[python3] = "-DPYTHON3_NUMPY_INCLUDE_DIRS:PATH=${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include,,python3-numpy,"
137PACKAGECONFIG[samples] = "-DBUILD_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON,-DBUILD_EXAMPLES=OFF,,"
138PACKAGECONFIG[tbb] = "-DWITH_TBB=ON,-DWITH_TBB=OFF,tbb,"
139PACKAGECONFIG[tests] = "-DBUILD_TESTS=ON,-DBUILD_TESTS=OFF,,"
140PACKAGECONFIG[text] = "-DBUILD_opencv_text=ON,-DBUILD_opencv_text=OFF,tesseract,"
141PACKAGECONFIG[tiff] = "-DWITH_TIFF=ON,-DWITH_TIFF=OFF,tiff,"
142PACKAGECONFIG[v4l] = "-DWITH_V4L=ON,-DWITH_V4L=OFF,v4l-utils,"
143
144inherit pkgconfig cmake
145
146inherit ${@bb.utils.contains('PACKAGECONFIG', 'python3', 'setuptools3-base', '', d)}
147inherit ${@bb.utils.contains('PACKAGECONFIG', 'python2', 'distutils-base', '', d)}
148
149export PYTHON_CSPEC="-I${STAGING_INCDIR}/${PYTHON_DIR}"
150export PYTHON="${STAGING_BINDIR_NATIVE}/${@bb.utils.contains('PACKAGECONFIG', 'python3', 'python3', 'python', d)}"
151export ORACLE_JAVA_HOME="${STAGING_DIR_NATIVE}/usr/bin/java"
152export JAVA_HOME="${STAGING_DIR_NATIVE}/usr/lib/jvm/openjdk-8-native"
153export ANT_DIR="${STAGING_DIR_NATIVE}/usr/share/ant/"
154
155TARGET_CC_ARCH += "-I${S}/include "
156
157PACKAGES += "${@bb.utils.contains('PACKAGECONFIG', 'samples', '${PN}-samples', '', d)} \
158 ${@bb.utils.contains('PACKAGECONFIG', 'oracle-java', '${PN}-java', '', d)} \
159 ${@bb.utils.contains('PACKAGECONFIG', 'java', '${PN}-java', '', d)} \
160 ${@bb.utils.contains('PACKAGECONFIG', 'python2', 'python-${BPN}', '', d)} \
161 ${@bb.utils.contains('PACKAGECONFIG', 'python3', 'python3-${BPN}', '', d)} \
162 ${PN}-apps"
163
164python populate_packages:prepend () {
165 cv_libdir = d.expand('${libdir}')
166 do_split_packages(d, cv_libdir, r'^lib(.*)\.so$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev', allow_links=True)
167 do_split_packages(d, cv_libdir, r'^lib(.*)\.la$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev')
168 do_split_packages(d, cv_libdir, r'^lib(.*)\.a$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev')
169 do_split_packages(d, cv_libdir, r'^lib(.*)\.so\.*', 'lib%s', 'OpenCV %s library', extra_depends='', allow_links=True)
170
171 pn = d.getVar('PN')
172 metapkg = pn + '-dev'
173 d.setVar('ALLOW_EMPTY:' + metapkg, "1")
174 blacklist = [ metapkg ]
175 metapkg_rdepends = [ ]
176 packages = d.getVar('PACKAGES').split()
177 for pkg in packages[1:]:
178 if not pkg in blacklist and not pkg in metapkg_rdepends and pkg.endswith('-dev'):
179 metapkg_rdepends.append(pkg)
180 d.setVar('RRECOMMENDS:' + metapkg, ' '.join(metapkg_rdepends))
181
182 metapkg = pn
183 d.setVar('ALLOW_EMPTY:' + metapkg, "1")
184 blacklist = [ metapkg, "libopencv-ts" ]
185 metapkg_rdepends = [ ]
186 for pkg in packages[1:]:
187 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'):
188 metapkg_rdepends.append(pkg)
189 d.setVar('RDEPENDS:' + metapkg, ' '.join(metapkg_rdepends))
190}
191
192PACKAGES_DYNAMIC += "^libopencv-.*"
193
194FILES:${PN} = ""
195FILES:${PN}-dbg += "${datadir}/OpenCV/java/.debug/* ${datadir}/OpenCV/samples/bin/.debug/*"
196FILES:${PN}-dev = "${includedir} ${libdir}/pkgconfig ${libdir}/cmake/opencv4/*.cmake"
197FILES:${PN}-staticdev += "${libdir}/opencv4/3rdparty/*.a"
198FILES:${PN}-apps = "${bindir}/* ${datadir}/opencv4 ${datadir}/licenses"
199FILES:${PN}-java = "${datadir}/OpenCV/java"
200FILES:${PN}-samples = "${datadir}/opencv4/samples/"
201
202INSANE_SKIP:${PN}-java = "libdir"
203INSANE_SKIP:${PN}-dbg = "libdir"
204
205ALLOW_EMPTY:${PN} = "1"
206
207SUMMARY:python-opencv = "Python bindings to opencv"
208FILES:python-opencv = "${PYTHON_SITEPACKAGES_DIR}/*"
209RDEPENDS:python-opencv = "python-core python-numpy"
210
211SUMMARY:python3-opencv = "Python bindings to opencv"
212FILES:python3-opencv = "${PYTHON_SITEPACKAGES_DIR}/*"
213RDEPENDS:python3-opencv = "python3-core python3-numpy"
214
215RDEPENDS:${PN}-apps = "bash"
216
217do_compile:prepend() {
218 # remove the build host info to improve reproducibility
219 if [ -f ${WORKDIR}/build/modules/core/version_string.inc ]; then
220 sed -i "s#${WORKDIR}#/workdir#g" ${WORKDIR}/build/modules/core/version_string.inc
221 fi
222}
223
224do_install:append() {
225 # Move Python files into correct library folder (for multilib build)
226 if [ "$libdir" != "/usr/lib" -a -d ${D}/usr/lib ]; then
227 mv ${D}/usr/lib/* ${D}/${libdir}/
228 rm -rf ${D}/usr/lib
229 fi
230 # remove build host path to improve reproducibility
231 if [ -f ${D}${libdir}/cmake/opencv4/OpenCVModules.cmake ]; then
232 sed -e 's@${STAGING_DIR_HOST}@@g' \
233 -i ${D}${libdir}/cmake/opencv4/OpenCVModules.cmake
234 fi
235 # remove setup_vars_opencv4.sh as its content is confusing and useless
236 if [ -f ${D}${bindir}/setup_vars_opencv4.sh ]; then
237 rm -rf ${D}${bindir}/setup_vars_opencv4.sh
238 fi
239}