Skip to content

fix: Use PkgConfig for WebP and WebM#1400

Open
candrews wants to merge 2 commits intoleejet:masterfrom
candrews:patch-1
Open

fix: Use PkgConfig for WebP and WebM#1400
candrews wants to merge 2 commits intoleejet:masterfrom
candrews:patch-1

Conversation

@candrews
Copy link
Copy Markdown

@candrews candrews commented Apr 7, 2026

PkgConfig is the standard approach to locating and using system libraries. It does not rely on the library having been built with CMake, improving compatibility.

webpmux is the library name; it should not be prefixed with lib. See: webmproject/libwebp@bfad7ab

Closes: #1399

Copy link
Copy Markdown
Contributor

@wbruna wbruna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we shouldn't assume pkg-config will always be available, e.g. on Windows. I believe it would be best to call pkg_check_modules as a fallback, in case the CMake module isn't found.

PkgConfig is the standard approach to locating and using system libraries. It does not rely on the library having been built with CMake, improving compatibility.

webpmux is the library name; it should not be prefixed with lib.
See: webmproject/libwebp@bfad7ab

Closes: leejet#1399
@candrews
Copy link
Copy Markdown
Author

candrews commented Apr 8, 2026

Pretty sure we shouldn't assume pkg-config will always be available, e.g. on Windows. I believe it would be best to call pkg_check_modules as a fallback, in case the CMake module isn't found.

That's a good point. I've done as you suggested, only use PkgConfig if it's available.

@candrews candrews requested a review from wbruna April 8, 2026 03:05
@leejet
Copy link
Copy Markdown
Owner

leejet commented Apr 8, 2026

This change appears to have broken CI (link error with -lwebpmux). Please fix the build regression first.

Also, I think there are two issues in the current implementation:

  1. Fallback logic is still incorrect
    The code only falls back when find_package(PkgConfig) is not found. However, a much more common failure case is when pkg-config exists but the required .pc files are missing or mismatched.
    Using pkg_check_modules(... REQUIRED ...) will fail configuration immediately in that case, so the fallback path is never reached.

  2. Missing libwebpmux in pkg-config path
    The pkg-config branch only resolves libwebp, but webpmux is a separate module upstream (libwebpmux.pc).
    So PkgConfig::WebP may only provide -lwebp, while the examples still require webpmux to be resolved and linked separately.

@candrews
Copy link
Copy Markdown
Author

candrews commented Apr 9, 2026

This change appears to have broken CI (link error with -lwebpmux). Please fix the build regression first.

Done! I added an alias so libwebpmux and webpmux both work in all cases. I undid the modifications to examples/{cli,server}.

Also, I think there are two issues in the current implementation:

1. **Fallback logic is still incorrect**
   The code only falls back when `find_package(PkgConfig)` is not found. However, a much more common failure case is when `pkg-config` exists but the required `.pc` files are missing or mismatched.
   Using `pkg_check_modules(... REQUIRED ...)` will fail configuration immediately in that case, so the fallback path is never reached.

I've addressed that by trying the CMake approach first, then the PkgConfig approach. I also used cmake_pkg_config to eliminate the use of the PkgConfig executable and simplify the logic.

2. **Missing `libwebpmux` in pkg-config path**
   The pkg-config branch only resolves `libwebp`, but `webpmux` is a separate module upstream (`libwebpmux.pc`).
   So `PkgConfig::WebP` may only provide `-lwebp`, while the examples still require `webpmux` to be resolved and linked separately.

I added webpmux. This wasn't necessary on my system, but it makes sense to have it, and it still works.

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 4.1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMake 4.1 seems to be younger than a year; this would exclude most current Linux distros (e.g. Debian Stable has 3.31.6).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't require cmake files when using system webp and webm, use PkgConfig instead

3 participants