linux_xanmod: 5.11.14 -> 5.11.15
[NixPkgs.git] / pkgs / development / libraries / opencv / default.nix
blob2575f6bb45d5f65618599aad616d92e47bbc3326
1 { lib, stdenv, fetchFromGitHub, cmake, pkg-config, unzip
2 , zlib
3 , enablePython ? false, pythonPackages
4 , enableGtk2 ? false, gtk2
5 , enableJPEG ? true, libjpeg
6 , enablePNG ? true, libpng
7 , enableTIFF ? true, libtiff
8 , enableEXR ? (!stdenv.isDarwin), openexr, ilmbase
9 , enableFfmpeg ? false, ffmpeg_3
10 , enableGStreamer ? false, gst_all_1
11 , enableEigen ? true, eigen
12 , Cocoa, QTKit
15 let
16   opencvFlag = name: enabled: "-DWITH_${name}=${if enabled then "ON" else "OFF"}";
20 stdenv.mkDerivation rec {
21   pname = "opencv";
22   version = "2.4.13.7";
24   src = fetchFromGitHub {
25     owner = "opencv";
26     repo = "opencv";
27     rev = version;
28     sha256 = "062js7zhh4ixi2wk61wyi23qp9zsk5vw24iz2i5fab2hp97y5zq3";
29   };
31   patches =
32     [ # Don't include a copy of the CMake status output in the
33       # build. This causes a runtime dependency on GCC.
34       ./no-build-info.patch
35     ];
37   # This prevents cmake from using libraries in impure paths (which causes build failure on non NixOS)
38   postPatch = ''
39     sed -i '/Add these standard paths to the search paths for FIND_LIBRARY/,/^\s*$/{d}' CMakeLists.txt
40   '';
42   outputs = [ "out" "dev" ];
44   buildInputs =
45        [ zlib ]
46     ++ lib.optional enablePython pythonPackages.python
47     ++ lib.optional enableGtk2 gtk2
48     ++ lib.optional enableJPEG libjpeg
49     ++ lib.optional enablePNG libpng
50     ++ lib.optional enableTIFF libtiff
51     ++ lib.optionals enableEXR [ openexr ilmbase ]
52     ++ lib.optional enableFfmpeg ffmpeg_3
53     ++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base ])
54     ++ lib.optional enableEigen eigen
55     ++ lib.optionals stdenv.isDarwin [ Cocoa QTKit ]
56     ;
58   propagatedBuildInputs = lib.optional enablePython pythonPackages.numpy;
60   nativeBuildInputs = [ cmake pkg-config unzip ];
62   NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
64   cmakeFlags = [
65     (opencvFlag "TIFF" enableTIFF)
66     (opencvFlag "JPEG" enableJPEG)
67     (opencvFlag "PNG" enablePNG)
68     (opencvFlag "OPENEXR" enableEXR)
69     (opencvFlag "GSTREAMER" enableGStreamer)
70   ];
72   hardeningDisable = [ "bindnow" "relro" ];
74   # Fix pkg-config file that gets broken with multiple outputs
75   postFixup = ''
76     sed -i $dev/lib/pkgconfig/opencv.pc -e "s|includedir_old=.*|includedir_old=$dev/include/opencv|"
77     sed -i $dev/lib/pkgconfig/opencv.pc -e "s|includedir_new=.*|includedir_new=$dev/include|"
78   '';
80   passthru = lib.optionalAttrs enablePython { pythonPath = []; };
82   meta = with lib; {
83     description = "Open Computer Vision Library with more than 500 algorithms";
84     homepage = "https://opencv.org/";
85     license = licenses.bsd3;
86     maintainers = with maintainers; [ ];
87     platforms = platforms.linux;
88   };