summarylogtreecommitdiffstats
path: root/ppsspp-ffmpeg.patch
blob: 87d278065a9aebe517f49b65c263fe42f66ce5ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
From 983ae517e17a635e21a84a8abdff338e1805f33b Mon Sep 17 00:00:00 2001
From: Maxime Gauduin <alucryd@gmail.com>
Date: Mon, 1 Jun 2015 15:29:54 +0200
Subject: [PATCH] Try to dynamically link against system ffmpeg when possible

---
 CMakeLists.txt              | 192 ++++++++++++++++++++++++--------------------
 CMakeTests/FindFFMPEG.cmake | 167 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 271 insertions(+), 88 deletions(-)
 create mode 100644 CMakeTests/FindFFMPEG.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb66586..00cf33a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -98,6 +98,7 @@ option(UNITTEST "Set to ON to generate the unittest target" ${UNITTEST})
 option(SIMULATOR "Set to ON when targeting an x86 simulator of an ARM platform" ${SIMULATOR})
 # :: Options
 option(USE_FFMPEG "Build with FFMPEG support" ${USE_FFMPEG})
+option(USE_SYSTEM_FFMPEG "Dynamically link against system FFMPEG" ${USE_SYSTEM_FFMPEG})
 
 if(ANDROID OR BLACKBERRY OR IOS)
 	if (NOT CMAKE_TOOLCHAIN_FILE)
@@ -411,96 +412,101 @@ add_library(stb_vorbis STATIC
 	native/ext/stb_vorbis/stb_vorbis.h)
 include_directories(native/ext/stb_vorbis)
 
-if(USE_FFMPEG AND NOT DEFINED FFMPEG_BUILDDIR)
-	if(ANDROID)
-		if(ARMV7)
-			set(PLATFORM_ARCH "android/armv7")
-		elseif(ARM)
-			set(PLATFORM_ARCH "android/arm")
-		elseif(X86)
-			set(PLATFORM_ARCH "android/x86")
-		endif()
-	elseif(BLACKBERRY)
-		set(PLATFORM_ARCH "blackberry/armv7")
-	elseif(IOS)
-		set(PLATFORM_ARCH "ios/universal")
-	elseif(MACOSX)
-		set(PLATFORM_ARCH "macosx/x86_64")
-	elseif(LINUX)
-		if(ARMV7)
-			set(PLATFORM_ARCH "linux/armv7")
-		elseif(ARM)
-			set(PLATFORM_ARCH "linux/arm")
-		elseif(MIPS)
-			set(PLATFORM_ARCH "linux/mips32")
-		elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
-			set(PLATFORM_ARCH "linux/x86_64")
-		else()
-			set(PLATFORM_ARCH "linux/x86")
-		endif()
-	endif()
-	# Using static libraries
-	if (DEFINED PLATFORM_ARCH)
-		include_directories(ffmpeg/${PLATFORM_ARCH}/include)
-		link_directories(ffmpeg/${PLATFORM_ARCH}/lib)
-		set(FFMPEG_LIBRARIES libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a)
+if(USE_FFMPEG)
+	if(USE_SYSTEM_FFMPEG)
+		include(FindFFMPEG)
 	else()
-		# Manual definition of system library locations by the user.
-		if (DEFINED FFMPEG_INCLUDE_PATH)
-			include_directories(ffmpeg ${FFMPEG_INCLUDE_PATH})
-		endif()
-		if (DEFINED AVFORMAT_PATH)
+		set(FFMPEG_FOUND OFF)
+	endif()
+	if(NOT FFMPEG_FOUND)
+		if(NOT DEFINED FFMPEG_BUILDDIR)
+			if(ANDROID)
+				if(ARMV7)
+					set(PLATFORM_ARCH "android/armv7")
+				elseif(ARM)
+					set(PLATFORM_ARCH "android/arm")
+				elseif(X86)
+					set(PLATFORM_ARCH "android/x86")
+				endif()
+			elseif(BLACKBERRY)
+				set(PLATFORM_ARCH "blackberry/armv7")
+			elseif(IOS)
+				set(PLATFORM_ARCH "ios/universal")
+			elseif(MACOSX)
+				set(PLATFORM_ARCH "macosx/x86_64")
+			elseif(LINUX)
+				if(ARMV7)
+					set(PLATFORM_ARCH "linux/armv7")
+				elseif(ARM)
+					set(PLATFORM_ARCH "linux/arm")
+				elseif(MIPS)
+					set(PLATFORM_ARCH "linux/mips32")
+				elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
+					set(PLATFORM_ARCH "linux/x86_64")
+				else()
+					set(PLATFORM_ARCH "linux/x86")
+				endif()
+			endif()
+			# Using static libraries
+			if (DEFINED PLATFORM_ARCH)
+				include_directories(ffmpeg/${PLATFORM_ARCH}/include)
+				link_directories(ffmpeg/${PLATFORM_ARCH}/lib)
+				set(FFMPEG_LIBRARIES libavformat.a libavcodec.a libavutil.a libswresample.a libswscale.a)
+			else()
+				# Manual definition of system library locations by the user.
+				if (DEFINED FFMPEG_INCLUDE_PATH)
+					include_directories(ffmpeg ${FFMPEG_INCLUDE_PATH})
+				endif()
+				if (DEFINED AVFORMAT_PATH)
+					add_library(libavformat STATIC IMPORTED)
+					set_target_properties(libavformat PROPERTIES IMPORTED_LOCATION ${AVFORMAT_PATH})
+					SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libavformat)
+				endif()
+				if (DEFINED AVCODEC_PATH)
+					add_library(libavcodec STATIC IMPORTED)
+					set_target_properties(libavcodec PROPERTIES IMPORTED_LOCATION ${AVCODEC_PATH})
+					SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libavcodec)
+				endif()
+				if (DEFINED AVUTIL_PATH)
+					add_library(libavutil STATIC IMPORTED)
+					set_target_properties(libavutil PROPERTIES IMPORTED_LOCATION ${AVUTIL_PATH})
+					SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libavutil)
+				endif()
+				if (DEFINED SWRESAMPLE_PATH)
+					add_library(libswresample STATIC IMPORTED)
+					set_target_properties(libswresample PROPERTIES IMPORTED_LOCATION ${SWRESAMPLE_PATH})
+					SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libswresample)
+				endif()
+				if (DEFINED SWSCALE_PATH)
+					add_library(libswscale STATIC IMPORTED)
+					set_target_properties(libswscale PROPERTIES IMPORTED_LOCATION ${SWSCALE_PATH})
+					SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libswscale)
+				endif()
+			endif(DEFINED PLATFORM_ARCH)
+		else(NOT DEFINED FFMPEG_BUILDDIR)
+			# Using shared libraries
+			include_directories(ffmpeg ${FFMPEG_BUILDDIR})
+
 			add_library(libavformat STATIC IMPORTED)
-			set_target_properties(libavformat PROPERTIES IMPORTED_LOCATION ${AVFORMAT_PATH})
-			SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libavformat)
-		endif()
-		if (DEFINED AVCODEC_PATH)
+			set_target_properties(libavformat PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libavformat/libavformat.a)
 			add_library(libavcodec STATIC IMPORTED)
-			set_target_properties(libavcodec PROPERTIES IMPORTED_LOCATION ${AVCODEC_PATH})
-			SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libavcodec)
-		endif()
-		if (DEFINED AVUTIL_PATH)
+			set_target_properties(libavcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libavcodec/libavcodec.a)
 			add_library(libavutil STATIC IMPORTED)
-			set_target_properties(libavutil PROPERTIES IMPORTED_LOCATION ${AVUTIL_PATH})
-			SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libavutil)
-		endif()
-		if (DEFINED SWRESAMPLE_PATH)
+			set_target_properties(libavutil PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libavutil/libavutil.a)
 			add_library(libswresample STATIC IMPORTED)
-			set_target_properties(libswresample PROPERTIES IMPORTED_LOCATION ${SWRESAMPLE_PATH})
-			SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libswresample)
-		endif()
-		if (DEFINED SWSCALE_PATH)
+			set_target_properties(libswresample PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libswresample/libswresample.a)
 			add_library(libswscale STATIC IMPORTED)
-			set_target_properties(libswscale PROPERTIES IMPORTED_LOCATION ${SWSCALE_PATH})
-			SET (FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} libswscale)
-		endif()
-	endif(DEFINED PLATFORM_ARCH)
-endif(USE_FFMPEG AND NOT DEFINED FFMPEG_BUILDDIR)
-
-if(USE_FFMPEG)
-	# Using shared libraries
-	if(DEFINED FFMPEG_BUILDDIR)
-		include_directories(ffmpeg ${FFMPEG_BUILDDIR})
-
-		add_library(libavformat STATIC IMPORTED)
-		set_target_properties(libavformat PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libavformat/libavformat.a)
-		add_library(libavcodec STATIC IMPORTED)
-		set_target_properties(libavcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libavcodec/libavcodec.a)
-		add_library(libavutil STATIC IMPORTED)
-		set_target_properties(libavutil PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libavutil/libavutil.a)
-		add_library(libswresample STATIC IMPORTED)
-		set_target_properties(libswresample PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libswresample/libswresample.a)
-		add_library(libswscale STATIC IMPORTED)
-		set_target_properties(libswscale PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libswscale/libswscale.a)
-
-		SET (FFMPEG_LIBRARIES
-			libavformat
-			libavcodec
-			libavutil
-			libswresample
-			libswscale
-		)
-	endif()
+			set_target_properties(libswscale PROPERTIES IMPORTED_LOCATION ${FFMPEG_BUILDDIR}/libswscale/libswscale.a)
+
+			SET (FFMPEG_LIBRARIES
+				libavformat
+				libavcodec
+				libavutil
+				libswresample
+				libswscale
+			)
+		endif(NOT DEFINED FFMPEG_BUILDDIR)
+	endif(NOT FFMPEG_FOUND)
 
 	find_library(ICONV_LIBRARY NAMES iconv)
 	if (ICONV_LIBRARY)
@@ -514,15 +520,25 @@ if(USE_FFMPEG)
 		endif()
 	endif(APPLE)
 
-	set(LinkCommon ${LinkCommon} ${FFMPEG_LIBRARIES})
+	if(FFMPEG_FOUND)
+		set(nativeExtraLibs ${nativeExtraLibs} ${FFMPEG_LIBRARIES})
+	else()
+		set(LinkCommon ${LinkCommon} ${FFMPEG_LIBRARIES})
+	endif()
+	target_link_libraries(Common ${FFMPEG_LIBRARIES})
 	add_definitions(-DUSE_FFMPEG)
 endif(USE_FFMPEG)
 
 # Modification to show where we are pulling the ffmpeg libraries from.
 if(USE_FFMPEG AND DEFINED FFMPEG_LIBRARIES)
-	target_link_libraries(Common ${FFMPEG_LIBRARIES})
 	message(STATUS "FFMPEG library locations:")
-	if(DEFINED PLATFORM_ARCH)
+	if(FFMPEG_FOUND)
+		message(STATUS "libavcodec location: ${FFMPEG_avcodec_LIBRARY}")
+		message(STATUS "libavformat location: ${FFMPEG_avformat_LIBRARY}")
+		message(STATUS "libavutil location: ${FFMPEG_avutil_LIBRARY}")
+		message(STATUS "libswresample location: ${FFMPEG_swresample_LIBRARY}")
+		message(STATUS "libswscale location: ${FFMPEG_swscale_LIBRARY}")
+	elseif(DEFINED PLATFORM_ARCH)
 		set(TEMP ${CMAKE_SOURCE_DIR}/ffmpeg/${PLATFORM_ARCH}/lib)
 		message(STATUS "libavcodec location: ${TEMP}/libavcodec.a")
 		message(STATUS "libavformat location: ${TEMP}/libavformat.a")
@@ -540,7 +556,7 @@ if(USE_FFMPEG AND DEFINED FFMPEG_LIBRARIES)
 		message(STATUS "libswresample location: ${TEMP}")
 		get_target_property(TEMP libswscale IMPORTED_LOCATION)
 		message(STATUS "libswscale location: ${TEMP}")
-	endif(DEFINED PLATFORM_ARCH)
+	endif()
 else()
 	message(STATUS "ERROR: No FFMPEG library locations")
 endif()
diff --git a/CMakeTests/FindFFMPEG.cmake b/CMakeTests/FindFFMPEG.cmake
new file mode 100644
index 0000000..8fac08f
--- /dev/null
+++ b/CMakeTests/FindFFMPEG.cmake
@@ -0,0 +1,167 @@
+# FindFFMPEG
+# ----------
+#
+# Find the native FFMPEG includes and libraries
+#
+# This module defines:
+#
+#  FFMPEG_INCLUDE_DIR, where to find avformat.h, avcodec.h...
+#  FFMPEG_LIBRARIES, the libraries to link against to use FFMPEG.
+#  FFMPEG_FOUND, If false, do not try to use FFMPEG.
+#
+# also defined, but not for general use are:
+#
+#   FFMPEG_avformat_LIBRARY, where to find the FFMPEG avformat library.
+#   FFMPEG_avcodec_LIBRARY, where to find the FFMPEG avcodec library.
+#
+# This is useful to do it this way so that we can always add more libraries
+# if needed to ``FFMPEG_LIBRARIES`` if ffmpeg ever changes...
+
+#=============================================================================
+# Copyright: 1993-2008 Ken Martin, Will Schroeder, Bill Lorensen
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of ppsspp, substitute the full
+#  License text for the above reference.)
+
+find_path(FFMPEG_INCLUDE_DIR1 avformat.h
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/ffmpeg
+  $ENV{FFMPEG_DIR}/libavformat
+  $ENV{FFMPEG_DIR}/include/libavformat
+  $ENV{FFMPEG_DIR}/include/ffmpeg
+  /usr/local/include/ffmpeg
+  /usr/include/ffmpeg
+  /usr/include/libavformat
+  /usr/include/ffmpeg/libavformat
+  /usr/local/include/libavformat
+)
+
+find_path(FFMPEG_INCLUDE_DIR2 avcodec.h
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/ffmpeg
+  $ENV{FFMPEG_DIR}/libavcodec
+  $ENV{FFMPEG_DIR}/include/libavcodec
+  $ENV{FFMPEG_DIR}/include/ffmpeg
+  /usr/local/include/ffmpeg
+  /usr/include/ffmpeg
+  /usr/include/libavcodec
+  /usr/include/ffmpeg/libavcodec
+  /usr/local/include/libavcodec
+)
+
+find_path(FFMPEG_INCLUDE_DIR3 avutil.h
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/ffmpeg
+  $ENV{FFMPEG_DIR}/libavutil
+  $ENV{FFMPEG_DIR}/include/libavutil
+  $ENV{FFMPEG_DIR}/include/ffmpeg
+  /usr/local/include/ffmpeg
+  /usr/include/ffmpeg
+  /usr/include/libavutil
+  /usr/include/ffmpeg/libavutil
+  /usr/local/include/libavutil
+)
+
+find_path(FFMPEG_INCLUDE_DIR4 swresample.h
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/ffmpeg
+  $ENV{FFMPEG_DIR}/libswresample
+  $ENV{FFMPEG_DIR}/include/libswresample
+  $ENV{FFMPEG_DIR}/include/ffmpeg
+  /usr/local/include/ffmpeg
+  /usr/include/ffmpeg
+  /usr/include/libswresample
+  /usr/include/ffmpeg/libswresample
+  /usr/local/include/libswresample
+)
+
+find_path(FFMPEG_INCLUDE_DIR5 swscale.h
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/ffmpeg
+  $ENV{FFMPEG_DIR}/libswscale
+  $ENV{FFMPEG_DIR}/include/libswscale
+  $ENV{FFMPEG_DIR}/include/ffmpeg
+  /usr/local/include/ffmpeg
+  /usr/include/ffmpeg
+  /usr/include/libswscale
+  /usr/include/ffmpeg/libswscale
+  /usr/local/include/libswscale
+)
+
+if(FFMPEG_INCLUDE_DIR1 AND
+   FFMPEG_INCLUDE_DIR2 AND
+   FFMPEG_INCLUDE_DIR3 AND
+   FFMPEG_INCLUDE_DIR4 AND
+   FFMPEG_INCLUDE_DIR5
+)
+  set(FFMPEG_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR1}
+                         ${FFMPEG_INCLUDE_DIR2}
+                         ${FFMPEG_INCLUDE_DIR3}
+                         ${FFMPEG_INCLUDE_DIR4}
+                         ${FFMPEG_INCLUDE_DIR5}
+  )
+endif()
+
+find_library(FFMPEG_avformat_LIBRARY avformat
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/lib
+  $ENV{FFMPEG_DIR}/libavformat
+  /usr/local/lib
+  /usr/lib
+)
+
+find_library(FFMPEG_avcodec_LIBRARY avcodec
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/lib
+  $ENV{FFMPEG_DIR}/libavcodec
+  /usr/local/lib
+  /usr/lib
+)
+
+find_library(FFMPEG_avutil_LIBRARY avutil
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/lib
+  $ENV{FFMPEG_DIR}/libavutil
+  /usr/local/lib
+  /usr/lib
+)
+
+find_library(FFMPEG_swresample_LIBRARY swresample
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/lib
+  $ENV{FFMPEG_DIR}/libswresample
+  /usr/local/lib
+  /usr/lib
+)
+
+find_library(FFMPEG_swscale_LIBRARY swscale
+  $ENV{FFMPEG_DIR}
+  $ENV{FFMPEG_DIR}/lib
+  $ENV{FFMPEG_DIR}/libswscale
+  /usr/local/lib
+  /usr/lib
+)
+
+if(FFMPEG_INCLUDE_DIR)
+  if(FFMPEG_avformat_LIBRARY AND
+     FFMPEG_avcodec_LIBRARY AND
+     FFMPEG_avutil_LIBRARY AND
+     FFMPEG_swresample_LIBRARY AND
+     FFMPEG_swscale_LIBRARY
+  )
+    set(FFMPEG_FOUND "YES")
+    set(FFMPEG_LIBRARIES ${FFMPEG_avformat_LIBRARY}
+                         ${FFMPEG_avcodec_LIBRARY}
+                         ${FFMPEG_avutil_LIBRARY}
+                         ${FFMPEG_swresample_LIBRARY}
+                         ${FFMPEG_swscale_LIBRARY}
+    )
+  endif()
+endif()
-- 
2.4.2