blob: 7eefbccfe0ff3df788474ebb66837018fe34edb8 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001SUMMARY = "Opencv : The Open Computer Vision Library"
2HOMEPAGE = "http://opencv.org/"
3SECTION = "libs"
4
Andrew Geissler4b7c1152020-11-30 19:55:29 -06005LICENSE = "Apache-2.0"
6LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57"
Brad Bishop19323692019-04-05 15:28:33 -04007
Patrick Williams213cb262021-08-07 19:21:33 -05008ARM_INSTRUCTION_SET:armv4 = "arm"
9ARM_INSTRUCTION_SET:armv5 = "arm"
Brad Bishop19323692019-04-05 15:28:33 -040010
11DEPENDS = "libtool swig-native bzip2 zlib glib-2.0 libwebp"
12
Andrew Geisslere34f8962021-04-15 15:53:51 -050013SRCREV_opencv = "69357b1e88680658a07cffde7678a4d697469f03"
14SRCREV_contrib = "f5d7f6712d4ff229ba4f45cf79dfd11c557d56fd"
Andrew Geissler7f40b712020-05-15 14:09:53 -050015SRCREV_ipp = "a56b6ac6f030c312b2dce17430eef13aed9af274"
Brad Bishop19323692019-04-05 15:28:33 -040016SRCREV_boostdesc = "34e4206aef44d50e6bbcd0ab06354b52e7466d26"
17SRCREV_vgg = "fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d"
Brad Bishope42b3e32020-01-15 22:08:42 -050018SRCREV_face = "8afa57abc8229d611c4937165d20e2a2d9fc5a12"
Andrew Geisslere34f8962021-04-15 15:53:51 -050019SRCREV_wechat-qrcode = "a8b69ccc738421293254aec5ddb38bd523503252"
Brad Bishop19323692019-04-05 15:28:33 -040020
21def ipp_filename(d):
22 import re
23 arch = d.getVar('TARGET_ARCH')
24 if re.match("i.86$", arch):
Andrew Geissler7f40b712020-05-15 14:09:53 -050025 return "ippicv_2020_lnx_ia32_20191018_general.tgz"
Brad Bishop19323692019-04-05 15:28:33 -040026 else:
Andrew Geissler7f40b712020-05-15 14:09:53 -050027 return "ippicv_2020_lnx_intel64_20191018_general.tgz"
Brad Bishop19323692019-04-05 15:28:33 -040028
29def ipp_md5sum(d):
30 import re
31 arch = d.getVar('TARGET_ARCH')
32 if re.match("i.86$", arch):
Andrew Geissler7f40b712020-05-15 14:09:53 -050033 return "ad189a940fb60eb71f291321322fe3e8"
Brad Bishop19323692019-04-05 15:28:33 -040034 else:
Andrew Geissler7f40b712020-05-15 14:09:53 -050035 return "7421de0095c7a39162ae13a6098782f9"
Brad Bishop19323692019-04-05 15:28:33 -040036
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 \
Brad Bishop26bdd442019-08-16 17:08:17 -040042 git://github.com/opencv/opencv_contrib.git;destsuffix=contrib;name=contrib \
Andrew Geissler7f40b712020-05-15 14:09:53 -050043 git://github.com/opencv/opencv_3rdparty.git;branch=ippicv/master_20191018;destsuffix=ipp;name=ipp \
Brad Bishop26bdd442019-08-16 17:08:17 -040044 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_xfeatures2d_boostdesc_20161012;destsuffix=boostdesc;name=boostdesc \
45 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_xfeatures2d_vgg_20160317;destsuffix=vgg;name=vgg \
Brad Bishope42b3e32020-01-15 22:08:42 -050046 git://github.com/opencv/opencv_3rdparty.git;branch=contrib_face_alignment_20170818;destsuffix=face;name=face \
Andrew Geisslere34f8962021-04-15 15:53:51 -050047 git://github.com/WeChatCV/opencv_3rdparty.git;branch=wechat_qrcode;destsuffix=wechat_qrcode;name=wechat-qrcode \
Brad Bishop26bdd442019-08-16 17:08:17 -040048 file://0001-3rdparty-ippicv-Use-pre-downloaded-ipp.patch \
Brad Bishop26bdd442019-08-16 17:08:17 -040049 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 \
Brad Bishope42b3e32020-01-15 22:08:42 -050052 file://download.patch \
Andrew Geisslerc87764f2020-06-27 00:16:32 -050053 file://0001-Make-ts-module-external.patch \
Andrew Geisslere34f8962021-04-15 15:53:51 -050054 file://0001-sfm-link-with-Glog_LIBS.patch;patchdir=../contrib \
Brad Bishop26bdd442019-08-16 17:08:17 -040055 "
Patrick Williams213cb262021-08-07 19:21:33 -050056SRC_URI:append:riscv64 = " file://0001-Use-Os-to-compile-tinyxml2.cpp.patch;patchdir=../contrib"
Brad Bishop19323692019-04-05 15:28:33 -040057
58S = "${WORKDIR}/git"
59
Brad Bishope42b3e32020-01-15 22:08:42 -050060# 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
Brad Bishop19323692019-04-05 15:28:33 -040064do_unpack_extra() {
Brad Bishop19323692019-04-05 15:28:33 -040065 tar xzf ${WORKDIR}/ipp/ippicv/${IPP_FILENAME} -C ${WORKDIR}
Brad Bishope42b3e32020-01-15 22:08:42 -050066
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
Andrew Geisslere34f8962021-04-15 15:53:51 -050083 cache wechat_qrcode ${WORKDIR}/wechat_qrcode/*.caffemodel
84 cache wechat_qrcode ${WORKDIR}/wechat_qrcode/*.prototxt
Brad Bishop19323692019-04-05 15:28:33 -040085}
86addtask unpack_extra after do_unpack before do_patch
87
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -050088CMAKE_VERBOSE = "VERBOSE=1"
89
Brad Bishop19323692019-04-05 15:28:33 -040090EXTRA_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 \
Brad Bishop868407c2019-11-04 13:24:47 -050096 -DOPENCV_GENERATE_PKGCONFIG=ON \
Brad Bishope42b3e32020-01-15 22:08:42 -050097 -DOPENCV_DOWNLOAD_PATH=${OPENCV_DLDIR} \
98 -DOPENCV_ALLOW_DOWNLOADS=OFF \
Brad Bishop19323692019-04-05 15:28:33 -040099 ${@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"
Patrick Williams213cb262021-08-07 19:21:33 -0500103EXTRA_OECMAKE:append:x86 = " -DX86=ON"
Brad Bishop19323692019-04-05 15:28:33 -0400104
Brad Bishope42b3e32020-01-15 22:08:42 -0500105PACKAGECONFIG ??= "gapi python3 eigen jpeg png tiff v4l libv4l gstreamer samples tbb gphoto2 \
Brad Bishop19323692019-04-05 15:28:33 -0400106 ${@bb.utils.contains("DISTRO_FEATURES", "x11", "gtk", "", d)} \
107 ${@bb.utils.contains("LICENSE_FLAGS_WHITELIST", "commercial", "libav", "", d)}"
108
William A. Kennington IIIb95905d2021-06-02 12:40:56 -0700109# TBB does not build for powerpc so disable that package config
Patrick Williams213cb262021-08-07 19:21:33 -0500110PACKAGECONFIG:remove:powerpc = "tbb"
William A. Kennington IIIb95905d2021-06-02 12:40:56 -0700111# tbb now needs getcontect/setcontext which is not there for all arches on musl
Patrick Williams213cb262021-08-07 19:21:33 -0500112PACKAGECONFIG:remove:libc-musl:riscv64 = "tbb"
113PACKAGECONFIG:remove:libc-musl:riscv32 = "tbb"
William A. Kennington IIIb95905d2021-06-02 12:40:56 -0700114
Brad Bishope42b3e32020-01-15 22:08:42 -0500115PACKAGECONFIG[gapi] = "-DWITH_ADE=ON -Dade_DIR=${STAGING_LIBDIR},-DWITH_ADE=OFF,ade"
Brad Bishop19323692019-04-05 15:28:33 -0400116PACKAGECONFIG[amdblas] = "-DWITH_OPENCLAMDBLAS=ON,-DWITH_OPENCLAMDBLAS=OFF,libclamdblas,"
117PACKAGECONFIG[amdfft] = "-DWITH_OPENCLAMDFFT=ON,-DWITH_OPENCLAMDFFT=OFF,libclamdfft,"
118PACKAGECONFIG[dnn] = "-DBUILD_opencv_dnn=ON -DPROTOBUF_UPDATE_FILES=ON -DBUILD_PROTOBUF=OFF,-DBUILD_opencv_dnn=OFF,protobuf protobuf-native,"
119PACKAGECONFIG[eigen] = "-DWITH_EIGEN=ON,-DWITH_EIGEN=OFF,libeigen gflags glog,"
120PACKAGECONFIG[freetype] = "-DBUILD_opencv_freetype=ON,-DBUILD_opencv_freetype=OFF,freetype,"
121PACKAGECONFIG[gphoto2] = "-DWITH_GPHOTO2=ON,-DWITH_GPHOTO2=OFF,libgphoto2,"
122PACKAGECONFIG[gstreamer] = "-DWITH_GSTREAMER=ON,-DWITH_GSTREAMER=OFF,gstreamer1.0 gstreamer1.0-plugins-base,"
123PACKAGECONFIG[gtk] = "-DWITH_GTK=ON,-DWITH_GTK=OFF,gtk+3,"
124PACKAGECONFIG[jasper] = "-DWITH_JASPER=ON,-DWITH_JASPER=OFF,jasper,"
125PACKAGECONFIG[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,"
126PACKAGECONFIG[jpeg] = "-DWITH_JPEG=ON,-DWITH_JPEG=OFF,jpeg,"
127PACKAGECONFIG[libav] = "-DWITH_FFMPEG=ON,-DWITH_FFMPEG=OFF,libav,"
128PACKAGECONFIG[libv4l] = "-DWITH_LIBV4L=ON,-DWITH_LIBV4L=OFF,v4l-utils,"
129PACKAGECONFIG[opencl] = "-DWITH_OPENCL=ON,-DWITH_OPENCL=OFF,opencl-headers virtual/opencl-icd,"
130PACKAGECONFIG[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,"
131PACKAGECONFIG[png] = "-DWITH_PNG=ON,-DWITH_PNG=OFF,libpng,"
132PACKAGECONFIG[python2] = "-DPYTHON2_NUMPY_INCLUDE_DIRS:PATH=${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include,,python-numpy,"
133PACKAGECONFIG[python3] = "-DPYTHON3_NUMPY_INCLUDE_DIRS:PATH=${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include,,python3-numpy,"
134PACKAGECONFIG[samples] = "-DBUILD_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON,-DBUILD_EXAMPLES=OFF,,"
135PACKAGECONFIG[tbb] = "-DWITH_TBB=ON,-DWITH_TBB=OFF,tbb,"
Andrew Geissler97771a32021-03-05 15:23:11 -0600136PACKAGECONFIG[tests] = "-DBUILD_TESTS=ON,-DBUILD_TESTS=OFF,,"
Brad Bishop19323692019-04-05 15:28:33 -0400137PACKAGECONFIG[text] = "-DBUILD_opencv_text=ON,-DBUILD_opencv_text=OFF,tesseract,"
138PACKAGECONFIG[tiff] = "-DWITH_TIFF=ON,-DWITH_TIFF=OFF,tiff,"
139PACKAGECONFIG[v4l] = "-DWITH_V4L=ON,-DWITH_V4L=OFF,v4l-utils,"
140
141inherit pkgconfig cmake
142
143inherit ${@bb.utils.contains('PACKAGECONFIG', 'python3', 'distutils3-base', '', d)}
144inherit ${@bb.utils.contains('PACKAGECONFIG', 'python2', 'distutils-base', '', d)}
145
146export PYTHON_CSPEC="-I${STAGING_INCDIR}/${PYTHON_DIR}"
147export PYTHON="${STAGING_BINDIR_NATIVE}/${@bb.utils.contains('PACKAGECONFIG', 'python3', 'python3', 'python', d)}"
148export ORACLE_JAVA_HOME="${STAGING_DIR_NATIVE}/usr/bin/java"
149export JAVA_HOME="${STAGING_DIR_NATIVE}/usr/lib/jvm/openjdk-8-native"
150export ANT_DIR="${STAGING_DIR_NATIVE}/usr/share/ant/"
151
152TARGET_CC_ARCH += "-I${S}/include "
153
154PACKAGES += "${@bb.utils.contains('PACKAGECONFIG', 'samples', '${PN}-samples', '', d)} \
155 ${@bb.utils.contains('PACKAGECONFIG', 'oracle-java', '${PN}-java', '', d)} \
156 ${@bb.utils.contains('PACKAGECONFIG', 'java', '${PN}-java', '', d)} \
157 ${@bb.utils.contains('PACKAGECONFIG', 'python2', 'python-${BPN}', '', d)} \
158 ${@bb.utils.contains('PACKAGECONFIG', 'python3', 'python3-${BPN}', '', d)} \
159 ${PN}-apps"
160
Patrick Williams213cb262021-08-07 19:21:33 -0500161python populate_packages:prepend () {
Brad Bishop19323692019-04-05 15:28:33 -0400162 cv_libdir = d.expand('${libdir}')
163 do_split_packages(d, cv_libdir, '^lib(.*)\.so$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev', allow_links=True)
164 do_split_packages(d, cv_libdir, '^lib(.*)\.la$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev')
165 do_split_packages(d, cv_libdir, '^lib(.*)\.a$', 'lib%s-dev', 'OpenCV %s development package', extra_depends='${PN}-dev')
166 do_split_packages(d, cv_libdir, '^lib(.*)\.so\.*', 'lib%s', 'OpenCV %s library', extra_depends='', allow_links=True)
167
168 pn = d.getVar('PN')
169 metapkg = pn + '-dev'
Patrick Williams213cb262021-08-07 19:21:33 -0500170 d.setVar('ALLOW_EMPTY:' + metapkg, "1")
Brad Bishop19323692019-04-05 15:28:33 -0400171 blacklist = [ metapkg ]
172 metapkg_rdepends = [ ]
173 packages = d.getVar('PACKAGES').split()
174 for pkg in packages[1:]:
175 if not pkg in blacklist and not pkg in metapkg_rdepends and pkg.endswith('-dev'):
176 metapkg_rdepends.append(pkg)
Patrick Williams213cb262021-08-07 19:21:33 -0500177 d.setVar('RRECOMMENDS:' + metapkg, ' '.join(metapkg_rdepends))
Brad Bishop19323692019-04-05 15:28:33 -0400178
179 metapkg = pn
Patrick Williams213cb262021-08-07 19:21:33 -0500180 d.setVar('ALLOW_EMPTY:' + metapkg, "1")
Brad Bishop19323692019-04-05 15:28:33 -0400181 blacklist = [ metapkg, "libopencv-ts" ]
182 metapkg_rdepends = [ ]
183 for pkg in packages[1:]:
184 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'):
185 metapkg_rdepends.append(pkg)
Patrick Williams213cb262021-08-07 19:21:33 -0500186 d.setVar('RDEPENDS:' + metapkg, ' '.join(metapkg_rdepends))
Brad Bishop19323692019-04-05 15:28:33 -0400187}
188
189PACKAGES_DYNAMIC += "^libopencv-.*"
190
Patrick Williams213cb262021-08-07 19:21:33 -0500191FILES:${PN} = ""
192FILES:${PN}-dbg += "${datadir}/OpenCV/java/.debug/* ${datadir}/OpenCV/samples/bin/.debug/*"
193FILES:${PN}-dev = "${includedir} ${libdir}/pkgconfig ${libdir}/cmake/opencv4/*.cmake"
194FILES:${PN}-staticdev += "${libdir}/opencv4/3rdparty/*.a"
195FILES:${PN}-apps = "${bindir}/* ${datadir}/opencv4 ${datadir}/licenses"
196FILES:${PN}-java = "${datadir}/OpenCV/java"
197FILES:${PN}-samples = "${datadir}/opencv4/samples/"
Brad Bishop19323692019-04-05 15:28:33 -0400198
Patrick Williams213cb262021-08-07 19:21:33 -0500199INSANE_SKIP:${PN}-java = "libdir"
200INSANE_SKIP:${PN}-dbg = "libdir"
Brad Bishop19323692019-04-05 15:28:33 -0400201
Patrick Williams213cb262021-08-07 19:21:33 -0500202ALLOW_EMPTY:${PN} = "1"
Brad Bishop19323692019-04-05 15:28:33 -0400203
Patrick Williams213cb262021-08-07 19:21:33 -0500204SUMMARY:python-opencv = "Python bindings to opencv"
205FILES:python-opencv = "${PYTHON_SITEPACKAGES_DIR}/*"
206RDEPENDS:python-opencv = "python-core python-numpy"
Brad Bishop19323692019-04-05 15:28:33 -0400207
Patrick Williams213cb262021-08-07 19:21:33 -0500208SUMMARY:python3-opencv = "Python bindings to opencv"
209FILES:python3-opencv = "${PYTHON_SITEPACKAGES_DIR}/*"
210RDEPENDS:python3-opencv = "python3-core python3-numpy"
Brad Bishop19323692019-04-05 15:28:33 -0400211
Patrick Williams213cb262021-08-07 19:21:33 -0500212RDEPENDS:${PN}-apps = "bash"
Brad Bishop19323692019-04-05 15:28:33 -0400213
Patrick Williams213cb262021-08-07 19:21:33 -0500214do_compile:prepend() {
Andrew Geisslerd688a012020-09-18 13:36:00 -0500215 # remove the build host info to improve reproducibility
216 if [ -f ${WORKDIR}/build/modules/core/version_string.inc ]; then
217 sed -i "s#${WORKDIR}#/workdir#g" ${WORKDIR}/build/modules/core/version_string.inc
218 fi
219}
220
Patrick Williams213cb262021-08-07 19:21:33 -0500221do_install:append() {
Brad Bishop19323692019-04-05 15:28:33 -0400222 # Move Python files into correct library folder (for multilib build)
223 if [ "$libdir" != "/usr/lib" -a -d ${D}/usr/lib ]; then
224 mv ${D}/usr/lib/* ${D}/${libdir}/
225 rm -rf ${D}/usr/lib
226 fi
Andrew Geisslerac970dd2021-02-12 15:32:45 -0600227 # remove build host path to improve reproducibility
228 if [ -f ${D}${libdir}/cmake/opencv4/OpenCVModules.cmake ]; then
229 sed -e 's@${STAGING_DIR_HOST}@@g' \
230 -i ${D}${libdir}/cmake/opencv4/OpenCVModules.cmake
231 fi
Brad Bishop19323692019-04-05 15:28:33 -0400232}