Add explicit ncurses dependency to finch.

Thu, 29 Nov 2018 23:06:14 -0500

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Thu, 29 Nov 2018 23:06:14 -0500
changeset 39362
3e92f470c176
parent 39361
a1068caa3600
child 39363
3932ab2393a7

Add explicit ncurses dependency to finch.

This should hopefully be temporary until libgnt wraps the functionality.

finch/gntblist.c file | annotate | diff | comparison | revisions
finch/gntconv.c file | annotate | diff | comparison | revisions
finch/gntpounce.c file | annotate | diff | comparison | revisions
finch/gntsound.c file | annotate | diff | comparison | revisions
finch/meson.build file | annotate | diff | comparison | revisions
finch/plugins/gntgf.c file | annotate | diff | comparison | revisions
finch/plugins/meson.build file | annotate | diff | comparison | revisions
--- a/finch/gntblist.c	Thu Nov 22 03:21:24 2018 -0500
+++ b/finch/gntblist.c	Thu Nov 29 23:06:14 2018 -0500
@@ -21,6 +21,8 @@
 #include <internal.h>
 #include "finch.h"
 
+#include NCURSES_HEADER
+
 #include <account.h>
 #include <buddylist.h>
 #include <log.h>
--- a/finch/gntconv.c	Thu Nov 22 03:21:24 2018 -0500
+++ b/finch/gntconv.c	Thu Nov 29 23:06:14 2018 -0500
@@ -22,6 +22,8 @@
 #include <internal.h>
 #include "finch.h"
 
+#include NCURSES_HEADER
+
 #include <cmds.h>
 #include <core.h>
 #include <idle.h>
--- a/finch/gntpounce.c	Thu Nov 22 03:21:24 2018 -0500
+++ b/finch/gntpounce.c	Thu Nov 29 23:06:14 2018 -0500
@@ -21,6 +21,8 @@
  */
 #include <internal.h>
 
+#include NCURSES_HEADER
+
 #include <gnt.h>
 #include <gntbox.h>
 #include <gntbutton.h>
--- a/finch/gntsound.c	Thu Nov 22 03:21:24 2018 -0500
+++ b/finch/gntsound.c	Thu Nov 29 23:06:14 2018 -0500
@@ -21,6 +21,8 @@
 #include "finch.h"
 #include <internal.h>
 
+#include NCURSES_HEADER
+
 #ifdef _WIN32
 #include <windows.h>
 #include <mmsystem.h>
--- a/finch/meson.build	Thu Nov 22 03:21:24 2018 -0500
+++ b/finch/meson.build	Thu Nov 29 23:06:14 2018 -0500
@@ -9,7 +9,74 @@
 		libgnt_gir = libgnt_proj.get_variable('libgnt_gir')
 	endif
 
-	if libgnt_dep.found()
+	#######################################################################
+	# Check for ncurses and other things used by it
+	# FIXME: This should be temporary until libgnt wraps the functionality.
+	#######################################################################
+	ncurses_available = true
+	ncurses_header = 'ncurses.h'
+	# Some distros put the headers in ncursesw/, some don't. These are ordered to
+	# pick the last available as most-specific version.
+	ncursesw_header_paths = ['', 'ncursesw/']
+
+	ncurses = dependency('ncursesw', required : false)
+	if ncurses.found()
+		foreach location : ncursesw_header_paths
+			f = location + 'ncurses.h'
+			if compiler.has_header_symbol(f, 'get_wch',
+			    prefix : '#define _XOPEN_SOURCE_EXTENDED')
+				ncurses_header = f
+			endif
+		endforeach
+	else
+		ncurses_available = false
+		ncurses_inc = []
+		ncurses_libs = compiler.find_library('ncursesw', required : false)
+		if ncurses_libs.found()
+			foreach location : ncursesw_header_paths
+				f = location + 'ncurses.h'
+				if compiler.has_header_symbol(f, 'get_wch',
+				    prefix : '#define _XOPEN_SOURCE_EXTENDED')
+					ncurses_available = true
+					ncurses_header = f
+				endif
+			endforeach
+
+			if ncurses_available
+				ncurses = declare_dependency(
+				    include_directories : ncurses_inc,
+				    dependencies : ncurses_libs
+				)
+			endif
+		endif
+	endif
+
+	if not ncurses_available
+		# ncursesw was not found. Look for plain old ncurses
+		ncurses = dependency('ncurses', required : false)
+		if ncurses.found()
+			ncurses_available = true
+		else
+			ncurses_libs = compiler.find_library('ncurses', required : false)
+			ncurses_available = ncurses_libs.found()
+			ncurses = declare_dependency(dependencies : ncurses_libs)
+		endif
+	endif
+
+	if not ncurses_available and host_machine.system() == 'windows'
+		# Try pdcurses too.
+		ncurses_header = 'curses.h'
+		ncurses_libs = compiler.find_library('pdcurses', required : false)
+		ncurses_available = compiler.has_header(ncurses_header) and ncurses_libs.found()
+		ncurses = declare_dependency(dependencies : ncurses_libs)
+	endif
+
+	if not ncurses_available
+		error('ncurses could not be found!')
+	endif
+
+	if libgnt_dep.found() and ncurses_available
+		ncurses_header = '-DNCURSES_HEADER="@0@"'.format(ncurses_header)
 		enable_consoleui = true
 	else
 		error('''
@@ -96,10 +163,10 @@
 	libfinch_inc = include_directories('.')
 	libfinch = shared_library('finch',
 	    libfinch_SOURCES,
-	    c_args : '-DSTANDALONE',
+	    c_args : ['-DSTANDALONE', ncurses_header],
 	    include_directories : [toplevel_inc],
 	    version : PURPLE_LIB_VERSION,
-	    dependencies : [libpurple_dep, libgnt_dep, glib],
+	    dependencies : [libpurple_dep, libgnt_dep, ncurses, glib],
 	    install : true)
 	libfinch_dep = declare_dependency(
 	    include_directories : [toplevel_inc, libfinch_inc],
--- a/finch/plugins/gntgf.c	Thu Nov 22 03:21:24 2018 -0500
+++ b/finch/plugins/gntgf.c	Thu Nov 29 23:06:14 2018 -0500
@@ -21,6 +21,8 @@
 
 #include "internal.h"
 
+#include NCURSES_HEADER
+
 #define PLUGIN_STATIC_NAME	GntGf
 
 #define PREFS_PREFIX          "/plugins/gnt/gntgf"
--- a/finch/plugins/meson.build	Thu Nov 22 03:21:24 2018 -0500
+++ b/finch/plugins/meson.build	Thu Nov 29 23:06:14 2018 -0500
@@ -6,7 +6,8 @@
 		    install : true, install_dir : FINCH_PLUGINDIR)
 
 		gntgf = library('gntgf', 'gntgf.c',
-		    dependencies : [x11, libpurple_dep, libfinch_dep, glib],
+		    c_args : ncurses_header,
+		    dependencies : [x11, libpurple_dep, libfinch_dep, ncurses, glib],
 		    name_prefix : '',
 		    install : true, install_dir : FINCH_PLUGINDIR)
 	endif
@@ -17,7 +18,7 @@
 	    install : true, install_dir : FINCH_PLUGINDIR)
 
 	gntlastlog = library('gntlastlog', 'lastlog.c',
-	    dependencies : [libpurple_dep, libfinch_dep, glib],
+	    dependencies : [libpurple_dep, libfinch_dep, ncurses, glib],
 	    name_prefix : '',
 	    install : true, install_dir : FINCH_PLUGINDIR)
 

mercurial