Changeset View
Changeset View
Standalone View
Standalone View
cmake/FindFFmpeg.cmake
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
45 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 45 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
46 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 46 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 47 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
48 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 48 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
49 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 49 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
50 | # SUCH DAMAGE. | 50 | # SUCH DAMAGE. | ||
51 | 51 | | |||
52 | include(FindPackageHandleStandardArgs) | 52 | include(FindPackageHandleStandardArgs) | ||
53 | include(CheckStructHasMember) | ||||
53 | 54 | | |||
54 | # The default components were taken from a survey over other FindFFMPEG.cmake files | 55 | # The default components were taken from a survey over other FindFFMPEG.cmake files | ||
55 | if (NOT FFmpeg_FIND_COMPONENTS) | 56 | if (NOT FFmpeg_FIND_COMPONENTS) | ||
56 | set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) | 57 | set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) | ||
57 | endif () | 58 | endif () | ||
58 | 59 | | |||
59 | # | 60 | # | ||
60 | ### Macro: set_component_found | 61 | ### Macro: set_component_found | ||
61 | # | 62 | # | ||
62 | # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present. | 63 | # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present. | ||
63 | # | 64 | # | ||
64 | macro(set_component_found _component ) | 65 | macro(set_component_found _component ) | ||
65 | if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) | 66 | if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) | ||
66 | # message(STATUS " - ${_component} found.") | 67 | # message(STATUS " - ${_component} found.") | ||
67 | set(${_component}_FOUND TRUE) | 68 | set(${_component}_FOUND TRUE) | ||
69 | set(FFmpeg_${_component}_FOUND TRUE) | ||||
68 | else () | 70 | else () | ||
69 | # message(STATUS " - ${_component} not found.") | 71 | # message(STATUS " - ${_component} not found.") | ||
70 | endif () | 72 | endif () | ||
71 | endmacro() | 73 | endmacro() | ||
72 | 74 | | |||
73 | # | 75 | # | ||
74 | ### Macro: find_component | 76 | ### Macro: find_component | ||
75 | # | 77 | # | ||
76 | # Checks for the given component by invoking pkgconfig and then looking up the libraries and | 78 | # Checks for the given component by invoking pkgconfig and then looking up the libraries and | ||
77 | # include directories. | 79 | # include directories. | ||
78 | # | 80 | # | ||
79 | macro(find_component _component _pkgconfig _library _header) | 81 | macro(find_component _component _pkgconfig _library _header _version) | ||
80 | 82 | | |||
81 | if (NOT WIN32) | 83 | if (NOT WIN32) | ||
82 | # use pkg-config to get the directories and then use these values | 84 | # use pkg-config to get the directories and then use these values | ||
83 | # in the FIND_PATH() and FIND_LIBRARY() calls | 85 | # in the FIND_PATH() and FIND_LIBRARY() calls | ||
84 | find_package(PkgConfig) | 86 | find_package(PkgConfig) | ||
85 | if (PKG_CONFIG_FOUND) | 87 | if (PKG_CONFIG_FOUND) | ||
86 | pkg_check_modules(PC_${_component} ${_pkgconfig}) | 88 | pkg_check_modules(PC_${_component} ${_pkgconfig}>=${_version}) | ||
87 | endif () | 89 | endif () | ||
88 | endif (NOT WIN32) | 90 | endif (NOT WIN32) | ||
89 | 91 | | |||
90 | find_path(${_component}_INCLUDE_DIRS ${_header} | 92 | find_path(${_component}_INCLUDE_DIRS ${_header} | ||
91 | HINTS | 93 | HINTS | ||
92 | ${PC_LIB${_component}_INCLUDEDIR} | 94 | ${PC_LIB${_component}_INCLUDEDIR} | ||
93 | ${PC_LIB${_component}_INCLUDE_DIRS} | 95 | ${PC_LIB${_component}_INCLUDE_DIRS} | ||
94 | PATH_SUFFIXES | 96 | PATH_SUFFIXES | ||
Show All 14 Lines | |||||
109 | mark_as_advanced( | 111 | mark_as_advanced( | ||
110 | ${_component}_INCLUDE_DIRS | 112 | ${_component}_INCLUDE_DIRS | ||
111 | ${_component}_LIBRARIES | 113 | ${_component}_LIBRARIES | ||
112 | ${_component}_DEFINITIONS | 114 | ${_component}_DEFINITIONS | ||
113 | ${_component}_VERSION) | 115 | ${_component}_VERSION) | ||
114 | 116 | | |||
115 | endmacro() | 117 | endmacro() | ||
116 | 118 | | |||
117 | | ||||
118 | # Check for cached results. If there are skip the costly part. | 119 | # Check for cached results. If there are skip the costly part. | ||
119 | if (NOT FFMPEG_LIBRARIES) | 120 | if (NOT FFMPEG_LIBRARIES) | ||
120 | 121 | | |||
121 | # Check for all possible component. | 122 | # Check for all possible component. | ||
122 | find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) | 123 | find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h ${FFmpeg_FIND_VERSION}) | ||
123 | find_component(AVFORMAT libavformat avformat libavformat/avformat.h) | 124 | find_component(AVFORMAT libavformat avformat libavformat/avformat.h ${FFmpeg_FIND_VERSION}) | ||
124 | find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) | 125 | find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h ${FFmpeg_FIND_VERSION}) | ||
125 | find_component(AVUTIL libavutil avutil libavutil/avutil.h) | 126 | find_component(AVUTIL libavutil avutil libavutil/avutil.h ${FFmpeg_FIND_VERSION}) | ||
126 | find_component(SWSCALE libswscale swscale libswscale/swscale.h) | 127 | find_component(SWSCALE libswscale swscale libswscale/swscale.h ${FFmpeg_FIND_VERSION}) | ||
127 | find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h) | 128 | find_component(POSTPROCESS libpostproc postproc libpostproc/postprocess.h ${FFmpeg_FIND_VERSION}) | ||
128 | 129 | | |||
129 | # Check if the required components were found and add their stuff to the FFMPEG_* vars. | 130 | # Check if the required components were found and add their stuff to the FFMPEG_* vars. | ||
130 | foreach (_component ${FFmpeg_FIND_COMPONENTS}) | 131 | foreach (_component ${FFmpeg_FIND_COMPONENTS}) | ||
131 | if (${_component}_FOUND) | 132 | if (${_component}_FOUND) | ||
132 | # message(STATUS "Required component ${_component} present.") | 133 | # message(STATUS "Required component ${_component} present.") | ||
133 | set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES}) | 134 | set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES}) | ||
134 | set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS}) | 135 | set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS}) | ||
135 | list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS}) | 136 | list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS}) | ||
Show All 13 Lines | |||||
149 | set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE) | 150 | set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE) | ||
150 | 151 | | |||
151 | mark_as_advanced(FFMPEG_INCLUDE_DIRS | 152 | mark_as_advanced(FFMPEG_INCLUDE_DIRS | ||
152 | FFMPEG_LIBRARIES | 153 | FFMPEG_LIBRARIES | ||
153 | FFMPEG_DEFINITIONS) | 154 | FFMPEG_DEFINITIONS) | ||
154 | 155 | | |||
155 | endif () | 156 | endif () | ||
156 | 157 | | |||
158 | set(CMAKE_REQUIRED_INCLUDES ${AVCODEC_INCLUDE_DIRS}) | ||||
159 | CHECK_STRUCT_HAS_MEMBER(AVStream codecpar "stdint.h;libavformat/avformat.h" HAVE_AVSTREAM_CODECPAR LANGUAGE CXX) | ||||
160 | | ||||
157 | # Now set the noncached _FOUND vars for the components. | 161 | # Now set the noncached _FOUND vars for the components. | ||
158 | foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) | 162 | foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) | ||
159 | set_component_found(${_component}) | 163 | set_component_found(${_component}) | ||
160 | endforeach () | 164 | endforeach () | ||
161 | 165 | | |||
162 | # Compile the list of required vars | 166 | # Compile the list of required vars | ||
163 | set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) | 167 | set(_FFmpeg_REQUIRED_VARS HAVE_AVSTREAM_CODECPAR FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) | ||
164 | foreach (_component ${FFmpeg_FIND_COMPONENTS}) | 168 | foreach (_component ${FFmpeg_FIND_COMPONENTS}) | ||
165 | list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) | 169 | list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) | ||
166 | endforeach () | 170 | endforeach () | ||
167 | 171 | | |||
172 | | ||||
173 | | ||||
168 | # Give a nice error message if some of the required vars are missing. | 174 | # Give a nice error message if some of the required vars are missing. | ||
169 | find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) | 175 | find_package_handle_standard_args(FFmpeg | ||
176 | REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS} | ||||
177 | HANDLE_COMPONENTS) | ||||
178 | |