archrelease: copy trunk to extra-x86_64
[arch-packages.git] / opencv / trunk / PKGBUILD
blobacee1b825262bfcc0d779779b3628c09102adb67
1 # Maintainer: Antonio Rojas <arojas@archlinux.org>
2 # Contributor: Ray Rashif <schiv@archlinux.org>
3 # Contributor: Tobias Powalowski <tpowa@archlinux.org>
5 pkgbase=opencv
6 pkgname=(opencv opencv-samples python-opencv opencv-cuda)
7 pkgver=4.7.0
8 pkgrel=10
9 pkgdesc='Open Source Computer Vision Library'
10 arch=(x86_64)
11 license=(BSD)
12 url='https://opencv.org/'
13 depends=(tbb openexr gst-plugins-base libdc1394 cblas lapack libgphoto2 openjpeg2 ffmpeg protobuf)
14 makedepends=(cmake python-numpy python-setuptools mesa eigen hdf5 lapacke qt6-5compat vtk glew ant java-environment
15              pugixml openmpi cudnn fmt nlohmann-json)
16 optdepends=('opencv-samples: samples'
17             'vtk: for the viz module'
18             'glew: for the viz module'
19             'qt6-base: for the HighGUI module'
20             'hdf5: for the HDF5 module'
21             'opencl-icd-loader: For coding with OpenCL'
22             'java-runtime: Java interface')
23 source=(https://github.com/opencv/opencv/archive/$pkgver/$pkgname-$pkgver.tar.gz
24         https://github.com/opencv/opencv_contrib/archive/$pkgver/opencv_contrib-$pkgver.tar.gz
25         vtk9.patch)
26 sha256sums=('8df0079cdbe179748a18d44731af62a245a45ebf5085223dc03133954c662973'
27             '42df840cf9055e59d0e22c249cfb19f04743e1bdad113d31b1573d3934d62584'
28             'f35a2d4ea0d6212c7798659e59eda2cb0b5bc858360f7ce9c696c77d3029668e')
30 prepare() {
31   patch -d $pkgname-$pkgver -p1 < vtk9.patch # Don't require all vtk optdepends
34 build() {
35   export JAVA_HOME="/usr/lib/jvm/default"
36   # cmake's FindLAPACK doesn't add cblas to LAPACK_LIBRARIES, so we need to specify them manually
37   _opts="-DWITH_OPENCL=ON \
38          -DWITH_OPENGL=ON \
39          -DOpenGL_GL_PREFERENCE=LEGACY \
40          -DWITH_TBB=ON \
41          -DWITH_VULKAN=ON \
42          -DWITH_QT=ON \
43          -DBUILD_TESTS=OFF \
44          -DBUILD_PERF_TESTS=OFF \
45          -DBUILD_EXAMPLES=ON \
46          -DBUILD_PROTOBUF=OFF \
47          -DPROTOBUF_UPDATE_FILES=ON \
48          -DINSTALL_C_EXAMPLES=ON \
49          -DINSTALL_PYTHON_EXAMPLES=ON \
50          -DCMAKE_INSTALL_PREFIX=/usr \
51          -DCPU_BASELINE_DISABLE=SSE3 \
52          -DCPU_BASELINE_REQUIRE=SSE2 \
53          -DOPENCV_EXTRA_MODULES_PATH=$srcdir/opencv_contrib-$pkgver/modules \
54          -DOPENCV_SKIP_PYTHON_LOADER=ON \
55          -DLAPACK_LIBRARIES=/usr/lib/liblapack.so;/usr/lib/libblas.so;/usr/lib/libcblas.so \
56          -DLAPACK_CBLAS_H=/usr/include/cblas.h \
57          -DLAPACK_LAPACKE_H=/usr/include/lapacke.h \
58          -DOPENCV_GENERATE_PKGCONFIG=ON \
59          -DOPENCV_ENABLE_NONFREE=ON \
60          -DOPENCV_JNI_INSTALL_PATH=lib \
61          -DOPENCV_GENERATE_SETUPVARS=OFF \
62          -DEIGEN_INCLUDE_PATH=/usr/include/eigen3"
64   cmake -B build -S $pkgname-$pkgver $_opts \
65     -DBUILD_WITH_DEBUG_INFO=ON
66   cmake --build build
68   CFLAGS="${CFLAGS} -fno-lto" CXXFLAGS="${CXXFLAGS} -fno-lto" LDFLAGS="${LDFLAGS} -fno-lto" \
69   cmake -B build-cuda -S $pkgname-$pkgver $_opts \
70     -DBUILD_WITH_DEBUG_INFO=OFF \
71     -DWITH_CUDA=ON \
72     -DWITH_CUDNN=ON \
73     -DCUDA_ARCH_BIN='52-real;53-real;60-real;61-real;62-real;70-real;72-real;75-real;80-real;86-real;87-real;89-real;90-real;90-virtual' \
74     -DCUDA_ARCH_PTX='90-virtual'
75   cmake --build build-cuda
78 package_opencv() {
79   DESTDIR="$pkgdir" cmake --install build
81   # install license file
82   install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
84   # separate samples package
85   mv "$pkgdir"/usr/share/opencv4/samples "$srcdir"
87   # Add java symlinks expected by some binary blobs
88   ln -sr "$pkgdir"/usr/share/java/{opencv4/opencv-${pkgver//./},opencv}.jar
89   ln -sr "$pkgdir"/usr/lib/{libopencv_java${pkgver//./},libopencv_java}.so
91   # Split Python bindings
92   rm -r "$pkgdir"/usr/lib/python3*
95 package_opencv-samples() {
96   pkgdesc+=' (samples)'
97   depends=(opencv)
98   unset optdepends
100   mkdir -p "$pkgdir"/usr/share/opencv4
101   mv samples "$pkgdir"/usr/share/opencv4
103   # install license file
104   install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
107 package_python-opencv() {
108   pkgdesc='Python bindings for OpenCV'
109   depends=(python-numpy opencv vtk glew qt6-base hdf5 jsoncpp openmpi pugixml fmt)
110   unset optdepends
112   DESTDIR="$pkgdir" cmake --install build/modules/python3
114   # install license file
115   install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
118 package_opencv-cuda() {
119   pkgdesc+=' (with CUDA support)'
120   depends+=(cudnn)
121   conflicts=(opencv)
122   provides=(opencv=$pkgver)
123   options=(!debug)
125   DESTDIR="$pkgdir" cmake --install build-cuda
127   # install license file
128   install -Dm644 $pkgbase-$pkgver/LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname
130   # Split samples
131   rm -r "$pkgdir"/usr/share/opencv4/samples
133   # Add java symlinks expected by some binary blobs
134   ln -sr "$pkgdir"/usr/share/java/{opencv4/opencv-${pkgver//./},opencv}.jar
135   ln -sr "$pkgdir"/usr/lib/{libopencv_java${pkgver//./},libopencv_java}.so
137   # Split Python bindings
138   rm -r "$pkgdir"/usr/lib/python3*