| 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 it will additionally set. |
| 11 |
# - AVCODEC |
| 12 |
# - AVDEVICE |
| 13 |
# - AVFORMAT |
| 14 |
# - AVFILTER |
| 15 |
# - AVUTIL |
| 16 |
# - POSTPROC |
| 17 |
# - SWSCALE |
| 18 |
# the following variables will be defined |
| 19 |
# <component>_FOUND - System has <component> |
| 20 |
# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers |
| 21 |
# <component>_LIBRARIES - Link these to use <component> |
| 22 |
# <component>_DEFINITIONS - Compiler switches required for using <component> |
| 23 |
# <component>_VERSION - The components version |
| 24 |
# |
| 25 |
# SPDX-FileCopyrightText: 2006 Matthias Kretz <[email protected]> |
| 26 |
# SPDX-FileCopyrightText: 2008 Alexander Neundorf <[email protected]> |
| 27 |
# SPDX-FileCopyrightText: 2011 Michael Jansen <[email protected]> |
| 28 |
# |
| 29 |
# SPDX-License-Identifier: BSD-3-Clause |
| 30 |
|
| 31 |
include(FindPackageHandleStandardArgs) |
| 32 |
|
| 33 |
# The default components were taken from a survey over other FindFFMPEG.cmake files |
| 34 |
if (NOT FFmpeg_FIND_COMPONENTS) |
| 35 |
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) |
| 36 |
endif () |
| 37 |
|
| 38 |
# |
| 39 |
### Macro: set_component_found |
| 40 |
# |
| 41 |
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present. |
| 42 |
# |
| 43 |
macro(set_component_found _component ) |
| 44 |
if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) |
| 45 |
# message(STATUS " - ${_component} found.") |
| 46 |
set(${_component}_FOUND TRUE) |
| 47 |
else () |
| 48 |
# message(STATUS " - ${_component} not found.") |
| 49 |
endif () |
| 50 |
endmacro() |
| 51 |
|
| 52 |
# |
| 53 |
### Macro: find_component |
| 54 |
# |
| 55 |
# Checks for the given component by invoking pkgconfig and then looking up the libraries and |
| 56 |
# include directories. |
| 57 |
# |
| 58 |
macro(find_component _component _pkgconfig _library _header) |
| 59 |
|
| 60 |
if (NOT WIN32) |
| 61 |
# use pkg-config to get the directories and then use these values |
| 62 |
# in the FIND_PATH() and FIND_LIBRARY() calls |
| 63 |
find_package(PkgConfig) |
| 64 |
if (PKG_CONFIG_FOUND) |
| 65 |
pkg_check_modules(PC_${_component} ${_pkgconfig}) |
| 66 |
endif () |
| 67 |
endif (NOT WIN32) |
| 68 |
|
| 69 |
find_path(${_component}_INCLUDE_DIRS ${_header} |
| 70 |
HINTS |
| 71 |
${PC_LIB${_component}_INCLUDEDIR} |
| 72 |
${PC_LIB${_component}_INCLUDE_DIRS} |
| 73 |
PATH_SUFFIXES |
| 74 |
ffmpeg |
| 75 |
) |
| 76 |
|
| 77 |
find_library(${_component}_LIBRARIES NAMES ${_library} |
| 78 |
HINTS |
| 79 |
${PC_LIB${_component}_LIBDIR} |
| 80 |
${PC_LIB${_component}_LIBRARY_DIRS} |
| 81 |
) |
| 82 |
|
| 83 |
set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.") |
| 84 |
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.") |
| 85 |
|
| 86 |
set_component_found(${_component}) |
| 87 |
|
| 88 |
mark_as_advanced( |
| 89 |
${_component}_INCLUDE_DIRS |
| 90 |
${_component}_LIBRARIES |
| 91 |
${_component}_DEFINITIONS |
| 92 |
${_component}_VERSION) |
| 93 |
|
| 94 |
endmacro() |
| 95 |
|
| 96 |
|
| 97 |
# Check for cached results. If there are skip the costly part. |
| 98 |
if (NOT FFMPEG_LIBRARIES) |
| 99 |
|
| 100 |
# Check for all possible component. |
| 101 |
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) |
| 102 |
find_component(AVFORMAT libavformat avformat libavformat/avformat.h) |
| 103 |
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) |
| 104 |
find_component(AVUTIL libavutil avutil libavutil/avutil.h) |
| 105 |
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h) |
| 106 |
find_component(SWSCALE libswscale swscale libswscale/swscale.h) |
| 107 |
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h) |
| 108 |
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h) |
| 109 |
|
| 110 |
# Check if the required components were found and add their stuff to the FFMPEG_* vars. |
| 111 |
foreach (_component ${FFmpeg_FIND_COMPONENTS}) |
| 112 |
if (${_component}_FOUND) |
| 113 |
# message(STATUS "Required component ${_component} present.") |
| 114 |
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES}) |
| 115 |
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS}) |
| 116 |
list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS}) |
| 117 |
else () |
| 118 |
# message(STATUS "Required component ${_component} missing.") |
| 119 |
endif () |
| 120 |
endforeach () |
| 121 |
|
| 122 |
# Build the include path with duplicates removed. |
| 123 |
if (FFMPEG_INCLUDE_DIRS) |
| 124 |
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) |
| 125 |
endif () |
| 126 |
|
| 127 |
# cache the vars. |
| 128 |
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE) |
| 129 |
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE) |
| 130 |
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE) |
| 131 |
|
| 132 |
mark_as_advanced(FFMPEG_INCLUDE_DIRS |
| 133 |
FFMPEG_LIBRARIES |
| 134 |
FFMPEG_DEFINITIONS) |
| 135 |
|
| 136 |
endif () |
| 137 |
|
| 138 |
# Now set the noncached _FOUND vars for the components. |
| 139 |
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) |
| 140 |
set_component_found(${_component}) |
| 141 |
endforeach () |
| 142 |
|
| 143 |
# Compile the list of required vars |
| 144 |
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) |
| 145 |
foreach (_component ${FFmpeg_FIND_COMPONENTS}) |
| 146 |
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) |
| 147 |
endforeach () |
| 148 |
|
| 149 |
# Give a nice error message if some of the required vars are missing. |
| 150 |
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) |