1
# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
3
# Once done this will define
4
# FFMPEG_FOUND - System has the all required components.
5
# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
7
# For each of the components it will additionally set.
15
# the following target will be defined
16
# FFmpeg::SDL::<component> - link to this target to
17
# the following variables will be defined
18
# FFmpeg_<component>_FOUND - System has <component>
19
# FFmpeg_<component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
20
# FFmpeg_<component>_LIBRARIES - Link these to use <component>
21
# FFmpeg_<component>_DEFINITIONS - Compiler switches required for using <component>
22
# FFmpeg_<component>_VERSION - The components version
24
# Copyright (c) 2006, Matthias Kretz, <kretz@kde.org>
25
# Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
26
# Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
27
# Copyright (c) 2023, Sam lantinga, <slouken@libsdl.org>
29
# Redistribution and use is allowed according to the terms of the BSD license.
30
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
32
include(FindPackageHandleStandardArgs)
33
include("${CMAKE_CURRENT_LIST_DIR}/PkgConfigHelper.cmake")
35
# The default components were taken from a survey over other FindFFMPEG.cmake files
36
if(NOT FFmpeg_FIND_COMPONENTS)
37
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
38
foreach(_component IN LISTS FFmpeg_FIND_COMPONENTS)
39
set(FFmpeg_FIND_REQUIRED_${_component} TRUE)
43
find_package(PkgConfig QUIET)
46
### Macro: find_component
48
# Checks for the given component by invoking pkgconfig and then looking up the libraries and
51
macro(find_component _component _pkgconfig _library _header)
53
# use pkg-config to get the directories and then use these values
54
# in the FIND_PATH() and FIND_LIBRARY() calls
56
pkg_check_modules(PC_${_component} QUIET ${_pkgconfig})
59
find_path(FFmpeg_${_component}_INCLUDE_DIRS
62
${PC_${_component}_INCLUDE_DIRS}
67
find_library(FFmpeg_${_component}_LIBRARY
70
${PC_${_component}_LIBRARY_DIRS}
73
if(FFmpeg_${_component}_INCLUDE_DIRS AND FFmpeg_${_component}_LIBRARY)
74
set(FFmpeg_${_component}_FOUND TRUE)
77
if(PC_${_component}_FOUND)
78
get_flags_from_pkg_config("${FFmpeg_${_component}_LIBRARY}" "PC_${_component}" "${_component}")
81
set(FFmpeg_${_component}_VERSION "${PC_${_component}_VERSION}")
83
set(FFmpeg_${_component}_COMPILE_OPTIONS "${${_component}_options}" CACHE STRING "Extra compile options of FFmpeg ${_component}")
85
set(FFmpeg_${_component}_LIBRARIES "${${_component}_link_libraries}" CACHE STRING "Extra link libraries of FFmpeg ${_component}")
87
set(FFmpeg_${_component}_LINK_OPTIONS "${${_component}_link_options}" CACHE STRING "Extra link flags of FFmpeg ${_component}")
89
set(FFmpeg_${_component}_LINK_DIRECTORIES "${${_component}_link_directories}" CACHE PATH "Extra link directories of FFmpeg ${_component}")
92
FFmpeg_${_component}_INCLUDE_DIRS
93
FFmpeg_${_component}_LIBRARY
94
FFmpeg_${_component}_COMPILE_OPTIONS
95
FFmpeg_${_component}_LIBRARIES
96
FFmpeg_${_component}_LINK_OPTIONS
97
FFmpeg_${_component}_LINK_DIRECTORIES
101
# Check for all possible component.
102
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
103
find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
104
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
105
find_component(AVUTIL libavutil avutil libavutil/avutil.h)
106
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
107
find_component(SWSCALE libswscale swscale libswscale/swscale.h)
108
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
109
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
111
# Compile the list of required vars
112
set(_FFmpeg_REQUIRED_VARS)
113
foreach(_component ${FFmpeg_FIND_COMPONENTS})
114
list(APPEND _FFmpeg_REQUIRED_VARS FFmpeg_${_component}_INCLUDE_DIRS FFmpeg_${_component}_LIBRARY)
117
# Give a nice error message if some of the required vars are missing.
118
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})
122
foreach(_component IN LISTS FFmpeg_FIND_COMPONENTS)
123
if(FFmpeg_${_component}_FOUND)
124
list(APPEND FFMPEG_LIBRARIES FFmpeg::SDL::${_component})
125
if(NOT TARGET FFmpeg::SDL::${_component})
126
add_library(FFmpeg::SDL::${_component} UNKNOWN IMPORTED)
127
set_target_properties(FFmpeg::SDL::${_component} PROPERTIES
128
IMPORTED_LOCATION "${FFmpeg_${_component}_LIBRARY}"
129
INTERFACE_INCLUDE_DIRECTORIES "${FFmpeg_${_component}_INCLUDE_DIRS}"
130
INTERFACE_COMPILE_OPTIONS "${FFmpeg_${_component}_COMPILE_OPTIONS}"
131
INTERFACE_LINK_LIBRARIES "${FFmpeg_${_component}_LIBRARIES}"
132
INTERFACE_LINK_OPTIONS "${FFmpeg_${_component}_LINK_OPTIONS}"
133
INTERFACE_LINK_DIRECTORIES "${FFmpeg_${_component}_LINK_DIRECTORIES}"