1{ lib, stdenv
2, fetchFromGitHub
3, fetchpatch
4, pkg-config
5, cmake
6, argtable
7, catch2
8, curl
9, doxygen
10, hiredis
11, jsoncpp
12, libmicrohttpd
13}:
14
15stdenv.mkDerivation rec {
16 pname = "libjson-rpc-cpp";
17 version = "1.3.0";
18
19 src = fetchFromGitHub {
20 owner = "cinemast";
21 repo = "libjson-rpc-cpp";
22 sha256 = "sha256-EAakiqlfMprwLjloDekOssaB/EnAmn5njcwHGZtYs9w=";
23 rev = "v${version}";
24 };
25
26 NIX_CFLAGS_COMPILE = "-I${catch2}/include/catch2";
27
28 patches = [
29 (fetchpatch {
30 name = "int-to-MHD_Result.patch";
31 url = "https://patch-diff.githubusercontent.com/raw/cinemast/libjson-rpc-cpp/pull/299.patch";
32 sha256 = "sha256-hiey6etzbOxhMElTMX7offKbey7c2OO/UWeN03k0AaM=";
33 })
34 ];
35
36 nativeBuildInputs = [ pkg-config cmake doxygen ];
37 buildInputs = [
38 argtable
39 catch2
40 curl
41 hiredis
42 jsoncpp
43 libmicrohttpd
44 ];
45
46 postPatch = ''
47 for f in cmake/FindArgtable.cmake \
48 src/stubgenerator/stubgenerator.cpp \
49 src/stubgenerator/stubgeneratorfactory.cpp
50 do
51 sed -i -re 's/argtable2/argtable3/g' $f
52 done
53
54 sed -i -re 's#MATCHES "jsoncpp"#MATCHES ".*/jsoncpp/json$"#g' cmake/FindJsoncpp.cmake
55 '';
56
57 preConfigure = ''
58 mkdir -p Build/Install
59 pushd Build
60 '';
61
62 # this hack is needed because the cmake scripts
63 # require write permission to absolute paths
64 configurePhase = ''
65 runHook preConfigure
66 cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd)/Install \
67 -DCMAKE_BUILD_TYPE=Release
68 runHook postConfigure
69 '';
70
71 preInstall = ''
72 function fixRunPath {
73 p=$(patchelf --print-rpath $1)
74 q="$p:${lib.makeLibraryPath [ jsoncpp argtable libmicrohttpd curl ]}:$out/lib"
75 patchelf --set-rpath $q $1
76 }
77
78 mkdir -p $out
79 '';
80
81 postInstall = ''
82 sed -i -re "s#-([LI]).*/Build/Install(.*)#-\1$out\2#g" Install/lib64/pkgconfig/*.pc
83 for f in Install/lib64/*.so* $(find Install/bin -executable -type f); do
84 fixRunPath $f
85 done
86 cp -r Install/* $out
87 '';
88
89 installPhase = ''
90 runHook preInstall
91 make install
92 runHook postInstall
93 '';
94
95 meta = with lib; {
96 description = "C++ framework for json-rpc (json remote procedure call)";
97 homepage = "https://github.com/cinemast/libjson-rpc-cpp";
98 license = licenses.mit;
99 platforms = platforms.linux;
100 };
101}