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