From b4cd6a8bd807c8b7e0e43c22770cc43dd18e6315 Mon Sep 17 00:00:00 2001
From: Alexandre Janniaux <ajanni@videolabs.io>
Date: Thu, 28 Apr 2022 09:46:29 +0200
Subject: [PATCH] contrib: librist: patch meson.build for libcjson

Debian is using cJSON from github.com/DaveGamble/cJSON, as well as
archlinux and homebrew, which is shipping a libcjson.pc file. Only
ubuntu is using a different version not including the .pc file.

Homebrew is also shipping a libcjson.pc file, and without this, it would
generate a pc file like that:

    prefix=/foo/bar/vlc/contrib/x86_64-apple-darwin21
    libdir=${prefix}/lib
    includedir=${prefix}/include

    Name: librist
    Description: Reliable Internet Stream Transport (RIST)
    Version: 0.2.4
    Libs: -L${libdir} -lrist /usr/local/Cellar/cjson/1.7.15/lib/libcjson.1.7.15.dylib
    Cflags: -I${includedir} -I/usr/local/Cellar/cjson/1.7.15/include

Which won't be valid, especially for a standalone build with the
macosx/build.sh script.

It was leading to undefined references to cJSON symbols when it's
installed from homebrew.

Backport from upstream 809390b3b75a259a704079d0fb4d8f1b5f7fa956.

Refs #26860
---
 .../src/librist/librist-fix-libcjson-meson.patch    | 13 +++++++++++++
 contrib/src/librist/rules.mak                       |  1 +
 2 files changed, 14 insertions(+)
 create mode 100644 contrib/src/librist/librist-fix-libcjson-meson.patch

diff --git a/contrib/src/librist/librist-fix-libcjson-meson.patch b/contrib/src/librist/librist-fix-libcjson-meson.patch
new file mode 100644
index 000000000000..d7ae7090ace3
--- /dev/null
+++ b/contrib/src/librist/librist-fix-libcjson-meson.patch
@@ -0,0 +1,13 @@
+diff --git a/meson.build b/meson.build
+index a77780667dfb07d700d39c6c3353c0ba4906b178..0ed820152476e0caed3ba6d203ba236083fb8438 100755
+--- a/meson.build
++++ b/meson.build
+@@ -156,7 +156,7 @@ endif
+ 
+ #On ubuntu cjson does not come with pkgconfig files, hence the extended checking.
+ if not builtin_cjson
+-	cjson_lib = dependency('cJSON', required: false)
++	cjson_lib = dependency('libcjson', required: false)
+ 	if not cjson_lib.found()
+ 		cjson_lib = cc.find_library('cjson', required: required_library, has_headers: ['cjson/cJSON.h'])
+ 		if not cjson_lib.found()
diff --git a/contrib/src/librist/rules.mak b/contrib/src/librist/rules.mak
index 612fa8a6996f..8afd5226f7d7 100644
--- a/contrib/src/librist/rules.mak
+++ b/contrib/src/librist/rules.mak
@@ -20,6 +20,7 @@ $(TARBALLS)/librist-$(LIBRIST_VERSION).tar.gz:
 
 librist: librist-$(LIBRIST_VERSION).tar.gz .sum-librist
 	$(UNPACK)
+	$(APPLY) $(SRC)/librist/librist-fix-libcjson-meson.patch
 	$(MOVE)
 
 .librist: librist crossfile.meson
-- 
GitLab