nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 cmake,
6}:
7
8stdenv.mkDerivation (finalAttrs: {
9 pname = "cjson";
10 version = "1.7.19";
11
12 src = fetchFromGitHub {
13 owner = "DaveGamble";
14 repo = "cJSON";
15 rev = "v${finalAttrs.version}";
16 sha256 = "sha256-WjgzokT9aHJ7dB40BtmhS7ur1slTuXmemgDimZHLVQM=";
17 };
18
19 nativeBuildInputs = [ cmake ];
20
21 cmakeFlags = lib.optional (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) (
22 lib.cmakeBool "ENABLE_CUSTOM_COMPILER_FLAGS" false
23 );
24
25 postPatch =
26 # cJSON actually uses C99 standard, not C89
27 # https://github.com/DaveGamble/cJSON/issues/275
28 ''
29 substituteInPlace CMakeLists.txt --replace -std=c89 -std=c99
30 ''
31 # Fix the build with CMake 4.
32 #
33 # See:
34 # * <https://github.com/DaveGamble/cJSON/issues/946>
35 # * <https://github.com/DaveGamble/cJSON/pull/935>
36 # * <https://github.com/DaveGamble/cJSON/pull/949>
37 + ''
38 substituteInPlace CMakeLists.txt \
39 --replace-fail \
40 'cmake_minimum_required(VERSION 3.0)' \
41 'cmake_minimum_required(VERSION 3.10)'
42 '';
43
44 meta = {
45 homepage = "https://github.com/DaveGamble/cJSON";
46 description = "Ultralightweight JSON parser in ANSI C";
47 license = lib.licenses.mit;
48 maintainers = [ lib.maintainers.matthiasbeyer ];
49 platforms = lib.platforms.unix;
50 };
51})