|
| 1 | +{ lib |
| 2 | +, stdenv |
| 3 | +, fetchFromGitHub |
| 4 | +, cmake |
| 5 | +, pkg-config |
| 6 | + |
| 7 | +, assimp |
| 8 | +, boost |
| 9 | +, ceres-solver |
| 10 | +, clp |
| 11 | +, eigen |
| 12 | +, expat |
| 13 | +, flann |
| 14 | +, geogram |
| 15 | +, lemon-graph |
| 16 | +, lz4 |
| 17 | +, nanoflann |
| 18 | +, openexr |
| 19 | +, openimageio |
| 20 | +, zlib |
| 21 | + |
| 22 | +, enableOpenMP ? true |
| 23 | +# Separate openmp input only required on Darwin stdenv (LLVM) |
| 24 | +, openmp |
| 25 | + |
| 26 | +, enableAlembic ? true, alembic |
| 27 | +, enableCctag ? true, cctag |
| 28 | +, enableOpenCV ? true, enableOpenCVContrib ? enableOpenCV, opencv |
| 29 | +}: |
| 30 | + |
| 31 | +stdenv.mkDerivation rec { |
| 32 | + pname = "alice-vision"; |
| 33 | + version = "3.0.0"; |
| 34 | + |
| 35 | + outputs = [ "out" "dev" ]; |
| 36 | + |
| 37 | + src = fetchFromGitHub { |
| 38 | + owner = "alicevision"; |
| 39 | + repo = "AliceVision"; |
| 40 | + rev = "v${version}"; |
| 41 | + hash = "sha256-rFd2AFtvC1RugKGv4tI2k3rtDqXHjdDC3pgOrqDqIT0="; |
| 42 | + }; |
| 43 | + |
| 44 | + nativeBuildInputs = [ |
| 45 | + cmake |
| 46 | + pkg-config |
| 47 | + ]; |
| 48 | + |
| 49 | + buildInputs = [ |
| 50 | + flann |
| 51 | + nanoflann |
| 52 | + openexr |
| 53 | + |
| 54 | + # Temporary fix until flann 1.9.2 is in Nixpkgs |
| 55 | + lz4 |
| 56 | + ]; |
| 57 | + |
| 58 | + propagatedBuildInputs = [ |
| 59 | + assimp |
| 60 | + boost |
| 61 | + ceres-solver |
| 62 | + clp |
| 63 | + eigen |
| 64 | + expat |
| 65 | + geogram |
| 66 | + lemon-graph |
| 67 | + openimageio |
| 68 | + zlib |
| 69 | + ] ++ lib.optional enableAlembic alembic |
| 70 | + ++ lib.optional enableCctag cctag |
| 71 | + ++ lib.optional enableOpenCV opencv |
| 72 | + ++ lib.optional stdenv.cc.isClang openmp; |
| 73 | + |
| 74 | + patches = [ |
| 75 | + # Don't optimize for the host processor (could lead to reproducibility issues) |
| 76 | + ./cmake-disable-optimize-for-architecture.patch |
| 77 | + |
| 78 | + # Upstream uses patched Clp/Osi/CoinUtils containing CMake build scripts. |
| 79 | + # Instead of the patched versions, we re-use our packages and add CMake |
| 80 | + # find modules that use the pkg-config files already generated by those |
| 81 | + # dependencies. |
| 82 | + ./find-coin-modules.patch |
| 83 | + |
| 84 | + ./find-flann.patch |
| 85 | + ]; |
| 86 | + |
| 87 | + # Instead of using dependencies from Git submodules, we use Nix packages |
| 88 | + # This speeds up fetching and reduces the source archive size |
| 89 | + postPatch = '' |
| 90 | + rmdir src/dependencies/nanoflann |
| 91 | + ln -s ${nanoflann} src/dependencies/nanoflann |
| 92 | +
|
| 93 | + rm -r src/dependencies/lemon |
| 94 | + rm -r src/dependencies/flann |
| 95 | +
|
| 96 | + rm src/cmake/FindFlann.cmake |
| 97 | +
|
| 98 | + substituteInPlace src/CMakeLists.txt \ |
| 99 | + --replace 'if(NOT EXISTS ''${CMAKE_CURRENT_SOURCE_DIR}/dependencies/flann/src)' 'if(FALSE)' |
| 100 | +
|
| 101 | + substituteInPlace src/aliceVision/matching/CMakeLists.txt \ |
| 102 | + --replace ' ''${FLANN_LIBRARY}' ' flann::flann_cpp' \ |
| 103 | + --replace \ |
| 104 | + 'alicevision_add_test(matching_test.cpp NAME "matching" LINKS aliceVision_matching)' \ |
| 105 | + 'alicevision_add_test(matching_test.cpp NAME "matching" LINKS aliceVision_matching lz4)' |
| 106 | + ''; |
| 107 | + |
| 108 | + # Disable warning causing compile error on certain Clang versions |
| 109 | + CXXFLAGS = lib.optionalString stdenv.cc.isClang "-Wno-c++11-narrowing"; |
| 110 | + |
| 111 | + cmakeFlags = |
| 112 | + let |
| 113 | + cmakeOption = name: enabled: "-D${name}:BOOL=" + (if enabled then "ON" else "OFF"); |
| 114 | + in |
| 115 | + lib.mapAttrsToList (name: cmakeOption "ALICEVISION_USE_${lib.toUpper (lib.removePrefix "enable" name)}") { |
| 116 | + inherit enableAlembic enableCctag enableOpenCV enableOpenMP; |
| 117 | + |
| 118 | + enableApriltag = false; |
| 119 | + enableMeshSDFilter = false; |
| 120 | + enableOpenGV = false; |
| 121 | + |
| 122 | + enableCuda = false; |
| 123 | + enablePopsift = false; |
| 124 | + enableUncertaintyTE = false; |
| 125 | + |
| 126 | + enableOpenCV_Contrib = enableOpenCVContrib; |
| 127 | + |
| 128 | + # Could be enabled, but does not compile as of v2.4.0 (upstream bug) |
| 129 | + enableOcvsift = false; |
| 130 | + } ++ lib.mapAttrsToList cmakeOption { |
| 131 | + ALICEVISION_BUILD_DEPENDENCIES = false; |
| 132 | + |
| 133 | + # Disable most binaries - most of them don't build due to compile errors |
| 134 | + ALICEVISION_BUILD_DOC = false; |
| 135 | + ALICEVISION_BUILD_EXAMPLES = false; |
| 136 | + ALICEVISION_BUILD_SOFTWARE = false; |
| 137 | + |
| 138 | + ALICEVISION_BUILD_TESTS = doCheck; |
| 139 | + |
| 140 | + ALICEVISION_REQUIRE_CERES_WITH_SUITESPARSE = true; |
| 141 | + } ++ [ |
| 142 | + # Note: Don't explicitly set ALICEVISION_USE_INTERNAL_FLANN or ALICEVISION_USE_INTERNAL_LEMON |
| 143 | + # to OFF, as that will cause the opposite effect since the CMake script only checks whether these |
| 144 | + # variables are defined (instead of picking up their value). |
| 145 | + |
| 146 | + "-DFLANN_INCLUDE_DIR_HINTS:PATH=${flann}" |
| 147 | + "-DLEMON_INCLUDE_DIR_HINTS:PATH=${lemon-graph}" |
| 148 | + ]; |
| 149 | + |
| 150 | + # Remove third-party dependency headers |
| 151 | + postInstall = '' |
| 152 | + mv $out/share $dev |
| 153 | + mv $out/include/aliceVision/* $dev/include/aliceVision |
| 154 | + mv $out/include/aliceVision_dependencies $dev/include |
| 155 | + rmdir $out/include/aliceVision |
| 156 | + rmdir $out/include |
| 157 | + ''; |
| 158 | + |
| 159 | + doCheck = true; |
| 160 | + |
| 161 | + checkPhase = |
| 162 | + let |
| 163 | + disabledTests = [ |
| 164 | + # sfm_panorama tests hang |
| 165 | + "^test_aliceVision_test_sfm_panorama_(radial3|equidistant)(_outliers)?$" |
| 166 | + |
| 167 | + # Broken due to lz4 linking issue |
| 168 | + "^test_aliceVision_test_matching$" |
| 169 | + |
| 170 | + # Tests that can take a long time (>30 seconds) to run |
| 171 | + "^test_aliceVision_test_hdr_(debevec|laguerre|grossberg)$" |
| 172 | + |
| 173 | + "^test_aliceVision_test_voctree_kmeans$" |
| 174 | + ] ++ lib.optionals stdenv.isDarwin [ |
| 175 | + # Regular timeouts |
| 176 | + "^test_aliceVision_test_colorHarmonization_gainOffsetConstraintBuilder$" |
| 177 | + "^test_aliceVision_test_image$" |
| 178 | + "^test_aliceVision_test_features$" |
| 179 | + |
| 180 | + # Fails on Darwin |
| 181 | + "^test_aliceVision_test_voctree_vocabularyTree$" |
| 182 | + ]; |
| 183 | + excludeRegex = lib.concatStringsSep "|" disabledTests; |
| 184 | + exclude = "--exclude-regex ${lib.escapeShellArg excludeRegex}"; |
| 185 | + in |
| 186 | + '' |
| 187 | + runHook preCheck |
| 188 | +
|
| 189 | + ${lib.optionalString stdenv.isDarwin '' |
| 190 | + export DYLD_LIBRARY_PATH="${lib.getLib geogram}/lib:$(pwd)" |
| 191 | + ''} |
| 192 | +
|
| 193 | + ctest \ |
| 194 | + --force-new-ctest-process \ |
| 195 | + --timeout 120 \ |
| 196 | + ${exclude} |
| 197 | +
|
| 198 | + runHook postCheck |
| 199 | + ''; |
| 200 | + |
| 201 | + meta = with lib; { |
| 202 | + description = "Photogrammetric Computer Vision Framework which provides a 3D Reconstruction and Camera Tracking algorithms"; |
| 203 | + homepage = "https://alicevision.org"; |
| 204 | + downloadPage = "https://github.com/alicevision/AliceVision"; |
| 205 | + license = with licenses; [ mpl20 mit bsd2 ]; |
| 206 | + maintainers = with maintainers; [ tmarkus ]; |
| 207 | + }; |
| 208 | +} |
0 commit comments