Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ majorVersion, minorVersion, sourceSha256, patchesToFetch ? [] }: 2{ stdenv, lib, fetchurl, cmake, libGLU, libGL, libX11, xorgproto, libXt, libpng, libtiff 3, fetchpatch 4, enableQt ? false, qtbase, 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}: 10 11let 12 inherit (lib) optionalString optionals optional; 13 14 pythonMajor = lib.substring 0 1 python.pythonVersion; 15 16in stdenv.mkDerivation rec { 17 pname = "vtk${optionalString enableQt "-qvtk"}"; 18 version = "${majorVersion}.${minorVersion}"; 19 20 src = fetchurl { 21 url = "https://www.vtk.org/files/release/${majorVersion}/VTK-${version}.tar.gz"; 22 sha256 = sourceSha256; 23 }; 24 25 nativeBuildInputs = [ cmake ]; 26 27 buildInputs = [ libpng libtiff ] 28 ++ optionals enableQt (if lib.versionOlder majorVersion "9" 29 then [ qtbase qtx11extras qttools ] 30 else [ (qtEnv "qvtk-qt-env" [ qtx11extras qttools qtdeclarative ]) ]) 31 ++ optionals stdenv.isLinux [ 32 libGLU 33 xorgproto 34 libXt 35 ] ++ optionals stdenv.isDarwin [ 36 xpc 37 AGL 38 Cocoa 39 CoreServices 40 DiskArbitration 41 IOKit 42 CFNetwork 43 Security 44 ApplicationServices 45 CoreText 46 IOSurface 47 ImageIO 48 OpenGL 49 GLUT 50 ] ++ optionals enablePython [ 51 python 52 ]; 53 propagatedBuildInputs = optionals stdenv.isDarwin [ libobjc ] 54 ++ optionals stdenv.isLinux [ libX11 libGL ]; 55 # see https://github.com/NixOS/nixpkgs/pull/178367#issuecomment-1238827254 56 57 patches = map fetchpatch patchesToFetch; 58 59 dontWrapQtApps = true; 60 61 # Shared libraries don't work, because of rpath troubles with the current 62 # nixpkgs cmake approach. It wants to call a binary at build time, just 63 # built and requiring one of the shared objects. 64 # At least, we use -fPIC for other packages to be able to use this in shared 65 # objects. 66 cmakeFlags = [ 67 "-DCMAKE_C_FLAGS=-fPIC" 68 "-DCMAKE_CXX_FLAGS=-fPIC" 69 "-D${if lib.versionOlder version "9.0" then "VTK_USE_SYSTEM_PNG" else "VTK_MODULE_USE_EXTERNAL_vtkpng"}=ON" 70 "-D${if lib.versionOlder version "9.0" then "VTK_USE_SYSTEM_TIFF" else "VTK_MODULE_USE_EXTERNAL_vtktiff"}=1" 71 ] ++ lib.optionals (!stdenv.isDarwin) [ 72 "-DOPENGL_INCLUDE_DIR=${libGL}/include" 73 ] ++ [ 74 "-DCMAKE_INSTALL_LIBDIR=lib" 75 "-DCMAKE_INSTALL_INCLUDEDIR=include" 76 "-DCMAKE_INSTALL_BINDIR=bin" 77 "-DVTK_VERSIONED_INSTALL=OFF" 78 ] ++ optionals enableQt [ 79 "-D${if lib.versionOlder version "9.0" then "VTK_Group_Qt:BOOL=ON" else "VTK_GROUP_ENABLE_Qt:STRING=YES"}" 80 ] ++ optionals (enableQt && lib.versionOlder version "8.0") [ 81 "-DVTK_QT_VERSION=5" 82 ] 83 ++ optionals stdenv.isDarwin [ "-DOPENGL_INCLUDE_DIR=${OpenGL}/Library/Frameworks" ] 84 ++ optionals enablePython [ 85 "-DVTK_WRAP_PYTHON:BOOL=ON" 86 "-DVTK_PYTHON_VERSION:STRING=${pythonMajor}" 87 ]; 88 89 postPatch = optionalString stdenv.isDarwin '' 90 sed -i 's|COMMAND vtkHashSource|COMMAND "DYLD_LIBRARY_PATH=''${VTK_BINARY_DIR}/lib" ''${VTK_BINARY_DIR}/bin/vtkHashSource-${majorVersion}|' ./Parallel/Core/CMakeLists.txt 91 sed -i 's/fprintf(output, shift)/fprintf(output, "%s", shift)/' ./ThirdParty/libxml2/vtklibxml2/xmlschemas.c 92 sed -i 's/fprintf(output, shift)/fprintf(output, "%s", shift)/g' ./ThirdParty/libxml2/vtklibxml2/xpath.c 93 ''; 94 95 postInstall = optionalString enablePython '' 96 substitute \ 97 ${./vtk.egg-info} \ 98 $out/${python.sitePackages}/vtk-${version}.egg-info \ 99 --subst-var-by VTK_VER "${version}" 100 ''; 101 102 meta = with lib; { 103 description = "Open source libraries for 3D computer graphics, image processing and visualization"; 104 homepage = "https://www.vtk.org/"; 105 license = licenses.bsd3; 106 maintainers = with maintainers; [ knedlsepp tfmoraes lheckemann ]; 107 platforms = with platforms; unix; 108 # /nix/store/xxxxxxx-apple-framework-Security/Library/Frameworks/Security.framework/Headers/Authorization.h:192:7: error: variably modified 'bytes' at file scope 109 broken = stdenv.isDarwin && (lib.versions.major majorVersion == "8"); 110 }; 111}