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