Commit 50224aa6 authored by qbisi's avatar qbisi
Browse files

netgen: add support for darwin platform

parent 61cacc68
Loading
Loading
Loading
Loading
+31 −14
Original line number Diff line number Diff line
@@ -65,22 +65,25 @@ stdenv.mkDerivation (finalAttrs: {
      url = "${patchSource}/include_stdlib.patch";
      hash = "sha256-W+NgGBuy/UmzVbPTSqR8FRUlyN/9dl9l9e9rxKklmIc=";
    })
    (fetchpatch2 {
      url = "${patchSource}/fix-version.patch";
      hash = "sha256-CT98Wq3UufB81z/jYLiH9nXvt+QzoZ7210OeuFXCfmc=";
    })
  ];

  # when generating python stub file utilizing system python pybind11_stubgen module
  # cmake need to inherit pythonpath
  postPatch =
    ''
      sed -i '/-DBDIR=''\'''${CMAKE_CURRENT_BINARY_DIR}/a\
      -DNETGEN_VERSION_GIT=''\'''${NETGEN_VERSION_GIT}
      ' CMakeLists.txt

      substituteInPlace python/CMakeLists.txt \
        --replace-fail ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}' \
                       ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}:$ENV{PYTHONPATH}'

      substituteInPlace ng/ng.tcl ng/onetcl.cpp \
        --replace-fail "libnggui" "$out/lib/libnggui"

      substituteInPlace ng/Togl2.1/CMakeLists.txt \
        --replace-fail "/usr/bin/gcc" "$CC"
    ''
    + lib.optionalString (!stdenv.hostPlatform.isx86_64) ''
      # mesh generation differs on x86_64 and aarch64 platform
@@ -115,6 +118,12 @@ stdenv.mkDerivation (finalAttrs: {

  cmakeFlags = [
    (lib.cmakeFeature "NETGEN_VERSION_GIT" "v${finalAttrs.version}-0")
    (lib.cmakeFeature "NG_INSTALL_DIR_BIN" "bin")
    (lib.cmakeFeature "NG_INSTALL_DIR_LIB" "lib")
    (lib.cmakeFeature "NG_INSTALL_DIR_CMAKE" "lib/cmake/${finalAttrs.pname}")
    (lib.cmakeFeature "NG_INSTALL_DIR_PYTHON" python3Packages.python.sitePackages)
    (lib.cmakeFeature "NG_INSTALL_DIR_RES" "share")
    (lib.cmakeFeature "NG_INSTALL_DIR_INCLUDE" "include")
    (lib.cmakeFeature "CMAKE_CXX_FLAGS" archFlags)
    (lib.cmakeBool "USE_MPI" true)
    (lib.cmakeBool "USE_MPI4PY" true)
@@ -128,6 +137,17 @@ stdenv.mkDerivation (finalAttrs: {
    (lib.cmakeBool "ENABLE_UNIT_TESTS" finalAttrs.finalPackage.doInstallCheck)
  ];

  __darwinAllowLocalNetworking = true;

  postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
    rm $out/bin/{Netgen1,startup.sh}
    mkdir -p $out/Applications/${finalAttrs.pname}.app/Contents/{MacOS,Resouces}
    substituteInPlace $out/Info.plist --replace-fail "Netgen1" "netgen"
    mv $out/Info.plist $out/Applications/${finalAttrs.pname}.app/Contents
    mv $out/Netgen.icns $out/Applications/${finalAttrs.pname}.app/Contents/Resouces
    ln -s $out/bin/netgen $out/Applications/${finalAttrs.pname}.app/Contents/MacOS/netgen
  '';

  doInstallCheck = true;

  preInstallCheck = ''
@@ -163,10 +183,7 @@ stdenv.mkDerivation (finalAttrs: {
      boost
      publicDomain
    ];
    platforms = [
      "x86_64-linux"
      "aarch64-linux"
    ];
    platforms = lib.platforms.unix;
    mainProgram = "netgen";
    maintainers = with lib.maintainers; [ qbisi ];
  };