Commit 3994ebf8 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

python3Packages.pymeshlab: 2023.12 -> 2025.7 + use system dependencies

parent 1376ce75
Loading
Loading
Loading
Loading
+49 −68
Original line number Diff line number Diff line
{
  stdenv,
  lib,

  stdenv,
  fetchFromGitHub,
  libGLU,
  qtbase,
  qtscript,
  qtxmlpatterns,
  lib3ds,
  bzip2,
  muparser,
  eigen,
  glew,
  gmp,
  levmar,
  qhull,
  fetchpatch,

  # nativeBuildInputs
  cmake,
  cgal,
  boost,
  mpfr,
  xercesc,
  onetbb,
  embree,
  vcg,
  libigl,
  corto,
  openctm,
  structuresynth,
  wrapQtAppsHook,
  python3Packages,

  # propagatedBuildInputs
  meshlab,

  # buildInputs
  libsForQt5,
  glew,
  vcg,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "pymeshlab";
  version = "2023.12";
  version = "2025.7";

  src = fetchFromGitHub {
    owner = "cnr-isti-vclab";
    repo = "pymeshlab";
    rev = "v${finalAttrs.version}";
    hash = "sha256-IOlRdXoUPOJt67g3HqsLchV5aL+JUEks2y1Sy+wpwsg=";
    fetchSubmodules = true;
    tag = "v${finalAttrs.version}";
    hash = "sha256-LCR2/AyX9uVX4xhZareUL6YlpUsCFiGDMBB5nFp+H6k=";
  };

  buildInputs = [
    libGLU
    qtbase
    qtscript
    qtxmlpatterns
    lib3ds
    bzip2
    muparser
    eigen
    glew
    gmp
    levmar
    qhull
    cgal
    boost
    mpfr
    xercesc
    onetbb
    embree
    vcg
    libigl
    corto
    structuresynth
    openctm
  patches = [
    # CMake: allow use of system-provided meshlab & pybind11
    # ref. https://github.com/cnr-isti-vclab/PyMeshLab/pull/445
    # merged upstream
    (fetchpatch {
      url = "https://github.com/cnr-isti-vclab/PyMeshLab/commit/b363caae4362746b3f9e9326fe7b72a2ec7824d9.patch";
      hash = "sha256-euKfOx/T0qdeMx79dpEalzmdWsr4nbDFJfKdksvULBw=";
    })
  ];

  nativeBuildInputs = [
    cmake
    wrapQtAppsHook
    python3Packages.pybind11
  ];

  propagatedBuildInputs = [
    meshlab
    python3Packages.numpy
    python3Packages.pythonImportsCheckHook
  ];

  preConfigure = ''
    substituteInPlace src/meshlab/src/external/libigl.cmake \
      --replace-fail '$'{MESHLAB_EXTERNAL_DOWNLOAD_DIR}/libigl-2.4.0 ${libigl}
    substituteInPlace src/meshlab/src/external/nexus.cmake \
      --replace-fail '$'{NEXUS_DIR}/src/corto ${corto.src}
    substituteInPlace src/meshlab/src/external/levmar.cmake \
      --replace-fail '$'{LEVMAR_LINK} ${levmar.src} \
      --replace-warn "MD5 ''${LEVMAR_MD5}" ""
    substituteInPlace src/meshlab/src/external/ssynth.cmake \
      --replace-fail '$'{SSYNTH_LINK} ${structuresynth.src} \
      --replace-warn "MD5 ''${SSYNTH_MD5}" ""
  '';
  buildInputs = [
    glew
    libsForQt5.qtbase
    vcg
  ];

  dontWrapQtApps = true;

  cmakeFlags = [
    "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}/${python3Packages.python.sitePackages}/pymeshlab"
    "-DVCGDIR=${vcg.src}"
  ];

  # Get io & filter plugins from meshlab, to avoild render, decorate & edit ones
  postInstall = ''
    install -D -t $out/${python3Packages.python.sitePackages}/pymeshlab/lib/plugins \
      ${meshlab}/lib/meshlab/plugins/libio_* \
      ${meshlab}/lib/meshlab/plugins/libfilter_*
  '';

  postFixup = ''
    patchelf \
      --add-needed ${meshlab}/lib/meshlab/libmeshlab-common.so \
      $out/${python3Packages.python.sitePackages}/pymeshlab/pmeshlab.*.so
  '';

  pythonImportsCheck = [ "pymeshlab" ];

  meta = {
    description = "Open source mesh processing python library";
    homepage = "https://github.com/cnr-isti-vclab/PyMeshLab";
    license = lib.licenses.gpl3Only;
    maintainers = with lib.maintainers; [ nim65s ];
    platforms = with lib.platforms; linux;
    platforms = with lib.platforms; linux ++ darwin;
  };
})