opensfm-9999.ebuild 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # Copyright 1999-2024 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=8
  4. PYTHON_COMPAT=( python3_{10..12} )
  5. MY_PN="OpenSfM"
  6. inherit distutils-r1 cmake
  7. DISTUTILS_USE_SETUPTOOLS=no
  8. DISTUTILS_OPTIONAL=1
  9. DISTUTILS_USE_PEP517=setuptools
  10. DISTUTILS_SINGLE_IMPL=1
  11. DISTUTILS_EXT=1
  12. DESCRIPTION="Open source Structure-from-Motion pipeline"
  13. HOMEPAGE="https://www.opensfm.org"
  14. if [[ ${PV} = *9999 ]]; then
  15. inherit git-r3
  16. EGIT_REPO_URI="https://github.com/mapillary/${MY_PN}"
  17. EGIT_SUBMODULES=( '*' '-opensfm/src/third_party/pybind11' )
  18. EGIT_BRANCH="main"
  19. KEYWORDS=""
  20. CERES_PV=2.3.0
  21. else
  22. SRC_URI="https://github.com/mapillary/${MY_PN}/archive/v${PV}/${P}.tar.gz -> ${P}.tar.gz"
  23. KEYWORDS="~amd64 ~x86 ~arm64 ~arm"
  24. CERES_PV=2.1.0
  25. S=${WORKDIR}/${MY_PN}-${PV}
  26. fi
  27. QA_PRESTRIPPED="usr/lib/python.*/site-packages/opensfm/.*"
  28. LICENSE="BSD-2"
  29. SLOT="0"
  30. IUSE="debug doc test lto"
  31. REQUIRED_USE="${PYTHON_REQUIRED_USE}"
  32. #media-libs/opengv[python,${PYTHON_USEDEP}]
  33. DEPEND="
  34. dev-libs/boost[${PYTHON_USEDEP}]
  35. media-libs/opencv:=[python,${PYTHON_USEDEP}]
  36. <=sci-libs/ceres-solver-${CERES_PV}:=
  37. >=sci-libs/suitesparseconfig-7.6.0:=
  38. >=sci-libs/amd-3.3.1:=
  39. >=sci-libs/camd-3.3.1:=
  40. >=sci-libs/colamd-3.3.1:=
  41. >=sci-libs/ccolamd-3.3.1:=
  42. >=sci-libs/cholmod-5.2.0:=
  43. >=sci-libs/cxsparse-4.3.1:=
  44. >=sci-libs/spqr-4.3.2:=
  45. >=sci-libs/metis-5.2.1:=
  46. >=dev-python/cloudpickle-0.4.0[${PYTHON_USEDEP}]
  47. >=dev-python/exifread-2.1.2[${PYTHON_USEDEP}]
  48. >=dev-python/joblib-0.14.1[${PYTHON_USEDEP}]
  49. >=dev-python/loky-1.0.0[${PYTHON_USEDEP}]
  50. dev-python/matplotlib[${PYTHON_USEDEP}]
  51. >=dev-python/networkx-1.11[${PYTHON_USEDEP}]
  52. >=dev-python/pillow-8.1.1[${PYTHON_USEDEP}]
  53. >=dev-python/pyproj-1.9.5.1[${PYTHON_USEDEP}]
  54. >=dev-python/pytest-3.0.7[${PYTHON_USEDEP}]
  55. >=dev-python/python-dateutil-2.6.0[${PYTHON_USEDEP}]
  56. >=dev-python/pyyaml-5.1[${PYTHON_USEDEP}]
  57. dev-python/numpy[${PYTHON_USEDEP}]
  58. dev-python/scipy[${PYTHON_USEDEP}]
  59. dev-python/repoze-lru[${PYTHON_USEDEP}]
  60. >=dev-python/fpdf2-2.4.6[${PYTHON_USEDEP}]
  61. doc? (
  62. >=dev-python/sphinx-3.4.3[${PYTHON_USEDEP}]
  63. dev-python/six[${PYTHON_USEDEP}]
  64. )
  65. >=dev-python/xmltodict-0.10.2[${PYTHON_USEDEP}]
  66. dev-python/wheel[${PYTHON_USEDEP}]
  67. "
  68. RDEPEND="${DEPEND}"
  69. BDEPEND="
  70. dev-python/pybind11[${PYTHON_USEDEP}]
  71. dev-python/cython[${PYTHON_USEDEP}]
  72. media-libs/vlfeat
  73. >=dev-build/cmake-3.0.0
  74. dev-cpp/glog[gflags]
  75. "
  76. RESTRICT="
  77. mirror
  78. test ( test )
  79. "
  80. src_prepare() {
  81. use doc || sed -i -e "/from sphinx\.setup_command import BuildDoc/d" -e "/\"build_doc\": BuildDoc\,/d" setup.py || die "Sed failed"
  82. sed -e '/"bin\/opensfm"\,/a "bin\/opensfm_main\.py",' -i setup.py || die "Sed failed"
  83. if [[ ${PV} = *9999 ]]; then
  84. #Enable cxx17 as CERES-2.0 req it
  85. sed -e "s|\(set(CMAKE_CXX_STANDARD \)14|\117|" -i opensfm/src/CMakeLists.txt || die "Sed failed"
  86. #unbundle pybind11
  87. sed -e "s|add_subdirectory(third_party\/pybind11)|find_package (pybind11 CONFIG REQUIRED)|" -i opensfm/src/CMakeLists.txt || die "Sed failed"
  88. sed -e "/include_directories(third_party\/pybind11\/include)/d" -i opensfm/src/CMakeLists.txt || die "Sed failed"
  89. #sed -e "s/include_directories(third_party\/pybind11\/include)/include_directories(\/usr\/include\/pybind11)/" -i opensfm/src/CMakeLists.txt || die "Sed failed"
  90. sed -e "/^target_link_libraries(/,/)/s|pybind11|pybind11::headers|g" -i opensfm/src/{bundle,dense,features,foundation,geometry,robust,sfm,geo,map}/CMakeLists.txt || die "Sed failed"
  91. #eapply "${FILESDIR}/unbundle-pybind.patch"
  92. eapply "${FILESDIR}/opensfm-fix-vl-src-path.patch"
  93. eapply "${FILESDIR}/opensfm-fix-hahog-vl-covdet.patch"
  94. else
  95. #Enable cxx17 as CERES-2.0 req it
  96. sed -e "s|\(set(CMAKE_CXX_STANDARD \)11|\114|" -i opensfm/src/CMakeLists.txt || die "Sed failed"
  97. #unbundle pybind11
  98. sed -e "s|add_subdirectory(third_party\/pybind11)|find_package (pybind11 CONFIG REQUIRED)|" -i opensfm/src/CMakeLists.txt || die "Sed failed"
  99. sed -e "/^target_link_libraries(/,/)/s|pybind11|pybind11::pybind11|g" -i opensfm/src/{dense,features,foundation,geometry,robust,sfm}/CMakeLists.txt || die "Sed failed"
  100. fi
  101. # Build C extension with gentoo cmake eclass
  102. sed -e "/^configure_c_extension()$/d" -i setup.py || die "Sed failed"
  103. sed -e "/^build_c_extension()$/d" -i setup.py || die "Sed failed"
  104. CMAKE_USE_DIR="${S}/opensfm/src"
  105. cmake_src_prepare
  106. python_prepare_all
  107. }
  108. python_prepare_all() {
  109. python_setup
  110. python_fix_shebang .
  111. distutils-r1_python_prepare_all
  112. }
  113. src_configure() {
  114. CMAKE_BUILD_TYPE=$(usex debug RelWithDebInfo Release)
  115. CMAKE_CXX_STANDARD=17
  116. CMAKE_CXX_STANDARD_REQUIRED=ON
  117. CMAKE_INTERPROCEDURAL_OPTIMIZATION=$(usex lto)
  118. CMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
  119. local mycmakeargs=(
  120. -DCMAKE_SKIP_RPATH=ON
  121. -DCMAKE_POLICY_DEFAULT_CMP0057="NEW"
  122. -DOPENSFM_BUILD_TESTS=$(usex test)
  123. -DPYBIND11_FINDPYTHON=OFF
  124. )
  125. cmake_src_configure
  126. distutils-r1_src_configure
  127. }
  128. src_compile() {
  129. cmake_src_compile
  130. distutils-r1_src_compile
  131. }
  132. src_install() {
  133. pushd ${PN}/src >/dev/null || die
  134. distutils-r1_src_install
  135. popd >/dev/null || die
  136. }
  137. python_compile_all() {
  138. local targets=()
  139. use doc && targets+=( build_doc )
  140. use test && targets+=( bundle_test )
  141. if [[ ${targets[@]} ]]; then
  142. ${EPYTHON} esetup.py "${targets[@]}"
  143. fi
  144. }
  145. python_test() {
  146. ${EPYTHON} esetup.py test
  147. }