at 23.11-beta 202 lines 4.9 kB view raw
1{ version, rev, sha256 }: 2 3{ stdenv 4, lib 5, fetchFromGitHub 6, cmake 7, pkg-config 8, zlib 9, libjpeg 10, libpng 11, fontconfig 12, freetype 13, libX11 14, libXext 15, libXinerama 16, libXfixes 17, libXcursor 18, libXft 19, libXrender 20, ApplicationServices 21, Carbon 22, Cocoa 23 24, withGL ? true 25, libGL 26, libGLU 27, glew 28, OpenGL 29 30, withCairo ? true 31, cairo 32 33, withPango ? (lib.strings.versionAtLeast version "1.4" && stdenv.hostPlatform.isLinux) 34, pango 35 36, withDocs ? true 37, doxygen 38, graphviz 39 40, withExamples ? (stdenv.buildPlatform == stdenv.hostPlatform) 41, withShared ? true 42}: 43 44let 45 onOff = value: if value then "ON" else "OFF"; 46in 47stdenv.mkDerivation rec { 48 pname = "fltk"; 49 inherit version; 50 51 src = fetchFromGitHub { 52 owner = "fltk"; 53 repo = "fltk"; 54 inherit rev sha256; 55 }; 56 57 outputs = [ "out" ] 58 ++ lib.optional withExamples "bin" 59 ++ lib.optional withDocs "doc"; 60 61 # Manually move example & test binaries to $bin to avoid cyclic dependencies on dev binaries 62 outputBin = lib.optionalString withExamples "out"; 63 64 patches = lib.optionals stdenv.hostPlatform.isDarwin [ 65 ./nsosv.patch 66 ]; 67 68 postPatch = '' 69 patchShebangs documentation/make_* 70 ''; 71 72 nativeBuildInputs = [ 73 cmake 74 pkg-config 75 ] ++ lib.optionals withDocs [ 76 doxygen 77 graphviz 78 ]; 79 80 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ 81 ApplicationServices 82 Carbon 83 ] ++ lib.optionals (withGL && !stdenv.hostPlatform.isDarwin) [ 84 libGL 85 libGLU 86 ] ++ lib.optionals (withExamples && withGL) [ 87 glew 88 ]; 89 90 propagatedBuildInputs = [ 91 zlib 92 libjpeg 93 libpng 94 ] ++ lib.optionals stdenv.hostPlatform.isLinux [ 95 freetype 96 fontconfig 97 libX11 98 libXext 99 libXinerama 100 libXfixes 101 libXcursor 102 libXft 103 libXrender 104 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ 105 Cocoa 106 ] ++ lib.optionals (withGL && stdenv.hostPlatform.isDarwin) [ 107 OpenGL 108 ] ++ lib.optionals withCairo [ 109 cairo 110 ] ++ lib.optionals withPango [ 111 pango 112 ]; 113 114 cmakeFlags = [ 115 # Common 116 "-DOPTION_BUILD_SHARED_LIBS=${onOff withShared}" 117 "-DOPTION_USE_SYSTEM_ZLIB=ON" 118 "-DOPTION_USE_SYSTEM_LIBJPEG=ON" 119 "-DOPTION_USE_SYSTEM_LIBPNG=ON" 120 121 # X11 122 "-DOPTION_USE_XINERAMA=${onOff stdenv.hostPlatform.isLinux}" 123 "-DOPTION_USE_XFIXES=${onOff stdenv.hostPlatform.isLinux}" 124 "-DOPTION_USE_XCURSOR=${onOff stdenv.hostPlatform.isLinux}" 125 "-DOPTION_USE_XFT=${onOff stdenv.hostPlatform.isLinux}" 126 "-DOPTION_USE_XRENDER=${onOff stdenv.hostPlatform.isLinux}" 127 "-DOPTION_USE_XDBE=${onOff stdenv.hostPlatform.isLinux}" 128 129 # GL 130 "-DOPTION_USE_GL=${onOff withGL}" 131 "-DOpenGL_GL_PREFERENCE=GLVND" 132 133 # Cairo 134 "-DOPTION_CAIRO=${onOff withCairo}" 135 "-DOPTION_CAIROEXT=${onOff withCairo}" 136 137 # Pango 138 "-DOPTION_USE_PANGO=${onOff withPango}" 139 140 # Examples & Tests 141 "-DFLTK_BUILD_EXAMPLES=${onOff withExamples}" 142 "-DFLTK_BUILD_TEST=${onOff withExamples}" 143 144 # Docs 145 "-DOPTION_BUILD_HTML_DOCUMENTATION=${onOff withDocs}" 146 "-DOPTION_BUILD_PDF_DOCUMENTATION=OFF" 147 "-DOPTION_INSTALL_HTML_DOCUMENTATION=${onOff withDocs}" 148 "-DOPTION_INSTALL_PDF_DOCUMENTATION=OFF" 149 "-DOPTION_INCLUDE_DRIVER_DOCUMENTATION=${onOff withDocs}" 150 151 # RPATH of binary /nix/store/.../bin/... contains a forbidden reference to /build/ 152 "-DCMAKE_SKIP_BUILD_RPATH=ON" 153 ]; 154 155 preBuild = lib.optionalString (withCairo && withShared && stdenv.hostPlatform.isDarwin) '' 156 # unresolved symbols in cairo dylib without this: https://github.com/fltk/fltk/issues/250 157 export NIX_LDFLAGS="$NIX_LDFLAGS -undefined dynamic_lookup" 158 ''; 159 160 postBuild = lib.optionalString withDocs '' 161 make docs 162 ''; 163 164 postInstall = lib.optionalString withExamples '' 165 mkdir -p $bin/bin 166 mv bin/{test,examples}/* $bin/bin/ 167 '' + lib.optionalString stdenv.hostPlatform.isDarwin '' 168 mkdir -p $out/Library/Frameworks 169 mv $out{,/Library/Frameworks}/FLTK.framework 170 171 moveAppBundles() { 172 echo "Moving and symlinking $1" 173 appname="$(basename "$1")" 174 binname="$(basename "$(find "$1"/Contents/MacOS/ -type f -executable | head -n1)")" 175 curpath="$(dirname "$1")" 176 177 mkdir -p "$curpath"/../Applications/ 178 mv "$1" "$curpath"/../Applications/ 179 [ -f "$curpath"/"$binname" ] && rm "$curpath"/"$binname" 180 ln -s ../Applications/"$appname"/Contents/MacOS/"$binname" "$curpath"/"$binname" 181 } 182 183 rm $out/bin/fluid.icns 184 for app in $out/bin/*.app ${lib.optionalString withExamples "$bin/bin/*.app"}; do 185 moveAppBundles "$app" 186 done 187 ''; 188 189 postFixup = '' 190 substituteInPlace $out/bin/fltk-config \ 191 --replace "/$out/" "/" 192 ''; 193 194 meta = with lib; { 195 description = "A C++ cross-platform lightweight GUI library"; 196 homepage = "https://www.fltk.org"; 197 platforms = platforms.unix; 198 # LGPL2 with static linking exception 199 # https://www.fltk.org/COPYING.php 200 license = licenses.lgpl2Only; 201 }; 202}