1- # - Try to find FFMPEG
1+ # vim: ts=2 sw=2
2+ # - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
3+ #
24# Once done this will define
3- #
4- # FFMPEG_FOUND - system has FFMPEG
5- # FFMPEG_INCLUDE_DIR - the include directory
6- # FFMPEG_LIBRARY_DIR - the directory containing the libraries
7- # FFMPEG_LIBRARIES - Link these to use FFMPEG
8- #
9-
10- # FindAvformat
11- FIND_PATH ( AVFORMAT_INCLUDE_DIR libavformat/avformat.h
12- PATHS /usr/include /
13- /usr/include /ffmpeg/
14- $ENV{FFMPEGDIR} /include /
15- $ENV{FFMPEGDIR} /include /ffmpeg/ )
16-
17- FIND_LIBRARY ( AVFORMAT_LIBRARY avformat avformat-55 avformat-57
18- PATHS /usr/lib/
19- /usr/lib/ffmpeg/
20- $ENV{FFMPEGDIR} /lib/
21- $ENV{FFMPEGDIR} /lib/ffmpeg/
22- $ENV{FFMPEGDIR} /bin/ )
23-
24- #FindAvcodec
25- FIND_PATH ( AVCODEC_INCLUDE_DIR libavcodec/avcodec.h
26- PATHS /usr/include /
27- /usr/include /ffmpeg/
28- $ENV{FFMPEGDIR} /include /
29- $ENV{FFMPEGDIR} /include /ffmpeg/ )
30-
31- FIND_LIBRARY ( AVCODEC_LIBRARY avcodec avcodec-55 avcodec-57
32- PATHS /usr/lib/
33- /usr/lib/ffmpeg/
34- $ENV{FFMPEGDIR} /lib/
35- $ENV{FFMPEGDIR} /lib/ffmpeg/
36- $ENV{FFMPEGDIR} /bin/ )
37-
38- #FindAvutil
39- FIND_PATH ( AVUTIL_INCLUDE_DIR libavutil/avutil.h
40- PATHS /usr/include /
41- /usr/include /ffmpeg/
42- $ENV{FFMPEGDIR} /include /
43- $ENV{FFMPEGDIR} /include /ffmpeg/ )
44-
45- FIND_LIBRARY ( AVUTIL_LIBRARY avutil avutil-52 avutil-55
46- PATHS /usr/lib/
47- /usr/lib/ffmpeg/
48- $ENV{FFMPEGDIR} /lib/
49- $ENV{FFMPEGDIR} /lib/ffmpeg/
50- $ENV{FFMPEGDIR} /bin/ )
51-
52- #FindAvdevice
53- FIND_PATH ( AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h
54- PATHS /usr/include /
55- /usr/include /ffmpeg/
56- $ENV{FFMPEGDIR} /include /
57- $ENV{FFMPEGDIR} /include /ffmpeg/ )
58-
59- FIND_LIBRARY ( AVDEVICE_LIBRARY avdevice avdevice-55 avdevice-56
60- PATHS /usr/lib/
61- /usr/lib/ffmpeg/
62- $ENV{FFMPEGDIR} /lib/
63- $ENV{FFMPEGDIR} /lib/ffmpeg/
64- $ENV{FFMPEGDIR} /bin/ )
65-
66- #FindSwscale
67- FIND_PATH ( SWSCALE_INCLUDE_DIR libswscale/swscale.h
68- PATHS /usr/include /
69- /usr/include /ffmpeg/
70- $ENV{FFMPEGDIR} /include /
71- $ENV{FFMPEGDIR} /include /ffmpeg/ )
72-
73- FIND_LIBRARY ( SWSCALE_LIBRARY swscale swscale-2 swscale-4
74- PATHS /usr/lib/
75- /usr/lib/ffmpeg/
76- $ENV{FFMPEGDIR} /lib/
77- $ENV{FFMPEGDIR} /lib/ffmpeg/
78- $ENV{FFMPEGDIR} /bin/ )
79-
80- #FindAvresample
81- FIND_PATH ( AVRESAMPLE_INCLUDE_DIR libavresample/avresample.h
82- PATHS /usr/include /
83- /usr/include /ffmpeg/
84- $ENV{FFMPEGDIR} /include /
85- $ENV{FFMPEGDIR} /include /ffmpeg/ )
86-
87- FIND_LIBRARY ( AVRESAMPLE_LIBRARY avresample avresample-2 avresample-3
88- PATHS /usr/lib/
89- /usr/lib/ffmpeg/
90- $ENV{FFMPEGDIR} /lib/
91- $ENV{FFMPEGDIR} /lib/ffmpeg/
92- $ENV{FFMPEGDIR} /bin/ )
93-
94- SET ( FFMPEG_FOUND FALSE )
95-
96- IF ( AVFORMAT_INCLUDE_DIR AND AVFORMAT_LIBRARY )
97- SET ( AVFORMAT_FOUND TRUE )
98- ENDIF ( AVFORMAT_INCLUDE_DIR AND AVFORMAT_LIBRARY )
99-
100- IF ( AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY )
101- SET ( AVCODEC_FOUND TRUE )
102- ENDIF ( AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY )
103-
104- IF ( AVUTIL_INCLUDE_DIR AND AVUTIL_LIBRARY )
105- SET ( AVUTIL_FOUND TRUE )
106- ENDIF ( AVUTIL_INCLUDE_DIR AND AVUTIL_LIBRARY )
107-
108- IF ( AVDEVICE_INCLUDE_DIR AND AVDEVICE_LIBRARY )
109- SET ( AVDEVICE_FOUND TRUE )
110- ENDIF ( AVDEVICE_INCLUDE_DIR AND AVDEVICE_LIBRARY )
111-
112- IF ( SWSCALE_INCLUDE_DIR AND SWSCALE_LIBRARY )
113- SET ( SWSCALE_FOUND TRUE )
114- ENDIF ( SWSCALE_INCLUDE_DIR AND SWSCALE_LIBRARY )
115-
116- IF ( AVRESAMPLE_INCLUDE_DIR AND AVRESAMPLE_LIBRARY )
117- SET ( AVRESAMPLE_FOUND TRUE )
118- ENDIF ( AVRESAMPLE_INCLUDE_DIR AND AVRESAMPLE_LIBRARY )
119-
120- IF ( AVFORMAT_INCLUDE_DIR OR AVCODEC_INCLUDE_DIR OR AVUTIL_INCLUDE_DIR OR AVDEVICE_FOUND OR SWSCALE_FOUND OR AVRESAMPLE_FOUND )
121-
122- SET ( FFMPEG_FOUND TRUE )
123-
124- SET ( FFMPEG_INCLUDE_DIR
125- ${AVFORMAT_INCLUDE_DIR}
126- ${AVCODEC_INCLUDE_DIR}
127- ${AVUTIL_INCLUDE_DIR}
128- ${AVDEVICE_INCLUDE_DIR}
129- ${SWSCALE_INCLUDE_DIR}
130- ${AVRESAMPLE_INCLUDE_DIR} )
131-
132- SET ( FFMPEG_LIBRARIES
133- ${AVFORMAT_LIBRARY}
134- ${AVCODEC_LIBRARY}
135- ${AVUTIL_LIBRARY}
136- ${AVDEVICE_LIBRARY}
137- ${SWSCALE_LIBRARY}
138- ${AVRESAMPLE_LIBRARY} )
139-
140- ENDIF ( AVFORMAT_INCLUDE_DIR OR AVCODEC_INCLUDE_DIR OR AVUTIL_INCLUDE_DIR OR AVDEVICE_FOUND OR SWSCALE_FOUND OR AVRESAMPLE_FOUND )
141-
142- MARK_AS_ADVANCED (
143- FFMPEG_LIBRARY_DIR
144- FFMPEG_INCLUDE_DIR
145- )
5+ # FFMPEG_FOUND - System has the all required components.
6+ # FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
7+ # FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
8+ # FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
9+ #
10+ # For each of the components it will additionally set.
11+ # - AVCODEC
12+ # - AVDEVICE
13+ # - AVFORMAT
14+ # - AVFILTER
15+ # - AVUTIL
16+ # - POSTPROC
17+ # - SWSCALE
18+ # - SWRESAMPLE
19+ # - AVRESAMPLE
20+ # the following variables will be defined
21+ # <component>_FOUND - System has <component>
22+ # <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
23+ # <component>_LIBRARIES - Link these to use <component>
24+ # <component>_DEFINITIONS - Compiler switches required for using <component>
25+ # <component>_VERSION - The components version
26+ #
27+ # Copyright (c) 2006, Matthias Kretz, <[email protected] > 28+ # Copyright (c) 2008, Alexander Neundorf, <[email protected] > 29+ # Copyright (c) 2011, Michael Jansen, <[email protected] > 30+ #
31+ # Redistribution and use is allowed according to the terms of the BSD license.
32+ # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
14633
14734include (FindPackageHandleStandardArgs)
148- # handle the QUIETLY and REQUIRED arguments and set FFMPEG_FOUND to TRUE
149- # if all listed variables are TRUE
150- find_package_handle_standard_args(FFMPEG DEFAULT_MSG
151- FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIR)
35+
36+ # The default components were taken from a survey over other FindFFMPEG.cmake files
37+ if (NOT FFmpeg_FIND_COMPONENTS)
38+ set (FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
39+ endif ()
40+
41+ #
42+ ### Macro: set_component_found
43+ #
44+ # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
45+ #
46+ macro (set_component_found _component )
47+ if (${_component} _LIBRARIES AND ${_component} _INCLUDE_DIRS)
48+ # message(STATUS " - ${_component} found.")
49+ set (${_component} _FOUND TRUE )
50+ else ()
51+ # message(STATUS " - ${_component} not found.")
52+ endif ()
53+ endmacro ()
54+
55+ #
56+ ### Macro: find_component
57+ #
58+ # Checks for the given component by invoking pkgconfig and then looking up the libraries and
59+ # include directories.
60+ #
61+ macro (find_component _component _pkgconfig _library _header)
62+
63+ if (NOT WIN32 )
64+ # use pkg-config to get the directories and then use these values
65+ # in the FIND_PATH() and FIND_LIBRARY() calls
66+ find_package (PkgConfig)
67+ if (PKG_CONFIG_FOUND)
68+ pkg_check_modules(PC_${_component} ${_pkgconfig} )
69+ endif ()
70+ endif (NOT WIN32 )
71+
72+ find_path (${_component} _INCLUDE_DIRS ${_header}
73+ HINTS
74+ /opt/
75+ /opt/include /
76+ ${PC_LIB${_component} _INCLUDEDIR}
77+ ${PC_LIB${_component} _INCLUDE_DIRS}
78+ $ENV{FFMPEGDIR} /include /
79+ $ENV{FFMPEGDIR} /include /ffmpeg/
80+ PATH_SUFFIXES
81+ ffmpeg
82+ )
83+
84+ find_library (${_component} _LIBRARIES NAMES ${_library}
85+ HINTS
86+ ${PC_LIB${_component} _LIBDIR}
87+ ${PC_LIB${_component} _LIBRARY_DIRS}
88+ $ENV{FFMPEGDIR} /lib/
89+ $ENV{FFMPEGDIR} /lib/ffmpeg/
90+ $ENV{FFMPEGDIR} /bin/
91+ )
92+
93+ set (${_component} _DEFINITIONS ${PC_${_component} _CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS." )
94+ set (${_component} _VERSION ${PC_${_component} _VERSION} CACHE STRING "The ${_component} version number." )
95+
96+ set_component_found(${_component} )
97+
98+ mark_as_advanced (
99+ ${_component} _INCLUDE_DIRS
100+ ${_component} _LIBRARIES
101+ ${_component} _DEFINITIONS
102+ ${_component} _VERSION)
103+
104+ endmacro ()
105+
106+
107+ # Check for cached results. If there are skip the costly part.
108+ if (NOT FFMPEG_LIBRARIES)
109+
110+ # Check for all possible component.
111+ find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
112+ find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
113+ find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
114+ find_component(AVUTIL libavutil avutil libavutil/avutil.h)
115+ find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
116+ find_component(SWSCALE libswscale swscale libswscale/swscale.h)
117+ find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
118+ find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
119+ find_component(AVRESAMPLE libavresample avresample libavresample/avresample.h)
120+
121+ # Check if the required components were found and add their stuff to the FFMPEG_* vars.
122+ foreach (_component ${FFmpeg_FIND_COMPONENTS} )
123+ if (${_component} _FOUND)
124+ # message(STATUS "Required component ${_component} present.")
125+ set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component} _LIBRARIES})
126+ set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component} _DEFINITIONS})
127+ list (APPEND FFMPEG_INCLUDE_DIRS ${${_component} _INCLUDE_DIRS})
128+ else ()
129+ # message(STATUS "Required component ${_component} missing.")
130+ endif ()
131+ endforeach ()
132+
133+ # Build the include path with duplicates removed.
134+ if (FFMPEG_INCLUDE_DIRS)
135+ list (REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
136+ endif ()
137+
138+ # cache the vars.
139+ set (FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
140+ set (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
141+ set (FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
142+
143+ mark_as_advanced (FFMPEG_INCLUDE_DIRS
144+ FFMPEG_LIBRARIES
145+ FFMPEG_DEFINITIONS)
146+
147+ endif ()
148+
149+ # Now set the noncached _FOUND vars for the components.
150+ foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE SWRESAMPLE AVRESAMPLE)
151+ set_component_found(${_component} )
152+ endforeach ()
153+
154+ # Compile the list of required vars
155+ set (_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
156+ foreach (_component ${FFmpeg_FIND_COMPONENTS} )
157+ list (APPEND _FFmpeg_REQUIRED_VARS ${_component} _LIBRARIES ${_component} _INCLUDE_DIRS)
158+ endforeach ()
159+
160+ # Give a nice error message if some of the required vars are missing.
161+ find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS} )
0 commit comments