1 { majorVersion, minorVersion, sourceSha256, patchesToFetch ? [] }:
2 { stdenv, lib, fetchurl, cmake, libGLU, libGL, libX11, xorgproto, libXt, libpng, libtiff
4 , enableQt ? false, qtx11extras, qttools, qtdeclarative, qtEnv
5 , enablePython ? false, python ? throw "vtk: Python support requested, but no python interpreter was given."
7 , AGL, Cocoa, CoreServices, DiskArbitration, IOKit, CFNetwork, Security, GLUT, OpenGL
8 , ApplicationServices, CoreText, IOSurface, ImageIO, xpc, libobjc
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"}";
22 url = "https://www.vtk.org/files/release/${majorVersion}/VTK-${version}.tar.gz";
23 sha256 = sourceSha256;
26 nativeBuildInputs = [ cmake ];
28 buildInputs = [ libpng libtiff ]
29 ++ optionals enableQt [ (qtEnv "qvtk-qt-env" [ qtx11extras qttools qtdeclarative ]) ]
30 ++ optionals stdenv.isLinux [
34 ] ++ optionals stdenv.isDarwin [
49 ] ++ optionals enablePython [
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
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"
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"
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}"
86 env = lib.optionalAttrs stdenv.cc.isClang {
87 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
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
96 postInstall = optionalString enablePython ''
99 $out/${python.sitePackages}/vtk-${version}.egg-info \
100 --subst-var-by VTK_VER "${version}"
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;