summary refs log tree commit diff
path: root/pkgs/applications/science
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2023-01-06 15:11:47 -0500
committerBen Gamari <ben@smart-cactus.org>2023-01-09 19:01:02 -0500
commit34dd176116870d24d6a5b93e263e79edad06fd00 (patch)
tree668d50eb66bde4b271fff9b1040747d53c0f3a79 /pkgs/applications/science
parent4ed69ca0957e29c40bcabb6f55c634b590b3a669 (diff)
downloadnixpkgs-34dd176116870d24d6a5b93e263e79edad06fd00.tar
nixpkgs-34dd176116870d24d6a5b93e263e79edad06fd00.tar.gz
nixpkgs-34dd176116870d24d6a5b93e263e79edad06fd00.tar.bz2
nixpkgs-34dd176116870d24d6a5b93e263e79edad06fd00.tar.lz
nixpkgs-34dd176116870d24d6a5b93e263e79edad06fd00.tar.xz
nixpkgs-34dd176116870d24d6a5b93e263e79edad06fd00.tar.zst
nixpkgs-34dd176116870d24d6a5b93e263e79edad06fd00.zip
gmsh: enable python bindings
Diffstat (limited to 'pkgs/applications/science')
-rw-r--r--pkgs/applications/science/math/gmsh/default.nix18
-rw-r--r--pkgs/applications/science/math/gmsh/fix-python.patch50
2 files changed, 66 insertions, 2 deletions
diff --git a/pkgs/applications/science/math/gmsh/default.nix b/pkgs/applications/science/math/gmsh/default.nix
index 3153c128057..4d9b3afe31c 100644
--- a/pkgs/applications/science/math/gmsh/default.nix
+++ b/pkgs/applications/science/math/gmsh/default.nix
@@ -1,7 +1,9 @@
 { lib, stdenv, fetchurl, cmake, blas, lapack, gfortran, gmm, fltk, libjpeg
-, zlib, libGL, libGLU, xorg, opencascade-occt }:
+, zlib, libGL, libGLU, xorg, opencascade-occt
+, python ? null, enablePython ? false }:
 
 assert (!blas.isILP64) && (!lapack.isILP64);
+assert enablePython -> (python != null);
 
 stdenv.mkDerivation rec {
   pname = "gmsh";
@@ -18,10 +20,16 @@ stdenv.mkDerivation rec {
     libGL libGLU xorg.libXrender xorg.libXcursor xorg.libXfixes
     xorg.libXext xorg.libXft xorg.libXinerama xorg.libX11 xorg.libSM
     xorg.libICE
-  ];
+  ] ++ lib.optional enablePython python;
 
   enableParallelBuilding = true;
 
+  patches = [ ./fix-python.patch ];
+
+  postPatch = ''
+    substituteInPlace api/gmsh.py --subst-var-by LIBPATH ${placeholder "out"}/lib/libgmsh.so
+  '';
+
   # N.B. the shared object is used by bindings
   cmakeFlags = [
     "-DENABLE_BUILD_SHARED=ON"
@@ -31,6 +39,12 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ cmake gfortran ];
 
+  postFixup = lib.optionalString enablePython ''
+    mkdir -p $out/lib/python${python.pythonVersion}/site-packages
+    mv $out/lib/gmsh.py $out/lib/python${python.pythonVersion}/site-packages
+    mv $out/lib/*.dist-info $out/lib/python${python.pythonVersion}/site-packages
+  '';
+
   doCheck = true;
 
   meta = {
diff --git a/pkgs/applications/science/math/gmsh/fix-python.patch b/pkgs/applications/science/math/gmsh/fix-python.patch
new file mode 100644
index 00000000000..ac07c169c99
--- /dev/null
+++ b/pkgs/applications/science/math/gmsh/fix-python.patch
@@ -0,0 +1,50 @@
+diff --git a/api/gmsh.py b/api/gmsh.py
+index 747acb203..02004da5d 100644
+--- a/api/gmsh.py
++++ b/api/gmsh.py
+@@ -44,44 +44,7 @@ moduledir = os.path.dirname(os.path.realpath(__file__))
+ parentdir1 = os.path.dirname(moduledir)
+ parentdir2 = os.path.dirname(parentdir1)
+ 
+-if platform.system() == "Windows":
+-    libname = "gmsh-4.11.dll"
+-elif platform.system() == "Darwin":
+-    libname = "libgmsh.4.11.dylib"
+-else:
+-    libname = "libgmsh.so.4.11"
+-
+-# check if the library is in the same directory as the module...
+-libpath = os.path.join(moduledir, libname)
+-
+-# ... or in the parent directory or its lib or Lib subdirectory
+-if not os.path.exists(libpath):
+-    libpath = os.path.join(parentdir1, libname)
+-if not os.path.exists(libpath):
+-    libpath = os.path.join(parentdir1, "lib", libname)
+-if not os.path.exists(libpath):
+-    libpath = os.path.join(parentdir1, "Lib", libname)
+-
+-# ... or in the parent of the parent directory or its lib or Lib subdirectory
+-if not os.path.exists(libpath):
+-    libpath = os.path.join(parentdir2, libname)
+-if not os.path.exists(libpath):
+-    libpath = os.path.join(parentdir2, "lib", libname)
+-if not os.path.exists(libpath):
+-    libpath = os.path.join(parentdir2, "Lib", libname)
+-
+-# if we couldn't find it, use ctype's find_library utility...
+-if not os.path.exists(libpath):
+-    if platform.system() == "Windows":
+-        libpath = find_library("gmsh-4.11")
+-        if not libpath:
+-            libpath = find_library("gmsh")
+-    else:
+-        libpath = find_library("gmsh")
+-
+-# ... and print a warning if everything failed
+-if not os.path.exists(libpath):
+-    print("Warning: could not find Gmsh shared library " + libname)
++libpath = "@LIBPATH@"
+ 
+ lib = CDLL(libpath)
+