lol
1{ lib, stdenv, fetchFromGitHub, fetchpatch, cmake, pkg-config
2, libdeflate, libpng, libtiff, zlib, lcms2, jpylyzer
3, jpipLibSupport ? false # JPIP library & executables
4, jpipServerSupport ? false, curl, fcgi # JPIP Server
5, jdk
6, poppler
7}:
8
9let
10 mkFlag = optSet: flag: "-D${flag}=${if optSet then "ON" else "OFF"}";
11in
12
13stdenv.mkDerivation rec {
14 pname = "openjpeg";
15 version = "2.5.0";
16
17 src = fetchFromGitHub {
18 owner = "uclouvain";
19 repo = "openjpeg";
20 rev = "v${version}";
21 sha256 = "sha256-/0o3Fl6/jx5zu854TCqMyOz/8mnEyEC9lpZ6ij/tbHc=";
22 };
23
24 outputs = [ "out" "dev" ];
25
26 patches = [
27 # modernise cmake files, also fixes them for multiple outputs
28 # https://github.com/uclouvain/openjpeg/pull/1424
29 (fetchpatch {
30 name = "uclouvain-openjpeg-pull-1424.patch";
31 url = "https://github.com/uclouvain/openjpeg/compare/52927287402a9f7353de8854c88f931051211e2f...9d4f70cfe99626f82f9c8dcbf45f07709e3511b2.patch";
32 sha256 = "sha256-CxVRt1u4HVOMUjWiZ2plmZC29t/zshCpSY+N4Wlrlvg=";
33 })
34 # fix cmake files cross compilation
35 (fetchpatch {
36 url = "https://github.com/uclouvain/openjpeg/commit/c6ceb84c221b5094f1e8a4c0c247dee3fb5074e8.patch";
37 sha256 = "sha256-gBUtmO/7RwSWEl7rc8HGr8gNtvNFdhjEwm0Dd51p5O8=";
38 })
39 ];
40
41 cmakeFlags = [
42 "-DCMAKE_INSTALL_NAME_DIR=\${CMAKE_INSTALL_PREFIX}/lib"
43 "-DBUILD_SHARED_LIBS=ON"
44 "-DBUILD_CODEC=ON"
45 "-DBUILD_THIRDPARTY=OFF"
46 (mkFlag jpipLibSupport "BUILD_JPIP")
47 (mkFlag jpipServerSupport "BUILD_JPIP_SERVER")
48 "-DBUILD_VIEWER=OFF"
49 "-DBUILD_JAVA=OFF"
50 (mkFlag doCheck "BUILD_TESTING")
51 ];
52
53 nativeBuildInputs = [ cmake pkg-config ];
54
55 buildInputs = [ libpng libtiff zlib lcms2 ]
56 ++ lib.optionals jpipServerSupport [ curl fcgi ]
57 ++ lib.optional (jpipLibSupport) jdk;
58
59 doCheck = (!stdenv.isAarch64 && !stdenv.hostPlatform.isPower64); # tests fail on aarch64-linux and powerpc64
60 nativeCheckInputs = [ jpylyzer ];
61 checkPhase = ''
62 substituteInPlace ../tools/ctest_scripts/travis-ci.cmake \
63 --replace "JPYLYZER_EXECUTABLE=" "JPYLYZER_EXECUTABLE=\"$(command -v jpylyzer)\" # "
64 OPJ_SOURCE_DIR=.. ctest -S ../tools/ctest_scripts/travis-ci.cmake
65 '';
66
67 passthru = {
68 incDir = "openjpeg-${lib.versions.majorMinor version}";
69 tests = {
70 inherit poppler;
71 };
72 };
73
74 meta = with lib; {
75 description = "Open-source JPEG 2000 codec written in C language";
76 homepage = "https://www.openjpeg.org/";
77 license = licenses.bsd2;
78 maintainers = with maintainers; [ codyopel ];
79 platforms = platforms.all;
80 changelog = "https://github.com/uclouvain/openjpeg/blob/v${version}/CHANGELOG.md";
81 };
82}