|
| 1 | +#.rst: |
| 2 | +# FindFFmpeg |
| 3 | +# ---------- |
| 4 | +# |
| 5 | +# Try to find the required ffmpeg components (default: AVFORMAT, AVUTIL, AVCODEC) |
| 6 | +# |
| 7 | +# Next variables can be used to hint FFmpeg libs search: |
| 8 | +# |
| 9 | +# :: |
| 10 | +# |
| 11 | +# PC_<component>_LIBRARY_DIRS |
| 12 | +# PC_FFMPEG_LIBRARY_DIRS |
| 13 | +# PC_<component>_INCLUDE_DIRS |
| 14 | +# PC_FFMPEG_INCLUDE_DIRS |
| 15 | +# |
| 16 | +# Once done this will define |
| 17 | +# |
| 18 | +# :: |
| 19 | +# |
| 20 | +# FFMPEG_FOUND - System has the all required components. |
| 21 | +# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers. |
| 22 | +# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components. |
| 23 | +# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components. |
| 24 | +# |
| 25 | +# For each of the components it will additionally set. |
| 26 | +# |
| 27 | +# :: |
| 28 | +# |
| 29 | +# AVCODEC |
| 30 | +# AVDEVICE |
| 31 | +# AVFORMAT |
| 32 | +# AVFILTER |
| 33 | +# AVUTIL |
| 34 | +# POSTPROC |
| 35 | +# SWSCALE |
| 36 | +# |
| 37 | +# the following variables will be defined |
| 38 | +# |
| 39 | +# :: |
| 40 | +# |
| 41 | +# <component>_FOUND - System has <component> |
| 42 | +# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers |
| 43 | +# <component>_LIBRARIES - Link these to use <component> |
| 44 | +# <component>_DEFINITIONS - Compiler switches required for using <component> |
| 45 | +# <component>_VERSION - The components version |
| 46 | +# |
| 47 | +# the following import targets is created |
| 48 | +# |
| 49 | +# :: |
| 50 | +# |
| 51 | +# FFmpeg::FFmpeg - for all components |
| 52 | +# FFmpeg::<component> - where <component> in lower case (FFmpeg::avcodec) for each components |
| 53 | +# |
| 54 | +# Copyright (c) 2006, Matthias Kretz, <[email protected]> |
| 55 | +# Copyright (c) 2008, Alexander Neundorf, <[email protected]> |
| 56 | +# Copyright (c) 2011, Michael Jansen, <[email protected]> |
| 57 | +# Copyright (c) 2017, Alexander Drozdov, <[email protected]> |
| 58 | +# |
| 59 | +# Redistribution and use is allowed according to the terms of the BSD license. |
| 60 | +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 61 | + |
| 62 | +include(FindPackageHandleStandardArgs) |
| 63 | + |
| 64 | +# The default components were taken from a survey over other FindFFMPEG.cmake files |
| 65 | +if (NOT FFmpeg_FIND_COMPONENTS) |
| 66 | + set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) |
| 67 | +endif () |
| 68 | + |
| 69 | +# |
| 70 | +### Macro: set_component_found |
| 71 | +# |
| 72 | +# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present. |
| 73 | +# |
| 74 | +macro(set_component_found _component ) |
| 75 | + if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) |
| 76 | + # message(STATUS " - ${_component} found.") |
| 77 | + set(${_component}_FOUND TRUE) |
| 78 | + else () |
| 79 | + # message(STATUS " - ${_component} not found.") |
| 80 | + endif () |
| 81 | +endmacro() |
| 82 | + |
| 83 | +# |
| 84 | +### Macro: find_component |
| 85 | +# |
| 86 | +# Checks for the given component by invoking pkgconfig and then looking up the libraries and |
| 87 | +# include directories. |
| 88 | +# |
| 89 | +macro(find_component _component _pkgconfig _library _header) |
| 90 | + |
| 91 | + #if (NOT WIN32) |
| 92 | + # use pkg-config to get the directories and then use these values |
| 93 | + # in the FIND_PATH() and FIND_LIBRARY() calls |
| 94 | + find_package(PkgConfig) |
| 95 | + if (PKG_CONFIG_FOUND) |
| 96 | + pkg_check_modules(PC_${_component} REQUIRED ${_pkgconfig}) |
| 97 | + endif () |
| 98 | + #endif (NOT WIN32) |
| 99 | + |
| 100 | + find_path(${_component}_INCLUDE_DIRS ${_header} |
| 101 | + HINTS |
| 102 | + ${PC_${_component}_INCLUDEDIR} |
| 103 | + ${PC_${_component}_INCLUDE_DIRS} |
| 104 | + ${PC_FFMPEG_INCLUDE_DIRS} |
| 105 | + PATH_SUFFIXES |
| 106 | + ffmpeg |
| 107 | + ) |
| 108 | + |
| 109 | + find_library(${_component}_LIBRARIES NAMES ${PC_${_component}_LIBRARIES} ${_library} |
| 110 | + HINTS |
| 111 | + ${PC_${_component}_LIBDIR} |
| 112 | + ${PC_${_component}_LIBRARY_DIRS} |
| 113 | + ${PC_FFMPEG_LIBRARY_DIRS} |
| 114 | + ) |
| 115 | + |
| 116 | + #message(STATUS ${${_component}_LIBRARIES}) |
| 117 | + #message(STATUS ${PC_${_component}_LIBRARIES}) |
| 118 | + |
| 119 | + set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.") |
| 120 | + set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.") |
| 121 | + |
| 122 | + set_component_found(${_component}) |
| 123 | + |
| 124 | + mark_as_advanced( |
| 125 | + ${_component}_INCLUDE_DIRS |
| 126 | + ${_component}_LIBRARIES |
| 127 | + ${_component}_DEFINITIONS |
| 128 | + ${_component}_VERSION) |
| 129 | + |
| 130 | +endmacro() |
| 131 | + |
| 132 | + |
| 133 | +# Check for cached results. If there are skip the costly part. |
| 134 | +if (NOT FFMPEG_LIBRARIES) |
| 135 | + |
| 136 | + # Check for all possible component. |
| 137 | + find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) |
| 138 | + find_component(AVFORMAT libavformat avformat libavformat/avformat.h) |
| 139 | + find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) |
| 140 | + find_component(AVUTIL libavutil avutil libavutil/avutil.h) |
| 141 | + find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h) |
| 142 | + find_component(SWSCALE libswscale swscale libswscale/swscale.h) |
| 143 | + find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h) |
| 144 | + find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h) |
| 145 | + |
| 146 | + # Check if the required components were found and add their stuff to the FFMPEG_* vars. |
| 147 | + foreach (_component ${FFmpeg_FIND_COMPONENTS}) |
| 148 | + if (${_component}_FOUND) |
| 149 | + # message(STATUS "Required component ${_component} present.") |
| 150 | + set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES}) |
| 151 | + set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS}) |
| 152 | + list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS}) |
| 153 | + |
| 154 | + string(TOLOWER ${_component} _lowerComponent) |
| 155 | + if (NOT TARGET FFmpeg::${_lowerComponent}) |
| 156 | + add_library(FFmpeg::${_lowerComponent} INTERFACE IMPORTED) |
| 157 | + set_target_properties(FFmpeg::${_lowerComponent} PROPERTIES |
| 158 | + INTERFACE_COMPILE_OPTIONS "${${_component}_DEFINITIONS}" |
| 159 | + INTERFACE_INCLUDE_DIRECTORIES ${${_component}_INCLUDE_DIRS} |
| 160 | + INTERFACE_LINK_LIBRARIES "${${_component}_LIBRARIES}") |
| 161 | + endif() |
| 162 | + |
| 163 | + else () |
| 164 | + # message(STATUS "Required component ${_component} missing.") |
| 165 | + endif () |
| 166 | + endforeach () |
| 167 | + |
| 168 | + # Build the include path with duplicates removed. |
| 169 | + if (FFMPEG_INCLUDE_DIRS) |
| 170 | + list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) |
| 171 | + endif () |
| 172 | + |
| 173 | + # cache the vars. |
| 174 | + set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE) |
| 175 | + set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE) |
| 176 | + set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE) |
| 177 | + |
| 178 | + mark_as_advanced(FFMPEG_INCLUDE_DIRS |
| 179 | + FFMPEG_LIBRARIES |
| 180 | + FFMPEG_DEFINITIONS) |
| 181 | + |
| 182 | +endif () |
| 183 | + |
| 184 | +if (NOT TARGET FFmpeg::FFmpeg) |
| 185 | + add_library(FFmpeg::FFmpeg INTERFACE IMPORTED) |
| 186 | + set_target_properties(FFmpeg::FFmpeg PROPERTIES |
| 187 | + INTERFACE_COMPILE_OPTIONS "${FFMPEG_DEFINITIONS}" |
| 188 | + INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIRS} |
| 189 | + INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES}") |
| 190 | +endif() |
| 191 | + |
| 192 | +# Now set the noncached _FOUND vars for the components. |
| 193 | +foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) |
| 194 | + set_component_found(${_component}) |
| 195 | +endforeach () |
| 196 | + |
| 197 | +# Compile the list of required vars |
| 198 | +set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) |
| 199 | +foreach (_component ${FFmpeg_FIND_COMPONENTS}) |
| 200 | + list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) |
| 201 | +endforeach () |
| 202 | + |
| 203 | +# Give a nice error message if some of the required vars are missing. |
| 204 | +find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) |
0 commit comments