Skip to content

Commit

Permalink
libwebp: build with cmake (#335702)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaz authored Oct 6, 2024
2 parents 84fce7e + d7fda42 commit 1be025f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 58 deletions.
12 changes: 0 additions & 12 deletions pkgs/applications/networking/browsers/ladybird/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ stdenv.mkDerivation (finalAttrs: {
substituteInPlace Meta/CMake/lagom_install_options.cmake \
--replace-fail "\''${CMAKE_INSTALL_BINDIR}" "bin" \
--replace-fail "\''${CMAKE_INSTALL_LIBDIR}" "lib"
# libwebp is not built with cmake support yet
# https://github.com/NixOS/nixpkgs/issues/334148
cat > Meta/CMake/FindWebP.cmake <<'EOF'
find_package(PkgConfig)
pkg_check_modules(WEBP libwebp REQUIRED)
include_directories(''${WEBP_INCLUDE_DIRS})
link_directories(''${WEBP_LIBRARY_DIRS})
EOF
substituteInPlace Userland/Libraries/LibGfx/CMakeLists.txt \
--replace-fail 'WebP::' "" \
--replace-fail libwebpmux webpmux
'';

preConfigure = ''
Expand Down
107 changes: 61 additions & 46 deletions pkgs/development/libraries/libwebp/default.nix
Original file line number Diff line number Diff line change
@@ -1,67 +1,82 @@
{ lib, stdenv, fetchFromGitHub, autoreconfHook, libtool
, threadingSupport ? true # multi-threading
, openglSupport ? false, libglut, libGL, libGLU # OpenGL (required for vwebp)
, pngSupport ? true, libpng # PNG image format
, jpegSupport ? true, libjpeg # JPEG image format
, tiffSupport ? true, libtiff # TIFF image format
, gifSupport ? true, giflib # GIF image format
, alignedSupport ? false # Force aligned memory operations
, swap16bitcspSupport ? false # Byte swap for 16bit color spaces
, experimentalSupport ? false # Experimental code
, libwebpmuxSupport ? true # Build libwebpmux
, libwebpdemuxSupport ? true # Build libwebpdemux
, libwebpdecoderSupport ? true # Build libwebpdecoder
{
lib,
stdenv,
fetchFromGitHub,
cmake,
threadingSupport ? true, # multi-threading
openglSupport ? false,
libglut,
libGL,
libGLU, # OpenGL (required for vwebp)
pngSupport ? true,
libpng, # PNG image format
jpegSupport ? true,
libjpeg, # JPEG image format
tiffSupport ? true,
libtiff, # TIFF image format
gifSupport ? true,
giflib, # GIF image format
swap16bitcspSupport ? false, # Byte swap for 16bit color spaces
libwebpmuxSupport ? true, # Build libwebpmux

# for passthru.tests
, gd
, graphicsmagick
, haskellPackages
, imagemagick
, imlib2
, libjxl
, opencv
, python3
, vips
# for passthru.tests
gd,
graphicsmagick,
haskellPackages,
imagemagick,
imlib2,
libjxl,
opencv,
python3,
vips,
}:

stdenv.mkDerivation rec {
pname = "libwebp";
version = "1.4.0";

src = fetchFromGitHub {
owner = "webmproject";
repo = pname;
rev = "v${version}";
hash = "sha256-OR/VzKNn3mnwjf+G+RkEGAaaKrhVlAu1e2oTRwdsPj8=";
owner = "webmproject";
repo = "libwebp";
rev = "v${version}";
hash = "sha256-OR/VzKNn3mnwjf+G+RkEGAaaKrhVlAu1e2oTRwdsPj8=";
};

configureFlags = [
(lib.enableFeature threadingSupport "threading")
(lib.enableFeature openglSupport "gl")
(lib.enableFeature pngSupport "png")
(lib.enableFeature jpegSupport "jpeg")
(lib.enableFeature tiffSupport "tiff")
(lib.enableFeature gifSupport "gif")
(lib.enableFeature alignedSupport "aligned")
(lib.enableFeature swap16bitcspSupport "swap-16bit-csp")
(lib.enableFeature experimentalSupport "experimental")
(lib.enableFeature libwebpmuxSupport "libwebpmux")
(lib.enableFeature libwebpdemuxSupport "libwebpdemux")
(lib.enableFeature libwebpdecoderSupport "libwebpdecoder")
cmakeFlags = [
(lib.cmakeBool "BUILD_SHARED_LIBS" true)
(lib.cmakeBool "WEBP_USE_THREAD" threadingSupport)
(lib.cmakeBool "WEBP_BUILD_VWEBP" openglSupport)
(lib.cmakeBool "WEBP_BUILD_IMG2WEBP" (pngSupport || jpegSupport || tiffSupport))
(lib.cmakeBool "WEBP_BUILD_GIF2WEBP" gifSupport)
(lib.cmakeBool "WEBP_BUILD_ANIM_UTILS" false) # Not installed
(lib.cmakeBool "WEBP_BUILD_EXTRAS" false) # Not installed
(lib.cmakeBool "WEBP_ENABLE_SWAP_16BIT_CSP" swap16bitcspSupport)
(lib.cmakeBool "WEBP_BUILD_LIBWEBPMUX" libwebpmuxSupport)
];

nativeBuildInputs = [ autoreconfHook libtool ];
buildInputs = [ ]
++ lib.optionals openglSupport [ libglut libGL libGLU ]
nativeBuildInputs = [ cmake ];
buildInputs =
[ ]
++ lib.optionals openglSupport [
libglut
libGL
libGLU
]
++ lib.optionals pngSupport [ libpng ]
++ lib.optionals jpegSupport [ libjpeg ]
++ lib.optionals tiffSupport [ libtiff ]
++ lib.optionals gifSupport [ giflib ];

enableParallelBuilding = true;

passthru.tests = {
inherit gd graphicsmagick imagemagick imlib2 libjxl opencv vips;
inherit
gd
graphicsmagick
imagemagick
imlib2
libjxl
opencv
vips
;
inherit (python3.pkgs) pillow imread;
haskell-webp = haskellPackages.webp;
};
Expand Down

0 comments on commit 1be025f

Please sign in to comment.