Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / libraries / vtk / generic.nix
blob02309b275bdcbce07253d0503f97c5423bd41ee0
1 { majorVersion, minorVersion, sourceSha256, patchesToFetch ? [] }:
2 { stdenv, lib, fetchurl, cmake, libGLU, libGL, libX11, xorgproto, libXt, libpng, libtiff
3 , fetchpatch
4 , enableQt ? false, qtx11extras, qttools, qtdeclarative, qtEnv
5 , enablePython ? false, python ? throw "vtk: Python support requested, but no python interpreter was given."
6 # Darwin support
7 , AGL, Cocoa, CoreServices, DiskArbitration, IOKit, CFNetwork, Security, GLUT, OpenGL
8 , ApplicationServices, CoreText, IOSurface, ImageIO, xpc, libobjc
9 }:
11 let
12   inherit (lib) optionalString optionals optional;
14   version = "${majorVersion}.${minorVersion}";
15   pythonMajor = lib.substring 0 1 python.pythonVersion;
17 in stdenv.mkDerivation {
18   pname = "vtk${optionalString enableQt "-qvtk"}";
19   inherit version;
21   src = fetchurl {
22     url = "https://www.vtk.org/files/release/${majorVersion}/VTK-${version}.tar.gz";
23     sha256 = sourceSha256;
24   };
26   nativeBuildInputs = [ cmake ];
28   buildInputs = [ libpng libtiff ]
29     ++ optionals enableQt [ (qtEnv "qvtk-qt-env" [ qtx11extras qttools qtdeclarative ]) ]
30     ++ optionals stdenv.isLinux [
31       libGLU
32       xorgproto
33       libXt
34     ] ++ optionals stdenv.isDarwin [
35       xpc
36       AGL
37       Cocoa
38       CoreServices
39       DiskArbitration
40       IOKit
41       CFNetwork
42       Security
43       ApplicationServices
44       CoreText
45       IOSurface
46       ImageIO
47       OpenGL
48       GLUT
49     ] ++ optionals enablePython [
50       python
51     ];
52   propagatedBuildInputs = optionals stdenv.isDarwin [ libobjc ]
53     ++ optionals stdenv.isLinux [ libX11 libGL ];
54     # see https://github.com/NixOS/nixpkgs/pull/178367#issuecomment-1238827254
56   patches = map fetchpatch patchesToFetch;
58   dontWrapQtApps = true;
60   # Shared libraries don't work, because of rpath troubles with the current
61   # nixpkgs cmake approach. It wants to call a binary at build time, just
62   # built and requiring one of the shared objects.
63   # At least, we use -fPIC for other packages to be able to use this in shared
64   # objects.
65   cmakeFlags = [
66     "-DCMAKE_C_FLAGS=-fPIC"
67     "-DCMAKE_CXX_FLAGS=-fPIC"
68     "-DVTK_MODULE_USE_EXTERNAL_vtkpng=ON"
69     "-DVTK_MODULE_USE_EXTERNAL_vtktiff=1"
70   ] ++ lib.optionals (!stdenv.isDarwin) [
71     "-DOPENGL_INCLUDE_DIR=${libGL}/include"
72   ] ++ [
73     "-DCMAKE_INSTALL_LIBDIR=lib"
74     "-DCMAKE_INSTALL_INCLUDEDIR=include"
75     "-DCMAKE_INSTALL_BINDIR=bin"
76     "-DVTK_VERSIONED_INSTALL=OFF"
77   ] ++ optionals enableQt [
78     "-DVTK_GROUP_ENABLE_Qt:STRING=YES"
79   ]
80     ++ optionals stdenv.isDarwin [ "-DOPENGL_INCLUDE_DIR=${OpenGL}/Library/Frameworks" ]
81     ++ optionals enablePython [
82       "-DVTK_WRAP_PYTHON:BOOL=ON"
83       "-DVTK_PYTHON_VERSION:STRING=${pythonMajor}"
84     ];
86   env = lib.optionalAttrs stdenv.cc.isClang {
87     NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
88   };
90   postPatch = optionalString stdenv.isDarwin ''
91     sed -i 's|COMMAND vtkHashSource|COMMAND "DYLD_LIBRARY_PATH=''${VTK_BINARY_DIR}/lib" ''${VTK_BINARY_DIR}/bin/vtkHashSource-${majorVersion}|' ./Parallel/Core/CMakeLists.txt
92     sed -i 's/fprintf(output, shift)/fprintf(output, "%s", shift)/' ./ThirdParty/libxml2/vtklibxml2/xmlschemas.c
93     sed -i 's/fprintf(output, shift)/fprintf(output, "%s", shift)/g' ./ThirdParty/libxml2/vtklibxml2/xpath.c
94   '';
96   postInstall = optionalString enablePython ''
97     substitute \
98       ${./vtk.egg-info} \
99       $out/${python.sitePackages}/vtk-${version}.egg-info \
100       --subst-var-by VTK_VER "${version}"
101   '';
103   meta = with lib; {
104     description = "Open source libraries for 3D computer graphics, image processing and visualization";
105     homepage = "https://www.vtk.org/";
106     license = licenses.bsd3;
107     maintainers = with maintainers; [ knedlsepp tfmoraes lheckemann ];
108     platforms = with platforms; unix;
109   };