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