1{ stdenv
2, lib
3, fetchFromGitHub
4, cmake
5, gflags
6, staticOnly ? stdenv.hostPlatform.isStatic
7}:
8
9stdenv.mkDerivation rec {
10 pname = "crc32c";
11 version = "1.1.2";
12
13 src = fetchFromGitHub {
14 owner = "google";
15 repo = "crc32c";
16 rev = version;
17 sha256 = "0c383p7vkfq9rblww6mqxz8sygycyl27rr0j3bzb8l8ga71710ii";
18 fetchSubmodules = true;
19 };
20
21 nativeBuildInputs = [ cmake ];
22 buildInputs = [ gflags ];
23
24 NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isAarch64 "-march=armv8-a+crc";
25
26 cmakeFlags = [
27 "-DCRC32C_INSTALL=1"
28 "-DCRC32C_BUILD_TESTS=1"
29 "-DCRC32C_BUILD_BENCHMARKS=0"
30 "-DCRC32C_USE_GLOG=0"
31 "-DBUILD_SHARED_LIBS=${if staticOnly then "0" else "1"}"
32 ] ++ lib.optionals stdenv.isDarwin [
33 "-DCMAKE_SKIP_BUILD_RPATH=OFF" # for tests
34 ];
35
36 doCheck = false;
37 doInstallCheck = true;
38
39 installCheckPhase = ''
40 runHook preInstallCheck
41
42 ctest
43
44 runHook postInstallCheck
45 '';
46
47 postInstallCheck = ''
48 # without removing these libraries, dependents will look for
49 # libgtest/libgmock etc here, which can result in link time errors
50 rm $out/lib/libg*
51 '';
52
53 postFixup = ''
54 # dependents shouldn't be able to find gtest libraries as dependencies of
55 # this package
56 rm -r $out/lib/pkgconfig
57
58 # remove GTest cmake config files
59 rm -r $out/lib/cmake/GTest
60
61 # fix bogus include paths
62 for f in $(find $out/lib/cmake -name '*.cmake'); do
63 substituteInPlace "$f" --replace "\''${_IMPORT_PREFIX}/$out/include" "\''${_IMPORT_PREFIX}/include"
64 done
65 '';
66
67 meta = with lib; {
68 homepage = "https://github.com/google/crc32c";
69 description = "CRC32C implementation with support for CPU-specific acceleration instructions";
70 license = with licenses; [ bsd3 ];
71 maintainers = with maintainers; [ andir cpcloud ];
72 };
73}