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 Feb 15, 2024
1 parent 3c193c9 commit 933edf0
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/nix/store/ipz4izl82p822flysklls9bnm686ay14-source/src/CMakeLists.txt b/pkgs/applications/graphics/alice-vision/CMakeLists.txt
index 118281d65cb..85b15586452 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -178,7 +178,6 @@ endif()
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(OptimizeForArchitecture)
-OptimizeForArchitecture()
set(ALICEVISION_HAVE_SSE 0)
if(SSE2_FOUND OR TARGET_ARCHITECTURE STREQUAL "native")
if(MSVC AND NOT ${CMAKE_CL_64})
123 changes: 123 additions & 0 deletions pkgs/by-name/al/alice-vision/find-coin-modules.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
--- a/src/CMakeLists.txt 1970-01-01 01:00:01.000000000 +0100
+++ b/src/CMakeLists.txt 2023-04-03 16:32:16.994922955 +0200
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.11)

+list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../modules)
+
# ==============================================================================
# AliceVision version
# ==============================================================================
@@ -433,6 +435,7 @@
find_package(CoinUtils REQUIRED)
find_package(Clp REQUIRED)
find_package(Osi REQUIRED)
+ find_package(OsiClp REQUIRED)
endif()

# ==============================================================================
--- a/src/aliceVision/linearProgramming/CMakeLists.txt 1970-01-01 01:00:01.000000000 +0100
+++ b/src/aliceVision/linearProgramming/CMakeLists.txt 2023-04-03 16:33:09.883053876 +0200
@@ -13,6 +13,7 @@
Coin::Clp # clp + solver wrapper
Coin::CoinUtils # container tools
Coin::Osi # generic LP
+ Coin::OsiClp
)

if (NOT MOSEK_FOUND)
--- /dev/null 2023-03-27 18:27:39.858686170 +0200
+++ b/modules/FindCoinUtils.cmake 2023-04-03 16:12:16.146494958 +0200
@@ -0,0 +1,21 @@
+find_package(PkgConfig REQUIRED)
+if(PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_COINUTILS REQUIRED IMPORTED_TARGET coinutils)
+
+ add_library(Coin::CoinUtils ALIAS PkgConfig::PC_COINUTILS)
+endif()
+
+find_path(COINUTILS_INCLUDE_DIRS
+ NAMES CoinUtilsConfig.h
+ HINTS ${PC_COINUTILS_INCLUDE_DIRS})
+
+if (EXISTS "${COINUTILS_INCLUDE_DIRS}/CoinUtilsConfig.h")
+ file(STRINGS "${COINUTILS_INCLUDE_DIRS}/CoinUtilsConfig.h" coinutils_version_str REGEX "^#define[\t ]+COINUTILS_VERSION[\t ]+\".*\"")
+ string(REGEX REPLACE "^#define[\t ]+COINUTILS_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CoinUtils_VERSION "${coinutils_version_str}")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(CoinUtils
+ REQUIRED_VARS COINUTILS_INCLUDE_DIRS
+ VERSION_VAR CoinUtils_VERSION
+ )
--- /dev/null 2023-03-27 18:27:39.858686170 +0200
+++ b/modules/FindClp.cmake 2023-04-03 16:12:16.146494958 +0200
@@ -0,0 +1,21 @@
+find_package(PkgConfig REQUIRED)
+if(PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_CLP REQUIRED IMPORTED_TARGET clp)
+
+ add_library(Coin::Clp ALIAS PkgConfig::PC_CLP)
+endif()
+
+find_path(CLP_INCLUDE_DIRS
+ NAMES ClpConfig.h
+ HINTS ${PC_CLP_INCLUDE_DIRS})
+
+if (EXISTS "${CLP_INCLUDE_DIRS}/ClpConfig.h")
+ file(STRINGS "${CLP_INCLUDE_DIRS}/ClpConfig.h" clp_version_str REGEX "^#define[\t ]+CLP_VERSION[\t ]+\".*\"")
+ string(REGEX REPLACE "^#define[\t ]+CLP_VERSION[\t ]+\"([^\"]*)\".*" "\\1" Clp_VERSION "${clp_version_str}")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Clp
+ REQUIRED_VARS CLP_INCLUDE_DIRS
+ VERSION_VAR Clp_VERSION
+ )
--- /dev/null 2023-03-27 18:27:39.858686170 +0200
+++ b/modules/FindOsi.cmake 2023-04-03 16:12:16.147494961 +0200
@@ -0,0 +1,22 @@
+find_package(PkgConfig REQUIRED)
+if(PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_OSI REQUIRED IMPORTED_TARGET osi)
+
+ add_library(Coin::Osi ALIAS PkgConfig::PC_OSI)
+endif()
+
+find_path(OSI_INCLUDE_DIRS
+ NAMES OsiConfig.h
+ HINTS ${PC_OSI_INCLUDE_DIRS})
+
+if (EXISTS "${OSI_INCLUDE_DIRS}/OsiConfig.h")
+ file(STRINGS "${OSI_INCLUDE_DIRS}/OsiConfig.h" osi_version_str REGEX "^#define[\t ]+OSI_VERSION[\t ]+\".*\"")
+ string(REGEX REPLACE "^#define[\t ]+OSI_VERSION[\t ]+\"([^\"]*)\".*" "\\1" Osi_VERSION "${osi_version_str}")
+endif()
+
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Osi
+ REQUIRED_VARS OSI_INCLUDE_DIRS
+ VERSION_VAR Osi_VERSION
+ )
--- /dev/null 2023-03-27 18:27:39.858686170 +0200
+++ b/modules/FindOsiClp.cmake 2023-04-03 16:31:08.255752799 +0200
@@ -0,0 +1,18 @@
+find_package(PkgConfig REQUIRED)
+if(PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_OSI_CLP REQUIRED IMPORTED_TARGET osi-clp)
+
+ add_library(Coin::OsiClp ALIAS PkgConfig::PC_OSI_CLP)
+
+ set(OsiClp_VERSION ${PC_OSI_CLP_VERSION})
+endif()
+
+find_path(OSI_CLP_INCLUDE_DIRS
+ NAMES OsiSolverInterface.hpp
+ HINTS ${PC_OSI_CLP_INCLUDE_DIRS})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(OsiClp
+ REQUIRED_VARS OSI_CLP_INCLUDE_DIRS
+ VERSION_VAR OsiClp_VERSION
+ )

23 changes: 23 additions & 0 deletions pkgs/by-name/al/alice-vision/find-flann.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- /dev/null 2023-04-03 16:53:39.918168848 +0200
+++ b/modules/FindFlann.cmake 2023-04-03 21:33:25.433754406 +0200
@@ -0,0 +1,20 @@
+find_package(PkgConfig REQUIRED)
+if(PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_FLANN REQUIRED IMPORTED_TARGET flann)
+ pkg_check_modules(PC_LZ4 REQUIRED IMPORTED_TARGET liblz4)
+
+ add_library(flann::flann_cpp ALIAS PkgConfig::PC_FLANN)
+ set(FLANN_LIBRARY flann::flann_cpp)
+
+ set(FLANN_VERSION ${PC_FLANN_VERSION})
+endif()
+
+find_path(FLANN_INCLUDE_DIRS
+ NAMES flann/flann.hpp
+ HINTS ${PC_FLANN_INCLUDE_DIRS})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Flann
+ REQUIRED_VARS FLANN_INCLUDE_DIRS
+ VERSION_VAR FLANN_VERSION
+ )
232 changes: 232 additions & 0 deletions pkgs/by-name/al/alice-vision/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
{ 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
, onnxruntime
, 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.1.0";

outputs = [ "out" "dev" ];

src = fetchFromGitHub {
owner = "alicevision";
repo = "AliceVision";
rev = "v${version}";
hash = "sha256-9PSXyygBr5cWutt+qnJvDawyxpTHxJFfRYLvyr43IlQ=";
};

nativeBuildInputs = [
cmake
pkg-config
];

buildInputs = [
flann
nanoflann
onnxruntime
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;
# CCTag package does not support alignment yet, and this must be
# consistent between both packages
AV_EIGEN_MEMORY_ALIGNMENT = ! enableCctag;

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$"
"^test_aliceVision_test_robustEstimation_acRansac$"

# 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 933edf0

Please sign in to comment.