summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/pymeshlab/default.nix
blob: a95ebb42bf3eefd8c7dc5086fd4b397b3d8127f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{
  lib,

  stdenv,
  fetchFromGitHub,
  fetchpatch,
  buildPythonPackage,
  python,

  # nativeBuildInputs
  cmake,
  pybind11,

  # propagatedBuildInputs
  meshlab,
  numpy,

  # buildInputs
  libsForQt5,
  llvmPackages,
  glew,
  vcg,
}:

let
  version = "2025.7";
in
buildPythonPackage {
  inherit version;
  pname = "pymeshlab";
  pyproject = false;

  src = fetchFromGitHub {
    owner = "cnr-isti-vclab";
    repo = "pymeshlab";
    tag = "v${version}";
    hash = "sha256-LCR2/AyX9uVX4xhZareUL6YlpUsCFiGDMBB5nFp+H6k=";
  };

  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
    pybind11
  ];

  propagatedBuildInputs = [
    meshlab
    numpy
  ];

  buildInputs = [
    glew
    libsForQt5.qtbase
    vcg
  ]
  ++ lib.optionals stdenv.cc.isClang [
    llvmPackages.openmp
  ];

  dontWrapQtApps = true;

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

  # Get io & filter plugins from meshlab, to avoild render, decorate & edit ones
  postInstall =
    let
      plugins =
        if stdenv.hostPlatform.isDarwin then
          "Applications/meshlab.app/Contents/PlugIns"
        else
          "lib/meshlab/plugins";
      pyPlugins = if stdenv.hostPlatform.isDarwin then "PlugIns" else "lib/plugins";
    in
    ''
      install -D -t $out/${python.sitePackages}/pymeshlab/${pyPlugins} \
        ${meshlab}/${plugins}/libio_* \
        ${meshlab}/${plugins}/libfilter_*
    '';

  postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
    patchelf \
      --add-needed ${meshlab}/lib/meshlab/libmeshlab-common.so \
      $out/${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 ++ darwin;
  };
}