Unverified Commit 66b68624 authored by dish's avatar dish Committed by GitHub
Browse files

meshlab{,-unstable}: add darwin support (#396295)

parents 8d1beb88 831e9edf
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -4,19 +4,24 @@
  fetchurl,
}:

stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "levmar";
  version = "2.6";

  src = fetchurl {
    url = "https://www.ics.forth.gr/~lourakis/levmar/${pname}-${version}.tgz";
    sha256 = "1mxsjip9x782z6qa6k5781wjwpvj5aczrn782m9yspa7lhgfzx1v";
    url = "https://www.ics.forth.gr/~lourakis/levmar/levmar-${finalAttrs.version}.tgz";
    hash = "sha256-O/TvHqRHXe1TFejY/Jkqcl8ueUCnTKOw+QKdnm6Uutc=";
  };

  patchPhase = ''
    substituteInPlace levmar.h --replace "define HAVE_LAPACK" "undef HAVE_LAPACK"
  postPatch = ''
    substituteInPlace levmar.h --replace-fail "define HAVE_LAPACK" "undef HAVE_LAPACK"
    sed -i 's/LAPACKLIBS=.*/LAPACKLIBS=/' Makefile
    substituteInPlace Makefile --replace "gcc" "${stdenv.cc.targetPrefix}cc"
    substituteInPlace Makefile --replace-fail "gcc" "${stdenv.cc.targetPrefix}cc"
  ''
  + lib.optionalString stdenv.cc.isClang ''
    substituteInPlace compiler.h \
      --replace-fail "#define LM_FINITE finite // ICC, GCC" \
                     "#define LM_FINITE isfinite // ICC, GCC"
  '';

  installPhase = ''
@@ -29,6 +34,7 @@ stdenv.mkDerivation rec {
    description = "ANSI C implementations of Levenberg-Marquardt, usable also from C++";
    homepage = "https://www.ics.forth.gr/~lourakis/levmar/";
    license = lib.licenses.gpl2Plus;
    maintainers = [ ];
    platforms = lib.platforms.all;
  };
}
})
+39 −8
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
  lib,
  stdenv,
  fetchFromGitHub,
  llvmPackages,
  libsForQt5,
  libGLU,
  lib3ds,
@@ -29,14 +30,15 @@ let
  tinygltf-src = fetchFromGitHub {
    owner = "syoyo";
    repo = "tinygltf";
    rev = "v2.6.3";
    tag = "v2.6.3";
    hash = "sha256-IyezvHzgLRyc3z8HdNsQMqDEhP+Ytw0stFNak3C8lTo=";
  };

  # requires submodules to build
  lib3mf-src = fetchFromGitHub {
    owner = "3MFConsortium";
    repo = "lib3mf";
    rev = "v2.3.2";
    tag = "v2.3.2";
    fetchSubmodules = true;
    hash = "sha256-pKjnN9H6/A2zPvzpFed65J+mnNwG/dkSE2/pW7IlN58=";
  };
@@ -50,11 +52,19 @@ stdenv.mkDerivation {
    repo = "meshlab";
    # note that this is in branch devel
    rev = "72142583980b6dbfc5b85c6cca226a72f48497a9";
    sha256 = "1q7qga4d82pvpcbsp9pi2i7nzdbflhp6q0d3y31kpch9r3r9pzks";
    hash = "sha256-ev6b8sgJsjvD8KMBbC6kbrVvTxTxpqsXu/sK1Ih6+OA=";
    # needed for an updated version of vcg in their submodule
    fetchSubmodules = true;
  };

  postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
    substituteInPlace src/meshlab/CMakeLists.txt \
      --replace-fail "set_additional_settings_info_plist(" "# set_additional_settings_info_plist(" \
      --replace-fail "	TARGET meshlab" "#	TARGET meshlab" \
      --replace-fail "	FILE \''${MESHLAB_BUILD_DISTRIB_DIR}/meshlab.app/Contents/Info.plist)" \
                     "#	FILE \''${MESHLAB_BUILD_DISTRIB_DIR}/meshlab.app/Contents/Info.plist)"
  '';

  buildInputs = [
    libGLU
    libsForQt5.qtbase
@@ -78,6 +88,9 @@ stdenv.mkDerivation {
    corto
    openctm
    structuresynth
  ]
  ++ lib.optionals stdenv.cc.isClang [
    llvmPackages.openmp
  ];

  nativeBuildInputs = [
@@ -106,14 +119,32 @@ stdenv.mkDerivation {
      --replace-warn "MESHLAB_LIB_INSTALL_DIR" "CMAKE_INSTALL_LIBDIR"
  '';

  postFixup = ''
  postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
    mkdir -p $out/{Applications,bin,lib}
    mv $out/meshlab.app $out/Applications/
    ln $out/Applications/meshlab.app/Contents/Frameworks/* $out/lib/
    makeWrapper $out/{Applications/meshlab.app/Contents/MacOS,bin}/meshlab
  '';

  postFixup =
    lib.optionalString stdenv.hostPlatform.isLinux ''
      patchelf --add-needed $out/lib/meshlab/libmeshlab-common.so $out/bin/.meshlab-wrapped
      patchelf --add-needed $out/lib/meshlab/lib3mf.so $out/lib/meshlab/plugins/libio_3mf.so
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      wrapQtApp "$out/Applications/meshlab.app/Contents/MacOS/meshlab"
      install_name_tool -change libopenctm.dylib "${lib.getOutput "out" openctm}/lib/libopenctm.dylib" \
        "$out/Applications/meshlab.app/Contents/PlugIns/libio_ctm.so"
    '';

  # The hook will wrap all the plugin binaries, make they are not a
  # valid plugin. So we have to wrap the main app manually.
  # See: https://github.com/NixOS/nixpkgs/pull/396295#issuecomment-3137779781
  dontWrapQtApps = stdenv.hostPlatform.isDarwin;

  # display a black screen on wayland, so force XWayland for now.
  # Might be fixed when upstream will be ready for Qt6.
  qtWrapperArgs = [
  qtWrapperArgs = lib.optionals stdenv.hostPlatform.isLinux [
    "--set QT_QPA_PLATFORM xcb"
  ];

@@ -123,6 +154,6 @@ stdenv.mkDerivation {
    homepage = "https://www.meshlab.net/";
    license = lib.licenses.gpl3Only;
    maintainers = with lib.maintainers; [ pca006132 ];
    platforms = with lib.platforms; linux;
    platforms = with lib.platforms; linux ++ darwin;
  };
}
+71 −21
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
  lib,
  stdenv,
  fetchFromGitHub,
  llvmPackages,
  libsForQt5,
  libGLU,
  lib3ds,
@@ -30,21 +31,47 @@ let
  tinygltf-src = fetchFromGitHub {
    owner = "syoyo";
    repo = "tinygltf";
    rev = "v2.6.3";
    tag = "v2.6.3";
    hash = "sha256-IyezvHzgLRyc3z8HdNsQMqDEhP+Ytw0stFNak3C8lTo=";
  };

  downloads = [
    "DLL_EMBREE"
    "SOURCE_BOOST"
    "SOURCE_CGAL"
    "SOURCE_EMBREE"
    "SOURCE_LEVMAR"
    "SOURCE_LIB3DS"
    "SOURCE_LIBE57"
    "SOURCE_LIBIGL"
    "SOURCE_MUPARSER"
    "SOURCE_NEXUS"
    "SOURCE_OPENCTM"
    "SOURCE_QHULL"
    "SOURCE_STRUCTURE_SYNTH"
    "SOURCE_TINYGLTF"
    "SOURCE_U3D"
    "SOURCE_XERCE"
  ];
  cmakeFlagsDisallowDownload = lib.map (x: "-DMESHLAB_ALLOW_DOWNLOAD_${x}=OFF") downloads;
in
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "meshlab";
  version = "2023.12";

  src = fetchFromGitHub {
    owner = "cnr-isti-vclab";
    repo = "meshlab";
    rev = "MeshLab-${version}";
    sha256 = "sha256-AdUAWS741RQclYaSE3Tz1/I0YSinNAnfSaqef+Tib8Y=";
    tag = "MeshLab-${finalAttrs.version}";
    hash = "sha256-AdUAWS741RQclYaSE3Tz1/I0YSinNAnfSaqef+Tib8Y=";
  };

  nativeBuildInputs = [
    cmake
    libsForQt5.wrapQtAppsHook
    vcg # templated library
  ];

  buildInputs = [
    libGLU
    libsForQt5.qtbase
@@ -64,20 +91,16 @@ stdenv.mkDerivation rec {
    xercesc
    tbb
    embree
    vcg
    libigl
    corto
    openctm
    structuresynth
  ]
  ++ lib.optionals stdenv.cc.isClang [
    llvmPackages.openmp
  ];

  nativeBuildInputs = [
    cmake
    libsForQt5.wrapQtAppsHook
  ];

  preConfigure = ''
    substituteAll ${./meshlab.desktop} resources/linux/meshlab.desktop
  postPatch = ''
    substituteInPlace src/external/tinygltf.cmake \
      --replace-fail '$'{MESHLAB_EXTERNAL_DOWNLOAD_DIR}/tinygltf-2.6.3 ${tinygltf-src}
    substituteInPlace src/external/libigl.cmake \
@@ -92,28 +115,55 @@ stdenv.mkDerivation rec {
      --replace-warn "MD5 ''${SSYNTH_MD5}" ""
    substituteInPlace src/common_gui/CMakeLists.txt \
      --replace-warn "MESHLAB_LIB_INSTALL_DIR" "CMAKE_INSTALL_LIBDIR"
  ''
  + lib.optionalString stdenv.hostPlatform.isLinux ''
    substituteAll ${./meshlab.desktop} resources/linux/meshlab.desktop
  ''
  + lib.optionalString stdenv.hostPlatform.isDarwin ''
    substituteInPlace src/meshlab/CMakeLists.txt \
      --replace-fail "set_additional_settings_info_plist(" "# set_additional_settings_info_plist(" \
      --replace-fail "	TARGET meshlab" "#	TARGET meshlab" \
      --replace-fail "	FILE \''${MESHLAB_BUILD_DISTRIB_DIR}/meshlab.app/Contents/Info.plist)" \
                     "#	FILE \''${MESHLAB_BUILD_DISTRIB_DIR}/meshlab.app/Contents/Info.plist)"
  '';

  cmakeFlags = [
    "-DVCGDIR=${vcg.src}"
  ];
  ]
  ++ cmakeFlagsDisallowDownload;

  postFixup = ''
    patchelf --add-needed $out/lib/meshlab/libmeshlab-common.so $out/bin/.meshlab-wrapped
  postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
    mkdir -p $out/{Applications,bin,lib}
    mv $out/meshlab.app $out/Applications/
    ln $out/Applications/meshlab.app/Contents/Frameworks/libmeshlab-common.dylib $out/lib/
    makeWrapper $out/{Applications/meshlab.app/Contents/MacOS,bin}/meshlab
  '';

  # The hook will wrap all the plugin binaries, make they are not a
  # valid plugin. So we have to wrap the main app manually.
  # See: https://github.com/NixOS/nixpkgs/pull/396295#issuecomment-3137779781
  dontWrapQtApps = stdenv.hostPlatform.isDarwin;

  # display a black screen on wayland, so force XWayland for now.
  # Might be fixed when upstream will be ready for Qt6.
  qtWrapperArgs = [
    "--set QT_QPA_PLATFORM xcb"
  ];
  qtWrapperArgs = lib.optional stdenv.hostPlatform.isLinux "--set QT_QPA_PLATFORM xcb";

  postFixup =
    lib.optionalString stdenv.hostPlatform.isLinux ''
      patchelf --add-needed $out/lib/meshlab/libmeshlab-common.so $out/bin/.meshlab-wrapped
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      wrapQtApp "$out/Applications/meshlab.app/Contents/MacOS/meshlab"
      install_name_tool -change libopenctm.dylib "${lib.getOutput "out" openctm}/lib/libopenctm.dylib" \
        "$out/Applications/meshlab.app/Contents/PlugIns/libio_ctm.so"
    '';

  meta = {
    description = "System for processing and editing 3D triangular meshes";
    mainProgram = "meshlab";
    homepage = "https://www.meshlab.net/";
    license = lib.licenses.gpl3Only;
    maintainers = [ ];
    platforms = with lib.platforms; linux;
    maintainers = with lib.maintainers; [ yzx9 ];
    platforms = with lib.platforms; linux ++ darwin;
  };
}
})
+10 −0
Original line number Diff line number Diff line
@@ -12196,6 +12196,16 @@ with pkgs;

  mercurialFull = mercurial.override { fullBuild = true; };

  meshlab = callPackage ../by-name/me/meshlab/package.nix {
    stdenv = if stdenv.hostPlatform.isDarwin then llvmPackages_18.stdenv else stdenv;
    llvmPackages = llvmPackages_18;
  };

  meshlab-unstable = callPackage ../by-name/me/meshlab-unstable/package.nix {
    stdenv = if stdenv.hostPlatform.isDarwin then llvmPackages_18.stdenv else stdenv;
    llvmPackages = llvmPackages_18;
  };

  meshcentral = callPackage ../tools/admin/meshcentral { };

  michabo = libsForQt5.callPackage ../applications/misc/michabo { };