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