| 1 |
macro(_ffmpeg_set_found component status) |
| 2 |
if("${status}") |
| 3 |
set("FFMPEG_${component}_FOUND" 1 PARENT_SCOPE) |
| 4 |
else() |
| 5 |
if("${ARGV2}") |
| 6 |
set("FFMPEG_${component}_NOT_FOUND_MESSAGE" "${ARGV2}" PARENT_SCOPE) |
| 7 |
else() |
| 8 |
set("FFMPEG_${component}_NOT_FOUND_MESSAGE" |
| 9 |
"Could not find ${message}" PARENT_SCOPE) |
| 10 |
endif() |
| 11 |
endif() |
| 12 |
endmacro() |
| 13 |
|
| 14 |
function(_ffmpeg_find_component component) |
| 15 |
# |
| 16 |
# argument handling |
| 17 |
# |
| 18 |
|
| 19 |
# parse options |
| 20 |
set(options) |
| 21 |
set(one_value_args HEADER LIBRARY) |
| 22 |
set(multi_value_args NEEDS) |
| 23 |
cmake_parse_arguments(PARSE_ARGV 1 arg |
| 24 |
"${options}" |
| 25 |
"${one_value_args}" |
| 26 |
"${multi_value_args}" |
| 27 |
) |
| 28 |
|
| 29 |
# validate component |
| 30 |
if(NOT component) |
| 31 |
message(FATAL_ERROR "Component name is required") |
| 32 |
endif() |
| 33 |
|
| 34 |
# setup default values |
| 35 |
if(NOT arg_HEADER) |
| 36 |
set(arg_HEADER "lib${component}/${component}.h") |
| 37 |
endif() |
| 38 |
if(NOT arg_LIBRARY) |
| 39 |
set(arg_LIBRARY "${component}") |
| 40 |
endif() |
| 41 |
|
| 42 |
# |
| 43 |
# find component |
| 44 |
# |
| 45 |
|
| 46 |
find_path("FFMPEG_${component}_INCLUDE_DIR" |
| 47 |
NAMES |
| 48 |
"${arg_HEADER}" |
| 49 |
HINTS |
| 50 |
"${FFMPEG_ROOT}/include" |
| 51 |
PATH_SUFFIXES |
| 52 |
ffmpeg |
| 53 |
) |
| 54 |
mark_as_advanced("FFMPEG_${component}_INCLUDE_DIR") |
| 55 |
|
| 56 |
if(NOT FFMPEG_${component}_INCLUDE_DIR) |
| 57 |
_ffmpeg_set_found(${component} FALSE |
| 58 |
"Could not find header '${arg_HEADER}' for ${component}." |
| 59 |
) |
| 60 |
return() |
| 61 |
endif() |
| 62 |
|
| 63 |
find_library("FFMPEG_${component}_LIBRARY" |
| 64 |
NAMES |
| 65 |
"${arg_LIBRARY}" |
| 66 |
HINTS |
| 67 |
"${FFMPEG_ROOT}/lib" |
| 68 |
"${FFMPEG_ROOT}/bin" |
| 69 |
) |
| 70 |
mark_as_advanced("FFMPEG_${component}_LIBRARY") |
| 71 |
|
| 72 |
if(NOT FFMPEG_${component}_LIBRARY) |
| 73 |
_ffmpeg_set_found(${component} FALSE |
| 74 |
"Could not find library '${arg_LIBRARY}' for ${component}." |
| 75 |
) |
| 76 |
return() |
| 77 |
endif() |
| 78 |
|
| 79 |
foreach(dep IN LISTS arg_NEEDS) |
| 80 |
if(NOT TARGET "FFMPEG::${dep}") |
| 81 |
_ffmpeg_set_found(${component} FALSE |
| 82 |
"Could not find dependency '${dep}' for ${component}." |
| 83 |
) |
| 84 |
return() |
| 85 |
endif() |
| 86 |
endforeach() |
| 87 |
|
| 88 |
_ffmpeg_set_found("${component}" TRUE) |
| 89 |
|
| 90 |
# |
| 91 |
# add target |
| 92 |
# |
| 93 |
|
| 94 |
if(NOT TARGET "FFMPEG::${component}") |
| 95 |
add_library("FFMPEG::${component}" UNKNOWN IMPORTED) |
| 96 |
# Build the list of dependency targets with FFMPEG:: prefix |
| 97 |
set(_dep_targets) |
| 98 |
foreach(_dep IN LISTS arg_NEEDS) |
| 99 |
list(APPEND _dep_targets "FFMPEG::${_dep}") |
| 100 |
endforeach() |
| 101 |
set_target_properties("FFMPEG::${component}" PROPERTIES |
| 102 |
IMPORTED_LOCATION "${FFMPEG_${component}_LIBRARY}" |
| 103 |
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_${component}_INCLUDE_DIR}" |
| 104 |
INTERFACE_LINK_LIBRARIES "${_dep_targets}" |
| 105 |
) |
| 106 |
unset(_dep_targets) |
| 107 |
endif() |
| 108 |
|
| 109 |
|
| 110 |
# try to find version |
| 111 |
cmake_path(APPEND version_header |
| 112 |
"${FFMPEG_${component}_INCLUDE_DIR}" |
| 113 |
"lib${component}" |
| 114 |
"version.h" |
| 115 |
) |
| 116 |
|
| 117 |
if(IS_READABLE "${version_header}") |
| 118 |
include(Pj/GetMacroValue) |
| 119 |
foreach(label IN ITEMS major minor micro) |
| 120 |
string(TOUPPER "LIB${component}_VERSION_${label}" macro) |
| 121 |
pj_get_macro_value("${version_header}" "${macro}" "${label}") |
| 122 |
endforeach() |
| 123 |
|
| 124 |
if (NOT major STREQUAL "" AND |
| 125 |
NOT minor STREQUAL "" AND |
| 126 |
NOT micro STREQUAL "") |
| 127 |
set("FFMPEG_${component}_VERSION" |
| 128 |
"${major}.${minor}.${micro}" PARENT_SCOPE |
| 129 |
) |
| 130 |
endif() |
| 131 |
endif() |
| 132 |
endfunction() |
| 133 |
|
| 134 |
_ffmpeg_find_component(avutil) |
| 135 |
_ffmpeg_find_component(avresample NEEDS avutil) |
| 136 |
_ffmpeg_find_component(swresample NEEDS avutil) |
| 137 |
_ffmpeg_find_component(swscale NEEDS avutil) |
| 138 |
_ffmpeg_find_component(avcodec NEEDS avutil) |
| 139 |
_ffmpeg_find_component(avformat NEEDS avutil avcodec) |
| 140 |
_ffmpeg_find_component(avfilter NEEDS avutil) |
| 141 |
_ffmpeg_find_component(avdevice NEEDS avutil avformat) |
| 142 |
|
| 143 |
set(FFMPEG_VERSION FFMPEG_VERSION-NOTFOUND) |
| 144 |
if(TARGET FFMPEG::avutil) |
| 145 |
cmake_path(APPEND _ffmpeg_version_header |
| 146 |
"${FFMPEG_avutil_INCLUDE_DIR}" |
| 147 |
"libavutil" |
| 148 |
"ffversion.h" |
| 149 |
) |
| 150 |
|
| 151 |
if(IS_READABLE "${_ffmpeg_version_header}") |
| 152 |
include(Pj/GetMacroValue) |
| 153 |
pj_get_macro_value("${_ffmpeg_version_header}" FFMPEG_VERSION |
| 154 |
_ffmpeg_version_value |
| 155 |
PATTERN [["n?([^"]*)"]] |
| 156 |
) |
| 157 |
|
| 158 |
if(NOT _ffmpeg_version_value STREQUAL "") |
| 159 |
set(FFMPEG_VERSION "${_ffmpeg_version_value}") |
| 160 |
endif() |
| 161 |
|
| 162 |
unset(_ffmpeg_version_value) |
| 163 |
endif() |
| 164 |
|
| 165 |
unset(_ffmpeg_version_header) |
| 166 |
endif() |
| 167 |
|
| 168 |
set(FFMPEG_INCLUDE_DIRS) |
| 169 |
set(FFMPEG_LIBRARIES) |
| 170 |
set(_ffmpeg_required_vars) |
| 171 |
foreach(_ffmpeg_component IN LISTS FFMPEG_FIND_COMPONENTS) |
| 172 |
if(TARGET "FFMPEG::${_ffmpeg_component}") |
| 173 |
# component variables |
| 174 |
set(FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS |
| 175 |
"${FFMPEG_${_ffmpeg_component}_INCLUDE_DIR}") |
| 176 |
set(FFMPEG_${_ffmpeg_component}_LIBRARIES |
| 177 |
"${FFMPEG_${_ffmpeg_component}_LIBRARY}") |
| 178 |
# ffmpeg variables |
| 179 |
list(APPEND FFMPEG_INCLUDE_DIRS |
| 180 |
"${FFMPEG_${_ffmpeg_component}_INCLUDE_DIRS}") |
| 181 |
list(APPEND FFMPEG_LIBRARIES |
| 182 |
"${FFMPEG_${_ffmpeg_component}_LIBRARIES}") |
| 183 |
# requirement check |
| 184 |
if (FFMEG_FIND_REQUIRED_${_ffmpeg_component}) |
| 185 |
list(APPEND _ffmpeg_required_vars |
| 186 |
"FFMPEG_${_ffmpeg_required_vars}_INCLUDE_DIRS") |
| 187 |
list(APPEND _ffmpeg_required_vars |
| 188 |
"FFMPEG_${_ffmpeg_required_vars}_LIBRARIES") |
| 189 |
endif () |
| 190 |
endif() |
| 191 |
endforeach() |
| 192 |
unset(_ffmpeg_component) |
| 193 |
|
| 194 |
if (FFMPEG_INCLUDE_DIRS) |
| 195 |
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) |
| 196 |
endif () |
| 197 |
|
| 198 |
include(FindPackageHandleStandardArgs) |
| 199 |
find_package_handle_standard_args(FFMPEG |
| 200 |
REQUIRED_VARS |
| 201 |
FFMPEG_INCLUDE_DIRS |
| 202 |
FFMPEG_LIBRARIES |
| 203 |
${_ffmpeg_required_vars} |
| 204 |
VERSION_VAR |
| 205 |
FFMPEG_VERSION |
| 206 |
HANDLE_COMPONENTS |
| 207 |
) |
| 208 |
unset(_ffmpeg_required_vars) |