Warning, /multimedia/kid3/src/plugins/acoustidimport/cmake/modules/FindFFmpeg.cmake is written in an unsupported language. File is not indexed.
0001 # Redistribution and use is allowed according to the terms of the BSD license.
0002 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
0003 #
0004 # FindFFmpeg
0005 # ----------
0006 #
0007 # Find the native FFmpeg includes and libraries
0008 #
0009 # This module defines the following variables:
0010 #
0011 # FFmpeg_INCLUDE_<component>: where to find <component>.h
0012 # FFmpeg_LIBRARY_<component>: where to find the <component> library
0013 # FFmpeg_INCLUDES: aggregate all the include paths
0014 # FFmpeg_LIBRARIES: aggregate all the paths to the libraries
0015 # FFmpeg_FOUND: True if all components have been found
0016 #
0017 # This module defines the following targets, which are preferred over variables:
0018 #
0019 # FFmpeg::<component>: Target to use <component> directly, with include path,
0020 # library and dependencies set up. If you are using a static build, you are
0021 # responsible for adding any external dependencies (such as zlib, bzlib...).
0022 #
0023 # <component> can be one of:
0024 # avcodec
0025 # avdevice
0026 # avfilter
0027 # avformat
0028 # postproc
0029 # swresample
0030 # swscale
0031 #
0032
0033 set(_FFmpeg_ALL_COMPONENTS
0034 avcodec
0035 avdevice
0036 avfilter
0037 avformat
0038 avutil
0039 postproc
0040 swresample
0041 swscale
0042 )
0043
0044 set(_FFmpeg_DEPS_avcodec avutil)
0045 set(_FFmpeg_DEPS_avdevice avcodec avformat avutil)
0046 set(_FFmpeg_DEPS_avfilter avutil)
0047 set(_FFmpeg_DEPS_avformat avcodec avutil)
0048 set(_FFmpeg_DEPS_postproc avutil)
0049 set(_FFmpeg_DEPS_swresample avutil)
0050 set(_FFmpeg_DEPS_swscale avutil)
0051
0052 function(find_ffmpeg LIBNAME)
0053 if(DEFINED ENV{FFMPEG_DIR})
0054 set(FFMPEG_DIR $ENV{FFMPEG_DIR})
0055 endif()
0056
0057 if(FFMPEG_DIR)
0058 list(APPEND INCLUDE_PATHS
0059 ${FFMPEG_DIR}
0060 ${FFMPEG_DIR}/ffmpeg
0061 ${FFMPEG_DIR}/lib${LIBNAME}
0062 ${FFMPEG_DIR}/include/lib${LIBNAME}
0063 ${FFMPEG_DIR}/include/ffmpeg
0064 ${FFMPEG_DIR}/include
0065 NO_DEFAULT_PATH
0066 NO_CMAKE_FIND_ROOT_PATH
0067 )
0068 list(APPEND LIB_PATHS
0069 ${FFMPEG_DIR}
0070 ${FFMPEG_DIR}/lib
0071 ${FFMPEG_DIR}/lib${LIBNAME}
0072 NO_DEFAULT_PATH
0073 NO_CMAKE_FIND_ROOT_PATH
0074 )
0075 else()
0076 list(APPEND INCLUDE_PATHS
0077 /usr/local/include/ffmpeg
0078 /usr/local/include/lib${LIBNAME}
0079 /usr/include/ffmpeg
0080 /usr/include/lib${LIBNAME}
0081 /usr/include/ffmpeg/lib${LIBNAME}
0082 )
0083
0084 list(APPEND LIB_PATHS
0085 /usr/local/lib
0086 /usr/lib
0087 )
0088 endif()
0089
0090 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
0091 HINTS ${INCLUDE_PATHS}
0092 )
0093
0094 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
0095 HINTS ${LIB_PATHS}
0096 )
0097
0098 if(NOT FFMPEG_DIR AND (NOT FFmpeg_LIBRARY_${LIBNAME} OR NOT FFmpeg_INCLUDE_${LIBNAME}))
0099 # Didn't find it in the usual paths, try pkg-config
0100 find_package(PkgConfig QUIET)
0101 pkg_check_modules(FFmpeg_PKGCONFIG_${LIBNAME} QUIET lib${LIBNAME})
0102
0103 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
0104 ${FFmpeg_PKGCONFIG_${LIBNAME}_INCLUDE_DIRS}
0105 )
0106
0107 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
0108 ${FFmpeg_PKGCONFIG_${LIBNAME}_LIBRARY_DIRS}
0109 )
0110 endif()
0111
0112 if(FFmpeg_INCLUDE_${LIBNAME} AND FFmpeg_LIBRARY_${LIBNAME})
0113 set(FFmpeg_INCLUDE_${LIBNAME} "${FFmpeg_INCLUDE_${LIBNAME}}" PARENT_SCOPE)
0114 set(FFmpeg_LIBRARY_${LIBNAME} "${FFmpeg_LIBRARY_${LIBNAME}}" PARENT_SCOPE)
0115 set(FFmpeg_${c}_FOUND TRUE PARENT_SCOPE)
0116 if(NOT FFmpeg_FIND_QUIETLY)
0117 message("-- Found ${LIBNAME}: ${FFmpeg_INCLUDE_${LIBNAME}} ${FFmpeg_LIBRARY_${LIBNAME}}")
0118 endif()
0119 endif()
0120 endfunction()
0121
0122 foreach(c ${_FFmpeg_ALL_COMPONENTS})
0123 find_ffmpeg(${c})
0124 endforeach()
0125
0126 foreach(c ${_FFmpeg_ALL_COMPONENTS})
0127 if(FFmpeg_${c}_FOUND)
0128 list(APPEND FFmpeg_INCLUDES ${FFmpeg_INCLUDE_${c}})
0129 list(APPEND FFmpeg_LIBRARIES ${FFmpeg_LIBRARY_${c}})
0130
0131 add_library(FFmpeg::${c} IMPORTED UNKNOWN)
0132 set_target_properties(FFmpeg::${c} PROPERTIES
0133 IMPORTED_LOCATION ${FFmpeg_LIBRARY_${c}}
0134 INTERFACE_INCLUDE_DIRECTORIES ${FFmpeg_INCLUDE_${c}}
0135 )
0136 if(_FFmpeg_DEPS_${c})
0137 set(deps)
0138 foreach(dep ${_FFmpeg_DEPS_${c}})
0139 list(APPEND deps FFmpeg::${dep})
0140 endforeach()
0141
0142 set_target_properties(FFmpeg::${c} PROPERTIES
0143 INTERFACE_LINK_LIBRARIES "${deps}"
0144 )
0145 unset(deps)
0146 endif()
0147 endif()
0148 endforeach()
0149
0150 if(FFmpeg_INCLUDES)
0151 list(REMOVE_DUPLICATES FFmpeg_INCLUDES)
0152 endif()
0153
0154 foreach(c ${FFmpeg_FIND_COMPONENTS})
0155 list(APPEND _FFmpeg_REQUIRED_VARS FFmpeg_INCLUDE_${c} FFmpeg_LIBRARY_${c})
0156 endforeach()
0157
0158 include(FindPackageHandleStandardArgs)
0159 find_package_handle_standard_args(FFmpeg
0160 REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS}
0161 HANDLE_COMPONENTS
0162 )
0163
0164 foreach(c ${_FFmpeg_ALL_COMPONENTS})
0165 unset(_FFmpeg_DEPS_${c})
0166 endforeach()
0167 unset(_FFmpeg_ALL_COMPONENTS)
0168 unset(_FFmpeg_REQUIRED_VARS)