summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt82
-rw-r--r--externals/find-modules/FindFFmpeg.cmake242
-rw-r--r--src/video_core/CMakeLists.txt4
3 files changed, 207 insertions, 121 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aafe73c44..fc3e93f80 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -391,45 +391,45 @@ if (YUZU_USE_BUNDLED_FFMPEG)
391 # Build FFmpeg from externals 391 # Build FFmpeg from externals
392 message(STATUS "Using FFmpeg from externals") 392 message(STATUS "Using FFmpeg from externals")
393 393
394 set(FFMPEG_PREFIX ${PROJECT_SOURCE_DIR}/externals/ffmpeg) 394 set(FFmpeg_PREFIX ${PROJECT_SOURCE_DIR}/externals/ffmpeg)
395 set(FFMPEG_BUILD_DIR ${PROJECT_BINARY_DIR}/externals/ffmpeg) 395 set(FFmpeg_BUILD_DIR ${PROJECT_BINARY_DIR}/externals/ffmpeg)
396 set(FFMPEG_MAKEFILE ${FFMPEG_BUILD_DIR}/Makefile) 396 set(FFmpeg_MAKEFILE ${FFmpeg_BUILD_DIR}/Makefile)
397 make_directory(${FFMPEG_BUILD_DIR}) 397 make_directory(${FFmpeg_BUILD_DIR})
398 398
399 # Read version string from external 399 # Read version string from external
400 file(READ ${FFMPEG_PREFIX}/RELEASE FFMPEG_VERSION) 400 file(READ ${FFmpeg_PREFIX}/RELEASE FFmpeg_VERSION)
401 set(FFMPEG_FOUND NO) 401 set(FFmpeg_FOUND NO)
402 if (NOT FFMPEG_VERSION STREQUAL "") 402 if (NOT FFmpeg_VERSION STREQUAL "")
403 set(FFMPEG_FOUND YES) 403 set(FFmpeg_FOUND YES)
404 endif() 404 endif()
405 405
406 set(FFMPEG_COMPONENTS 406 set(FFmpeg_COMPONENTS
407 avcodec 407 avcodec
408 avutil 408 avutil
409 swscale) 409 swscale)
410 410
411 foreach(COMPONENT ${FFMPEG_COMPONENTS}) 411 foreach(COMPONENT ${FFmpeg_COMPONENTS})
412 set(FFMPEG_${COMPONENT}_PREFIX "${FFMPEG_BUILD_DIR}/lib${COMPONENT}") 412 set(FFmpeg_${COMPONENT}_PREFIX "${FFmpeg_BUILD_DIR}/lib${COMPONENT}")
413 set(FFMPEG_${COMPONENT}_LIB_NAME "lib${COMPONENT}.a") 413 set(FFmpeg_${COMPONENT}_LIB_NAME "lib${COMPONENT}.a")
414 set(FFMPEG_${COMPONENT}_LIBRARY "${FFMPEG_${COMPONENT}_PREFIX}/${FFMPEG_${COMPONENT}_LIB_NAME}") 414 set(FFmpeg_${COMPONENT}_LIBRARY "${FFmpeg_${COMPONENT}_PREFIX}/${FFmpeg_${COMPONENT}_LIB_NAME}")
415 415
416 set(FFMPEG_LIBRARIES 416 set(FFmpeg_LIBRARIES
417 ${FFMPEG_LIBRARIES} 417 ${FFmpeg_LIBRARIES}
418 ${FFMPEG_${COMPONENT}_LIBRARY} 418 ${FFmpeg_${COMPONENT}_LIBRARY}
419 CACHE PATH "Paths to FFmpeg libraries" FORCE) 419 CACHE PATH "Paths to FFmpeg libraries" FORCE)
420 endforeach() 420 endforeach()
421 421
422 set(FFMPEG_INCLUDE_DIR 422 set(FFmpeg_INCLUDE_DIR
423 ${FFMPEG_PREFIX} 423 ${FFmpeg_PREFIX}
424 CACHE PATH "Path to FFmpeg headers" FORCE) 424 CACHE PATH "Path to FFmpeg headers" FORCE)
425 425
426 # `configure` parameters builds only exactly what yuzu needs from FFmpeg 426 # `configure` parameters builds only exactly what yuzu needs from FFmpeg
427 # `--disable-{vaapi,vdpau}` is needed to avoid linking issues 427 # `--disable-{vaapi,vdpau}` is needed to avoid linking issues
428 add_custom_command( 428 add_custom_command(
429 OUTPUT 429 OUTPUT
430 ${FFMPEG_MAKEFILE} 430 ${FFmpeg_MAKEFILE}
431 COMMAND 431 COMMAND
432 /bin/bash ${FFMPEG_PREFIX}/configure 432 /bin/bash ${FFmpeg_PREFIX}/configure
433 --disable-avdevice 433 --disable-avdevice
434 --disable-avfilter 434 --disable-avfilter
435 --disable-avformat 435 --disable-avformat
@@ -445,25 +445,25 @@ if (YUZU_USE_BUNDLED_FFMPEG)
445 --enable-decoder=h264 445 --enable-decoder=h264
446 --enable-decoder=vp9 446 --enable-decoder=vp9
447 WORKING_DIRECTORY 447 WORKING_DIRECTORY
448 ${FFMPEG_BUILD_DIR} 448 ${FFmpeg_BUILD_DIR}
449 ) 449 )
450 450
451 add_custom_command( 451 add_custom_command(
452 OUTPUT 452 OUTPUT
453 ${FFMPEG_LIBRARIES} 453 ${FFmpeg_LIBRARIES}
454 COMMAND 454 COMMAND
455 make 455 make
456 WORKING_DIRECTORY 456 WORKING_DIRECTORY
457 ${FFMPEG_BUILD_DIR} 457 ${FFmpeg_BUILD_DIR}
458 ) 458 )
459 459
460 # ALL makes this custom target build every time 460 # ALL makes this custom target build every time
461 # but it won't actually build if the DEPENDS parameter is up to date 461 # but it won't actually build if the DEPENDS parameter is up to date
462 add_custom_target(ffmpeg-build ALL DEPENDS ${FFMPEG_LIBRARIES}) 462 add_custom_target(ffmpeg-build ALL DEPENDS ${FFmpeg_LIBRARIES})
463 add_custom_target(ffmpeg-configure ALL DEPENDS ${FFMPEG_MAKEFILE}) 463 add_custom_target(ffmpeg-configure ALL DEPENDS ${FFmpeg_MAKEFILE})
464 464
465 if (FFMPEG_FOUND) 465 if (FFmpeg_FOUND)
466 message(STATUS "Found FFmpeg version ${FFMPEG_VERSION}") 466 message(STATUS "Found FFmpeg version ${FFmpeg_VERSION}")
467 467
468 add_dependencies(ffmpeg-build ffmpeg-configure) 468 add_dependencies(ffmpeg-build ffmpeg-configure)
469 else() 469 else()
@@ -471,22 +471,26 @@ if (YUZU_USE_BUNDLED_FFMPEG)
471 endif() 471 endif()
472 else() # WIN32 472 else() # WIN32
473 # Use yuzu FFmpeg binaries 473 # Use yuzu FFmpeg binaries
474 set(FFMPEG_EXT_NAME "ffmpeg-4.2.1") 474 set(FFmpeg_EXT_NAME "ffmpeg-4.2.1")
475 set(FFMPEG_PATH "${CMAKE_BINARY_DIR}/externals/${FFMPEG_EXT_NAME}") 475 set(FFmpeg_PATH "${CMAKE_BINARY_DIR}/externals/${FFmpeg_EXT_NAME}")
476 download_bundled_external("ffmpeg/" ${FFMPEG_EXT_NAME} "") 476 download_bundled_external("ffmpeg/" ${FFmpeg_EXT_NAME} "")
477 set(FFMPEG_FOUND YES) 477 set(FFmpeg_FOUND YES)
478 set(FFMPEG_INCLUDE_DIR "${FFMPEG_PATH}/include" CACHE PATH "Path to FFmpeg headers" FORCE) 478 set(FFmpeg_INCLUDE_DIR "${FFmpeg_PATH}/include" CACHE PATH "Path to FFmpeg headers" FORCE)
479 set(FFMPEG_LIBRARY_DIR "${FFMPEG_PATH}/bin" CACHE PATH "Path to FFmpeg library directory" FORCE) 479 set(FFmpeg_LIBRARY_DIR "${FFmpeg_PATH}/bin" CACHE PATH "Path to FFmpeg library directory" FORCE)
480 set(FFMPEG_DLL_DIR "${FFMPEG_PATH}/bin" CACHE PATH "Path to FFmpeg dll's" FORCE) 480 set(FFmpeg_DLL_DIR "${FFmpeg_PATH}/bin" CACHE PATH "Path to FFmpeg dll's" FORCE)
481 set(FFMPEG_LIBRARIES 481 set(FFmpeg_LIBRARIES
482 ${FFMPEG_LIBRARY_DIR}/swscale.lib 482 ${FFmpeg_LIBRARY_DIR}/swscale.lib
483 ${FFMPEG_LIBRARY_DIR}/avcodec.lib 483 ${FFmpeg_LIBRARY_DIR}/avcodec.lib
484 ${FFMPEG_LIBRARY_DIR}/avutil.lib 484 ${FFmpeg_LIBRARY_DIR}/avutil.lib
485 CACHE PATH "Paths to FFmpeg libraries" FORCE) 485 CACHE PATH "Paths to FFmpeg libraries" FORCE)
486 endif() 486 endif()
487else() 487else()
488 # Use system installed FFmpeg 488 # Use system installed FFmpeg
489 find_package(FFmpeg REQUIRED VERSION 4.0) 489 find_package(FFmpeg REQUIRED)
490
491 if (NOT FFmpeg_FOUND)
492 message(FATAL_ERROR "FFmpeg not found")
493 endif()
490endif() 494endif()
491 495
492# Prefer the -pthread flag on Linux. 496# Prefer the -pthread flag on Linux.
diff --git a/externals/find-modules/FindFFmpeg.cmake b/externals/find-modules/FindFFmpeg.cmake
index 77b331e00..86a3f5a5a 100644
--- a/externals/find-modules/FindFFmpeg.cmake
+++ b/externals/find-modules/FindFFmpeg.cmake
@@ -1,100 +1,182 @@
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 # Disabled
26# avfilter # Disabled
27# avformat # Disabled
28# avutil
29# postproc # Disabled
30# swresample # Disabled
31# swscale
19# 32#
20 33
21include(FindPackageHandleStandardArgs) 34set(_FFmpeg_ALL_COMPONENTS
22 35 avcodec
23find_package_handle_standard_args(FFMPEG 36 avutil
24 FOUND_VAR FFMPEG_FOUND 37 swscale
25 REQUIRED_VARS
26 FFMPEG_LIBRARY
27 FFMPEG_INCLUDE_DIR
28 VERSION_VAR FFMPEG_VERSION
29) 38)
30 39
31if(FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR) 40set(_FFmpeg_DEPS_avcodec avutil)
32 # in cache already 41set(_FFmpeg_DEPS_avdevice avcodec avformat avutil)
33 set(FFMPEG_FOUND TRUE) 42set(_FFmpeg_DEPS_avfilter avutil)
34else() 43set(_FFmpeg_DEPS_avformat avcodec avutil)
35 # use pkg-config to get the directories and then use these values 44set(_FFmpeg_DEPS_postproc avutil)
36 # in the FIND_PATH() and FIND_LIBRARY() calls 45set(_FFmpeg_DEPS_swresample avutil)
37 find_package(PkgConfig) 46set(_FFmpeg_DEPS_swscale avutil)
38 if(PKG_CONFIG_FOUND) 47
39 pkg_check_modules(_FFMPEG_AVCODEC libavcodec) 48function(find_ffmpeg LIBNAME)
40 pkg_check_modules(_FFMPEG_AVUTIL libavutil) 49 if(DEFINED ENV{FFMPEG_DIR})
41 pkg_check_modules(_FFMPEG_SWSCALE libswscale) 50 set(FFMPEG_DIR $ENV{FFMPEG_DIR})
42 endif() 51 endif()
43 52
44 find_path(FFMPEG_AVCODEC_INCLUDE_DIR 53 if(FFMPEG_DIR)
45 NAMES libavcodec/avcodec.h 54 list(APPEND INCLUDE_PATHS
46 PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS} 55 ${FFMPEG_DIR}
47 /usr/include 56 ${FFMPEG_DIR}/ffmpeg
48 /usr/local/include 57 ${FFMPEG_DIR}/lib${LIBNAME}
49 /opt/local/include 58 ${FFMPEG_DIR}/include/lib${LIBNAME}
50 /sw/include 59 ${FFMPEG_DIR}/include/ffmpeg
51 PATH_SUFFIXES ffmpeg libav) 60 ${FFMPEG_DIR}/include
52 61 NO_DEFAULT_PATH
53 find_library(FFMPEG_LIBAVCODEC 62 NO_CMAKE_FIND_ROOT_PATH
54 NAMES avcodec 63 )
55 PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS} 64 list(APPEND LIB_PATHS
56 /usr/lib 65 ${FFMPEG_DIR}
57 /usr/local/lib 66 ${FFMPEG_DIR}/lib
58 /opt/local/lib 67 ${FFMPEG_DIR}/lib${LIBNAME}
59 /sw/lib) 68 NO_DEFAULT_PATH
69 NO_CMAKE_FIND_ROOT_PATH
70 )
71 else()
72 list(APPEND INCLUDE_PATHS
73 /usr/local/include/ffmpeg
74 /usr/local/include/lib${LIBNAME}
75 /usr/include/ffmpeg
76 /usr/include/lib${LIBNAME}
77 /usr/include/ffmpeg/lib${LIBNAME}
78 )
60 79
61 find_library(FFMPEG_LIBAVUTIL 80 list(APPEND LIB_PATHS
62 NAMES avutil
63 PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}
64 /usr/lib
65 /usr/local/lib 81 /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 82 /usr/lib
73 /usr/local/lib 83 )
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() 84 endif()
80 85
81 if(FFMPEG_FOUND) 86 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
82 set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR}) 87 HINTS ${INCLUDE_PATHS}
83 set(FFMPEG_LIBRARIES 88 )
84 ${FFMPEG_LIBAVCODEC} 89
85 ${FFMPEG_LIBAVUTIL} 90 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
86 ${FFMPEG_LIBSWSCALE}) 91 HINTS ${LIB_PATHS}
92 )
93
94 if(NOT FFMPEG_DIR AND (NOT FFmpeg_LIBRARY_${LIBNAME} OR NOT FFmpeg_INCLUDE_${LIBNAME}))
95 # Didn't find it in the usual paths, try pkg-config
96 find_package(PkgConfig QUIET)
97 pkg_check_modules(FFmpeg_PKGCONFIG_${LIBNAME} QUIET lib${LIBNAME})
98
99 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
100 ${FFmpeg_PKGCONFIG_${LIBNAME}_INCLUDE_DIRS}
101 )
102
103 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
104 ${FFmpeg_PKGCONFIG_${LIBNAME}_LIBRARY_DIRS}
105 )
87 endif() 106 endif()
88 107
89 if(FFMPEG_FOUND) 108 if(FFmpeg_INCLUDE_${LIBNAME} AND FFmpeg_LIBRARY_${LIBNAME})
90 if(NOT FFMPEG_FIND_QUIETLY) 109 set(FFmpeg_INCLUDE_${LIBNAME} "${FFmpeg_INCLUDE_${LIBNAME}}" PARENT_SCOPE)
91 message(STATUS 110 set(FFmpeg_LIBRARY_${LIBNAME} "${FFmpeg_LIBRARY_${LIBNAME}}" PARENT_SCOPE)
92 "Found FFMPEG or Libav: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}") 111
112 # Extract FFmpeg version from version.h
113 foreach(v MAJOR MINOR MICRO)
114 set(FFmpeg_${LIBNAME}_VERSION_${v} 0)
115 endforeach()
116 string(TOUPPER ${LIBNAME} LIBNAME_UPPER)
117 file(STRINGS "${FFmpeg_INCLUDE_${LIBNAME}}/lib${LIBNAME}/version.h" _FFmpeg_VERSION_H_CONTENTS REGEX "#define LIB${LIBNAME_UPPER}_VERSION_(MAJOR|MINOR|MICRO) ")
118 set(_FFmpeg_VERSION_REGEX "([0-9]+)")
119 foreach(v MAJOR MINOR MICRO)
120 if("${_FFmpeg_VERSION_H_CONTENTS}" MATCHES "#define LIB${LIBNAME_UPPER}_VERSION_${v}[\\t ]+${_FFmpeg_VERSION_REGEX}")
121 set(FFmpeg_${LIBNAME}_VERSION_${v} "${CMAKE_MATCH_1}")
122 endif()
123 endforeach()
124 set(FFmpeg_${LIBNAME}_VERSION "${FFmpeg_${LIBNAME}_VERSION_MAJOR}.${FFmpeg_${LIBNAME}_VERSION_MINOR}.${FFmpeg_${LIBNAME}_VERSION_MICRO}")
125 set(FFmpeg_${c}_VERSION "${FFmpeg_${LIBNAME}_VERSION}" PARENT_SCOPE)
126 unset(_FFmpeg_VERSION_REGEX)
127 unset(_FFmpeg_VERSION_H_CONTENTS)
128
129 set(FFmpeg_${c}_FOUND TRUE PARENT_SCOPE)
130 if(NOT FFmpeg_FIND_QUIETLY)
131 message("-- Found ${LIBNAME}: ${FFmpeg_INCLUDE_${LIBNAME}} ${FFmpeg_LIBRARY_${LIBNAME}} (version: ${FFmpeg_${LIBNAME}_VERSION})")
93 endif() 132 endif()
94 else() 133 endif()
95 if(FFMPEG_FIND_REQUIRED) 134endfunction()
96 message(FATAL_ERROR 135
97 "Could not find libavcodec or libavutil or libswscale") 136foreach(c ${_FFmpeg_ALL_COMPONENTS})
137 find_ffmpeg(${c})
138endforeach()
139
140foreach(c ${_FFmpeg_ALL_COMPONENTS})
141 if(FFmpeg_${c}_FOUND)
142 list(APPEND FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_${c}})
143 list(APPEND FFmpeg_LIBRARIES ${FFmpeg_LIBRARY_${c}})
144
145 add_library(FFmpeg::${c} IMPORTED UNKNOWN)
146 set_target_properties(FFmpeg::${c} PROPERTIES
147 IMPORTED_LOCATION ${FFmpeg_LIBRARY_${c}}
148 INTERFACE_INCLUDE_DIRECTORIES ${FFmpeg_INCLUDE_${c}}
149 )
150 if(_FFmpeg_DEPS_${c})
151 set(deps)
152 foreach(dep ${_FFmpeg_DEPS_${c}})
153 list(APPEND deps FFmpeg::${dep})
154 endforeach()
155
156 set_target_properties(FFmpeg::${c} PROPERTIES
157 INTERFACE_LINK_LIBRARIES "${deps}"
158 )
159 unset(deps)
98 endif() 160 endif()
99 endif() 161 endif()
162endforeach()
163
164if(FFmpeg_INCLUDE_DIR)
165 list(REMOVE_DUPLICATES FFmpeg_INCLUDE_DIR)
100endif() 166endif()
167
168foreach(c ${FFmpeg_FIND_COMPONENTS})
169 list(APPEND _FFmpeg_REQUIRED_VARS FFmpeg_INCLUDE_${c} FFmpeg_LIBRARY_${c})
170endforeach()
171
172include(FindPackageHandleStandardArgs)
173find_package_handle_standard_args(FFmpeg
174 REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS}
175 HANDLE_COMPONENTS
176)
177
178foreach(c ${_FFmpeg_ALL_COMPONENTS})
179 unset(_FFmpeg_DEPS_${c})
180endforeach()
181unset(_FFmpeg_ALL_COMPONENTS)
182unset(_FFmpeg_REQUIRED_VARS)
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 01e284d8c..1434d0260 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -277,8 +277,8 @@ if (YUZU_USE_BUNDLED_FFMPEG AND NOT WIN32)
277 add_dependencies(video_core ffmpeg-build) 277 add_dependencies(video_core ffmpeg-build)
278endif() 278endif()
279 279
280target_include_directories(video_core PRIVATE ${FFMPEG_INCLUDE_DIR}) 280target_include_directories(video_core PRIVATE ${FFmpeg_INCLUDE_DIR})
281target_link_libraries(video_core PRIVATE ${FFMPEG_LIBRARIES}) 281target_link_libraries(video_core PRIVATE ${FFmpeg_LIBRARIES})
282 282
283add_dependencies(video_core host_shaders) 283add_dependencies(video_core host_shaders)
284target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE}) 284target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE})