summary refs log tree commit diff
path: root/pkgs/development/libraries/openjpeg/generic.nix
blob: 4ffcd62f982bea7bfcc6d9bfbe0eab5ecc341952 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ stdenv, cmake, pkgconfig, libpng, libtiff, lcms2, glib/*passthru only*/
, sharedLibsSupport ? true # Build shared libraries
, codecSupport ? true # Codec executables
, mj2Support ? true # MJ2 executables
, jpwlLibSupport ? true # JPWL library & executables
, jpipLibSupport ? true # JPIP library & executables
, jpipServerSupport ? false, curl ? null, fcgi ? null # JPIP Server
#, opjViewerSupport ? false, wxGTK ? null # OPJViewer executable
, openjpegJarSupport ? false, jdk ? null # Openjpeg jar (Java)
, jp3dSupport ? true # # JP3D comp
, thirdPartySupport ? false # Third party libraries - OFF: only build when found, ON: always build
, testsSupport ? false
# Inherit generics
, branch, src, version, ...
}:

assert jpipServerSupport -> (jpipLibSupport && (curl != null) && (fcgi != null));
#assert opjViewerSupport -> (wxGTK != null);
assert openjpegJarSupport -> (jdk != null);
assert testsSupport -> codecSupport;

let
  mkFlag = optSet: flag: if optSet then "-D${flag}=ON" else "-D${flag}=OFF";
in

with stdenv.lib;
stdenv.mkDerivation rec {
  name = "openjpeg-${version}";
  inherit branch;
  inherit version;
  inherit src;

  cmakeFlags = [
    (mkFlag sharedLibsSupport "BUILD_SHARED_LIBS")
    (mkFlag codecSupport "BUILD_CODEC")
    (mkFlag mj2Support "BUILD_MJ2")
    (mkFlag jpwlLibSupport "BUILD_JPWL")
    (mkFlag jpipLibSupport "BUILD_JPIP")
    (mkFlag jpipServerSupport "BUILD_JPIP_SERVER")
    #(mkFlag opjViewerSupport "BUILD_VIEWER")
    (mkFlag openjpegJarSupport "BUILD_JAVA")
    (mkFlag jp3dSupport "BUILD_JP3D")
    (mkFlag thirdPartySupport "BUILD_THIRDPARTY")
    (mkFlag testsSupport "BUILD_TESTING")
  ];

  nativebuildInputs = [ pkgconfig ];

  buildInputs = [ cmake ]
    ++ optionals jpipServerSupport [ curl fcgi ]
    #++ optional opjViewerSupport wxGTK
    ++ optional openjpegJarSupport jdk;

  propagatedBuildInputs = [ libpng libtiff lcms2 ];

  postInstall = glib.flattenInclude + ''
    mkdir -p "$out/lib/pkgconfig"
    cat > "$out/lib/pkgconfig/libopenjp2.pc" <<EOF
    prefix=$out
    libdir=$out/lib
    includedir=$out/include

    Name: openjp2
    Description: JPEG2000 library (Part 1 and 2)
    URL: http://www.openjpeg.org/
    Version: ${version}
    Libs: -L$out/lib -lopenjp2
    Cflags: -I$out/include
    EOF
  '';

  passthru = {
    incDir = "openjpeg-${branch}";
  };

  meta = {
    description = "Open-source JPEG 2000 codec written in C language";
    homepage    = http://www.openjpeg.org/;
    license     = licenses.bsd2;
    maintainer  = with maintainers; [ codyopel ];
    platforms   = platforms.all;
  };
}