From 69f09648a402c6ce63db631026feb5ee757b037e Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 27 May 2020 15:01:54 +0200
Subject: [PATCH] meson.build: attempt to detect WildMidi using pkg-config

The WildMidi project added the pkg-config file in version 0.3.3, but
unfortunately, Debian still doesn't ship it 4 years later:

 https://bugs.debian.org/916631

However, for cross-compiling, the pkg-config file is very helpful.
---
 NEWS                            | 2 ++
 src/decoder/plugins/meson.build | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index b4ea4bcf0..64df932ec 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ ver 0.21.24 (not yet released)
   - "tagtypes" requires no permissions
 * database
   - simple: fix crash when mounting twice
+* decoder
+  - wildmidi: attempt to detect WildMidi using pkg-config
 * Android
   - fix build failure with Android NDK r21
 * Windows
diff --git a/src/decoder/plugins/meson.build b/src/decoder/plugins/meson.build
index 50845e4df..ca90cc07d 100644
--- a/src/decoder/plugins/meson.build
+++ b/src/decoder/plugins/meson.build
@@ -129,7 +129,12 @@ if wavpack_dep.found()
   decoder_plugins_sources += 'WavpackDecoderPlugin.cxx'
 endif
 
-wildmidi_dep = c_compiler.find_library('WildMidi', required: get_option('wildmidi'))
+if not get_option('wildmidi').disabled()
+  wildmidi_dep = dependency('wildmidi', required: get_option('wildmidi'))
+endif
+if not wildmidi_dep.found()
+  wildmidi_dep = c_compiler.find_library('WildMidi', required: get_option('wildmidi'))
+endif
 conf.set('ENABLE_WILDMIDI', wildmidi_dep.found())
 if wildmidi_dep.found()
   decoder_plugins_sources += 'WildmidiDecoderPlugin.cxx'