Skip to content

Commit

Permalink
alice-vision: init at 3.0.0, add 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Isidor Zeuner committed Jan 31, 2024
1 parent 3c193c9 commit 1ef48fe
Show file tree
Hide file tree
Showing 6 changed files with 624 additions and 0 deletions.
225 changes: 225 additions & 0 deletions pkgs/development/libraries/alice-vision/3.0.0.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
{ lib
, stdenv
, fetchFromGitHub
, cmake
, pkg-config

, pkgs

, assimp
# use the same boost as in cctag here
, boost179
, ceres-solver
, clp
, eigen
, expat
, flann
, geogram
, lemon-graph
, lz4
, openexr
, openimageio
, zlib

, enableOpenMP ? true
# Separate openmp input only required on Darwin stdenv (LLVM)
, openmp

, enableAlembic ? true, alembic
, enableCctag ? true, cctag
, enableOpenCV ? true, enableOpenCVContrib ? enableOpenCV, opencv
}:

let
nanoflann = pkgs.nanoflann.overrideAttrs (
oldAttrs: rec {
version = "1.4.2";
src = fetchFromGitHub {
owner = "jlblancoc";
repo = "nanoflann";
rev = "v${version}";
hash = "sha256-znIX1S0mfOqLYPIcyVziUM1asBjENPEAdafLud1CfFI=";
};
}
);
in
stdenv.mkDerivation rec {
pname = "alice-vision";
version = "3.0.0";

outputs = [ "out" "dev" ];

src = fetchFromGitHub {
owner = "alicevision";
repo = "AliceVision";
rev = "v${version}";
hash = "sha256-rFd2AFtvC1RugKGv4tI2k3rtDqXHjdDC3pgOrqDqIT0=";
};

nativeBuildInputs = [
cmake
pkg-config
];

buildInputs = [
flann
nanoflann
openexr

# Temporary fix until flann 1.9.2 is in Nixpkgs
lz4
];

propagatedBuildInputs = [
assimp
boost179
ceres-solver
clp
eigen
expat
geogram
lemon-graph
openimageio
zlib
] ++ lib.optional enableAlembic alembic
++ lib.optional enableCctag cctag
++ lib.optional enableOpenCV opencv
++ lib.optional stdenv.cc.isClang openmp;

patches = [
# Don't optimize for the host processor (could lead to reproducibility issues)
./cmake-disable-optimize-for-architecture.patch

# Upstream uses patched Clp/Osi/CoinUtils containing CMake build scripts.
# Instead of the patched versions, we re-use our packages and add CMake
# find modules that use the pkg-config files already generated by those
# dependencies.
./find-coin-modules.patch

./find-flann.patch
];

# Instead of using dependencies from Git submodules, we use Nix packages
# This speeds up fetching and reduces the source archive size
postPatch = ''
rmdir src/dependencies/nanoflann
ln -s ${nanoflann} src/dependencies/nanoflann
rm -r src/dependencies/lemon
rm -r src/dependencies/flann
rm src/cmake/FindFlann.cmake
substituteInPlace src/CMakeLists.txt \
--replace 'if(NOT EXISTS ''${CMAKE_CURRENT_SOURCE_DIR}/dependencies/flann/src)' 'if(FALSE)'
substituteInPlace src/aliceVision/matching/CMakeLists.txt \
--replace ' ''${FLANN_LIBRARY}' ' flann::flann_cpp' \
--replace \
'alicevision_add_test(matching_test.cpp NAME "matching" LINKS aliceVision_matching)' \
'alicevision_add_test(matching_test.cpp NAME "matching" LINKS aliceVision_matching lz4)'
'';

# Disable warning causing compile error on certain Clang versions
CXXFLAGS = lib.optionalString stdenv.cc.isClang "-Wno-c++11-narrowing";

cmakeFlags =
let
cmakeOption = name: enabled: "-D${name}:BOOL=" + (if enabled then "ON" else "OFF");
in
lib.mapAttrsToList (name: cmakeOption "ALICEVISION_USE_${lib.toUpper (lib.removePrefix "enable" name)}") {
inherit enableAlembic enableCctag enableOpenCV enableOpenMP;

enableApriltag = false;
enableMeshSDFilter = false;
enableOpenGV = false;

enableCuda = false;
enablePopsift = false;
enableUncertaintyTE = false;

enableOpenCV_Contrib = enableOpenCVContrib;

# Could be enabled, but does not compile as of v2.4.0 (upstream bug)
enableOcvsift = false;
} ++ lib.mapAttrsToList cmakeOption {
ALICEVISION_BUILD_DEPENDENCIES = false;

# Disable most binaries - most of them don't build due to compile errors
ALICEVISION_BUILD_DOC = false;
ALICEVISION_BUILD_EXAMPLES = false;
ALICEVISION_BUILD_SOFTWARE = true;

ALICEVISION_BUILD_TESTS = doCheck;

ALICEVISION_REQUIRE_CERES_WITH_SUITESPARSE = true;
} ++ [
# Note: Don't explicitly set ALICEVISION_USE_INTERNAL_FLANN or ALICEVISION_USE_INTERNAL_LEMON
# to OFF, as that will cause the opposite effect since the CMake script only checks whether these
# variables are defined (instead of picking up their value).

"-DFLANN_INCLUDE_DIR_HINTS:PATH=${flann}"
"-DLEMON_INCLUDE_DIR_HINTS:PATH=${lemon-graph}"
];

# Remove third-party dependency headers
postInstall = ''
# do not move away the embedded OCIO configuration file to allow the
# binaries to be used
# mv $out/share $dev
mv $out/include/aliceVision/* $dev/include/aliceVision
mv $out/include/aliceVision_dependencies $dev/include
rmdir $out/include/aliceVision
rmdir $out/include
'';

doCheck = true;

checkPhase =
let
disabledTests = [
# sfm_panorama tests hang
"^test_aliceVision_test_sfm_panorama_(radial3|equidistant)(_outliers)?$"

# Broken due to lz4 linking issue
"^test_aliceVision_test_matching$"

# Tests that can take a long time (>30 seconds) to run
"^test_aliceVision_test_hdr_(debevec|laguerre|grossberg)$"

"^test_aliceVision_test_voctree_kmeans$"
] ++ lib.optionals stdenv.isDarwin [
# Regular timeouts
"^test_aliceVision_test_colorHarmonization_gainOffsetConstraintBuilder$"
"^test_aliceVision_test_image$"
"^test_aliceVision_test_features$"

# Fails on Darwin
"^test_aliceVision_test_voctree_vocabularyTree$"
];
excludeRegex = lib.concatStringsSep "|" disabledTests;
exclude = "--exclude-regex ${lib.escapeShellArg excludeRegex}";
in
''
runHook preCheck
${lib.optionalString stdenv.isDarwin ''
export DYLD_LIBRARY_PATH="${lib.getLib geogram}/lib:$(pwd)"
''}
ctest \
--force-new-ctest-process \
--timeout 120 \
${exclude}
runHook postCheck
'';

meta = with lib; {
description = "Photogrammetric Computer Vision Framework which provides a 3D Reconstruction and Camera Tracking algorithms";
homepage = "https://alicevision.org";
downloadPage = "https://github.com/alicevision/AliceVision";
license = with licenses; [ mpl20 mit bsd2 ];
maintainers = with maintainers; [ tmarkus gm6k ];
};
}
Loading

0 comments on commit 1ef48fe

Please sign in to comment.