1{
2 majorVersion,
3 minorVersion,
4 sourceSha256,
5 patchesToFetch ? [ ],
6}:
7{
8 stdenv,
9 lib,
10 fetchurl,
11 cmake,
12 libGLU,
13 libGL,
14 libX11,
15 xorgproto,
16 libXt,
17 libpng,
18 libtiff,
19 fetchpatch,
20 enableQt ? false,
21 qtx11extras,
22 qttools,
23 qtdeclarative,
24 qtEnv,
25 enablePython ? false,
26 python ? throw "vtk: Python support requested, but no python interpreter was given.",
27 enableEgl ? false,
28}:
29
30let
31 inherit (lib) optionalString optionals;
32
33 version = "${majorVersion}.${minorVersion}";
34 pythonMajor = lib.substring 0 1 python.pythonVersion;
35
36in
37stdenv.mkDerivation {
38 pname = "vtk" + optionalString enableEgl "-egl" + optionalString enableQt "-qvtk";
39 inherit version;
40
41 src = fetchurl {
42 url = "https://www.vtk.org/files/release/${majorVersion}/VTK-${version}.tar.gz";
43 sha256 = sourceSha256;
44 };
45
46 nativeBuildInputs = [ cmake ];
47
48 buildInputs =
49 [
50 libpng
51 libtiff
52 ]
53 ++ optionals enableQt [
54 (qtEnv "qvtk-qt-env" [
55 qtx11extras
56 qttools
57 qtdeclarative
58 ])
59 ]
60 ++ optionals stdenv.hostPlatform.isLinux [
61 libGLU
62 xorgproto
63 libXt
64 ]
65 ++ optionals enablePython [
66 python
67 ];
68 propagatedBuildInputs = optionals stdenv.hostPlatform.isLinux [
69 libX11
70 libGL
71 ];
72 # see https://github.com/NixOS/nixpkgs/pull/178367#issuecomment-1238827254
73
74 patches = map fetchpatch patchesToFetch;
75
76 # GCC 13: error: 'int64_t' in namespace 'std' does not name a type
77 postPatch =
78 ''
79 sed '1i#include <cstdint>' \
80 -i ThirdParty/libproj/vtklibproj/src/proj_json_streaming_writer.hpp \
81 -i IO/Image/vtkSEPReader.h
82 ''
83 + optionalString stdenv.hostPlatform.isDarwin ''
84 sed -i 's|COMMAND vtkHashSource|COMMAND "DYLD_LIBRARY_PATH=''${VTK_BINARY_DIR}/lib" ''${VTK_BINARY_DIR}/bin/vtkHashSource-${majorVersion}|' ./Parallel/Core/CMakeLists.txt
85 sed -i 's/fprintf(output, shift)/fprintf(output, "%s", shift)/' ./ThirdParty/libxml2/vtklibxml2/xmlschemas.c
86 sed -i 's/fprintf(output, shift)/fprintf(output, "%s", shift)/g' ./ThirdParty/libxml2/vtklibxml2/xpath.c
87 '';
88
89 dontWrapQtApps = true;
90
91 # Shared libraries don't work, because of rpath troubles with the current
92 # nixpkgs cmake approach. It wants to call a binary at build time, just
93 # built and requiring one of the shared objects.
94 # At least, we use -fPIC for other packages to be able to use this in shared
95 # objects.
96 cmakeFlags =
97 [
98 "-DCMAKE_C_FLAGS=-fPIC"
99 "-DCMAKE_CXX_FLAGS=-fPIC"
100 "-DVTK_MODULE_USE_EXTERNAL_vtkpng=ON"
101 "-DVTK_MODULE_USE_EXTERNAL_vtktiff=1"
102 "-DVTK_MODULE_ENABLE_VTK_RenderingExternal=YES"
103 ]
104 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
105 "-DOPENGL_INCLUDE_DIR=${lib.getInclude libGL}/include"
106 (lib.cmakeBool "VTK_OPENGL_HAS_EGL" enableEgl)
107 ]
108 ++ [
109 "-DCMAKE_INSTALL_LIBDIR=lib"
110 "-DCMAKE_INSTALL_INCLUDEDIR=include"
111 "-DCMAKE_INSTALL_BINDIR=bin"
112 "-DVTK_VERSIONED_INSTALL=OFF"
113 ]
114 ++ optionals enableQt [
115 "-DVTK_GROUP_ENABLE_Qt:STRING=YES"
116 ]
117 ++ optionals enablePython [
118 "-DVTK_WRAP_PYTHON:BOOL=ON"
119 "-DVTK_PYTHON_VERSION:STRING=${pythonMajor}"
120 ];
121
122 env = {
123 # Lots of warnings in vendored code…
124 NIX_CFLAGS_COMPILE =
125 if stdenv.cc.isClang then
126 "-Wno-error=incompatible-function-pointer-types"
127 else
128 "-Wno-error=incompatible-pointer-types";
129 };
130
131 postInstall = optionalString enablePython ''
132 substitute \
133 ${./vtk.egg-info} \
134 $out/${python.sitePackages}/vtk-${version}.egg-info \
135 --subst-var-by VTK_VER "${version}"
136 '';
137
138 meta = with lib; {
139 description = "Open source libraries for 3D computer graphics, image processing and visualization";
140 homepage = "https://www.vtk.org/";
141 license = licenses.bsd3;
142 maintainers = with maintainers; [
143 tfmoraes
144 ];
145 platforms = platforms.unix;
146 badPlatforms = optionals enableEgl platforms.darwin;
147 };
148}