From ff49dcfa47f673bcd27314b03ba68f99f7619c39 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <chewi@gentoo.org>
Date: Sat, 3 Jun 2023 17:51:00 +0100
Subject: [PATCH] Allow forced disabling of features instead of relying on
 pkg-config

So-called "automagic" behaviour is considered unhelpful by
distributions. A user may unintentionally build Moonlight with VDPAU
support simply because they had that library installed, only for the
whole application to break when they uninstall the library later. This
could happen on any distribution, but it should especially be avoided on
source-based distributions, where the user would not expect the package
manager to encounter such issues.

This commit is best viewed without whitespace changes.
---
 app/app.pro | 92 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 35 deletions(-)

diff --git a/app/app.pro b/app/app.pro
index dc21b854..45ee1f89 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -65,52 +65,74 @@ unix:!macx {
     CONFIG += link_pkgconfig
     PKGCONFIG += openssl sdl2 SDL2_ttf opus
 
-    packagesExist(libavcodec) {
-        PKGCONFIG += libavcodec libavutil
-        CONFIG += ffmpeg
-
-        packagesExist(libva) {
-            packagesExist(libva-x11) {
-                CONFIG += libva-x11
+    !disable-ffmpeg {
+        packagesExist(libavcodec) {
+            PKGCONFIG += libavcodec libavutil
+            CONFIG += ffmpeg
+
+            !disable-libva {
+                packagesExist(libva) {
+                    !disable-x11 {
+                        packagesExist(libva-x11) {
+                            CONFIG += libva-x11
+                        }
+                    }
+                    !disable-wayland {
+                        packagesExist(libva-wayland) {
+                            CONFIG += libva-wayland
+                        }
+                    }
+                    !disable-libdrm {
+                        packagesExist(libva-drm) {
+                            CONFIG += libva-drm
+                        }
+                    }
+                    CONFIG += libva
+                }
             }
-            packagesExist(libva-wayland) {
-                CONFIG += libva-wayland
+
+            !disable-libvdpau {
+                packagesExist(vdpau) {
+                    CONFIG += libvdpau
+                }
             }
-            packagesExist(libva-drm) {
-                CONFIG += libva-drm
+
+            !disable-mmal {
+                packagesExist(mmal) {
+                    PKGCONFIG += mmal
+                    CONFIG += mmal
+                }
             }
-            CONFIG += libva
-        }
 
-        packagesExist(vdpau) {
-            CONFIG += libvdpau
-        }
+            !disable-libdrm {
+                packagesExist(libdrm) {
+                    PKGCONFIG += libdrm
+                    CONFIG += libdrm
+                }
+            }
 
-        packagesExist(mmal) {
-            PKGCONFIG += mmal
-            CONFIG += mmal
+            !disable-cuda {
+                packagesExist(ffnvcodec) {
+                    PKGCONFIG += ffnvcodec
+                    CONFIG += cuda
+                }
+            }
         }
 
-        packagesExist(libdrm) {
-            PKGCONFIG += libdrm
-            CONFIG += libdrm
+        !disable-wayland {
+            packagesExist(wayland-client) {
+                DEFINES += HAS_WAYLAND
+                PKGCONFIG += wayland-client
+            }
         }
 
-        packagesExist(ffnvcodec) {
-            PKGCONFIG += ffnvcodec
-            CONFIG += cuda
+        !disable-x11 {
+            packagesExist(x11) {
+                DEFINES += HAS_X11
+                PKGCONFIG += x11
+            }
         }
     }
-
-    packagesExist(wayland-client) {
-        DEFINES += HAS_WAYLAND
-        PKGCONFIG += wayland-client
-    }
-
-    packagesExist(x11) {
-        DEFINES += HAS_X11
-        PKGCONFIG += x11
-    }
 }
 win32 {
     LIBS += -llibssl -llibcrypto -lSDL2 -lSDL2_ttf -lavcodec -lavutil -lopus -ldxgi -ld3d11
-- 
2.40.1

