[gtk+/wip/meson: 25/135] meson: Generate demos.h for gtk3-demo
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/meson: 25/135] meson: Generate demos.h for gtk3-demo
- Date: Fri, 28 Apr 2017 22:15:30 +0000 (UTC)
commit 14af0d59281a38ad44d74e4f58003b5aa4d1eecf
Author: Timm Bäder <mail baedert org>
Date: Tue Sep 20 16:29:14 2016 +0200
meson: Generate demos.h for gtk3-demo
demos/gtk-demo/geninclude.py | 108 ++++++++++++++++++++++++++++++++++++++++++
demos/gtk-demo/meson.build | 33 ++++++++++--
gdk/meson.build | 1 +
gtk/meson.build | 5 ++-
meson.build | 26 +++++++++-
5 files changed, 164 insertions(+), 9 deletions(-)
---
diff --git a/demos/gtk-demo/geninclude.py b/demos/gtk-demo/geninclude.py
new file mode 100755
index 0000000..57038a4
--- /dev/null
+++ b/demos/gtk-demo/geninclude.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import sys
+import re
+import os
+from collections import *
+
+out_file = sys.argv[1]
+in_files = sys.argv[2:]
+
+
+file_output = """
+typedef GtkWidget *(*GDoDemoFunc) (GtkWidget *do_widget);
+
+typedef struct _Demo Demo;
+
+struct _Demo
+{
+ gchar *name;
+ gchar *title;
+ gchar *filename;
+ GDoDemoFunc func;
+ Demo *children;
+};
+
+"""
+
+# Demo = namedtuple('Demo', ['name', 'title', 'file', 'func'])
+
+demos = []
+
+for demo_file in in_files:
+ filename = demo_file[demo_file.rfind('/')+1:]
+ demo_name = filename.replace(".c", "")
+ with open(demo_file, 'r') as f:
+ title = f.readline().replace("/*", "").strip()
+
+
+ file_output += "GtkWidget *do_" + demo_name + " (GtkWidget *do_widget);\n"
+ # demos += Demo(name = demo_name,
+ # title = title,
+ # file = demo_file,
+ # func = "do_" + title)
+ demos.append((demo_name, title, filename, "do_" + demo_name, -1))
+
+# Generate a List of "Parent names"
+parents = []
+parent_ids = []
+parent_index = 0
+for demo in demos:
+ if "/" in demo[1]:
+ slash_index = demo[1].index('/')
+ parent_name = demo[1][:slash_index]
+ do_break = False
+
+ # Check for duplicates
+ if not parent_name in parents:
+ parents.append(parent_name)
+ parent_ids.append(parent_index)
+ demos.append(("NULL", parent_name, "NULL", "NULL", parent_index))
+
+ parent_index = parent_index + 1
+
+
+# For every child with a parent, generate a list of child demos
+i = 0
+for parent in parents:
+ id = parent_ids[i]
+ file_output += "\nDemo child" + str(id) + "[] = {\n"
+ # iterate over all demos and check if the name starts with the given parent name
+ for child in demos:
+ if child[1].startswith(parent + "/"):
+ title = child[1][child[1].rfind('/') + 1:]
+ file_output += " { \"" + child[0] + "\", \"" + title + "\", \"" + child[2] + "\", " + child[3]
+ ", NULL },\n"
+
+
+ file_output += " { NULL }\n};\n"
+ i = i + 1
+
+
+# Sort demos by title
+demos = sorted(demos, key=lambda x: x[1])
+
+file_output += "\nDemo gtk_demos[] = {\n"
+for demo in demos:
+ # Do not generate one of these for demos with a parent demo
+ if "/" not in demo[1]:
+ child_array = "NULL"
+ name = demo[0];
+ title = demo[1];
+ file = demo[2]
+ if name != "NULL":
+ name = "\"" + name + "\""
+ if title != "NULL":
+ title = "\"" + title + "\""
+ if file != "NULL":
+ file = "\"" + file + "\""
+
+ if demo[4] != -1:
+ child_array = "child" + str(demo[4])
+ file_output += " { " + name + ", " + title + ", " + file + ", " + demo[3] + ", " + child_array + "
},\n"
+
+file_output += " { NULL }\n};\n"
+
+ofile = open(out_file, "w")
+ofile.write(file_output)
+ofile.close()
diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build
index 2edfdc0..c4cdd9c 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -1,4 +1,7 @@
-demos_base = files([
+
+## These should be in the order you want them to appear in the
+## demo app, which means alphabetized by demo title, not filename
+demos = files([
'application_demo.c',
'assistant.c',
'builder.c',
@@ -65,16 +68,33 @@ demos_base = files([
'toolpalette.c',
'transparent.c',
'tree_store.c',
-
- 'font_features.c', #TODO: IF BUILD_FONT_DEMO
- 'pagesetup.c' #TODO: IF OS_UNIX
])
-gtkdemo_sources = demos_base + files([
+
+gtkdemo_deps = [libgtk_dep]
+
+if build_font_demo
+ demos += files('font_features.c')
+ gtkdemo_deps += harfbuzz_dep
+endif
+
+if os_unix
+ demos += files('pagesetup.c')
+endif
+
+gtkdemo_sources = demos + files([
'main.c',
])
+geninclude = find_program('geninclude.py')
+demos_h = custom_target(
+ 'gtk3 demo header',
+ output : 'demos.h',
+ input : demos,
+ command : [geninclude, '@OUTPUT@', '@INPUT@'],
+)
+
gtkdemo_resources = gnome.compile_resources(
'gtkdemo_resources',
'demo.gresource.xml',
@@ -84,8 +104,9 @@ gtkdemo_resources = gnome.compile_resources(
gtkdemo = executable(
'gtk3-demo',
gtkdemo_sources,
+ demos_h,
gtkdemo_resources,
- dependencies: [libgtk_dep, harfbuzz_dep],
+ dependencies: gtkdemo_deps,
include_directories : confinc,
gui_app: true
)
diff --git a/gdk/meson.build b/gdk/meson.build
index 583a906..ac2ba34 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -366,6 +366,7 @@ endif
libgdk = shared_library('gdk',
gdk_sources,
+ gdkenum_h,
c_args: ['-DHAVE_CONFIG_H', '-DGDK_COMPILATION'],
include_directories: [confinc, xinc, wlinc],
dependencies: gdk_deps,
diff --git a/gtk/meson.build b/gtk/meson.build
index 9aeaf4a..f2c6379 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -785,7 +785,6 @@ gtk_deps = [
glib_dep,
atkbridge_dep,
pangocairo_dep,
- pangoft_dep,
pango_dep,
cairogobj_dep,
cairo_dep,
@@ -804,6 +803,7 @@ if x11_enabled
gtk_deps += [
xi_dep,
x11_dep,
+ pangoft_dep
]
endif
@@ -812,6 +812,9 @@ if wayland_enabled
gtk_wayland_sources,
gtk_use_wayland_or_x11_c_sources
]
+ gtk_deps += [
+ pangoft_dep
+ ]
endif
libgtk = shared_library('gtk',
diff --git a/meson.build b/meson.build
index 07fc5d6..40c161b 100644
--- a/meson.build
+++ b/meson.build
@@ -33,6 +33,25 @@ mkenum = find_program('build_enum.py')
perl = find_program('perl')
glib_mkenums = find_program('glib-mkenums')
+os_unix = false
+os_linux = false
+os_win32 = false
+os_darwin = false
+
+if host_machine.system().contains('darwin')
+ os_darwin = true
+elif host_machine.system().contains('mingw')
+ os_win32 = true
+elif host_machine.system().contains('linux')
+ os_linux = true
+endif
+
+os_unix = not os_win32
+
+build_font_demo = false
+
+
+
cc = meson.get_compiler('c')
cdata = configuration_data()
@@ -154,7 +173,7 @@ xcomposite_dep = dependency('xcomposite')
glib_dep = dependency('glib-2.0', version: '>= 2.49.4')
giounix_dep = dependency('gio-unix-2.0', required : false)
pango_dep = dependency('pango', version: '>=1.37.3')
-pangoft_dep = dependency('pangoft2')
+pangoft_dep = dependency('pangoft2', required: wayland_enabled or x11_enabled)
cairo_dep = dependency('cairo')
pangocairo_dep = dependency('pangocairo')
cairogobj_dep = dependency('cairo-gobject')
@@ -172,7 +191,10 @@ wlprotocolsdep = dependency('wayland-protocols', version: '>= 1.7')
wlcursordep = dependency('wayland-cursor')
wlegldep = dependency('wayland-egl')
xrandr_dep = dependency('xrandr')
-harfbuzz_dep = dependency('harfbuzz', version: '>= 0.9')
+
+
+harfbuzz_dep = dependency('harfbuzz', version: '>= 0.9', required: false)
+build_font_demo = harfbuzz_dep.found() and pangoft_dep.found()
if giounix_dep.found()
cdata.set('HAVE_GIO_UNIX', 1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]