1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, python3
6, validatePkgConfig
7, fetchpatch
8, secureMemory ? false
9, enableStatic ? stdenv.hostPlatform.isStatic
10}:
11
12stdenv.mkDerivation rec {
13 pname = "jsoncpp";
14 version = "1.9.4";
15
16 outputs = ["out" "dev"];
17
18 src = fetchFromGitHub {
19 owner = "open-source-parsers";
20 repo = "jsoncpp";
21 rev = version;
22 sha256 = "0qnx5y6c90fphl9mj9d20j2dfgy6s5yr5l0xnzid0vh71zrp6jwv";
23 };
24
25 patches = [
26 # Fix for https://github.com/open-source-parsers/jsoncpp/issues/1235.
27 (fetchpatch {
28 url = "https://github.com/open-source-parsers/jsoncpp/commit/ac2870298ed5b5a96a688d9df07461b31f83e906.patch";
29 sha256 = "02wswhiwypmf1jn3rj9q1fw164kljiv4l8h0q6wyijzr77hq4wsg";
30 })
31 ];
32
33 /* During darwin bootstrap, we have a cp that doesn't understand the
34 * --reflink=auto flag, which is used in the default unpackPhase for dirs
35 */
36 unpackPhase = ''
37 cp -a ${src} ${src.name}
38 chmod -R +w ${src.name}
39 export sourceRoot=${src.name}
40 '';
41
42 postPatch = lib.optionalString secureMemory ''
43 sed -i 's/#define JSONCPP_USING_SECURE_MEMORY 0/#define JSONCPP_USING_SECURE_MEMORY 1/' include/json/version.h
44 '';
45
46 nativeBuildInputs = [ cmake python3 validatePkgConfig ];
47
48 cmakeFlags = [
49 "-DBUILD_SHARED_LIBS=ON"
50 "-DBUILD_OBJECT_LIBS=OFF"
51 "-DJSONCPP_WITH_CMAKE_PACKAGE=ON"
52 ]
53 # the test's won't compile if secureMemory is used because there is no
54 # comparison operators and conversion functions between
55 # std::basic_string<..., Json::SecureAllocator<char>> vs.
56 # std::basic_string<..., [default allocator]>
57 ++ lib.optional ((stdenv.buildPlatform != stdenv.hostPlatform) || secureMemory) "-DJSONCPP_WITH_TESTS=OFF"
58 ++ lib.optional (!enableStatic) "-DBUILD_STATIC_LIBS=OFF";
59
60 # this is fixed and no longer necessary in 1.9.5 but there they use
61 # memset_s without switching to a different c++ standard in the cmake files
62 postInstall = lib.optionalString enableStatic ''
63 (cd $out/lib && ln -sf libjsoncpp_static.a libjsoncpp.a)
64 '';
65
66 meta = with lib; {
67 homepage = "https://github.com/open-source-parsers/jsoncpp";
68 description = "A C++ library for interacting with JSON";
69 maintainers = with maintainers; [ ttuegel cpages ];
70 license = licenses.mit;
71 platforms = platforms.all;
72 };
73}