meson: Generate demos.h for gtk3-demo

This commit is contained in:
Timm Bäder 2016-09-20 16:29:14 +02:00 committed by Emmanuele Bassi
parent fe42d645ad
commit 2144b776b2
5 changed files with 164 additions and 9 deletions

108
demos/gtk-demo/geninclude.py Executable file
View File

@ -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()

View File

@ -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
)

View File

@ -365,6 +365,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,

View File

@ -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',

View File

@ -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)