2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, cmake, pkg-config, unzip
|
2020-04-24 23:36:52 +00:00
|
|
|
, zlib
|
|
|
|
, enableGtk2 ? false, gtk2
|
|
|
|
, enableJPEG ? true, libjpeg
|
|
|
|
, enablePNG ? true, libpng
|
|
|
|
, enableTIFF ? true, libtiff
|
|
|
|
, enableEXR ? (!stdenv.isDarwin), openexr, ilmbase
|
2021-05-20 23:08:51 +00:00
|
|
|
, enableFfmpeg ? false, ffmpeg
|
2020-04-24 23:36:52 +00:00
|
|
|
, enableGStreamer ? false, gst_all_1
|
|
|
|
, enableEigen ? true, eigen
|
2021-10-01 09:20:50 +00:00
|
|
|
, enableUnfree ? false
|
2023-04-12 12:48:02 +00:00
|
|
|
, AVFoundation, Cocoa, QTKit, Accelerate
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
opencvFlag = name: enabled: "-DWITH_${name}=${if enabled then "ON" else "OFF"}";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "opencv";
|
2020-11-12 09:05:59 +00:00
|
|
|
version = "2.4.13.7";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2020-11-12 09:05:59 +00:00
|
|
|
owner = "opencv";
|
2020-04-24 23:36:52 +00:00
|
|
|
repo = "opencv";
|
|
|
|
rev = version;
|
2020-11-12 09:05:59 +00:00
|
|
|
sha256 = "062js7zhh4ixi2wk61wyi23qp9zsk5vw24iz2i5fab2hp97y5zq3";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
patches =
|
|
|
|
[ # Don't include a copy of the CMake status output in the
|
|
|
|
# build. This causes a runtime dependency on GCC.
|
|
|
|
./no-build-info.patch
|
|
|
|
];
|
|
|
|
|
|
|
|
# This prevents cmake from using libraries in impure paths (which causes build failure on non NixOS)
|
|
|
|
postPatch = ''
|
|
|
|
sed -i '/Add these standard paths to the search paths for FIND_LIBRARY/,/^\s*$/{d}' CMakeLists.txt
|
|
|
|
'';
|
|
|
|
|
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
|
|
|
buildInputs =
|
|
|
|
[ zlib ]
|
|
|
|
++ lib.optional enableGtk2 gtk2
|
|
|
|
++ lib.optional enableJPEG libjpeg
|
|
|
|
++ lib.optional enablePNG libpng
|
|
|
|
++ lib.optional enableTIFF libtiff
|
|
|
|
++ lib.optionals enableEXR [ openexr ilmbase ]
|
2021-05-20 23:08:51 +00:00
|
|
|
++ lib.optional enableFfmpeg ffmpeg
|
2020-04-24 23:36:52 +00:00
|
|
|
++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base ])
|
|
|
|
++ lib.optional enableEigen eigen
|
2023-04-12 12:48:02 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ AVFoundation Cocoa QTKit Accelerate ]
|
2020-04-24 23:36:52 +00:00
|
|
|
;
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
nativeBuildInputs = [ cmake pkg-config unzip ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
(opencvFlag "TIFF" enableTIFF)
|
|
|
|
(opencvFlag "JPEG" enableJPEG)
|
|
|
|
(opencvFlag "PNG" enablePNG)
|
|
|
|
(opencvFlag "OPENEXR" enableEXR)
|
|
|
|
(opencvFlag "GSTREAMER" enableGStreamer)
|
2021-10-01 09:20:50 +00:00
|
|
|
] ++ lib.optional (!enableUnfree) "-DBUILD_opencv_nonfree=OFF";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
hardeningDisable = [ "bindnow" "relro" ];
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
# Fix pkg-config file that gets broken with multiple outputs
|
2020-04-24 23:36:52 +00:00
|
|
|
postFixup = ''
|
|
|
|
sed -i $dev/lib/pkgconfig/opencv.pc -e "s|includedir_old=.*|includedir_old=$dev/include/opencv|"
|
|
|
|
sed -i $dev/lib/pkgconfig/opencv.pc -e "s|includedir_new=.*|includedir_new=$dev/include|"
|
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Open Computer Vision Library with more than 500 algorithms";
|
|
|
|
homepage = "https://opencv.org/";
|
2021-10-01 09:20:50 +00:00
|
|
|
license = if enableUnfree then licenses.unfree else licenses.bsd3;
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with maintainers; [ ];
|
2023-03-08 16:32:21 +00:00
|
|
|
platforms = platforms.unix;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|