| 1 |
# Taken Oct.2023 from VTK (Visualization Toolkit) |
| 2 |
|
| 3 |
#[==[ |
| 4 |
Provides the following variables: |
| 5 |
|
| 6 |
* `FFMPEG_INCLUDE_DIRS`: Include directories necessary to use FFMPEG. |
| 7 |
* `FFMPEG_LIBRARIES`: Libraries necessary to use FFMPEG. Note that this only |
| 8 |
includes libraries for the components requested. |
| 9 |
* `FFMPEG_VERSION`: The version of FFMPEG found. |
| 10 |
|
| 11 |
The following components are supported: |
| 12 |
|
| 13 |
* `avcodec` |
| 14 |
* `avdevice` |
| 15 |
* `avfilter` |
| 16 |
* `avformat` |
| 17 |
* `avresample` |
| 18 |
* `avutil` |
| 19 |
* `swresample` |
| 20 |
* `swscale` |
| 21 |
|
| 22 |
For each component, the following are provided: |
| 23 |
|
| 24 |
* `FFMPEG_<component>_FOUND`: Libraries for the component. |
| 25 |
* `FFMPEG_<component>_INCLUDE_DIRS`: Include directories for |
| 26 |
the component. |
| 27 |
* `FFMPEG_<component>_LIBRARIES`: Libraries for the component. |
| 28 |
* `FFMPEG::<component>`: A target to use with `target_link_libraries`. |
| 29 |
|
| 30 |
Note that only components requested with `COMPONENTS` or `OPTIONAL_COMPONENTS` |
| 31 |
are guaranteed to set these variables or provide targets. |
| 32 |
#]==] |
| 33 |
|
| 34 |
function (_ffmpeg_find component headername) |
| 35 |
find_path("FFMPEG_${component}_INCLUDE_DIR" |
| 36 |
NAMES |
| 37 |
"lib${component}/${headername}" |
| 38 |
PATHS |
| 39 |
"${FFMPEG_ROOT}/include" |
| 40 |
~/Library/Frameworks |
| 41 |
/Library/Frameworks |
| 42 |
/usr/local/include |
| 43 |
/usr/include |
| 44 |
/sw/include # Fink |
| 45 |
/opt/local/include # DarwinPorts |
| 46 |
/opt/csw/include # Blastwave |
| 47 |
/opt/include |
| 48 |
/usr/freeware/include |
| 49 |
PATH_SUFFIXES |
| 50 |
ffmpeg |
| 51 |
DOC "FFMPEG's ${component} include directory") |
| 52 |
mark_as_advanced("FFMPEG_${component}_INCLUDE_DIR") |
| 53 |
|
| 54 |
# On Windows, static FFMPEG is sometimes built as `lib<name>.a`. |
| 55 |
if (WIN32) |
| 56 |
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".lib") |
| 57 |
list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib") |
| 58 |
endif () |
| 59 |
|
| 60 |
find_library("FFMPEG_${component}_LIBRARY" |
| 61 |
NAMES |
| 62 |
"${component}" |
| 63 |
PATHS |
| 64 |
"${FFMPEG_ROOT}/lib" |
| 65 |
~/Library/Frameworks |
| 66 |
/Library/Frameworks |
| 67 |
/usr/local/lib |
| 68 |
/usr/local/lib64 |
| 69 |
/usr/lib |
| 70 |
/usr/lib64 |
| 71 |
/sw/lib |
| 72 |
/opt/local/lib |
| 73 |
/opt/csw/lib |
| 74 |
/opt/lib |
| 75 |
/usr/freeware/lib64 |
| 76 |
"${FFMPEG_ROOT}/bin" |
| 77 |
DOC "FFMPEG's ${component} library") |
| 78 |
mark_as_advanced("FFMPEG_${component}_LIBRARY") |
| 79 |
|
| 80 |
if (FFMPEG_${component}_LIBRARY AND FFMPEG_${component}_INCLUDE_DIR) |
| 81 |
set(_deps_found TRUE) |
| 82 |
set(_deps_link) |
| 83 |
foreach (_ffmpeg_dep IN LISTS ARGN) |
| 84 |
if (TARGET "FFMPEG::${_ffmpeg_dep}") |
| 85 |
list(APPEND _deps_link "FFMPEG::${_ffmpeg_dep}") |
| 86 |
else () |
| 87 |
set(_deps_found FALSE) |
| 88 |
endif () |
| 89 |
endforeach () |
| 90 |
if (_deps_found) |
| 91 |
if (NOT TARGET "FFMPEG::${component}") |
| 92 |
add_library("FFMPEG::${component}" UNKNOWN IMPORTED) |
| 93 |
set_target_properties("FFMPEG::${component}" PROPERTIES |
| 94 |
IMPORTED_LOCATION "${FFMPEG_${component}_LIBRARY}" |
| 95 |
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_${component}_INCLUDE_DIR}" |
| 96 |
IMPORTED_LINK_INTERFACE_LIBRARIES "${_deps_link}") |
| 97 |
endif () |
| 98 |
set("FFMPEG_${component}_FOUND" 1 |
| 99 |
PARENT_SCOPE) |
| 100 |
|
| 101 |
set(version_header_path "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version.h") |
| 102 |
if (EXISTS "${version_header_path}") |
| 103 |
string(TOUPPER "${component}" component_upper) |
| 104 |
file(STRINGS "${version_header_path}" version |
| 105 |
REGEX "#define *LIB${component_upper}_VERSION_(MAJOR|MINOR|MICRO) ") |
| 106 |
string(REGEX REPLACE ".*_MAJOR *\([0-9]*\).*" "\\1" major "${version}") |
| 107 |
string(REGEX REPLACE ".*_MINOR *\([0-9]*\).*" "\\1" minor "${version}") |
| 108 |
string(REGEX REPLACE ".*_MICRO *\([0-9]*\).*" "\\1" micro "${version}") |
| 109 |
if (NOT major STREQUAL "" AND |
| 110 |
NOT minor STREQUAL "" AND |
| 111 |
NOT micro STREQUAL "") |
| 112 |
set("FFMPEG_${component}_VERSION" "${major}.${minor}.${micro}" |
| 113 |
PARENT_SCOPE) |
| 114 |
endif () |
| 115 |
endif () |
| 116 |
else () |
| 117 |
set("FFMPEG_${component}_FOUND" 0 |
| 118 |
PARENT_SCOPE) |
| 119 |
set(what) |
| 120 |
if (NOT FFMPEG_${component}_LIBRARY) |
| 121 |
set(what "library") |
| 122 |
endif () |
| 123 |
if (NOT FFMPEG_${component}_INCLUDE_DIR) |
| 124 |
if (what) |
| 125 |
string(APPEND what " or headers") |
| 126 |
else () |
| 127 |
set(what "headers") |
| 128 |
endif () |
| 129 |
endif () |
| 130 |
set("FFMPEG_${component}_NOT_FOUND_MESSAGE" |
| 131 |
"Could not find the ${what} for ${component}." |
| 132 |
PARENT_SCOPE) |
| 133 |
endif () |
| 134 |
endif () |
| 135 |
endfunction () |
| 136 |
|
| 137 |
_ffmpeg_find(avutil avutil.h) |
| 138 |
_ffmpeg_find(avresample avresample.h |
| 139 |
avutil) |
| 140 |
_ffmpeg_find(swresample swresample.h |
| 141 |
avutil) |
| 142 |
_ffmpeg_find(swscale swscale.h |
| 143 |
avutil) |
| 144 |
_ffmpeg_find(avcodec avcodec.h |
| 145 |
avutil) |
| 146 |
_ffmpeg_find(avformat avformat.h |
| 147 |
avcodec avutil) |
| 148 |
_ffmpeg_find(avfilter avfilter.h |
| 149 |
avutil) |
| 150 |
_ffmpeg_find(avdevice avdevice.h |
| 151 |
avformat avutil) |
| 152 |
|
| 153 |
if (TARGET FFMPEG::avutil) |
| 154 |
set(_ffmpeg_version_header_path "${FFMPEG_avutil_INCLUDE_DIR}/libavutil/ffversion.h") |
| 155 |
if (EXISTS "${_ffmpeg_version_header_path}") |
| 156 |
file(STRINGS "${_ffmpeg_version_header_path}" _ffmpeg_version |
| 157 |
REGEX "FFMPEG_VERSION") |
| 158 |
string(REGEX REPLACE ".*\"n?\(.*\)\"" "\\1" FFMPEG_VERSION "${_ffmpeg_version}") |
| 159 |
unset(_ffmpeg_version) |
| 160 |
else () |
| 161 |
set(FFMPEG_VERSION FFMPEG_VERSION-NOTFOUND) |
| 162 |
endif () |
| 163 |
unset(_ffmpeg_version_header_path) |
| 164 |
endif () |
| 165 |
|
| 166 |
set(FFMPEG_INCLUDE_DIRS) |
| 167 |
set(FFMPEG_LIBRARIES) |
| 168 |
set(_ffmpeg_required_vars) |
| 169 |
foreach (_ffmpeg_component IN LISTS FFMPEG_FIND_COMPONENTS) |
| 170 |
if (TARGET "FFMPEG::${_ffmpeg_component}") |
| 171 |
set(FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS |
| 172 |
"${FFMPEG_${_ffmpeg_component}_INCLUDE_DIR}") |
| 173 |
set(FFMPEG_${_ffmpeg_component}_LIBRARIES |
| 174 |
"${FFMPEG_${_ffmpeg_component}_LIBRARY}") |
| 175 |
list(APPEND FFMPEG_INCLUDE_DIRS |
| 176 |
"${FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS}") |
| 177 |
list(APPEND FFMPEG_LIBRARIES |
| 178 |
"${FFMPEG_${_ffmpeg_component}_LIBRARIES}") |
| 179 |
if (FFMEG_FIND_REQUIRED_${_ffmpeg_component}) |
| 180 |
list(APPEND _ffmpeg_required_vars |
| 181 |
"FFMPEG_${_ffmpeg_required_vars}_INCLUDE_DIRS" |
| 182 |
"FFMPEG_${_ffmpeg_required_vars}_LIBRARIES") |
| 183 |
endif () |
| 184 |
endif () |
| 185 |
endforeach () |
| 186 |
unset(_ffmpeg_component) |
| 187 |
|
| 188 |
if (FFMPEG_INCLUDE_DIRS) |
| 189 |
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) |
| 190 |
endif () |
| 191 |
|
| 192 |
include(FindPackageHandleStandardArgs) |
| 193 |
find_package_handle_standard_args(FFMPEG |
| 194 |
REQUIRED_VARS FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES ${_ffmpeg_required_vars} |
| 195 |
VERSION_VAR FFMPEG_VERSION |
| 196 |
HANDLE_COMPONENTS) |
| 197 |
unset(_ffmpeg_required_vars) |
| 198 |
|