summaryrefslogtreecommitdiff
path: root/externals/find-modules/FindFFmpeg.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'externals/find-modules/FindFFmpeg.cmake')
-rw-r--r--externals/find-modules/FindFFmpeg.cmake247
1 files changed, 167 insertions, 80 deletions
diff --git a/externals/find-modules/FindFFmpeg.cmake b/externals/find-modules/FindFFmpeg.cmake
index 77b331e00..61b6dc8d2 100644
--- a/externals/find-modules/FindFFmpeg.cmake
+++ b/externals/find-modules/FindFFmpeg.cmake
@@ -1,100 +1,187 @@
1# - Try to find ffmpeg libraries (libavcodec, libavformat and libavutil) 1# FindFFmpeg
2# Once done this will define 2# ----------
3# 3#
4# FFMPEG_FOUND - system has ffmpeg or libav 4# Copyright 2019 Citra Emulator Project
5# FFMPEG_INCLUDE_DIR - the ffmpeg include directory 5# Licensed under GPLv2 or any later version
6# FFMPEG_LIBRARIES - Link these to use ffmpeg
7# FFMPEG_LIBAVCODEC
8# FFMPEG_LIBAVFORMAT
9# FFMPEG_LIBAVUTIL
10# 6#
11# Copyright (c) 2008 Andreas Schneider <mail@cynapses.org> 7# Find the native FFmpeg includes and libraries
12# Modified for other libraries by Lasse Kärkkäinen <tronic>
13# Modified for Hedgewars by Stepik777
14# Modified for FFmpeg-example Tuukka Pasanen 2018
15# Modified for yuzu toastUnlimted 2020
16# 8#
17# Redistribution and use is allowed according to the terms of the New 9# This module defines the following variables:
18# BSD license. 10#
11# FFmpeg_INCLUDE_<component>: where to find <component>.h
12# FFmpeg_LIBRARY_<component>: where to find the <component> library
13# FFmpeg_INCLUDE_DIR: aggregate all the include paths
14# FFmpeg_LIBRARIES: aggregate all the paths to the libraries
15# FFmpeg_FOUND: True if all components have been found
16#
17# This module defines the following targets, which are prefered over variables:
18#
19# FFmpeg::<component>: Target to use <component> directly, with include path,
20# library and dependencies set up. If you are using a static build, you are
21# responsible for adding any external dependencies (such as zlib, bzlib...).
22#
23# <component> can be one of:
24# avcodec
25# avdevice
26# avfilter
27# avformat
28# avutil
29# postproc
30# swresample
31# swscale
19# 32#
20 33
21include(FindPackageHandleStandardArgs) 34set(_FFmpeg_ALL_COMPONENTS
22 35 avcodec
23find_package_handle_standard_args(FFMPEG 36 avdevice
24 FOUND_VAR FFMPEG_FOUND 37 avfilter
25 REQUIRED_VARS 38 avformat
26 FFMPEG_LIBRARY 39 avutil
27 FFMPEG_INCLUDE_DIR 40 postproc
28 VERSION_VAR FFMPEG_VERSION 41 swresample
42 swscale
29) 43)
30 44
31if(FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR) 45set(_FFmpeg_DEPS_avcodec avutil)
32 # in cache already 46set(_FFmpeg_DEPS_avdevice avcodec avformat avutil)
33 set(FFMPEG_FOUND TRUE) 47set(_FFmpeg_DEPS_avfilter avutil)
34else() 48set(_FFmpeg_DEPS_avformat avcodec avutil)
35 # use pkg-config to get the directories and then use these values 49set(_FFmpeg_DEPS_postproc avutil)
36 # in the FIND_PATH() and FIND_LIBRARY() calls 50set(_FFmpeg_DEPS_swresample avutil)
37 find_package(PkgConfig) 51set(_FFmpeg_DEPS_swscale avutil)
38 if(PKG_CONFIG_FOUND) 52
39 pkg_check_modules(_FFMPEG_AVCODEC libavcodec) 53function(find_ffmpeg LIBNAME)
40 pkg_check_modules(_FFMPEG_AVUTIL libavutil) 54 if(DEFINED ENV{FFMPEG_DIR})
41 pkg_check_modules(_FFMPEG_SWSCALE libswscale) 55 set(FFMPEG_DIR $ENV{FFMPEG_DIR})
42 endif() 56 endif()
43 57
44 find_path(FFMPEG_AVCODEC_INCLUDE_DIR 58 if(FFMPEG_DIR)
45 NAMES libavcodec/avcodec.h 59 list(APPEND INCLUDE_PATHS
46 PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS} 60 ${FFMPEG_DIR}
47 /usr/include 61 ${FFMPEG_DIR}/ffmpeg
48 /usr/local/include 62 ${FFMPEG_DIR}/lib${LIBNAME}
49 /opt/local/include 63 ${FFMPEG_DIR}/include/lib${LIBNAME}
50 /sw/include 64 ${FFMPEG_DIR}/include/ffmpeg
51 PATH_SUFFIXES ffmpeg libav) 65 ${FFMPEG_DIR}/include
52 66 NO_DEFAULT_PATH
53 find_library(FFMPEG_LIBAVCODEC 67 NO_CMAKE_FIND_ROOT_PATH
54 NAMES avcodec 68 )
55 PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS} 69 list(APPEND LIB_PATHS
56 /usr/lib 70 ${FFMPEG_DIR}
57 /usr/local/lib 71 ${FFMPEG_DIR}/lib
58 /opt/local/lib 72 ${FFMPEG_DIR}/lib${LIBNAME}
59 /sw/lib) 73 NO_DEFAULT_PATH
74 NO_CMAKE_FIND_ROOT_PATH
75 )
76 else()
77 list(APPEND INCLUDE_PATHS
78 /usr/local/include/ffmpeg
79 /usr/local/include/lib${LIBNAME}
80 /usr/include/ffmpeg
81 /usr/include/lib${LIBNAME}
82 /usr/include/ffmpeg/lib${LIBNAME}
83 )
60 84
61 find_library(FFMPEG_LIBAVUTIL 85 list(APPEND LIB_PATHS
62 NAMES avutil
63 PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
64 /usr/lib
65 /usr/local/lib 86 /usr/local/lib
66 /opt/local/lib
67 /sw/lib)
68
69 find_library(FFMPEG_LIBSWSCALE
70 NAMES swscale
71 PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS}
72 /usr/lib 87 /usr/lib
73 /usr/local/lib 88 )
74 /opt/local/lib
75 /sw/lib)
76
77 if(FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE)
78 set(FFMPEG_FOUND TRUE)
79 endif() 89 endif()
80 90
81 if(FFMPEG_FOUND) 91 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
82 set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR}) 92 HINTS ${INCLUDE_PATHS}
83 set(FFMPEG_LIBRARIES 93 )
84 ${FFMPEG_LIBAVCODEC} 94
85 ${FFMPEG_LIBAVUTIL} 95 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
86 ${FFMPEG_LIBSWSCALE}) 96 HINTS ${LIB_PATHS}
97 )
98
99 if(NOT FFMPEG_DIR AND (NOT FFmpeg_LIBRARY_${LIBNAME} OR NOT FFmpeg_INCLUDE_${LIBNAME}))
100 # Didn't find it in the usual paths, try pkg-config
101 find_package(PkgConfig QUIET)
102 pkg_check_modules(FFmpeg_PKGCONFIG_${LIBNAME} QUIET lib${LIBNAME})
103
104 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
105 ${FFmpeg_PKGCONFIG_${LIBNAME}_INCLUDE_DIRS}
106 )
107
108 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
109 ${FFmpeg_PKGCONFIG_${LIBNAME}_LIBRARY_DIRS}
110 )
87 endif() 111 endif()
88 112
89 if(FFMPEG_FOUND) 113 if(FFmpeg_INCLUDE_${LIBNAME} AND FFmpeg_LIBRARY_${LIBNAME})
90 if(NOT FFMPEG_FIND_QUIETLY) 114 set(FFmpeg_INCLUDE_${LIBNAME} "${FFmpeg_INCLUDE_${LIBNAME}}" PARENT_SCOPE)
91 message(STATUS 115 set(FFmpeg_LIBRARY_${LIBNAME} "${FFmpeg_LIBRARY_${LIBNAME}}" PARENT_SCOPE)
92 "Found FFMPEG or Libav: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}") 116
117 # Extract FFmpeg version from version.h
118 foreach(v MAJOR MINOR MICRO)
119 set(FFmpeg_${LIBNAME}_VERSION_${v} 0)
120 endforeach()
121 string(TOUPPER ${LIBNAME} LIBNAME_UPPER)
122 file(STRINGS "${FFmpeg_INCLUDE_${LIBNAME}}/lib${LIBNAME}/version.h" _FFmpeg_VERSION_H_CONTENTS REGEX "#define LIB${LIBNAME_UPPER}_VERSION_(MAJOR|MINOR|MICRO) ")
123 set(_FFmpeg_VERSION_REGEX "([0-9]+)")
124 foreach(v MAJOR MINOR MICRO)
125 if("${_FFmpeg_VERSION_H_CONTENTS}" MATCHES "#define LIB${LIBNAME_UPPER}_VERSION_${v}[\\t ]+${_FFmpeg_VERSION_REGEX}")
126 set(FFmpeg_${LIBNAME}_VERSION_${v} "${CMAKE_MATCH_1}")
127 endif()
128 endforeach()
129 set(FFmpeg_${LIBNAME}_VERSION "${FFmpeg_${LIBNAME}_VERSION_MAJOR}.${FFmpeg_${LIBNAME}_VERSION_MINOR}.${FFmpeg_${LIBNAME}_VERSION_MICRO}")
130 set(FFmpeg_${c}_VERSION "${FFmpeg_${LIBNAME}_VERSION}" PARENT_SCOPE)
131 unset(_FFmpeg_VERSION_REGEX)
132 unset(_FFmpeg_VERSION_H_CONTENTS)
133
134 set(FFmpeg_${c}_FOUND TRUE PARENT_SCOPE)
135 if(NOT FFmpeg_FIND_QUIETLY)
136 message("-- Found ${LIBNAME}: ${FFmpeg_INCLUDE_${LIBNAME}} ${FFmpeg_LIBRARY_${LIBNAME}} (version: ${FFmpeg_${LIBNAME}_VERSION})")
93 endif() 137 endif()
94 else() 138 endif()
95 if(FFMPEG_FIND_REQUIRED) 139endfunction()
96 message(FATAL_ERROR 140
97 "Could not find libavcodec or libavutil or libswscale") 141foreach(c ${_FFmpeg_ALL_COMPONENTS})
142 find_ffmpeg(${c})
143endforeach()
144
145foreach(c ${_FFmpeg_ALL_COMPONENTS})
146 if(FFmpeg_${c}_FOUND)
147 list(APPEND FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_${c}})
148 list(APPEND FFmpeg_LIBRARIES ${FFmpeg_LIBRARY_${c}})
149
150 add_library(FFmpeg::${c} IMPORTED UNKNOWN)
151 set_target_properties(FFmpeg::${c} PROPERTIES
152 IMPORTED_LOCATION ${FFmpeg_LIBRARY_${c}}
153 INTERFACE_INCLUDE_DIRECTORIES ${FFmpeg_INCLUDE_${c}}
154 )
155 if(_FFmpeg_DEPS_${c})
156 set(deps)
157 foreach(dep ${_FFmpeg_DEPS_${c}})
158 list(APPEND deps FFmpeg::${dep})
159 endforeach()
160
161 set_target_properties(FFmpeg::${c} PROPERTIES
162 INTERFACE_LINK_LIBRARIES "${deps}"
163 )
164 unset(deps)
98 endif() 165 endif()
99 endif() 166 endif()
167endforeach()
168
169if(FFmpeg_INCLUDE_DIR)
170 list(REMOVE_DUPLICATES FFmpeg_INCLUDE_DIR)
100endif() 171endif()
172
173foreach(c ${FFmpeg_FIND_COMPONENTS})
174 list(APPEND _FFmpeg_REQUIRED_VARS FFmpeg_INCLUDE_${c} FFmpeg_LIBRARY_${c})
175endforeach()
176
177include(FindPackageHandleStandardArgs)
178find_package_handle_standard_args(FFmpeg
179 REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS}
180 HANDLE_COMPONENTS
181)
182
183foreach(c ${_FFmpeg_ALL_COMPONENTS})
184 unset(_FFmpeg_DEPS_${c})
185endforeach()
186unset(_FFmpeg_ALL_COMPONENTS)
187unset(_FFmpeg_REQUIRED_VARS)