1{ stdenv, fetchFromGitHub, cmake, python, fetchpatch }:
2
3stdenv.mkDerivation rec {
4 pname = "jsoncpp";
5 version = "1.9.2";
6
7 src = fetchFromGitHub {
8 owner = "open-source-parsers";
9 repo = "jsoncpp";
10 rev = version;
11 sha256 = "037d1b1qdmn3rksmn1j71j26bv4hkjv7sn7da261k853xb5899sg";
12 };
13
14 /* During darwin bootstrap, we have a cp that doesn't understand the
15 * --reflink=auto flag, which is used in the default unpackPhase for dirs
16 */
17 unpackPhase = ''
18 cp -a ${src} ${src.name}
19 chmod -R +w ${src.name}
20 export sourceRoot=${src.name}
21 '';
22
23 # Hack to be able to run the test, broken because we use
24 # CMAKE_SKIP_BUILD_RPATH to avoid cmake resetting rpath on install
25 preBuild = if stdenv.isDarwin then ''
26 export DYLD_LIBRARY_PATH="`pwd`/src/lib_json''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH"
27 '' else ''
28 export LD_LIBRARY_PATH="`pwd`/src/lib_json''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
29 '';
30
31 nativeBuildInputs = [ cmake python ];
32
33 # fix inverted sense in isAnyCharRequiredQuoting on aarch64. See: https://github.com/open-source-parsers/jsoncpp/pull/1120
34 patches = stdenv.lib.optionals stdenv.isAarch64 [
35 (fetchpatch {
36 url = "https://github.com/open-source-parsers/jsoncpp/commit/9093358efae9e5981aa60013487fc7215f040a59.patch";
37 sha256 = "1wiqp70sck2md14sfc0zdkblqk9750cl55ykf9d6b9vs1ifzzzq5";
38 })
39 ];
40
41 cmakeFlags = [
42 "-DBUILD_SHARED_LIBS=ON"
43 "-DBUILD_STATIC_LIBS=OFF"
44 "-DJSONCPP_WITH_CMAKE_PACKAGE=ON"
45 ];
46
47 meta = with stdenv.lib; {
48 inherit version;
49 homepage = https://github.com/open-source-parsers/jsoncpp;
50 description = "A C++ library for interacting with JSON.";
51 maintainers = with maintainers; [ ttuegel cpages nand0p ];
52 license = licenses.mit;
53 platforms = platforms.all;
54 };
55}