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