about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/libjson-rpc-cpp/default.nix
blob: 4e97ff2f4d5d5498c356345b652802b1824f879d (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{ lib, stdenv
, fetchFromGitHub
, fetchpatch
, pkg-config
, cmake
, argtable
, catch2
, curl
, doxygen
, hiredis
, jsoncpp
, libmicrohttpd
}:

stdenv.mkDerivation rec {
  pname = "libjson-rpc-cpp";
  version = "1.3.0";

  src = fetchFromGitHub {
    owner = "cinemast";
    repo = "libjson-rpc-cpp";
    sha256 = "sha256-EAakiqlfMprwLjloDekOssaB/EnAmn5njcwHGZtYs9w=";
    rev = "v${version}";
  };

  env.NIX_CFLAGS_COMPILE = "-I${catch2}/include/catch2";

  patches = [
    (fetchpatch {
      name = "int-to-MHD_Result.patch";
      url = "https://patch-diff.githubusercontent.com/raw/cinemast/libjson-rpc-cpp/pull/299.patch";
      sha256 = "sha256-hiey6etzbOxhMElTMX7offKbey7c2OO/UWeN03k0AaM=";
    })
  ];

  nativeBuildInputs = [ pkg-config cmake doxygen ];
  buildInputs = [
    argtable
    catch2
    curl
    hiredis
    jsoncpp
    libmicrohttpd
  ];

  postPatch = ''
    for f in cmake/FindArgtable.cmake \
             src/stubgenerator/stubgenerator.cpp \
             src/stubgenerator/stubgeneratorfactory.cpp
    do
      sed -i -re 's/argtable2/argtable3/g' $f
    done

    sed -i -re 's#MATCHES "jsoncpp"#MATCHES ".*/jsoncpp/json$"#g' cmake/FindJsoncpp.cmake
  '';

  preConfigure = ''
    mkdir -p Build/Install
    pushd Build
  '';

  # this hack is needed because the cmake scripts
  # require write permission to absolute paths
  configurePhase = ''
    runHook preConfigure
    cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd)/Install \
             -DCMAKE_BUILD_TYPE=Release
    runHook postConfigure
  '';

  preInstall = ''
    function fixRunPath {
      p=$(patchelf --print-rpath $1)
      q="$p:${lib.makeLibraryPath [ jsoncpp argtable libmicrohttpd curl ]}:$out/lib"
      patchelf --set-rpath $q $1
    }

    mkdir -p $out
  '';

  postInstall = ''
    sed -i -re "s#-([LI]).*/Build/Install(.*)#-\1$out\2#g" Install/lib64/pkgconfig/*.pc
    for f in Install/lib64/*.so* $(find Install/bin -executable -type f); do
      fixRunPath $f
    done
    cp -r Install/* $out
  '';

  installPhase = ''
    runHook preInstall
    make install
    runHook postInstall
  '';

  meta = with lib; {
    description = "C++ framework for json-rpc (json remote procedure call)";
    mainProgram = "jsonrpcstub";
    homepage = "https://github.com/cinemast/libjson-rpc-cpp";
    license = licenses.mit;
    platforms = platforms.linux;
  };
}