Repository: mesonbuild/meson

Issue:
Add a way for Meson to find “curses” generically 
Add a way for Meson to find `curses` generically.

There are definitely different names for `curses` library but what about a generic `curses_dep = dependency(‘curses’)` for finding the correct `curses` libraries like what Meson does with threads.


Discussion:
This would most likely  have to be added in https://github.com/mesonbuild/meson/blob/master/mesonbuild/dependencies/misc.py

Here is a meson.build snippet I use to find various Curses libraries, including Ncurses and PDcurses:

```meson
cc = meson.get_compiler('c')
curses = dependency('ncurses', required: false, disabler: true)
if not curses.found()
  curses_root = get_option('curses_root')
  curses_lib = cc.find_library('curses', dirs : curses_root, required : false, disabler: true)
  curses = declare_dependency(include_directories: curses_root, dependencies: curses_lib)
endif
```

The full program is at https://github.com/fortran-gaming/tetran/blob/master/meson.build

Note, I just made PDcurses buildable by Meson: https://github.com/wmcbrine/PDCurses/pull/78/files

I also updated my example [Tetran](https://github.com/fortran-gaming/tetran/) program to automatically use PDcurses as a Meson subproject if Curses isn't found on the system.

Resolving patch:
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py
--- a/mesonbuild/dependencies/__init__.py
+++ b/mesonbuild/dependencies/__init__.py
@@ -23,7 +23,8 @@
 from .coarrays import CoarrayDependency
 from .mpi import MPIDependency
 from .scalapack import ScalapackDependency
-from .misc import (BlocksDependency, NetCDFDependency, OpenMPDependency, Python3Dependency, ThreadDependency, PcapDependency, CupsDependency, LibWmfDependency, LibGCryptDependency, GpgmeDependency, ShadercDependency)
+from .misc import (BlocksDependency, CursesDependency, NetCDFDependency, OpenMPDependency, Python3Dependency, ThreadDependency,
+                   PcapDependency, CupsDependency, LibWmfDependency, LibGCryptDependency, GpgmeDependency, ShadercDependency)
 from .platform import AppleFrameworks
 from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, SDL2Dependency, WxDependency, VulkanDependency
 
@@ -46,6 +47,7 @@
 
     # From misc:
     'blocks': BlocksDependency,
+    'curses': CursesDependency,
     'netcdf': NetCDFDependency,
     'openmp': OpenMPDependency,
     'python3': Python3Dependency,
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py
--- a/mesonbuild/dependencies/misc.py
+++ b/mesonbuild/dependencies/misc.py
@@ -557,3 +557,26 @@ def _factory(cls, environment, kwargs):
     @staticmethod
     def get_methods():
         return [DependencyMethods.SYSTEM, DependencyMethods.PKGCONFIG]
+
+class CursesDependency(ExternalDependency):
+    def __init__(self, environment, kwargs):
+        super().__init__('curses', environment, None, kwargs)
+        self.name = 'curses'
+        self.is_found = False
+        methods = listify(self.methods)
+
+        if set([DependencyMethods.AUTO, DependencyMethods.PKGCONFIG]).intersection(methods):
+            pkgconfig_files = ['ncurses', 'ncursesw']
+            for pkg in pkgconfig_files:
+                pkgdep = PkgConfigDependency(pkg, environment, kwargs)
+                if pkgdep.found():
+                    self.compile_args = pkgdep.get_compile_args()
+                    self.link_args = pkgdep.get_link_args()
+                    self.version = pkgdep.get_version()
+                    self.is_found = True
+                    self.pcdep = pkgdep
+                    return
+
+    @staticmethod
+    def get_methods():
+        return [DependencyMethods.AUTO, DependencyMethods.PKGCONFIG]


Test patch:
diff --git a/test cases/frameworks/31 curses/main.c b/test cases/frameworks/31 curses/main.c
new file mode 100644
--- /dev/null
+++ b/test cases/frameworks/31 curses/main.c	
@@ -0,0 +1,7 @@
+#include "curses.h"
+
+int main(void) {
+initscr();
+endwin();
+return 0;
+}
\ No newline at end of file
diff --git a/test cases/frameworks/31 curses/meson.build b/test cases/frameworks/31 curses/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/frameworks/31 curses/meson.build	
@@ -0,0 +1,9 @@
+project('curses', 'c')
+
+curses = dependency('curses', required: false)
+if not curses.found()
+  error('MESON_SKIP_TEST: Curses library not found')
+endif
+
+exec = executable('basic', 'main.c', dependencies: curses)
+# didn't run the test because in general graphics fail on CI