about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/libfive/default.nix
blob: d789aafbcb4e400d281438aa5462fb264c032818 (plain) (blame)
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
{ lib
, stdenv
, wrapQtAppsHook
, fetchFromGitHub
, cmake
, ninja
, pkg-config
, eigen
, zlib
, libpng
, boost
, guile
, qtbase
, darwin
}:

stdenv.mkDerivation {
  pname = "libfive";
  version = "unstable-2023-06-07";

  src = fetchFromGitHub {
    owner = "libfive";
    repo = "libfive";
    rev = "c85ffe1ba1570c2551434c5bad731884aaf80598";
    hash = "sha256-OITy3fJx+Z6856V3D/KpSQRJztvOdJdqUv1c65wNgCc=";
  };

  nativeBuildInputs = [ wrapQtAppsHook cmake ninja pkg-config ];
  buildInputs = [ eigen zlib libpng boost guile qtbase ]
    ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk_11_0.frameworks.Cocoa ];

  preConfigure = ''
    substituteInPlace studio/src/guile/interpreter.cpp \
      --replace '"libfive/bind/guile"' \
                '"libfive/bind/guile:${placeholder "out"}/${guile.siteCcacheDir}"' \
      --replace '(app_resource_dir + ":" + finder_build_dir).toLocal8Bit()' \
                '"libfive/bind/guile:${placeholder "out"}/${guile.siteCcacheDir}"'

    substituteInPlace libfive/bind/guile/CMakeLists.txt \
      --replace "LIBFIVE_FRAMEWORK_DIR=$<TARGET_FILE_DIR:libfive>" \
                "LIBFIVE_FRAMEWORK_DIR=$out/lib" \
      --replace "LIBFIVE_STDLIB_DIR=$<TARGET_FILE_DIR:libfive-stdlib>" \
                "LIBFIVE_STDLIB_DIR=$out/lib"

    export XDG_CACHE_HOME=$(mktemp -d)/.cache
  '';

  cmakeFlags = [
    "-DGUILE_CCACHE_DIR=${placeholder "out"}/${guile.siteCcacheDir}"
  ] ++ lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "11") [
    # warning: 'aligned_alloc' is only available on macOS 10.15 or newer
    "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15"
  ];

  postInstall = lib.optionalString stdenv.isDarwin ''
    # No rules to install the mac app, so do it manually.
    mkdir -p $out/Applications
    cp -r studio/Studio.app $out/Applications/Studio.app

    install_name_tool -add_rpath $out/lib $out/Applications/Studio.app/Contents/MacOS/Studio

    makeWrapper $out/Applications/Studio.app/Contents/MacOS/Studio $out/bin/Studio
  '' + ''
    # Link "Studio" binary to "libfive-studio" to be more obvious:
    ln -s "$out/bin/Studio" "$out/bin/libfive-studio"
  '';

  meta = with lib; {
    description = "Infrastructure for solid modeling with F-Reps in C, C++, and Guile";
    homepage = "https://libfive.com/";
    maintainers = with maintainers; [ hodapp kovirobi ];
    license = with licenses; [ mpl20 gpl2Plus ];
    platforms = with platforms; all;
  };
}