|
| 1 | +# |
| 2 | +# This module defines the following variables: |
| 3 | +# |
| 4 | +# FFMPEG_FOUND - All required components and the core library were found |
| 5 | +# FFMPEG_INCLUDE_DIRS - Combined list of all components include dirs |
| 6 | +# FFMPEG_LIBRARIES - Combined list of all components libraries |
| 7 | +# FFMPEG_VERSION_STRING - Version of the first component requested |
| 8 | +# |
| 9 | +# For each requested component the following variables are defined: |
| 10 | +# |
| 11 | +# FFMPEG_<component>_FOUND - The component was found |
| 12 | +# FFMPEG_<component>_INCLUDE_DIRS - The components include dirs |
| 13 | +# FFMPEG_<component>_LIBRARIES - The components libraries |
| 14 | +# FFMPEG_<component>_VERSION_STRING - The components version string |
| 15 | +# FFMPEG_<component>_VERSION_MAJOR - The components major version |
| 16 | +# FFMPEG_<component>_VERSION_MINOR - The components minor version |
| 17 | +# FFMPEG_<component>_VERSION_MICRO - The components micro version |
| 18 | +# |
| 19 | +# <component> is the uppercase name of the component |
| 20 | + |
| 21 | + |
| 22 | +find_package(PkgConfig QUIET) |
| 23 | + |
| 24 | +if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 25 | + set(_lib_suffix 64) |
| 26 | +else() |
| 27 | + set(_lib_suffix 32) |
| 28 | +endif() |
| 29 | + |
| 30 | +function(find_ffmpeg_library component header) |
| 31 | + string(TOUPPER "${component}" component_u) |
| 32 | + set(FFMPEG_${component_u}_FOUND FALSE PARENT_SCOPE) |
| 33 | + set(FFmpeg_${component}_FOUND FALSE PARENT_SCOPE) |
| 34 | + |
| 35 | + if(PKG_CONFIG_FOUND) |
| 36 | + pkg_check_modules(PC_FFMPEG_${component} QUIET lib${component}) |
| 37 | + endif() |
| 38 | + |
| 39 | + find_path(FFMPEG_${component}_INCLUDE_DIR |
| 40 | + NAMES |
| 41 | + "lib${component}/${header}" "lib${component}/version.h" |
| 42 | + HINTS |
| 43 | + ENV FFmpegPath${_lib_suffix} |
| 44 | + ENV FFmpegPath |
| 45 | + ENV DepsPath${_lib_suffix} |
| 46 | + ENV DepsPath |
| 47 | + ${FFmpegPath${_lib_suffix}} |
| 48 | + ${FFmpegPath} |
| 49 | + ${DepsPath${_lib_suffix}} |
| 50 | + ${DepsPath} |
| 51 | + ${PC_FFMPEG_${component}_INCLUDE_DIRS} |
| 52 | + PATHS |
| 53 | + /usr/include /usr/local/include /opt/local/include /sw/include |
| 54 | + PATH_SUFFIXES ffmpeg libav include) |
| 55 | + |
| 56 | + find_library(FFMPEG_${component}_LIBRARY |
| 57 | + NAMES |
| 58 | + "${component}" "lib${component}" |
| 59 | + HINTS |
| 60 | + ENV FFmpegPath${_lib_suffix} |
| 61 | + ENV FFmpegPath |
| 62 | + ENV DepsPath${_lib_suffix} |
| 63 | + ENV DepsPath |
| 64 | + ${FFmpegPath${_lib_suffix}} |
| 65 | + ${FFmpegPath} |
| 66 | + ${DepsPath${_lib_suffix}} |
| 67 | + ${DepsPath} |
| 68 | + ${PC_FFMPEG_${component}_LIBRARY_DIRS} |
| 69 | + PATHS |
| 70 | + /usr/lib /usr/local/lib /opt/local/lib /sw/lib |
| 71 | + PATH_SUFFIXES |
| 72 | + lib${_lib_suffix} lib |
| 73 | + libs${_lib_suffix} libs |
| 74 | + bin${_lib_suffix} bin |
| 75 | + ../lib${_lib_suffix} ../lib |
| 76 | + ../libs${_lib_suffix} ../libs |
| 77 | + ../bin${_lib_suffix} ../bin) |
| 78 | + |
| 79 | + set(FFMPEG_${component_u}_INCLUDE_DIRS ${FFMPEG_${component}_INCLUDE_DIR} PARENT_SCOPE) |
| 80 | + set(FFMPEG_${component_u}_LIBRARIES ${FFMPEG_${component}_LIBRARY} PARENT_SCOPE) |
| 81 | + |
| 82 | + mark_as_advanced(FFMPEG_${component}_INCLUDE_DIR FFMPEG_${component}_LIBRARY) |
| 83 | + |
| 84 | + if(FFMPEG_${component}_INCLUDE_DIR AND FFMPEG_${component}_LIBRARY) |
| 85 | + set(FFMPEG_${component_u}_FOUND TRUE PARENT_SCOPE) |
| 86 | + set(FFmpeg_${component}_FOUND TRUE PARENT_SCOPE) |
| 87 | + |
| 88 | + list(APPEND FFMPEG_INCLUDE_DIRS ${FFMPEG_${component}_INCLUDE_DIR}) |
| 89 | + list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) |
| 90 | + set(FFMPEG_INCLUDE_DIRS "${FFMPEG_INCLUDE_DIRS}" PARENT_SCOPE) |
| 91 | + |
| 92 | + list(APPEND FFMPEG_LIBRARIES ${FFMPEG_${component}_LIBRARY}) |
| 93 | + list(REMOVE_DUPLICATES FFMPEG_LIBRARIES) |
| 94 | + set(FFMPEG_LIBRARIES "${FFMPEG_LIBRARIES}" PARENT_SCOPE) |
| 95 | + |
| 96 | + set(FFMPEG_${component_u}_VERSION_STRING "unknown" PARENT_SCOPE) |
| 97 | + set(_vfile "${FFMPEG_${component}_INCLUDE_DIR}/lib${component}/version.h") |
| 98 | + |
| 99 | + if(EXISTS "${_vfile}") |
| 100 | + file(STRINGS "${_vfile}" _version_parse REGEX "^.*VERSION_(MAJOR|MINOR|MICRO)[ \t]+[0-9]+[ \t]*$") |
| 101 | + string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _major "${_version_parse}") |
| 102 | + string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _minor "${_version_parse}") |
| 103 | + string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" _micro "${_version_parse}") |
| 104 | + |
| 105 | + set(FFMPEG_${component_u}_VERSION_MAJOR "${_major}" PARENT_SCOPE) |
| 106 | + set(FFMPEG_${component_u}_VERSION_MINOR "${_minor}" PARENT_SCOPE) |
| 107 | + set(FFMPEG_${component_u}_VERSION_MICRO "${_micro}" PARENT_SCOPE) |
| 108 | + |
| 109 | + set(FFMPEG_${component_u}_VERSION_STRING "${_major}.${_minor}.${_micro}" PARENT_SCOPE) |
| 110 | + else() |
| 111 | + message(STATUS "Failed parsing FFmpeg ${component} version") |
| 112 | + endif() |
| 113 | + endif() |
| 114 | +endfunction() |
| 115 | + |
| 116 | +set(FFMPEG_INCLUDE_DIRS) |
| 117 | +set(FFMPEG_LIBRARIES) |
| 118 | + |
| 119 | +if(NOT FFmpeg_FIND_COMPONENTS) |
| 120 | + message(FATAL_ERROR "No FFmpeg components requested") |
| 121 | +endif() |
| 122 | + |
| 123 | +list(GET FFmpeg_FIND_COMPONENTS 0 _first_comp) |
| 124 | +string(TOUPPER "${_first_comp}" _first_comp) |
| 125 | + |
| 126 | +foreach(component ${FFmpeg_FIND_COMPONENTS}) |
| 127 | + if(component STREQUAL "avcodec") |
| 128 | + find_ffmpeg_library("${component}" "avcodec.h") |
| 129 | + elseif(component STREQUAL "avdevice") |
| 130 | + find_ffmpeg_library("${component}" "avdevice.h") |
| 131 | + elseif(component STREQUAL "avfilter") |
| 132 | + find_ffmpeg_library("${component}" "avfilter.h") |
| 133 | + elseif(component STREQUAL "avformat") |
| 134 | + find_ffmpeg_library("${component}" "avformat.h") |
| 135 | + elseif(component STREQUAL "avresample") |
| 136 | + find_ffmpeg_library("${component}" "avresample.h") |
| 137 | + elseif(component STREQUAL "avutil") |
| 138 | + find_ffmpeg_library("${component}" "avutil.h") |
| 139 | + elseif(component STREQUAL "postproc") |
| 140 | + find_ffmpeg_library("${component}" "postprocess.h") |
| 141 | + elseif(component STREQUAL "swresample") |
| 142 | + find_ffmpeg_library("${component}" "swresample.h") |
| 143 | + elseif(component STREQUAL "swscale") |
| 144 | + find_ffmpeg_library("${component}" "swscale.h") |
| 145 | + else() |
| 146 | + message(FATAL_ERROR "Unknown FFmpeg component requested: ${component}") |
| 147 | + endif() |
| 148 | +endforeach() |
| 149 | + |
| 150 | +include(FindPackageHandleStandardArgs) |
| 151 | +find_package_handle_standard_args(FFmpeg |
| 152 | + FOUND_VAR FFMPEG_FOUND |
| 153 | + REQUIRED_VARS FFMPEG_${_first_comp}_LIBRARIES FFMPEG_${_first_comp}_INCLUDE_DIRS |
| 154 | + VERSION_VAR FFMPEG_${_first_comp}_VERSION_STRING |
| 155 | + HANDLE_COMPONENTS) |
0 commit comments