From 020a3e4b425a6efdda28c0ebd08891d9178fe471 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 6 Dec 2024 03:30:28 -0800 Subject: [PATCH] Get ffmpeg library versions when pkg-config is unavailable --- cmake/FindFFmpeg.cmake | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake index 26ed4d2faf..190c2c56c1 100644 --- a/cmake/FindFFmpeg.cmake +++ b/cmake/FindFFmpeg.cmake @@ -80,8 +80,37 @@ macro(find_component _component _pkgconfig _library _header) ${PC_LIB${_component}_LIBRARY_DIRS} ) - set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number." FORCE) - set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS." FORCE) + if(DEFINED ${PC_${_component}_VERSION}) + set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING + "The ${_component} version number." FORCE) + else() + if(EXISTS "${${_component}_INCLUDE_DIRS}/${_pkgconfig}/version_major.h") + file(STRINGS "${${_component}_INCLUDE_DIRS}/${_pkgconfig}/version_major.h" majorver + REGEX "^#define[ \t]+LIB${_component}_VERSION_MAJOR[ \t]+[0-9]+$") + else() + file(STRINGS "${${_component}_INCLUDE_DIRS}/${_pkgconfig}/version.h" majorver + REGEX "^#define[ \t]+LIB${_component}_VERSION_MAJOR[ \t]+[0-9]+$") + endif() + file(STRINGS "${${_component}_INCLUDE_DIRS}/${_pkgconfig}/version.h" minorver + REGEX "^#define[ \t]+LIB${_component}_VERSION_MINOR[ \t]+[0-9]+$") + file(STRINGS "${${_component}_INCLUDE_DIRS}/${_pkgconfig}/version.h" microver + REGEX "^#define[ \t]+LIB${_component}_VERSION_MICRO[ \t]+[0-9]+$") + + string(REGEX REPLACE "^#define[ \t]+LIB${_component}_VERSION_MAJOR[ \t]+([0-9]+)$" "\\1" + majorver "${majorver}") + string(REGEX REPLACE "^#define[ \t]+LIB${_component}_VERSION_MINOR[ \t]+([0-9]+)$" "\\1" + minorver "${minorver}") + string(REGEX REPLACE "^#define[ \t]+LIB${_component}_VERSION_MICRO[ \t]+([0-9]+)$" "\\1" + microver "${microver}") + + set(${_component}_VERSION "${majorver}.${minorver}.${microver}" CACHE STRING + "The ${_component} version number." FORCE) + unset(microver) + unset(minorver) + unset(majorver) + endif() + set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING + "The ${_component} CFLAGS." FORCE) set_component_found(${_component})