Repository: mesonbuild/meson

Issue:
Add gcrypt-config support
As used by libgcrypt. This is useful as the upstream refuses to have a pkg-config file because they don't understand how it works.


Discussion:
How is that possible... googling... [find this](https://lists.gnupg.org/pipermail/gcrypt-devel/2015-September/003569.html)... ok that explanation makes perfect sense.

Resolving patch:
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py
--- a/mesonbuild/dependencies/__init__.py
+++ b/mesonbuild/dependencies/__init__.py
@@ -18,7 +18,7 @@
     ExternalDependency, NotFoundDependency, ExternalLibrary, ExtraFrameworkDependency, InternalDependency,
     PkgConfigDependency, find_external_dependency, get_dep_identifier, packages, _packages_accept_language)
 from .dev import GMockDependency, GTestDependency, LLVMDependency, ValgrindDependency
-from .misc import (MPIDependency, OpenMPDependency, Python3Dependency, ThreadDependency, PcapDependency, CupsDependency, LibWmfDependency)
+from .misc import (MPIDependency, OpenMPDependency, Python3Dependency, ThreadDependency, PcapDependency, CupsDependency, LibWmfDependency, LibGCryptDependency)
 from .platform import AppleFrameworks
 from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, SDL2Dependency, WxDependency, VulkanDependency
 
@@ -39,6 +39,7 @@
     'pcap': PcapDependency,
     'cups': CupsDependency,
     'libwmf': LibWmfDependency,
+    'libgcrypt': LibGCryptDependency,
 
     # From platform:
     'appleframeworks': AppleFrameworks,
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py
--- a/mesonbuild/dependencies/misc.py
+++ b/mesonbuild/dependencies/misc.py
@@ -506,3 +506,34 @@ def tool_finish_init(ctdep):
     @staticmethod
     def get_methods():
         return [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL]
+
+
+class LibGCryptDependency(ExternalDependency):
+    def __init__(self, environment, kwargs):
+        super().__init__('libgcrypt', environment, None, kwargs)
+
+    @classmethod
+    def _factory(cls, environment, kwargs):
+        methods = cls._process_method_kw(kwargs)
+        candidates = []
+
+        if DependencyMethods.PKGCONFIG in methods:
+            candidates.append(functools.partial(PkgConfigDependency, 'libgcrypt', environment, kwargs))
+
+        if DependencyMethods.CONFIG_TOOL in methods:
+            candidates.append(functools.partial(ConfigToolDependency.factory,
+                                                'libgcrypt', environment, None, kwargs, ['libgcrypt-config'],
+                                                'libgcrypt-config',
+                                                LibGCryptDependency.tool_finish_init))
+
+        return candidates
+
+    @staticmethod
+    def tool_finish_init(ctdep):
+        ctdep.compile_args = ctdep.get_config_value(['--cflags'], 'compile_args')
+        ctdep.link_args = ctdep.get_config_value(['--libs'], 'link_args')
+        ctdep.version = ctdep.get_config_value(['--version'], 'version')[0]
+
+    @staticmethod
+    def get_methods():
+        return [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL]


Test patch:
diff --git a/test cases/frameworks/24 libgcrypt/libgcrypt_prog.c b/test cases/frameworks/24 libgcrypt/libgcrypt_prog.c
new file mode 100644
--- /dev/null
+++ b/test cases/frameworks/24 libgcrypt/libgcrypt_prog.c	
@@ -0,0 +1,8 @@
+#include <gcrypt.h>
+
+int
+main()
+{
+    gcry_check_version(NULL);
+    return 0;
+}
diff --git a/test cases/frameworks/24 libgcrypt/meson.build b/test cases/frameworks/24 libgcrypt/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/frameworks/24 libgcrypt/meson.build	
@@ -0,0 +1,23 @@
+project('libgcrypt test', 'c')
+
+wm = find_program('libgcrypt-config', required : false)
+if not wm.found()
+  error('MESON_SKIP_TEST: libgcrypt-config not installed')
+endif
+
+libgcrypt_dep = dependency('libgcrypt', version : '>= 1.0')
+libgcrypt_ver = libgcrypt_dep.version()
+assert(libgcrypt_ver.split('.').length() > 1, 'libgcrypt version is "@0@"'.format(libgcrypt_ver))
+message('libgcrypt version is "@0@"'.format(libgcrypt_ver))
+e = executable('libgcrypt_prog', 'libgcrypt_prog.c', dependencies : libgcrypt_dep)
+
+test('libgcrypttest', e)
+
+# Test using the method keyword:
+
+dependency('libgcrypt', method : 'config-tool')
+dependency('libgcrypt', method : 'pkg-config', required: false)
+
+# Check we can apply a version constraint
+dependency('libgcrypt', version: '>=@0@'.format(libgcrypt_dep.version()), method: 'pkg-config', required: false)
+dependency('libgcrypt', version: '>=@0@'.format(libgcrypt_dep.version()), method: 'config-tool')