Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / libraries / nlohmann_json / default.nix
blob29c7ca2c690bf7713fcd66be01136d840c1b7ec2
1 { stdenv
2 , lib
3 , fetchFromGitHub
4 , fetchpatch
5 , cmake
6 }:
7 let
8   testData = fetchFromGitHub {
9     owner = "nlohmann";
10     repo = "json_test_data";
11     rev = "v3.1.0";
12     hash = "sha256-bG34W63ew7haLnC82A3lS7bviPDnApLipaBjJAjLcVk=";
13   };
14 in stdenv.mkDerivation (finalAttrs: {
15   pname = "nlohmann_json";
16   version = "3.11.2";
18   src = fetchFromGitHub {
19     owner = "nlohmann";
20     repo = "json";
21     rev = "v${finalAttrs.version}";
22     hash = "sha256-SUdhIV7tjtacf5DkoWk9cnkfyMlrkg8ZU7XnPZd22Tw=";
23   };
25   patches = [
26     # Backport fix for gcc-13:
27     #   https://github.com/nlohmann/json/pull/3895
28     (fetchpatch {
29       name = "gcc-13-rebind.patch";
30       url = "https://github.com/nlohmann/json/commit/a5b09d50b786638ed9deb09ef13860a3cb64eb6b.patch";
31       hash = "sha256-Jbi0VwZP+ZHTGbpIwgKCVc66gOmwjkT5iOUe85eIzM0=";
32     })
34     # Backport fix for gcc-13:
35     #   https://github.com/nlohmann/json/pull/3950
36     (fetchpatch {
37       name = "gcc-13-eq-op.patch";
38       url = "https://github.com/nlohmann/json/commit/a49829bd984c0282be18fcec070df0c31bf77dd5.patch";
39       hash = "sha256-D+cRtdN6AXr4z3/y9Ui7Zqp3e/y10tp+DOL80ZtPz5E=";
40     })
41   ];
43   nativeBuildInputs = [ cmake ];
45   cmakeFlags = [
46     "-DJSON_BuildTests=${if finalAttrs.doCheck then "ON" else "OFF"}"
47     "-DJSON_FastTests=ON"
48     "-DJSON_MultipleHeaders=ON"
49   ] ++ lib.optional finalAttrs.doCheck "-DJSON_TestDataDirectory=${testData}";
51   doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
53   # skip tests that require git or modify “installed files”
54   preCheck = ''
55     checkFlagsArray+=("ARGS=-LE 'not_reproducible|git_required'")
56   '';
58   postInstall = "rm -rf $out/lib64";
60   meta = with lib; {
61     description = "JSON for Modern C++";
62     homepage = "https://json.nlohmann.me";
63     changelog = "https://github.com/nlohmann/json/blob/develop/ChangeLog.md";
64     license = licenses.mit;
65     platforms = platforms.all;
66   };