diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,9 @@ URL "http://www.exiv2.org" TYPE OPTIONAL PURPOSE "Support for image metadata") -find_package(FFmpeg 3.1) +find_package(FFmpeg 57.48 COMPONENTS AVCODEC) +find_package(FFmpeg 57.40 COMPONENTS AVFORMAT) +find_package(FFmpeg 55.27 COMPONENTS AVUTIL) set_package_properties(FFmpeg PROPERTIES DESCRIPTION "Video Tag reader" URL "http://ffmpeg.org" TYPE OPTIONAL PURPOSE "Support for video metadata") diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake --- a/cmake/FindFFmpeg.cmake +++ b/cmake/FindFFmpeg.cmake @@ -50,6 +50,7 @@ # SUCH DAMAGE. include(FindPackageHandleStandardArgs) +include(CheckStructHasMember) # The default components were taken from a survey over other FindFFMPEG.cmake files if (NOT FFmpeg_FIND_COMPONENTS) @@ -65,6 +66,7 @@ if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) # message(STATUS " - ${_component} found.") set(${_component}_FOUND TRUE) + set(FFmpeg_${_component}_FOUND TRUE) else () # message(STATUS " - ${_component} not found.") endif () @@ -76,14 +78,14 @@ # Checks for the given component by invoking pkgconfig and then looking up the libraries and # include directories. # -macro(find_component _component _pkgconfig _library _header) +macro(find_component _component _pkgconfig _library _header _version) if (NOT WIN32) # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls find_package(PkgConfig) if (PKG_CONFIG_FOUND) - pkg_check_modules(PC_${_component} ${_pkgconfig}) + pkg_check_modules(PC_${_component} ${_pkgconfig}>=${_version}) endif () endif (NOT WIN32) @@ -114,17 +116,16 @@ endmacro() - # Check for cached results. If there are skip the costly part. if (NOT FFMPEG_LIBRARIES) # Check for all possible component. - find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) - find_component(AVFORMAT libavformat avformat libavformat/avformat.h) - find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) - find_component(AVUTIL libavutil avutil libavutil/avutil.h) - find_component(SWSCALE libswscale swscale libswscale/swscale.h) - find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h) + find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h ${FFmpeg_FIND_VERSION}) + find_component(AVFORMAT libavformat avformat libavformat/avformat.h ${FFmpeg_FIND_VERSION}) + find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h ${FFmpeg_FIND_VERSION}) + find_component(AVUTIL libavutil avutil libavutil/avutil.h ${FFmpeg_FIND_VERSION}) + find_component(SWSCALE libswscale swscale libswscale/swscale.h ${FFmpeg_FIND_VERSION}) + find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h ${FFmpeg_FIND_VERSION}) # Check if the required components were found and add their stuff to the FFMPEG_* vars. foreach (_component ${FFmpeg_FIND_COMPONENTS}) @@ -154,16 +155,24 @@ endif () +set(CMAKE_REQUIRED_INCLUDES ${AVCODEC_INCLUDE_DIRS}) +CHECK_STRUCT_HAS_MEMBER(AVStream codecpar "stdint.h;libavformat/avformat.h" HAVE_AVSTREAM_CODECPAR LANGUAGE CXX) + # Now set the noncached _FOUND vars for the components. foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) set_component_found(${_component}) endforeach () # Compile the list of required vars -set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) +set(_FFmpeg_REQUIRED_VARS HAVE_AVSTREAM_CODECPAR FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) foreach (_component ${FFmpeg_FIND_COMPONENTS}) list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) endforeach () + + # Give a nice error message if some of the required vars are missing. -find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) +find_package_handle_standard_args(FFmpeg + REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS} + HANDLE_COMPONENTS) +