From fbb26e6173aee296bdfb6083c553d843ece58ccc Mon Sep 17 00:00:00 2001
From: lat9nq <22451773+lat9nq@users.noreply.github.com>
Date: Tue, 6 Jul 2021 12:06:14 -0400
Subject: [PATCH 1/2] cmake, ci: Build bundled FFmpeg with yuzu

Drops usage of CMAKE_DEPENDENT_OPTION to allow using
YUZU_USE_BUNDLED_FFMPEG as an option on any platform. CI then now builds
FFmpeg always, netting about 10 MB less used on the AppImage.

Also somewhat fixes YUZU_USE_BUNDLED_QT so that it can be used even if
CMake doesn't clean up its state after running the first find_package.
---
 .ci/scripts/linux/docker.sh | 3 ++-
 CMakeLists.txt              | 6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/.ci/scripts/linux/docker.sh b/.ci/scripts/linux/docker.sh
index 9b451d3ab..5070b92d1 100755
--- a/.ci/scripts/linux/docker.sh
+++ b/.ci/scripts/linux/docker.sh
@@ -18,7 +18,8 @@ cmake .. \
       -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON \
       -DENABLE_QT_TRANSLATION=ON \
       -DUSE_DISCORD_PRESENCE=ON \
-      -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${ENABLE_COMPATIBILITY_REPORTING:-"OFF"}
+      -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${ENABLE_COMPATIBILITY_REPORTING:-"OFF"} \
+      -DYUZU_USE_BUNDLED_FFMPEG=ON
 
 make -j$(nproc)
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8b1734f36..38a141652 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,7 +25,7 @@ option(YUZU_USE_BUNDLED_BOOST "Download bundled Boost" OFF)
 
 option(YUZU_USE_BUNDLED_LIBUSB "Compile bundled libusb" OFF)
 
-CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" ON "WIN32" OFF)
+option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" "${WIN32}")
 
 option(YUZU_USE_QT_WEB_ENGINE "Use QtWebEngine for web applet implementation" OFF)
 
@@ -253,7 +253,9 @@ if(ENABLE_QT)
 
     # Check for system Qt on Linux, fallback to bundled Qt
     if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
-        find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets)
+        if (NOT YUZU_USE_BUNDLED_QT)
+            find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets)
+        endif()
         if (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT)
             # Check for dependencies, then enable bundled Qt download
 

From ef70054367c1162df2634b9f462011c15614f191 Mon Sep 17 00:00:00 2001
From: lat9nq <22451773+lat9nq@users.noreply.github.com>
Date: Tue, 6 Jul 2021 12:54:24 -0400
Subject: [PATCH 2/2] cmake: Specify the compiler on autotools externals

Enables CCache on externals if available.
---
 CMakeLists.txt                  | 2 ++
 externals/libusb/CMakeLists.txt | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 38a141652..e68868797 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -605,6 +605,8 @@ if (YUZU_USE_BUNDLED_FFMPEG)
                     --disable-vdpau
                     --enable-decoder=h264
                     --enable-decoder=vp9
+                    --cc="${CMAKE_C_COMPILER}"
+                    --cxx="${CMAKE_CXX_COMPILER}"
             WORKING_DIRECTORY
                 ${FFmpeg_BUILD_DIR}
         )
diff --git a/externals/libusb/CMakeLists.txt b/externals/libusb/CMakeLists.txt
index 151ddc462..12bdc097a 100644
--- a/externals/libusb/CMakeLists.txt
+++ b/externals/libusb/CMakeLists.txt
@@ -67,6 +67,8 @@ if (MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux") OR APPLE)
             "${LIBUSB_MAKEFILE}"
         COMMAND
             env
+                CC="${CMAKE_C_COMPILER}"
+                CXX="${CMAKE_CXX_COMPILER}"
                 CFLAGS="${LIBUSB_CFLAGS}"
             sh "${LIBUSB_CONFIGURE}"
                 ${LIBUSB_CONFIGURE_ARGS}