fix: Use PkgConfig for WebP and WebM (#1400)

This commit is contained in:
Craig Andrews 2026-05-14 12:31:10 -04:00 committed by GitHub
parent 57ff2eb0f4
commit eeac950b44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -106,19 +106,28 @@ if(SD_WEBP)
"Or link against system library:\n cmake (...) -DSD_USE_SYSTEM_WEBP=ON") "Or link against system library:\n cmake (...) -DSD_USE_SYSTEM_WEBP=ON")
endif() endif()
if(SD_USE_SYSTEM_WEBP) if(SD_USE_SYSTEM_WEBP)
find_package(WebP REQUIRED) find_package(WebP)
add_library(webp ALIAS WebP::webp) if(WebP_FOUND)
# libwebp CMake target naming is not consistent across versions/distros. add_library(webp ALIAS WebP::webp)
# Some export WebP::libwebpmux, others export WebP::webpmux. # libwebp CMake target naming is not consistent across versions/distros.
if(TARGET WebP::libwebpmux) # Some export WebP::libwebpmux, others export WebP::webpmux.
add_library(libwebpmux ALIAS WebP::libwebpmux) if(TARGET WebP::libwebpmux)
elseif(TARGET WebP::webpmux) add_library(libwebpmux ALIAS WebP::libwebpmux)
add_library(libwebpmux ALIAS WebP::webpmux) elseif(TARGET WebP::webpmux)
add_library(libwebpmux ALIAS WebP::webpmux)
else()
message(FATAL_ERROR
"Could not find a compatible webpmux target in system WebP package. "
"Expected WebP::libwebpmux or WebP::webpmux."
)
endif()
else() else()
message(FATAL_ERROR find_package(PkgConfig REQUIRED)
"Could not find a compatible webpmux target in system WebP package. " pkg_check_modules(WebP REQUIRED IMPORTED_TARGET GLOBAL libwebp)
"Expected WebP::libwebpmux or WebP::webpmux." pkg_check_modules(WebPMux REQUIRED IMPORTED_TARGET GLOBAL libwebpmux)
) link_libraries(PkgConfig::WebP)
link_libraries(PkgConfig::WebPMux)
add_library(libwebpmux ALIAS PkgConfig::WebPMux)
endif() endif()
endif() endif()
endif() endif()
@ -133,18 +142,26 @@ if(SD_WEBM)
"Or link against system library:\n cmake (...) -DSD_USE_SYSTEM_WEBM=ON") "Or link against system library:\n cmake (...) -DSD_USE_SYSTEM_WEBM=ON")
endif() endif()
if(SD_USE_SYSTEM_WEBM) if(SD_USE_SYSTEM_WEBM)
find_path(WEBM_INCLUDE_DIR find_package(PkgConfig)
NAMES mkvmuxer/mkvmuxer.h mkvparser/mkvparser.h common/webmids.h if(PkgConfig_FOUND)
PATH_SUFFIXES webm pkg_check_modules(WebM REQUIRED IMPORTED_TARGET GLOBAL libwebm)
REQUIRED) endif()
find_library(WEBM_LIBRARY if(PkgConfig_FOUND AND WebM_FOUND)
NAMES webm libwebm link_libraries(PkgConfig::WebM)
REQUIRED) else()
find_path(WEBM_INCLUDE_DIR
NAMES mkvmuxer/mkvmuxer.h mkvparser/mkvparser.h common/webmids.h
PATH_SUFFIXES webm
REQUIRED)
find_library(WEBM_LIBRARY
NAMES webm libwebm
REQUIRED)
add_library(webm UNKNOWN IMPORTED) add_library(webm UNKNOWN IMPORTED)
set_target_properties(webm PROPERTIES set_target_properties(webm PROPERTIES
IMPORTED_LOCATION "${WEBM_LIBRARY}" IMPORTED_LOCATION "${WEBM_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${WEBM_INCLUDE_DIR}") INTERFACE_INCLUDE_DIRECTORIES "${WEBM_INCLUDE_DIR}")
endif()
endif() endif()
endif() endif()