Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, stdenv, fetchFromGitHub, cmake, pkg-config, unzip 2, zlib 3, enableGtk2 ? false, gtk2 4, enableJPEG ? true, libjpeg 5, enablePNG ? true, libpng 6, enableTIFF ? true, libtiff 7, enableEXR ? (!stdenv.isDarwin), openexr, ilmbase 8, enableFfmpeg ? false, ffmpeg 9, enableGStreamer ? false, gst_all_1 10, enableEigen ? true, eigen 11, enableUnfree ? false 12, AVFoundation, Cocoa, QTKit, Accelerate 13}: 14 15let 16 opencvFlag = name: enabled: "-DWITH_${name}=${if enabled then "ON" else "OFF"}"; 17 18in 19 20stdenv.mkDerivation rec { 21 pname = "opencv"; 22 version = "2.4.13.7"; 23 24 src = fetchFromGitHub { 25 owner = "opencv"; 26 repo = "opencv"; 27 rev = version; 28 sha256 = "062js7zhh4ixi2wk61wyi23qp9zsk5vw24iz2i5fab2hp97y5zq3"; 29 }; 30 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 ]; 36 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 ''; 41 42 outputs = [ "out" "dev" ]; 43 44 buildInputs = 45 [ zlib ] 46 ++ lib.optional enableGtk2 gtk2 47 ++ lib.optional enableJPEG libjpeg 48 ++ lib.optional enablePNG libpng 49 ++ lib.optional enableTIFF libtiff 50 ++ lib.optionals enableEXR [ openexr ilmbase ] 51 ++ lib.optional enableFfmpeg ffmpeg 52 ++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base ]) 53 ++ lib.optional enableEigen eigen 54 ++ lib.optionals stdenv.isDarwin [ AVFoundation Cocoa QTKit Accelerate ] 55 ; 56 57 nativeBuildInputs = [ cmake pkg-config unzip ]; 58 59 env.NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR"; 60 61 cmakeFlags = [ 62 (opencvFlag "TIFF" enableTIFF) 63 (opencvFlag "JPEG" enableJPEG) 64 (opencvFlag "PNG" enablePNG) 65 (opencvFlag "OPENEXR" enableEXR) 66 (opencvFlag "GSTREAMER" enableGStreamer) 67 ] ++ lib.optional (!enableUnfree) "-DBUILD_opencv_nonfree=OFF"; 68 69 hardeningDisable = [ "bindnow" "relro" ]; 70 71 # Fix pkg-config file that gets broken with multiple outputs 72 postFixup = '' 73 sed -i $dev/lib/pkgconfig/opencv.pc -e "s|includedir_old=.*|includedir_old=$dev/include/opencv|" 74 sed -i $dev/lib/pkgconfig/opencv.pc -e "s|includedir_new=.*|includedir_new=$dev/include|" 75 ''; 76 77 meta = with lib; { 78 description = "Open Computer Vision Library with more than 500 algorithms"; 79 homepage = "https://opencv.org/"; 80 license = if enableUnfree then licenses.unfree else licenses.bsd3; 81 maintainers = with maintainers; [ ]; 82 platforms = platforms.unix; 83 }; 84}