Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 cmake, 5 boost, 6 catch2, 7 fetchFromGitHub, 8}: 9 10stdenv.mkDerivation (finalAttrs: { 11 pname = "cppitertools"; 12 version = "2.1"; 13 14 src = fetchFromGitHub { 15 owner = "ryanhaining"; 16 repo = "cppitertools"; 17 tag = "v${finalAttrs.version}"; 18 hash = "sha256-mii4xjxF1YC3H/TuO/o4cEz8bx2ko6U0eufqNVw5LNA="; 19 }; 20 21 __structuredAttrs = true; 22 23 # cppitertools has support files for three buildsystems in its repo: 24 # Scons, Bazel, and CMake. The first two only have definitions for running 25 # tests. The CMake system defines tests and install targets, including a 26 # cppitertools-config.cmake, which is really helpful for downstream consumers 27 # to detect this package since it has no pkg-config. 28 # However the CMake system also specifies the entire source repo as an install 29 # target, including support files, the build directory, etc. 30 # We can't simply take cppitertools-config.cmake for ourselves because before 31 # install it's placed in non-specific private CMake subdirectory of the build 32 # directory. 33 # Therefore, we instead simply patch CMakeLists.txt to make the target that 34 # installs the entire directory non-default, and then install the headers manually. 35 36 strictDeps = true; 37 38 doCheck = true; 39 40 nativeBuildInputs = [ cmake ]; 41 42 buildInputs = [ boost ]; 43 44 nativeCheckInputs = [ catch2 ]; 45 46 # Required on case-sensitive filesystems to not conflict with the Bazel BUILD 47 # files that are also in that repo. 48 cmakeBuildDir = "cmake-build"; 49 50 includeInstallDir = "${builtins.placeholder "out"}/include/cppitertools"; 51 cmakeInstallDir = "${builtins.placeholder "out"}/share/cmake"; 52 53 # This version of cppitertools considers itself as having used the default value, 54 # and issues warning, unless -Dcppitertools_INSTALL_CMAKE_DIR is present as an 55 # *environment* variable. It doesn't actually use the value from this environment 56 # variable at all though, so we still need to pass it in cmakeFlags. 57 env.cppitertools_INSTALL_CMAKE_DIR = finalAttrs.cmakeInstallDir; 58 59 cmakeFlags = [ "-Dcppitertools_INSTALL_CMAKE_DIR=${finalAttrs.cmakeInstallDir}" ]; 60 61 prePatch = '' 62 # Mark the `.` install target as non-default. 63 substituteInPlace CMakeLists.txt \ 64 --replace-fail " DIRECTORY ." " DIRECTORY . EXCLUDE_FROM_ALL" 65 '' 66 + lib.optionalString finalAttrs.finalPackage.doCheck '' 67 # Required for tests. 68 cp ${lib.getDev catch2}/include/catch2/catch.hpp test/ 69 ''; 70 71 checkPhase = '' 72 runHook preCheck 73 cmake -B build-test -S ../test 74 cmake --build build-test -j$NIX_BUILD_CORES 75 runHook postCheck 76 ''; 77 78 installPhase = '' 79 runHook preInstall 80 # Install the -config.cmake files. 81 cmake --install . "--prefix=$out" 82 # Install the headers. 83 mkdir -p "$includeInstallDir" 84 cp -r ../*.hpp ../internal "$includeInstallDir" 85 runHook postInstall 86 ''; 87 88 meta = { 89 description = "Implementation of Python itertools and builtin iteration functions for C++17"; 90 longDescription = '' 91 Range-based for loop add-ons inspired by the Python builtins and itertools library 92 for C++17, using lazy evaluation wherever possible. 93 ''; 94 homepage = "https://github.com/ryanhaining/cppitertools"; 95 maintainers = with lib.maintainers; [ qyriad ]; 96 license = with lib.licenses; bsd2; 97 }; 98})