| 1 |
# vim: ts=2 sw=2 |
| 2 |
# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC) |
| 3 |
# |
| 4 |
# Once done this will define |
| 5 |
# FFMPEG_FOUND - System has the all required components. |
| 6 |
# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers. |
| 7 |
# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components. |
| 8 |
# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components. |
| 9 |
# |
| 10 |
# For each of the components |
| 11 |
# - AVCODEC |
| 12 |
# - AVDEVICE |
| 13 |
# - AVFORMAT |
| 14 |
# - AVUTIL |
| 15 |
# - POSTPROCESS |
| 16 |
# - SWSCALE |
| 17 |
# the following variables will be defined: |
| 18 |
# <component>_FOUND - System has <component> |
| 19 |
# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers |
| 20 |
# <component>_LIBRARIES - Link these to use <component> |
| 21 |
# <component>_DEFINITIONS - Compiler switches required for using <component> |
| 22 |
# <component>_VERSION - The components version |
| 23 |
# |
| 24 |
# As the versions of the various FFmpeg components differ for a given release, |
| 25 |
# and CMake supports only one common version for all components, use the |
| 26 |
# following to specify required versions for multiple components: |
| 27 |
# |
| 28 |
# find_package(FFmpeg 57.48 COMPONENTS AVCODEC) |
| 29 |
# find_package(FFmpeg 57.40 COMPONENTS AVFORMAT) |
| 30 |
# find_package(FFmpeg 55.27 COMPONENTS AVUTIL) |
| 31 |
# |
| 32 |
# SPDX-FileCopyrightText: 2006 Matthias Kretz <[email protected]> |
| 33 |
# SPDX-FileCopyrightText: 2008 Alexander Neundorf <[email protected]> |
| 34 |
# SPDX-FileCopyrightText: 2011 Michael Jansen <[email protected]> |
| 35 |
# SPDX-FileCopyrightText: 2021 Stefan BrĂ¼ns <[email protected]> |
| 36 |
# SPDX-License-Identifier: BSD-3-Clause |
| 37 |
|
| 38 |
include(FindPackageHandleStandardArgs) |
| 39 |
|
| 40 |
if (NOT FFmpeg_FIND_COMPONENTS) |
| 41 |
# The default components were taken from a survey over other FindFFMPEG.cmake files |
| 42 |
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) |
| 43 |
endif () |
| 44 |
|
| 45 |
list(LENGTH FFmpeg_FIND_COMPONENTS _numComponents) |
| 46 |
if ((${_numComponents} GREATER 1) AND DEFINED ${FFmpeg_FIND_VERSION}) |
| 47 |
message(WARNING "Using a required version in combination with multiple COMPONENTS is not supported") |
| 48 |
set(_FFmpeg_REQUIRED_VERSION 0) |
| 49 |
elseif (DEFINED FFmpeg_FIND_VERSION) |
| 50 |
set(_FFmpeg_REQUIRED_VERSION ${FFmpeg_FIND_VERSION}) |
| 51 |
else () |
| 52 |
set(_FFmpeg_REQUIRED_VERSION 0) |
| 53 |
endif () |
| 54 |
set(_FFmpeg_ALL_COMPONENTS AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) |
| 55 |
|
| 56 |
# |
| 57 |
### Macro: set_component_found |
| 58 |
# |
| 59 |
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present. |
| 60 |
# |
| 61 |
macro(set_component_found _component ) |
| 62 |
if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) |
| 63 |
set(${_component}_FOUND TRUE) |
| 64 |
set(FFmpeg_${_component}_FOUND TRUE) |
| 65 |
endif () |
| 66 |
endmacro() |
| 67 |
|
| 68 |
# |
| 69 |
### Macro: find_component |
| 70 |
# |
| 71 |
# Checks for the given component by invoking pkgconfig and then looking up the libraries and |
| 72 |
# include directories. |
| 73 |
# |
| 74 |
macro(find_component _component _pkgconfig _library _header) |
| 75 |
|
| 76 |
if (NOT WIN32) |
| 77 |
# use pkg-config to get the directories and then use these values |
| 78 |
# in the FIND_PATH() and FIND_LIBRARY() calls |
| 79 |
find_package(PkgConfig) |
| 80 |
if (PKG_CONFIG_FOUND) |
| 81 |
pkg_check_modules(PC_${_component} QUIET ${_pkgconfig}) |
| 82 |
endif () |
| 83 |
endif (NOT WIN32) |
| 84 |
|
| 85 |
find_path(${_component}_INCLUDE_DIRS ${_header} |
| 86 |
HINTS |
| 87 |
${PC_LIB${_component}_INCLUDEDIR} |
| 88 |
${PC_LIB${_component}_INCLUDE_DIRS} |
| 89 |
PATH_SUFFIXES |
| 90 |
ffmpeg |
| 91 |
) |
| 92 |
|
| 93 |
find_library(${_component}_LIBRARIES NAMES ${_library} |
| 94 |
HINTS |
| 95 |
${PC_LIB${_component}_LIBDIR} |
| 96 |
${PC_LIB${_component}_LIBRARY_DIRS} |
| 97 |
) |
| 98 |
|
| 99 |
set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.") |
| 100 |
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.") |
| 101 |
|
| 102 |
set_component_found(${_component}) |
| 103 |
|
| 104 |
mark_as_advanced( |
| 105 |
${_component}_INCLUDE_DIRS |
| 106 |
${_component}_LIBRARIES |
| 107 |
${_component}_DEFINITIONS |
| 108 |
${_component}_VERSION) |
| 109 |
|
| 110 |
endmacro() |
| 111 |
|
| 112 |
# Check for cached results. If there are skip the costly part. |
| 113 |
if (NOT FFMPEG_LIBRARIES) |
| 114 |
|
| 115 |
# Check for all possible component. |
| 116 |
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) |
| 117 |
find_component(AVFORMAT libavformat avformat libavformat/avformat.h) |
| 118 |
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) |
| 119 |
find_component(AVUTIL libavutil avutil libavutil/avutil.h) |
| 120 |
find_component(SWSCALE libswscale swscale libswscale/swscale.h) |
| 121 |
find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h) |
| 122 |
|
| 123 |
# Check if the required components were found and add their stuff to the FFMPEG_* vars. |
| 124 |
foreach (_component ${_FFmpeg_ALL_COMPONENTS}) |
| 125 |
if (${_component}_FOUND) |
| 126 |
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES}) |
| 127 |
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS}) |
| 128 |
list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS}) |
| 129 |
endif () |
| 130 |
endforeach () |
| 131 |
|
| 132 |
# Build the include path with duplicates removed. |
| 133 |
if (FFMPEG_INCLUDE_DIRS) |
| 134 |
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) |
| 135 |
endif () |
| 136 |
|
| 137 |
# cache the vars. |
| 138 |
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE) |
| 139 |
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE) |
| 140 |
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE) |
| 141 |
|
| 142 |
mark_as_advanced(FFMPEG_INCLUDE_DIRS |
| 143 |
FFMPEG_LIBRARIES |
| 144 |
FFMPEG_DEFINITIONS) |
| 145 |
|
| 146 |
else () |
| 147 |
# Set the noncached _FOUND vars for the components. |
| 148 |
foreach (_component ${_FFmpeg_ALL_COMPONENTS}) |
| 149 |
set_component_found(${_component}) |
| 150 |
endforeach () |
| 151 |
endif () |
| 152 |
|
| 153 |
# Compile the list of required vars |
| 154 |
unset(_FFmpeg_REQUIRED_VARS) |
| 155 |
set(_FFmpeg_FOUND_LIBRARIES "") |
| 156 |
foreach (_component ${FFmpeg_FIND_COMPONENTS}) |
| 157 |
if (${_component}_FOUND) |
| 158 |
if (${_component}_VERSION VERSION_LESS _FFmpeg_REQUIRED_VERSION) |
| 159 |
message(STATUS "${_component}: ${${_component}_VERSION} < ${_FFmpeg_REQUIRED_VERSION}") |
| 160 |
unset(${_component}_FOUND) |
| 161 |
endif () |
| 162 |
list(APPEND _FFmpeg_FOUND_LIBRARIES ${${_component}_LIBRARIES}) |
| 163 |
endif () |
| 164 |
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS ${_component}_FOUND) |
| 165 |
endforeach () |
| 166 |
list(INSERT _FFmpeg_REQUIRED_VARS 0 _FFmpeg_FOUND_LIBRARIES) |
| 167 |
|
| 168 |
# Give a nice error message if some of the required vars are missing. |
| 169 |
find_package_handle_standard_args(FFmpeg |
| 170 |
REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS} |
| 171 |
HANDLE_COMPONENTS) |