[gtk/wip/nirbheek/gtk-3-24-meson: 1/7] meson: Sync build files with master and update to 3.24



commit a07fad3b7eeed4afbbd22feb2a66ac69aeabad2b
Author: Nirbheek Chauhan <nirbheek centricular com>
Date:   Tue Nov 20 01:37:09 2018 +0530

    meson: Sync build files with master and update to 3.24

 build-aux/meson/post-install.sh    |  26 ++
 config.h.meson                     | 329 +++++++++++++++++
 demos/gtk-demo/geninclude.py       | 108 ++++++
 demos/gtk-demo/meson.build         |   3 +-
 demos/icon-browser/meson.build     |   1 -
 demos/widget-factory/meson.build   |   1 -
 gdk/broadway/meson.build           |  78 ++++
 gdk/gdkconfig.h.meson              |  20 +
 gdk/gen-gdk-gresources-xml.py      |  33 ++
 gdk/meson.build                    | 329 ++++++-----------
 gdk/quartz/meson.build             |  51 +++
 gdk/wayland/meson.build            | 214 +++++------
 gdk/win32/meson.build              |  48 +++
 gdk/x11/meson.build                |  81 ++++
 gtk/a11y/meson.build               |  61 ++-
 gtk/deprecated/meson.build         |  47 ++-
 gtk/gen-gtk-gresources-xml.py      |  89 +++++
 gtk/gentypefuncs.py                |  55 +++
 gtk/gtktestutils.c                 |   2 +-
 gtk/inspector/meson.build          |   4 +-
 gtk/meson.build                    | 620 +++++++++++++++++++------------
 gtk/theme/Adwaita/meson.build      |  30 ++
 gtk/theme/HighContrast/meson.build |  29 ++
 meson.build                        | 735 +++++++++++++++++++++++++++++--------
 meson_options.txt                  |  42 ++-
 modules/meson.build                |   8 +
 testsuite/gdk/meson.build          |  16 +-
 testsuite/gtk/meson.build          | 257 ++++++-------
 28 files changed, 2430 insertions(+), 887 deletions(-)
---
diff --git a/build-aux/meson/post-install.sh b/build-aux/meson/post-install.sh
new file mode 100755
index 0000000000..3471336bdb
--- /dev/null
+++ b/build-aux/meson/post-install.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+gtk_api_version=$1
+gtk_abi_version=$2
+gtk_libdir=$3
+gtk_datadir=$4
+
+# Package managers set this so we don't need to run
+if [ -z "$DESTDIR" ]; then
+  echo Compiling GSettings schemas...
+  glib-compile-schemas ${gtk_datadir}/glib-2.0/schemas
+
+  echo Updating desktop database...
+  update-desktop-database -q ${gtk_datadir}/applications
+
+  echo Updating icon cache...
+  gtk-update-icon-cache -q -t -f ${gtk_datadir}/icons/hicolor
+
+  echo Updating module cache for print backends...
+  mkdir -p ${gtk_libdir}/gtk-3.0/3.0.0/printbackends
+  gio-querymodules ${gtk_libdir}/gtk-3.0/3.0.0/printbackends
+
+  echo Updating module cache for input methods...
+  mkdir -p ${gtk_libdir}/gtk-3.0/3.0.0/immodules
+  gio-querymodules ${gtk_libdir}/gtk-3.0/3.0.0/immodules
+fi
diff --git a/config.h.meson b/config.h.meson
new file mode 100644
index 0000000000..9fd690f966
--- /dev/null
+++ b/config.h.meson
@@ -0,0 +1,329 @@
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* always defined to indicate that i18n is enabled */
+#mesondefine ENABLE_NLS
+
+/* The prefix for our gettext translation domains. */
+#mesondefine GETTEXT_PACKAGE
+
+/* Disable deprecation warnings from glib */
+#mesondefine GLIB_DISABLE_DEPRECATION_WARNINGS
+
+/* Define the location where the catalogs will be installed */
+#mesondefine GTK_LOCALEDIR
+
+/* Define to 1 if you have the `bind_textdomain_codeset' function. */
+#mesondefine HAVE_BIND_TEXTDOMAIN_CODESET
+
+/* define if we have colord */
+#mesondefine HAVE_COLORD
+
+/* Define to 1 if you have the <crt_externs.h> header file. */
+#mesondefine HAVE_CRT_EXTERNS_H
+
+/* Define to 1 if CUPS 1.6 API is available */
+#mesondefine HAVE_CUPS_API_1_6
+
+/* Define to 1 if you have the `dcgettext' function. */
+#mesondefine HAVE_DCGETTEXT
+
+/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
+   */
+#mesondefine HAVE_DECL_ISINF
+
+/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
+   */
+#mesondefine HAVE_DECL_ISNAN
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#mesondefine HAVE_DLFCN_H
+
+/* Define to 1 if you have the <ftw.h> header file. */
+#mesondefine HAVE_FTW_H
+
+/* Define to 1 if you have the `getpagesize' function. */
+#mesondefine HAVE_GETPAGESIZE
+
+/* Define to 1 if you have the `getresuid' function. */
+#mesondefine HAVE_GETRESUID
+
+/* Define if the GNU gettext() function is already present or preinstalled. */
+#mesondefine HAVE_GETTEXT
+
+/* Define if gio-unix is available */
+#mesondefine HAVE_GIO_UNIX
+
+/* Have GNU ftw */
+#mesondefine HAVE_GNU_FTW
+
+/* Define to 1 if you have the `httpGetAuthString' function. */
+#mesondefine HAVE_HTTPGETAUTHSTRING
+
+/* Define if cups http_t authstring field is accessible */
+#mesondefine HAVE_HTTP_AUTHSTRING
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#mesondefine HAVE_INTTYPES_H
+
+/* Define to 1 if the system has the type `IPrintDialogCallback'. */
+#mesondefine HAVE_IPRINTDIALOGCALLBACK
+
+/* Define if your <locale.h> file defines LC_MESSAGES. */
+#mesondefine HAVE_LC_MESSAGES
+
+/* Define to 1 if you have the `m' library (-lm). */
+#mesondefine HAVE_LIBM
+
+/* Define to 1 if you have the <locale.h> header file. */
+#mesondefine HAVE_LOCALE_H
+
+/* Define to 1 if you have the `localtime_r' function. */
+#mesondefine HAVE_LOCALTIME_R
+
+/* Define to 1 if you have the `lstat' function. */
+#mesondefine HAVE_LSTAT
+
+/* Define to 1 if you have the `mallinfo' function. */
+#mesondefine HAVE_MALLINFO
+
+/* Define to 1 if you have the <memory.h> header file. */
+#mesondefine HAVE_MEMORY_H
+
+/* Define to 1 if you have the `mkstemp' function. */
+#mesondefine HAVE_MKSTEMP
+
+/* Define to 1 if you have a working `mmap' system call. */
+#mesondefine HAVE_MMAP
+
+/* Define to 1 if you have the `nearbyint' function. */
+#mesondefine HAVE_NEARBYINT
+
+/* Define to 1 if libpapi available */
+#mesondefine HAVE_PAPI
+
+/* Define to 1 if you have the `posix_fallocate' function. */
+#mesondefine HAVE_POSIX_FALLOCATE
+
+/* Have the Xrandr extension library */
+#mesondefine HAVE_RANDR
+
+/* Have the Xrandr 1.5 extension library */
+#mesondefine HAVE_RANDR15
+
+/* Define to 1 if you have the `rint' function. */
+#mesondefine HAVE_RINT
+
+/* Define to 1 if you have the `round' function. */
+#mesondefine HAVE_ROUND
+
+/* Define to 1 if you have the `sincos' function. */
+#mesondefine HAVE_SINCOS
+
+/* Define to 1 if you have the `log2` function */
+#mesondefine HAVE_LOG2
+
+/* Define to 1 if you ahve the `exp2` function */
+#mesondefine HAVE_EXP2
+
+/* Have the sockaddr_un.sun_len member */
+#mesondefine HAVE_SOCKADDR_UN_SUN_LEN
+
+/* Define to 1 if solaris xinerama is available */
+#mesondefine HAVE_SOLARIS_XINERAMA
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#mesondefine HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#mesondefine HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#mesondefine HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#mesondefine HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#mesondefine HAVE_SYS_MMAN_H
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#mesondefine HAVE_SYS_PARAM_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#mesondefine HAVE_SYS_STAT_H
+
+/* Define to 1 if sys/sysinfo.h is available */
+#mesondefine HAVE_SYS_SYSINFO_H
+
+/* Define to 1 if sys/systeminfo.h is available */
+#mesondefine HAVE_SYS_SYSTEMINFO_H
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#mesondefine HAVE_SYS_TIME_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#mesondefine HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#mesondefine HAVE_UNISTD_H
+
+/* Have the XCOMPOSITE X extension */
+#mesondefine HAVE_XCOMPOSITE
+
+/* Have the Xcursor library */
+#mesondefine HAVE_XCURSOR
+
+/* Have the XDAMAGE X extension */
+#mesondefine HAVE_XDAMAGE
+
+/* Have the XFIXES X extension */
+#mesondefine HAVE_XFIXES
+
+/* Define to 1 if XFree Xinerama is available */
+#mesondefine HAVE_XFREE_XINERAMA
+
+/* Have XGenericEvent */
+#mesondefine HAVE_XGENERICEVENTS
+
+/* Define to 1 if xinerama is available */
+#mesondefine HAVE_XINERAMA
+
+/* Define to use XKB extension */
+#mesondefine HAVE_XKB
+
+/* Have the SYNC extension library */
+#mesondefine HAVE_XSYNC
+
+/* Define to 1 if you have the `_lock_file' function */
+#mesondefine HAVE__LOCK_FILE
+
+/* Define to 1 if you have the `flockfile' function */
+#mesondefine HAVE_FLOCKFILE
+
+/* Define if _NL_MEASUREMENT_MEASUREMENT is available */
+#mesondefine HAVE__NL_MEASUREMENT_MEASUREMENT
+
+/* Define if _NL_PAPER_HEIGHT is available */
+#mesondefine HAVE__NL_PAPER_HEIGHT
+
+/* Define if _NL_PAPER_WIDTH is available */
+#mesondefine HAVE__NL_PAPER_WIDTH
+
+/* Define if _NL_TIME_FIRST_WEEKDAY is available */
+#mesondefine HAVE__NL_TIME_FIRST_WEEKDAY
+
+/* Define to 1 if you have the `_NSGetEnviron' function. */
+#mesondefine HAVE__NSGETENVIRON
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#mesondefine LT_OBJDIR
+
+/* Define if <X11/extensions/XIproto.h> needed for xReply */
+#mesondefine NEED_XIPROTO_H_FOR_XREPLY
+
+/* Define to 1 if your C compiler doesn't accept -c and -o together. */
+#mesondefine NO_MINUS_C_MINUS_O
+
+/* Define to the address where bug reports for this package should be sent. */
+#mesondefine PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#mesondefine PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#mesondefine PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#mesondefine PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#mesondefine PACKAGE_URL
+
+/* Define to the version of this package. */
+#mesondefine PACKAGE_VERSION
+
+/* Use NSBundle functions to determine load paths for libraries, translations,
+   etc. */
+#mesondefine QUARTZ_RELOCATION
+
+/* Define to 1 if you have the ANSI C header files. */
+#mesondefine STDC_HEADERS
+
+/* Define to 1 if gmodule works and should be used */
+#mesondefine USE_GMODULE
+
+/* Enable extensions on AIX 3, Interix.  */
+#ifndef _ALL_SOURCE
+# undef _ALL_SOURCE
+#endif
+/* Enable GNU extensions on systems that have them.  */
+#ifndef _GNU_SOURCE
+# undef _GNU_SOURCE
+#endif
+/* Enable threading extensions on Solaris.  */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# undef _POSIX_PTHREAD_SEMANTICS
+#endif
+/* Enable extensions on HP NonStop.  */
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif
+/* Enable general extensions on Solaris.  */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
+
+
+/* Define to 1 if XInput 2.0 is available */
+#mesondefine XINPUT_2
+
+/* Define to 1 if XInput 2.2 is available */
+#mesondefine XINPUT_2_2
+
+/* Define to 1 if the X Window System is missing or not being used. */
+#mesondefine X_DISPLAY_MISSING
+
+/* Enable large inode numbers on Mac OS X 10.5.  */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#mesondefine _FILE_OFFSET_BITS
+
+/* defines how to decorate public symbols while building */
+#mesondefine _GDK_EXTERN
+
+/* Define for large files, on AIX-style hosts. */
+#mesondefine _LARGE_FILES
+
+/* Define to 1 if on MINIX. */
+#mesondefine _MINIX
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+   this defined. */
+#mesondefine _POSIX_1_SOURCE
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+#mesondefine _POSIX_SOURCE
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+#mesondefine gid_t
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+#mesondefine uid_t
+
+/* Define to 1 if linux/memfd.h exists */
+#mesondefine HAVE_LINUX_MEMFD_H
+
+#mesondefine GTK_LOCALEDIR
+
+#mesondefine GTK_DATADIR
+
+#mesondefine GTK_LIBDIR
+
+#mesondefine HAVE_LINUX_INPUT_H
+
+#mesondefine HAVE_DEV_EVDEV_INPUT_H
+
+#mesondefine HAVE_TRUNC
diff --git a/demos/gtk-demo/geninclude.py b/demos/gtk-demo/geninclude.py
new file mode 100755
index 0000000000..57038a43b8
--- /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 ee44a8530f..4a4489231a 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -75,7 +75,7 @@ gtkdemo_deps = [libgtk_dep]
 
 if harfbuzz_dep.found() and pangoft_dep.found()
   demos += files('font_features.c')
-  gtkdemo_deps += harfbuzz_dep
+  gtkdemo_deps += [harfbuzz_dep, pangoft_dep]
 endif
 
 if os_unix
@@ -108,6 +108,5 @@ gtkdemo = executable(
   gtkdemo_resources,
   dependencies: gtkdemo_deps,
   include_directories : confinc,
-  gui_app: true,
   install: true
 )
diff --git a/demos/icon-browser/meson.build b/demos/icon-browser/meson.build
index 661e5208c8..8bd7e9e5bb 100644
--- a/demos/icon-browser/meson.build
+++ b/demos/icon-browser/meson.build
@@ -17,6 +17,5 @@ iconbrowser = executable(
   iconbrowser_resources,
   dependencies: libgtk_dep,
   include_directories : confinc,
-  gui_app: true,
   install: true
 )
diff --git a/demos/widget-factory/meson.build b/demos/widget-factory/meson.build
index 170a59e4bc..184a8abbb4 100644
--- a/demos/widget-factory/meson.build
+++ b/demos/widget-factory/meson.build
@@ -15,6 +15,5 @@ widget_factory = executable(
   widgetfactory_resources,
   dependencies: libgtk_dep,
   include_directories : confinc,
-  gui_app: true,
   install: true
 )
diff --git a/gdk/broadway/meson.build b/gdk/broadway/meson.build
new file mode 100644
index 0000000000..57e3488786
--- /dev/null
+++ b/gdk/broadway/meson.build
@@ -0,0 +1,78 @@
+gdk_broadway_sources = files(
+  'gdkcursor-broadway.c',
+  'gdkdevice-broadway.c',
+  'gdkdevicemanager-broadway.c',
+  'gdkdisplay-broadway.c',
+  'gdkdnd-broadway.c',
+  'gdkeventsource.c',
+  'gdkglobals-broadway.c',
+  'gdkkeys-broadway.c',
+  'gdkmonitor-broadway.c',
+  'gdkproperty-broadway.c',
+  'gdkscreen-broadway.c',
+  'gdkselection-broadway.c',
+  'gdktestutils-broadway.c',
+  'gdkvisual-broadway.c',
+  'gdkwindow-broadway.c',
+  'gdkbroadway-server.c',
+)
+
+gdk_broadway_public_headers = files(
+  'gdkbroadwaydisplay.h',
+  'gdkbroadwaysurface.h',
+  'gdkbroadwaycursor.h',
+  'gdkbroadwaymonitor.h',
+)
+
+# Broadway backend headers aren't installed it seems
+#install_headers(gdk_broadway_public_headers, subdir: 'gtk-4.0/gdk/broadway/')
+#install_headers('gdkbroadway.h', subdir: 'gtk-4.0/gdk/')
+
+gdk_broadway_deps = [shmlib]
+
+gen_c_array = find_program('gen-c-array.py')
+
+clienthtml_h = custom_target('clienthtml.h',
+  input : 'client.html',
+  output : 'clienthtml.h',
+  command : [
+    gen_c_array,
+    '--array-name=client_html',
+    '--output=@OUTPUT@',
+    '@INPUT@',
+  ],
+)
+
+broadwayjs_h = custom_target('broadwayjs.h',
+  input : ['broadway.js'],
+  output : 'broadwayjs.h',
+  command : [
+    gen_c_array,
+    '--array-name=broadway_js',
+    '--output=@OUTPUT@',
+    '@INPUT0@',
+  ],
+)
+
+libgdk_broadway = static_library('gdk-broadway',
+  clienthtml_h, broadwayjs_h,
+  gdk_broadway_sources, gdkconfig, gdkenum_h,
+  include_directories: [confinc, gdkinc],
+  c_args: [
+    '-DGDK_COMPILATION',
+    '-DG_LOG_DOMAIN="Gdk"',
+  ] + common_cflags,
+  link_args: common_ldflags,
+  dependencies: [gdk_deps, gdk_broadway_deps])
+
+# gtk4-broadwayd
+
+broadwayd_syslib = os_win32 ? find_library('ws2_32') : shmlib
+
+executable('broadwayd',
+  clienthtml_h, broadwayjs_h,
+  'broadwayd.c', 'broadway-server.c', 'broadway-output.c',
+  include_directories: [confinc, gdkinc, include_directories('.')],
+  c_args: ['-DGDK_COMPILATION', '-DG_LOG_DOMAIN="Gdk"', ],
+  dependencies : [broadwayd_syslib, gdk_deps],
+  install : true)
diff --git a/gdk/gdkconfig.h.meson b/gdk/gdkconfig.h.meson
new file mode 100644
index 0000000000..14f9e8e1ae
--- /dev/null
+++ b/gdk/gdkconfig.h.meson
@@ -0,0 +1,20 @@
+#ifndef __GDKCONFIG_H__
+#define __GDKCONFIG_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+
+#mesondefine GDK_WINDOWING_X11
+#mesondefine GDK_WINDOWING_BROADWAY
+#mesondefine GDK_WINDOWING_WAYLAND
+#mesondefine GDK_WINDOWING_WIN32
+
+G_END_DECLS
+
+#endif  /* __GDKCONFIG_H__ */
diff --git a/gdk/gen-gdk-gresources-xml.py b/gdk/gen-gdk-gresources-xml.py
new file mode 100644
index 0000000000..694a9159aa
--- /dev/null
+++ b/gdk/gen-gdk-gresources-xml.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+#
+# Generate gdk.gresources.xml
+#
+# Usage: gen-gdk-gresources-xml SRCDIR_GDK [OUTPUT-FILE]
+
+import os, sys
+
+srcdir = sys.argv[1]
+
+xml = '''<?xml version='1.0' encoding='UTF-8'?>
+<gresources>
+  <gresource prefix='/org/gtk/libgdk'>
+
+'''
+
+def get_files(subdir,extension):
+  return sorted(filter(lambda x: x.endswith((extension)), os.listdir(os.path.join(srcdir,subdir))))
+
+for f in get_files('resources/glsl', '.glsl'):
+  xml += '    <file alias=\'glsl/{0}\'>resources/glsl/{0}</file>\n'.format(f)
+
+xml += '''
+  </gresource>
+</gresources>'''
+
+if len(sys.argv) > 2:
+  outfile = sys.argv[2]
+  f = open(outfile, 'w')
+  f.write(xml)
+  f.close()
+else:
+  print(xml)
diff --git a/gdk/meson.build b/gdk/meson.build
index cd5d4cbe2f..e9e7b8a819 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -1,5 +1,5 @@
-deprecated_gdk_sources = ['deprecated/gdkcolor.c']
-gdk_sources = files([
+deprecated_gdk_sources = files('deprecated/gdkcolor.c')
+gdk_sources = files(
   'gdk-private.c',
   'gdk.c',
   'gdkapplaunchcontext.c',
@@ -37,9 +37,9 @@ gdk_sources = files([
   'gdkdevicetool.c',
   'gdkdrawingcontext.c',
   'gdkmonitor.c'
-])
+)
 
-gdk_public_h_sources = files([
+gdk_public_headers = files(
   'gdk.h',
   'gdk-autocleanup.h',
   'gdkapplaunchcontext.h',
@@ -58,6 +58,7 @@ gdk_public_h_sources = files([
   'gdkglcontext.h',
   'gdkkeys.h',
   'gdkkeysyms.h',
+  'gdkkeysyms-compat.h',
   'gdkmain.h',
   'gdkmonitor.h',
   'gdkpango.h',
@@ -75,227 +76,125 @@ gdk_public_h_sources = files([
   'gdktypes.h',
   'gdkvisual.h',
   'gdkwindow.h',
-])
+)
+install_headers(gdk_public_headers, subdir : 'gtk-3.0/gdk')
+
+deprecated_h_sources = files('deprecated/gdkcolor.h')
+install_headers(deprecated_h_sources, subdir : 'gtk-3.0/gdk/deprecated')
 
-gdk_private_h_sources = files([
+# This variable is unused, but added just for completeness
+gdk_private_headers = files(
   'gdkseatdefaultprivate.h',
   'gdkdevicetoolprivate.h',
   'gdkdrawingcontextprivate.h',
   'gdkmonitorprivate.h',
   'gdkprivate.h',
-])
-
-gdk_x_sources = [
-  'x11/MwmUtil.h',
-  'x11/gdkapplaunchcontext-x11.c',
-  'x11/gdkasync.c',
-  'x11/gdkasync.h',
-  'x11/gdkcursor-x11.c',
-  'x11/gdkdevice-core-x11.c',
-  'x11/gdkdevice-xi2.c',
-  'x11/gdkdevicemanager-core-x11.c',
-  'x11/gdkdevicemanager-x11.c',
-  'x11/gdkdevicemanager-xi2.c',
-  'x11/gdkdisplaymanager-x11.c',
-  'x11/gdkdisplay-x11.c',
-  'x11/gdkdisplay-x11.h',
-  'x11/gdkdnd-x11.c',
-  'x11/gdkeventsource.c',
-  'x11/gdkeventsource.h',
-  'x11/gdkeventtranslator.c',
-  'x11/gdkeventtranslator.h',
-  'x11/gdkgeometry-x11.c',
-  'x11/gdkglcontext-x11.c',
-  'x11/gdkglcontext-x11.h',
-  'x11/gdkkeys-x11.c',
-  'x11/gdkmain-x11.c',
-  'x11/gdkproperty-x11.c',
-  'x11/gdkscreen-x11.c',
-  'x11/gdkscreen-x11.h',
-  'x11/gdkselection-x11.c',
-  'x11/gdktestutils-x11.c',
-  'x11/gdkvisual-x11.c',
-  'x11/gdkwindow-x11.c',
-  'x11/gdkwindow-x11.h',
-  'x11/gdkxftdefaults.c',
-  'x11/gdkxid.c',
-  'x11/gdkx.h',
-  'x11/xsettings-client.h',
-  'x11/xsettings-client.c',
-  'x11/gdkmonitor-x11.c',
-  'x11/gdkmonitor-x11.h',
-  'x11/gdkx11monitor.h'
-]
-
-gdk_x_private_sources = [
-  'x11/gdkprivate-x11.h',
-  'x11/gdkdevicemanagerprivate-core.h',
-]
+)
 
-gdk_wayland_sources = files([
+gdk_wayland_sources = files(
   'wayland/gdkapplaunchcontext-wayland.c',
   'wayland/gdkcursor-wayland.c',
   'wayland/gdkdevice-wayland.c',
   'wayland/gdkdisplay-wayland.c',
-  'wayland/gdkdisplay-wayland.h',
   'wayland/gdkdnd-wayland.c',
   'wayland/gdkeventsource.c',
   'wayland/gdkglcontext-wayland.c',
-  'wayland/gdkglcontext-wayland.h',
   'wayland/gdkkeys-wayland.c',
   'wayland/gdkmonitor-wayland.c',
-  'wayland/gdkmonitor-wayland.h',
   'wayland/gdkscreen-wayland.c',
-  'wayland/gdkseat-wayland.h',
   'wayland/gdkselection-wayland.c',
-  'wayland/gdkwaylanddevice.h',
-  'wayland/gdkwaylanddisplay.h',
-  'wayland/gdkwaylandglcontext.h',
-  'wayland/gdkwayland.h',
-  'wayland/gdkwaylandmonitor.h',
-  'wayland/gdkwaylandselection.h',
-  'wayland/gdkwaylandwindow.h',
   'wayland/gdkwindow-wayland.c',
   'wayland/wm-button-layout-translation.c',
-])
-
-gdk_wayland_private_sources = files([
-  'wayland/gdkprivate-wayland.h',
-])
-
-
+)
 
 gdk_broadway_sources = files([
   'broadway/gdkdisplay-broadway.c',
-  'broadway/gdkdisplay-broadway.h',
   'broadway/gdkscreen-broadway.c',
-  'broadway/gdkscreen-broadway.h',
   'broadway/broadway-output.c',
-  'broadway/broadway-output.h',
-  'broadway/broadway-server.h',
   'broadway/broadway-server.c',
   'broadway/gdkbroadway-server.c',
   'broadway/gdkcursor-broadway.c',
   'broadway/gdkvisual-broadway.c',
   'broadway/gdkselection-broadway.c',
   'broadway/gdkwindow-broadway.c',
-  'broadway/gdkwindow-broadway.h',
   'broadway/gdkmonitor-broadway.c',
-  'broadway/gdkmonitor-broadway.h',
   'broadway/gdkkeys-broadway.c',
   'broadway/gdkglobals-broadway.c',
   'broadway/gdkeventsource.c',
-  'broadway/gdkeventsource.h',
   'broadway/gdkdnd-broadway.c',
   'broadway/broadwayd.c',
   'broadway/gdkdevicemanager-broadway.c',
-  'broadway/gdkdevicemanager-broadway.h',
   'broadway/gdkdevice-broadway.c',
-  'broadway/gdkdevice-broadway.h',
   'broadway/broadway-buffer.c',
-  'broadway/broadway-buffer.h',
   'broadway/gdktestutils-broadway.c',
   'broadway/gdkproperty-broadway.c'
 ])
 
-gdk_broadway_private_sources = files([
-  'broadway/gdkprivate-broadway.h'
-])
+gdk_gresource_xml = configure_file(output : 'gdk.gresource.xml',
+  input : 'gen-gdk-gresources-xml.py',
+  command : [find_program('gen-gdk-gresources-xml.py'),
+             meson.current_source_dir(), '@OUTPUT@'])
 
-# glsl_sources = [
-  # 'gl3-texture-2d.fs.glsl',
-  # 'gl3-texture-2d.vs.glsl',
-  # 'gl3-texture-rect.fs.glsl',
-  # 'gl3-texture-rect.vs.glsl',
-  # 'gl2-texture-2d.fs.glsl',
-  # 'gl2-texture-2d.fs.glsl',
-  # 'gl2-texture-rect.vs.glsl',
-  # 'gl2-texture-rect.vs.glsl',
-  # 'gles2-texture.fs.glsl',
-  # 'gles2-texture.vs.glsl',
-# ]
-# resource_xml = ''
-# foreach glsl_file : glsl_sources
-  # resource_xml += '    <file alias="glsl/@0@">resources/glsl/@0@</file>\n'.format(glsl_file)
-# endforeach
-
-
-# cdata = configuration_data()
-# cdata.set('GDK_GRESOURCE_XML_FILES', resource_xml)
-# gdkresources_xml = configure_file(
-  # input  : 'gdk.gresource.xml.meson',
-  # output : 'gdk.gresource.xml',
-  # configuration : cdata
-# )
-
-gdkresources = gnome.compile_resources(
-  'gdkresources',
-  'gdk.gresource.xml',
+gdkresources = gnome.compile_resources('gdkresources',
+  gdk_gresource_xml,
   source_dir: '.',
   c_name: '_gdk',
   extra_args: '--manual-register'
 )
 
+gdk_headers = gdk_public_headers
 
-deprecated_h_sources = files(['deprecated/gdkcolor.h'])
-
-gdk_headers = gdk_public_h_sources + deprecated_h_sources + gdk_private_h_sources
-
-gdkenum_h = custom_target(
-  'gdkenum_h',
-  output  : 'gdkenumtypes.h',
-  input   : gdk_headers,
-  command : [mkenum, perl, glib_mkenums, meson.current_source_dir() + '/gdkenumtypes.h.template', 
'@OUTPUT@', '@INPUT@'])
+gdk_enums = gnome.mkenums('gdkenumtypes',
+  sources: gdk_public_headers,
+  c_template : 'gdkenumtypes.c.template',
+  h_template : 'gdkenumtypes.h.template',
+  install_dir: join_paths(gtk_includedir, 'gtk-3.0/gdk'),
+  install_header : true)
 
-gdkenum_c = custom_target(
-  'gdkenum_c',
-  output  : 'gdkenumtypes.c',
-  input   : gdk_headers,
-  depends : gdkenum_h,
-  command : [mkenum, perl, glib_mkenums, meson.current_source_dir() + '/gdkenumtypes.c.template', 
'@OUTPUT@', '@INPUT@'])
+gdkenum_h = gdk_enums[1]
 
-gdkmarshal_h = custom_target(
-  'gdkmarshal_h',
-  output  : 'gdkmarshalers.h',
-  input   : 'gdkmarshalers.list',
-  command : [mkmarshal, glib_marshal, '_gdk_marshal', '@INPUT@', '@OUTPUT@']
-)
-
-gdkmarshal_c = custom_target(
-  'gdkmarshal_c',
-  output  : 'gdkmarshalers.c',
-  input   : 'gdkmarshalers.list',
-  command : [mkmarshal, glib_marshal, '_gdk_marshal', '@INPUT@', '@OUTPUT@']
-)
+gdk_marshalers = gnome.genmarshal('gdkmarshalers',
+  sources : 'gdkmarshalers.list',
+  prefix : '_gdk_marshal',
+  valist_marshallers : true)
 
-cdata = configuration_data()
-cdata.set('GTK_MAJOR_VERSION', gtk_major_version)
-cdata.set('GTK_MINOR_VERSION', gtk_minor_version)
-cdata.set('GTK_MICRO_VERSION', gtk_micro_version)
+gdkmarshal_h = gdk_marshalers[1]
 
+gdkconfig_cdata = configuration_data()
+gdkconfig_cdata.set('GDK_WINDOWING_X11', x11_enabled)
+gdkconfig_cdata.set('GDK_WINDOWING_WAYLAND', wayland_enabled)
+gdkconfig_cdata.set('GDK_WINDOWING_WIN32', win32_enabled)
+gdkconfig_cdata.set('GDK_WINDOWING_BROADWAY', broadway_enabled)
 
-
-if x11_enabled      cdata.set('GDK_WINDOWING_X11', '')      endif
-if wayland_enabled  cdata.set('GDK_WINDOWING_WAYLAND', '')  endif
-if broadway_enabled cdata.set('GDK_WINDOWING_BROADWAY', '') endif
 gdkconfig = configure_file(
   input  : 'gdkconfig.h.meson',
   output : 'gdkconfig.h',
-  configuration : cdata
-)
+  configuration : gdkconfig_cdata,
+  install_dir: join_paths(gtk_includedir, 'gtk-3.0/gdk'),
+  install : true)
+
+
+gdkversion_cdata = configuration_data()
+gdkversion_cdata.set('GTK_MAJOR_VERSION', gtk_major_version)
+gdkversion_cdata.set('GTK_MINOR_VERSION', gtk_minor_version)
+gdkversion_cdata.set('GTK_MICRO_VERSION', gtk_micro_version)
 
 gdkversionmacros = configure_file(
   input  : 'gdkversionmacros.h.in',
   output : 'gdkversionmacros.h',
-  configuration: cdata
-)
+  configuration: gdkversion_cdata,
+  install_dir: join_paths(gtk_includedir, 'gtk-3.0/gdk'))
+
+gdkinc = include_directories('.')
+gdkx11_inc = include_directories('x11')
+gdkwayland_inc = include_directories('wayland')
 
-xinc = include_directories('x11')
 wlinc = include_directories('.')
 
+gdk_gen_headers = [gdkenum_h, gdkmarshal_h, gdkconfig, gdkversionmacros]
 
 gdk_deps = [
-  mlib,
+  libm,
   pixbuf_dep,
   cairo_dep,
   pango_dep,
@@ -303,80 +202,74 @@ gdk_deps = [
   glib_dep,
   epoxy_dep,
   fontconfig_dep,
-  giounix_dep,
+  platform_gio_dep,
   pangocairo_dep
 ]
 
+if win32_enabled
+  gdk_deps += [cc.find_library('advapi32'),
+               cc.find_library('comctl32'),
+               cc.find_library('dwmapi'),
+               cc.find_library('imm32'),
+               cc.find_library('setupapi'),
+               cc.find_library('winmm')]
+endif
+
 gdk_sources = [
+  # Generated
   gdkconfig,
-  gdk_sources,
-  deprecated_gdk_sources,
-  gdkenum_c, gdkenum_h,
-  gdkmarshal_c, gdkmarshal_h,
+  gdk_enums,
+  gdk_marshalers,
   gdkresources,
   gdkversionmacros,
-  gdk_headers
+  # Static
+  gdk_sources,
+  deprecated_gdk_sources,
 ]
 
-if x11_enabled
-  gdk_deps += [
-    xrender_dep,
-    xi_dep,
-    xext_dep,
-    x11_dep,
-    xcursor_dep,
-    xdamage_dep,
-    xfixes_dep,
-    xcomposite_dep,
-    xrandr_dep
-  ]
-  gdk_sources += [
-    gdk_x_sources,
-    gdk_x_private_sources
-  ]
+if wayland_enabled or broadway_enabled
+  if cc.has_function('shm_open')
+    shmlib = []
+  elif cc.has_function('shm_open', args : '-lrt')
+    shmlib = cc.find_library('rt')
+  else
+    shmlib = []
+  endif
 endif
 
-if wayland_enabled
-  subdir('wayland')
-  gdk_deps += [
-    shmlib,
-    xkbdep,
-    wlclientdep,
-    wlprotocolsdep,
-    wlcursordep,
-    wlegldep
-  ]
-  gdk_sources += [
-    gdk_wayland_sources,
-    gdk_wayland_private_sources
-  ]
-endif
-
-if broadway_enabled
-  gdk_deps += [
-    shmlib,
-  ]
-  gdk_sources += [
-    gdk_broadway_sources,
-    gdk_broadway_private_sources
-  ]
+gdk_backends = []
+gdk_backends_gen_headers = []  # non-public generated headers
+foreach backend : ['broadway', 'quartz', 'wayland', 'win32', 'x11']
+  if get_variable('@0@_enabled'.format(backend))
+    subdir(backend)
+    gdk_deps += get_variable('gdk_@0@_deps'.format(backend))
+    gdk_backends += get_variable('libgdk_@0@'.format(backend))
+    # Special-case this for now to work around Meson bug with get_variable()
+    # fallback being an empty array, or any array (#1481)
+    if backend == 'wayland'
+      gdk_backends_gen_headers += get_variable('gdk_@0@_gen_headers'.format(backend))
+    endif
+  endif
+endforeach
+
+if gdk_backends.length() == 0
+  error('No backends enabled')
 endif
 
-
-libgdk = shared_library('gdk',
-  sources: [gdk_sources, gdkconfig, gdkenum_h],
-  c_args: ['-DHAVE_CONFIG_H', '-DGDK_COMPILATION'],
-  include_directories: [confinc, xinc, wlinc],
-  dependencies: gdk_deps,
-  install: true
-)
-
+libgdk = shared_library('gdk-3',
+                        sources: [gdk_sources, gdk_backends_gen_headers, gdkconfig],
+                        dependencies: gdk_deps,
+                        include_directories: [confinc, gdkx11_inc, wlinc],
+                        c_args: [
+                          '-DGDK_COMPILATION',
+                          '-DG_LOG_DOMAIN="Gdk"',
+                        ] + common_cflags,
+                        link_whole: gdk_backends,
+                        link_args: common_ldflags,
+                        install: true)
 
 libgdk_dep = declare_dependency(
-  sources: ['gdk.h', gdkconfig, gdkenum_h],
-  depends: gdk_sources,
-  include_directories: [confinc, xinc, wlinc],
-  dependencies: gdk_deps,
   link_with: libgdk,
-  link_args: ['-Bsymbolic'],
-)
+  sources: ['gdk.h', gdkconfig, gdkenum_h],
+  include_directories: [confinc, gdkx11_inc, wlinc],
+  dependencies: gdk_deps)
diff --git a/gdk/quartz/meson.build b/gdk/quartz/meson.build
new file mode 100644
index 0000000000..8c1b8d1795
--- /dev/null
+++ b/gdk/quartz/meson.build
@@ -0,0 +1,51 @@
+# FIXME: do we need to do an add_language() for objective-c here?
+gdk_quartz_sources = files(
+  'GdkQuartzView.c',
+  'GdkQuartzNSWindow.c',
+  'gdkcursor-quartz.c',
+  'gdkdevice-core-quartz.c',
+  'gdkdevicemanager-core-quartz.c',
+  'gdkdisplay-quartz.c',
+  'gdkdisplaymanager-quartz.c',
+  'gdkdnd-quartz.c',
+  'gdkevents-quartz.c',
+  'gdkeventloop-quartz.c',
+  'gdkglcontext-quartz.c',
+  'gdkglobals-quartz.c',
+  'gdkkeys-quartz.c',
+  'gdkmonitor-quartz.c',
+  'gdkproperty-quartz.c',
+  'gdkscreen-quartz.c',
+  'gdkselection-quartz.c',
+  'gdktestutils-quartz.c',
+  'gdkutils-quartz.c',
+  'gdkvisual-quartz.c',
+  'gdkwindow-quartz.c',
+)
+
+gdk_quartz_public_headers = files(
+  'gdkquartzcursor.h',
+  'gdkquartzdevice-core.h',
+  'gdkquartzdevicemanager-core.h',
+  'gdkquartzdisplay.h',
+  'gdkquartzdisplaymanager.h',
+  'gdkquartzdnd.h',
+  'gdkquartzkeys.h',
+  'gdkquartzmonitor.h',
+  'gdkquartzscreen.h',
+  'gdkquartzutils.h',
+  'gdkquartzvisual.h',
+  'gdkquartzwindow.h',
+)
+
+install_headers(gdk_quartz_public_headers, subdir: 'gtk-3.0/gdk/quartz')
+install_headers('gdkquartz.h', subdir: 'gtk-3.0/gdk')
+
+gdk_quartz_deps = [ # FIXME
+]
+
+libgdk_quartz = static_library('gdk-quartz',
+  gdk_quartz_sources, gdkconfig, gdkenum_h,
+  include_directories: [confinc, gdkinc],
+  c_args: ['-DGDK_COMPILATION', '-DG_LOG_DOMAIN="Gdk"', '-xobjective-c'],
+  dependencies: [gdk_deps, gdk_quartz_deps])
diff --git a/gdk/wayland/meson.build b/gdk/wayland/meson.build
index 6783ecf193..559e02ba3d 100644
--- a/gdk/wayland/meson.build
+++ b/gdk/wayland/meson.build
@@ -1,115 +1,105 @@
-
-
-if wayland_enabled
-  runcmd = run_command('pkg-config', '--variable=pkgdatadir', 'wayland-protocols')
-  if runcmd.returncode() == 0
-    wayland_protocols_datadir = runcmd.stdout().strip() + '/'
+gdk_wayland_sources = files(
+  'gdkapplaunchcontext-wayland.c',
+  'gdkcursor-wayland.c',
+  'gdkdevice-wayland.c',
+  'gdkdisplay-wayland.c',
+  'gdkdnd-wayland.c',
+  'gdkeventsource.c',
+  'gdkkeys-wayland.c',
+  'gdkglcontext-wayland.c',
+  'gdkmonitor-wayland.c',
+  'gdkscreen-wayland.c',
+  'gdkselection-wayland.c',
+  'gdkwindow-wayland.c',
+  'wm-button-layout-translation.c',
+)
+
+gdk_wayland_public_headers = files(
+  'gdkwaylanddevice.h',
+  'gdkwaylanddisplay.h',
+  'gdkwaylandglcontext.h',
+  'gdkwaylandmonitor.h',
+  'gdkwaylandselection.h',
+  'gdkwaylandwindow.h',
+)
+
+install_headers(gdk_wayland_public_headers, subdir: 'gtk-3.0/gdk/wayland')
+install_headers('gdkwayland.h', subdir: 'gtk-3.0/gdk')
+
+gdk_wayland_deps = [
+  shmlib,
+  xkbdep,
+  wlclientdep,
+  wlprotocolsdep,
+  wlcursordep,
+  wlegldep,
+]
+
+# wayland protocols
+proto_dir = dependency('wayland-protocols').get_pkgconfig_variable('pkgdatadir')
+assert(proto_dir != '', 'Could not get pkgdatadir from wayland-protocols.pc')
+
+wayland_scanner = find_program('wayland-scanner')
+
+# Format:
+#  - protocol name
+#  - protocol stability ('private', 'stable' or 'unstable')
+#  - protocol version (if stability is 'unstable')
+proto_sources = [
+  ['gtk-shell', 'private', ],
+  ['gtk-primary-selection', 'private', ],
+  ['pointer-gestures', 'unstable', 'v1', ],
+  ['xdg-shell', 'unstable', 'v6', ],
+  ['xdg-shell', 'stable', ],
+  ['xdg-foreign', 'unstable', 'v1', ],
+  ['tablet', 'unstable', 'v2', ],
+  ['keyboard-shortcuts-inhibit', 'unstable', 'v1', ],
+  ['server-decoration', 'private' ],
+]
+
+gdk_wayland_gen_headers = []
+
+foreach p: proto_sources
+  proto_name = p.get(0)
+  proto_stability = p.get(1)
+
+  if proto_stability == 'stable'
+    output_base = proto_name
+    input = join_paths(proto_dir, '@0@/@1@/@2@.xml'.format(proto_stability, proto_name, output_base))
+  elif proto_stability == 'private'
+    output_base = proto_name
+    input = 'protocol/@0@.xml'.format(proto_name)
   else
-    error('Could not get wayland-protocols pkgdatadir via pkg-config.')
+    proto_version = p.get(2)
+    output_base = '@0@-@1@-@2@'.format(proto_name, proto_stability, proto_version)
+    input = join_paths(proto_dir, '@0@/@1@/@2@.xml'.format(proto_stability, proto_name, output_base))
   endif
 
-  wayland_scanner = find_program('wayland-scanner')
-  genprotocols = find_program('genprotocolfiles.py')
-
-  gtk_shell_h = custom_target(
-    'gtk shell protocol header',
-    input  : 'protocol/gtk-shell.xml',
-    output : 'gtk-shell-client-protocol.h',
-    command: [genprotocols, wayland_scanner, '@INPUT@', '@OUTPUT@', 'client-header']
-  )
-
-  gtk_shell_c = custom_target(
-    'gtk shell protocol source',
-    input  : 'protocol/gtk-shell.xml',
-    output : 'gtk-shell-protocol.c',
-    command: [genprotocols, wayland_scanner, '@INPUT@', '@OUTPUT@', 'code']
-  )
-
-  pointer_gestures_h = custom_target(
-    'pointer gestures header',
-    input  : wayland_protocols_datadir + 'unstable/pointer-gestures/pointer-gestures-unstable-v1.xml',
-    output : 'pointer-gestures-unstable-v1-client-protocol.h',
-    command: [genprotocols, wayland_scanner, '@INPUT@', '@OUTPUT@', 'client-header']
-  )
-
-  pointer_gestures_c = custom_target(
-    'pointer gestures source',
-    input  : wayland_protocols_datadir + 'unstable/pointer-gestures/pointer-gestures-unstable-v1.xml',
-    output : 'pointer-gestures-unstable-v1-protocol.c',
-    command: [genprotocols, wayland_scanner, '@INPUT@', '@OUTPUT@', 'code']
-  )
-
-  primary_selection_h = custom_target(
-    'primary selection header',
-    input  : 'protocol/gtk-primary-selection.xml',
-    output : 'gtk-primary-selection-client-protocol.h',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'client-header']
-  )
-
-  primary_selection_c = custom_target(
-    'primary selection source',
-    input  : 'protocol/gtk-primary-selection.xml',
-    output : 'gtk-primary-selection-protocol.c',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'code']
-  )
-
-  xdg_shell_h = custom_target(
-    'xdg shell v6 header',
-    input  : wayland_protocols_datadir + 'unstable/xdg-shell/xdg-shell-unstable-v6.xml',
-    output : 'xdg-shell-unstable-v6-client-protocol.h',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'client-header']
-  )
-
-  xdg_shell_c = custom_target(
-    'xdg shell v6 source',
-    input  : wayland_protocols_datadir + 'unstable/xdg-shell/xdg-shell-unstable-v6.xml',
-    output : 'xdg-shell-unstable-v6-protocol.c',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'code']
-  )
-
-  xdg_foreign_h = custom_target(
-    'xdg foreign v1 header',
-    input  : wayland_protocols_datadir + 'unstable/xdg-foreign/xdg-foreign-unstable-v1.xml',
-    output : 'xdg-foreign-unstable-v1-client-protocol.h',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'client-header']
-  )
-
-  xdg_foreign_c = custom_target(
-    'xdg foreign v1 source',
-    input  : wayland_protocols_datadir + 'unstable/xdg-foreign/xdg-foreign-unstable-v1.xml',
-    output : 'xdg-foreign-unstable-v1-protocol.c',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'code']
-  )
-
-  tablet_h = custom_target(
-    'tablet v2 header',
-    input  : wayland_protocols_datadir + 'unstable/tablet/tablet-unstable-v2.xml',
-    output : 'tablet-unstable-v2-client-protocol.h',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'client-header']
-  )
-
-  tablet_c = custom_target(
-    'tablet v2 source',
-    input  : wayland_protocols_datadir + 'unstable/tablet/tablet-unstable-v2.xml',
-    output : 'tablet-unstable-v2-protocol.c',
-    command: [genprotocols, wayland_scanner,'@INPUT@', '@OUTPUT@', 'code']
-  )
-
-
-
-  gdk_sources += [
-    gtk_shell_c,
-    gtk_shell_h,
-    pointer_gestures_h,
-    pointer_gestures_c,
-    primary_selection_h,
-    primary_selection_c,
-    xdg_shell_h,
-    xdg_shell_c,
-    xdg_foreign_h,
-    xdg_foreign_c,
-    tablet_h,
-    tablet_c
-  ]
-
-endif
+  gdk_wayland_gen_headers += custom_target('@0@ client header'.format(output_base),
+                                           input: input,
+                                           output: '@0@-client-protocol.h'.format(output_base),
+                                           command: [
+                                             wayland_scanner,
+                                             'client-header',
+                                             '@INPUT@', '@OUTPUT@',
+                                           ])
+
+  gdk_wayland_sources += custom_target('@0@ source'.format(output_base),
+                                       input: input,
+                                       output: '@0@-protocol.c'.format(output_base),
+                                       command: [
+                                         wayland_scanner,
+                                         'private-code',
+                                         '@INPUT@', '@OUTPUT@',
+                                       ])
+endforeach
+
+libgdk_wayland = static_library('gdk-wayland',
+                                gdk_wayland_sources, gdk_wayland_gen_headers, gdkconfig, gdkenum_h,
+                                include_directories: [ confinc, gdkinc, ],
+                                c_args: [
+                                  '-DGDK_COMPILATION',
+                                  '-DG_LOG_DOMAIN="Gdk"',
+                                ] + common_cflags,
+                                link_args: common_ldflags,
+                                dependencies: [ gdk_deps, gdk_wayland_deps, ])
diff --git a/gdk/win32/meson.build b/gdk/win32/meson.build
new file mode 100644
index 0000000000..343a9ff402
--- /dev/null
+++ b/gdk/win32/meson.build
@@ -0,0 +1,48 @@
+gdk_win32_sources = files(
+  'gdkcursor-win32.c',
+  'gdkdevicemanager-win32.c',
+  'gdkdevice-virtual.c',
+  'gdkdevice-win32.c',
+  'gdkdevice-wintab.c',
+  'gdkdisplay-win32.c',
+  'gdkdisplaymanager-win32.c',
+  'gdkdnd-win32.c',
+  'gdkevents-win32.c',
+  'gdkgeometry-win32.c',
+  'gdkglcontext-win32.c',
+  'gdkglobals-win32.c',
+  'gdkkeys-win32.c',
+  'gdkmain-win32.c',
+  'gdkmonitor-win32.c',
+  'gdkproperty-win32.c',
+  'gdkscreen-win32.c',
+  'gdkselection-win32.c',
+  'gdktestutils-win32.c',
+  'gdkwin32id.c',
+  'gdkwindow-win32.c',
+)
+
+gdk_win32_public_headers = files(
+  'gdkwin32cursor.h',
+  'gdkwin32display.h',
+  'gdkwin32displaymanager.h',
+  'gdkwin32dnd.h',
+  'gdkwin32glcontext.h',
+  'gdkwin32keys.h',
+  'gdkwin32misc.h',
+  'gdkwin32monitor.h',
+  'gdkwin32screen.h',
+  'gdkwin32window.h',
+)
+
+install_headers(gdk_win32_public_headers, subdir: 'gtk-3.0/gdk/win32')
+install_headers('gdkwin32.h', subdir: 'gtk-3.0/gdk')
+
+gdk_win32_deps = [ # FIXME
+]
+
+libgdk_win32 = static_library('gdk-win32',
+  gdk_win32_sources, gdkconfig, gdkenum_h,
+  include_directories: [confinc, gdkinc],
+  c_args: ['-DGDK_COMPILATION', '-DG_LOG_DOMAIN="Gdk"', '-DINSIDE_GDK_WIN32'],
+  dependencies: [gdk_deps, gdk_win32_deps])
diff --git a/gdk/x11/meson.build b/gdk/x11/meson.build
new file mode 100644
index 0000000000..c31a682d69
--- /dev/null
+++ b/gdk/x11/meson.build
@@ -0,0 +1,81 @@
+# Note: gdksettings.c gets included from xsettings-client.c, do not add here
+gdk_x11_sources = files(
+  'gdkapplaunchcontext-x11.c',
+  'gdkasync.c',
+  'gdkcursor-x11.c',
+  'gdkdevice-core-x11.c',
+  'gdkdevice-xi2.c',
+  'gdkdevicemanager-core-x11.c',
+  'gdkdevicemanager-x11.c',
+  'gdkdevicemanager-xi2.c',
+  'gdkdisplaymanager-x11.c',
+  'gdkdisplay-x11.c',
+  'gdkdnd-x11.c',
+  'gdkeventsource.c',
+  'gdkeventtranslator.c',
+  'gdkgeometry-x11.c',
+  'gdkglcontext-x11.c',
+  'gdkkeys-x11.c',
+  'gdkmain-x11.c',
+  'gdkproperty-x11.c',
+  'gdkscreen-x11.c',
+  'gdkscreen-x11.h',
+  'gdkselection-x11.c',
+  'gdktestutils-x11.c',
+  'gdkvisual-x11.c',
+  'gdkwindow-x11.c',
+  'gdkxftdefaults.c',
+  'gdkxid.c',
+  'xsettings-client.c',
+  'gdkmonitor-x11.c',
+)
+
+gdk_x11_public_headers = files(
+  'gdkx-autocleanups.h',
+  'gdkx11applaunchcontext.h',
+  'gdkx11cursor.h',
+  'gdkx11device.h',
+  'gdkx11device-core.h',
+  'gdkx11device-xi2.h',
+  'gdkx11devicemanager.h',
+  'gdkx11devicemanager-core.h',
+  'gdkx11devicemanager-xi2.h',
+  'gdkx11display.h',
+  'gdkx11displaymanager.h',
+  'gdkx11dnd.h',
+  'gdkx11glcontext.h',
+  'gdkx11keys.h',
+  'gdkx11monitor.h',
+  'gdkx11property.h',
+  'gdkx11screen.h',
+  'gdkx11selection.h',
+  'gdkx11utils.h',
+  'gdkx11visual.h',
+  'gdkx11window.h',
+)
+
+install_headers(gdk_x11_public_headers, subdir: 'gtk-3.0/gdk/x11/')
+install_headers('gdkx.h', subdir: 'gtk-3.0/gdk/')
+
+gdk_x11_deps = [
+  xrender_dep,
+  xi_dep,
+  xext_dep,
+  x11_dep,
+  xcursor_dep,
+  xdamage_dep,
+  xfixes_dep,
+  xcomposite_dep,
+  xrandr_dep,
+  xinerama_dep,
+]
+
+libgdk_x11 = static_library('gdk-x11', gdkmarshal_h,
+                            gdk_x11_sources, gdkconfig, gdkenum_h,
+                            include_directories: [ confinc, gdkinc, ],
+                            c_args: [
+                              '-DGDK_COMPILATION',
+                              '-DG_LOG_DOMAIN="Gdk"',
+                            ] + common_cflags,
+                            link_args: common_ldflags,
+                            dependencies: [ gdk_deps, gdk_x11_deps, ])
diff --git a/gtk/a11y/meson.build b/gtk/a11y/meson.build
index c53c22abdd..d0359158d0 100644
--- a/gtk/a11y/meson.build
+++ b/gtk/a11y/meson.build
@@ -45,6 +45,7 @@ a11y_sources = files(
   'gtkspinbuttonaccessible.c',
   'gtkspinneraccessible.c',
   'gtkstatusbaraccessible.c',
+  'gtkstackaccessible.c',
   'gtkswitchaccessible.c',
   'gtktextcellaccessible.c',
   'gtktextviewaccessible.c',
@@ -53,5 +54,61 @@ a11y_sources = files(
   'gtktreeviewaccessible.c',
   'gtkwidgetaccessible.c',
   'gtkwindowaccessible.c',
-  'gtkstackaccessible.c'
-  )
+)
+
+a11y_headers = files(
+  'gtk-a11y-autocleanups.h',
+  'gtkarrowaccessible.h',
+  'gtkbooleancellaccessible.h',
+  'gtkbuttonaccessible.h',
+  'gtkcellaccessible.h',
+  'gtkcellaccessibleparent.h',
+  'gtkcheckmenuitemaccessible.h',
+  'gtkcomboboxaccessible.h',
+  'gtkcontaineraccessible.h',
+  'gtkcontainercellaccessible.h',
+  'gtkentryaccessible.h',
+  'gtkexpanderaccessible.h',
+  'gtkflowboxaccessible.h',
+  'gtkflowboxchildaccessible.h',
+  'gtkframeaccessible.h',
+  'gtkiconviewaccessible.h',
+  'gtkimageaccessible.h',
+  'gtkimagecellaccessible.h',
+  'gtklabelaccessible.h',
+  'gtklevelbaraccessible.h',
+  'gtklinkbuttonaccessible.h',
+  'gtklistboxaccessible.h',
+  'gtklistboxrowaccessible.h',
+  'gtklockbuttonaccessible.h',
+  'gtkmenuaccessible.h',
+  'gtkmenubuttonaccessible.h',
+  'gtkmenuitemaccessible.h',
+  'gtkmenushellaccessible.h',
+  'gtknotebookaccessible.h',
+  'gtknotebookpageaccessible.h',
+  'gtkpanedaccessible.h',
+  'gtkpopoveraccessible.h',
+  'gtkprogressbaraccessible.h',
+  'gtkradiobuttonaccessible.h',
+  'gtkradiomenuitemaccessible.h',
+  'gtkrangeaccessible.h',
+  'gtkrenderercellaccessible.h',
+  'gtkscaleaccessible.h',
+  'gtkscalebuttonaccessible.h',
+  'gtkscrolledwindowaccessible.h',
+  'gtkspinbuttonaccessible.h',
+  'gtkspinneraccessible.h',
+  'gtkstatusbaraccessible.h',
+  'gtkstackaccessible.h',
+  'gtkswitchaccessible.h',
+  'gtktextcellaccessible.h',
+  'gtktextviewaccessible.h',
+  'gtktogglebuttonaccessible.h',
+  'gtktoplevelaccessible.h',
+  'gtktreeviewaccessible.h',
+  'gtkwidgetaccessible.h',
+  'gtkwindowaccessible.h',
+)
+
+install_headers(a11y_headers, subdir : 'gtk-3.0/gtk/a11y')
diff --git a/gtk/deprecated/meson.build b/gtk/deprecated/meson.build
index c2cf4757eb..9dfd5f0255 100644
--- a/gtk/deprecated/meson.build
+++ b/gtk/deprecated/meson.build
@@ -1,4 +1,4 @@
-gtk_deprecated_c_sources = files(
+gtk_deprecated_sources = files(
   'gtkactivatable.c',
   'gtkaction.c',
   'gtkactiongroup.c',
@@ -40,3 +40,48 @@ gtk_deprecated_c_sources = files(
   'gtkvseparator.c',
   'gtkvpaned.c',
 )
+
+gtk_deprecated_headers = files(
+  'gtkactivatable.h',
+  'gtkaction.h',
+  'gtkactiongroup.h',
+  'gtkalignment.h',
+  'gtkarrow.h',
+  'gtkcolorsel.h',
+  'gtkcolorseldialog.h',
+  'gtkfontsel.h',
+  'gtkgradient.h',
+  'gtkhandlebox.h',
+  'gtkhbbox.h',
+  'gtkhbox.h',
+  'gtkhpaned.h',
+  'gtkhscale.h',
+  'gtkhscrollbar.h',
+  'gtkhseparator.h',
+  'gtkhsv.h',
+  'gtkiconfactory.h',
+  'gtkimagemenuitem.h',
+  'gtkmisc.h',
+  'gtknumerableicon.h',
+  'gtkradioaction.h',
+  'gtkrc.h',
+  'gtkrecentaction.h',
+  'gtkstatusicon.h',
+  'gtkstock.h',
+  'gtkstyle.h',
+  'gtkstyleproperties.h',
+  'gtksymboliccolor.h',
+  'gtktable.h',
+  'gtktearoffmenuitem.h',
+  'gtkthemingengine.h',
+  'gtktoggleaction.h',
+  'gtkuimanager.h',
+  'gtkvbbox.h',
+  'gtkvbox.h',
+  'gtkvscale.h',
+  'gtkvscrollbar.h',
+  'gtkvseparator.h',
+  'gtkvpaned.h',
+)
+
+install_headers(gtk_deprecated_headers, subdir: 'gtk-3.0/gtk/deprecated/')
diff --git a/gtk/gen-gtk-gresources-xml.py b/gtk/gen-gtk-gresources-xml.py
new file mode 100644
index 0000000000..720d588a4e
--- /dev/null
+++ b/gtk/gen-gtk-gresources-xml.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+#
+# Generate gtk.gresources.xml
+#
+# Usage: gen-gtk-gresources-xml SRCDIR_GTK [OUTPUT-FILE]
+
+import os, sys
+
+srcdir = sys.argv[1]
+
+xml = '''<?xml version='1.0' encoding='UTF-8'?>
+<gresources>
+  <gresource prefix='/org/gtk/libgtk'>
+'''
+
+def get_files(subdir,extension):
+  return sorted(filter(lambda x: x.endswith((extension)), os.listdir(os.path.join(srcdir,subdir))))
+
+xml += '''
+    <file>theme/Adwaita/gtk.css</file>
+    <file>theme/Adwaita/gtk-dark.css</file>
+    <file>theme/Adwaita/gtk-contained.css</file>
+    <file>theme/Adwaita/gtk-contained-dark.css</file>
+'''
+
+for f in get_files('theme/Adwaita/assets', '.png'):
+  xml += '    <file preprocess=\'to-pixdata\'>theme/Adwaita/assets/{0}</file>\n'.format(f)
+
+xml += '\n'
+
+for f in get_files('theme/Adwaita/assets', '.svg'):
+  xml += '    <file>theme/Adwaita/assets/{0}</file>\n'.format(f)
+
+xml += '''
+    <file>theme/HighContrast/gtk.css</file>
+    <file alias='theme/HighContrastInverse/gtk.css'>theme/HighContrast/gtk-inverse.css</file>
+    <file>theme/HighContrast/gtk-contained.css</file>
+    <file>theme/HighContrast/gtk-contained-inverse.css</file>
+'''
+
+for f in get_files('theme/HighContrast/assets', '.png'):
+  xml += '    <file preprocess=\'to-pixdata\'>theme/HighContrast/assets/{0}</file>\n'.format(f)
+
+xml += '\n'
+
+for f in get_files('theme/HighContrast/assets', '.svg'):
+  xml += '    <file>theme/HighContrast/assets/{0}</file>\n'.format(f)
+
+xml += '''
+    <file>theme/win32/gtk-win32-base.css</file>
+    <file>theme/win32/gtk.css</file>
+'''
+
+for f in get_files('cursor', '.png'):
+  xml += '    <file>cursor/{0}</file>\n'.format(f)
+
+for f in get_files('gesture', '.symbolic.png'):
+  xml += '    <file alias=\'icons/64x64/actions/{0}\'>gesture/{0}</file>\n'.format(f)
+
+xml += '\n'
+
+for f in get_files('ui', '.ui'):
+  xml += '    <file preprocess=\'xml-stripblanks\'>ui/{0}</file>\n'.format(f)
+
+xml += '\n'
+
+for s in ['16x16', '22x22', '24x24', '32x32', '48x48']:
+  for c in ['actions', 'status', 'categories']:
+    icons_dir = 'icons/{0}/{1}'.format(s,c)
+    if os.path.exists(os.path.join(srcdir,icons_dir)):
+      for f in get_files(icons_dir, '.png'):
+        xml += '    <file>icons/{0}/{1}/{2}</file>\n'.format(s,c,f)
+
+for f in get_files('inspector', '.ui'):
+  xml += '    <file compressed=\'true\' preprocess=\'xml-stripblanks\'>inspector/{0}</file>\n'.format(f)
+
+xml += '''
+    <file>inspector/logo.png</file>
+    <file>emoji/emoji.data</file>
+  </gresource>
+</gresources>'''
+
+if len(sys.argv) > 2:
+  outfile = sys.argv[2]
+  f = open(outfile, 'w')
+  f.write(xml)
+  f.close()
+else:
+  print(xml)
diff --git a/gtk/gentypefuncs.py b/gtk/gentypefuncs.py
new file mode 100644
index 0000000000..b17b7233a1
--- /dev/null
+++ b/gtk/gentypefuncs.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import sys
+import re
+import os
+
+debug = os.getenv('GTK_GENTYPEFUNCS_DEBUG') is not None
+
+out_file = sys.argv[1]
+in_files = sys.argv[2:]
+
+funcs = []
+
+
+if debug: print ('Output file: ', out_file)
+
+if debug: print (len(in_files), 'input files')
+
+def open_file(filename, mode):
+    if sys.version_info[0] < 3:
+        return open(filename, mode=mode)
+    else:
+        return open(filename, mode=mode, encoding='utf-8')
+
+for filename in in_files:
+  if debug: print ('Input file: ', filename)
+  with open_file(filename, "r") as f:
+    for line in f:
+      line = line.rstrip('\n').rstrip('\r')
+      # print line
+      match = re.search(r'\bg[tds]k_[a-zA-Z0-9_]*_get_type\b', line)
+      if match:
+        func = match.group(0)
+        if not func in funcs:
+          funcs.append(func)
+          if debug: print ('Found ', func)
+
+file_output = 'G_GNUC_BEGIN_IGNORE_DEPRECATIONS\n'
+
+funcs = sorted(funcs)
+
+for f in funcs:
+  if f.startswith('gdk_x11') or f.startswith('gtk_socket') or f.startswith('gtk_plug'):
+    file_output += '#ifdef GDK_WINDOWING_X11\n'
+    file_output += '*tp++ = {0}();\n'.format(f)
+    file_output += '#endif\n'
+  else:
+    file_output += '*tp++ = {0}();\n'.format(f)
+
+if debug: print (len(funcs), 'functions')
+
+ofile = open(out_file, "w")
+ofile.write(file_output)
+ofile.close()
diff --git a/gtk/gtktestutils.c b/gtk/gtktestutils.c
index 7b78f739fe..5c0a362296 100644
--- a/gtk/gtktestutils.c
+++ b/gtk/gtktestutils.c
@@ -764,7 +764,7 @@ gtk_test_register_all_types (void)
       GType *tp;
       all_registered_types = g_new0 (GType, max_gtk_types);
       tp = all_registered_types;
-#include "gtktypefuncs.c"
+#include "gtktypefuncs.inc"
       n_all_registered_types = tp - all_registered_types;
       g_assert (n_all_registered_types + 1 < max_gtk_types);
       *tp = 0;
diff --git a/gtk/inspector/meson.build b/gtk/inspector/meson.build
index a119a08db8..7ca24ae2ee 100644
--- a/gtk/inspector/meson.build
+++ b/gtk/inspector/meson.build
@@ -8,6 +8,7 @@ inspector_sources = files(
   'general.c',
   'gestures.c',
   'graphdata.c',
+  'gtkstackcombo.c',
   'gtktreemodelcssnode.c',
   'init.c',
   'inspect-button.c',
@@ -23,9 +24,8 @@ inspector_sources = files(
   'signals-list.c',
   'size-groups.c',
   'statistics.c',
+  'strv-editor.c',
   'treewalk.c',
   'visual.c',
   'window.c',
-  'strv-editor.c',
-  'gtkstackcombo.c'
 )
diff --git a/gtk/meson.build b/gtk/meson.build
index 46fa1a9a4d..9526c049f7 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -2,7 +2,23 @@ subdir('deprecated')
 subdir('a11y')
 subdir('inspector')
 
-gtk_sources = files([
+gtk_cargs = [
+  '-DGTK_COMPILATION',
+  '-DG_LOG_DOMAIN="Gtk"',
+  # FIXME, support other backends
+  '-DGTK_PRINT_BACKENDS="file"',
+  '-DGTK_PRINT_BACKEND_ENABLE_UNSUPPORTED',
+  '-DGTK_BINARY_VERSION="@0@"'.format(gtk_binary_version),
+  '-DGTK_HOST="@0@"'.format(host_machine.system()),
+  '-DGTK_DATA_PREFIX="@0@"'.format(gtk_prefix),
+       '-DGTK_LIBDIR="@0@"'.format(gtk_libdir),
+       '-DGTK_LOCALEDIR="@0@"'.format(gtk_localedir),
+       '-DGTK_DATADIR="@0@"'.format(gtk_datadir),
+       '-DGTK_SYSCONFDIR="@0@"'.format(gtk_sysconfdir),
+]
+
+# List of sources to build the library from
+gtk_sources = files(
   'gtkactionmuxer.c',
   'gtkactionobserver.c',
   'gtkactionobservable.c',
@@ -28,6 +44,7 @@ gtk_sources = files([
   'gtkappchooserbutton.c',
   'gtkappchooserdialog.c',
   'gtkapplication.c',
+  'gtkapplicationaccels.c',
   'gtkapplicationimpl.c',
   'gtkapplicationwindow.c',
   'gtkaspectframe.c',
@@ -38,17 +55,14 @@ gtk_sources = files([
   'gtkbookmarksmanager.c',
   'gtkborder.c',
   'gtkbox.c',
+  'gtkboxgadget.c',
   'gtkbuildable.c',
   'gtkbuilder.c',
-  'gtkicon.c',
-  'gtkshortcutswindow.c',
-  'gtkshortcutssection.c',
   'gtkbuilderparser.c',
   'gtkbuilder-menus.c',
+  'gtkbuiltinicon.c',
   'gtkbutton.c',
   'gtkcairoblur.c',
-  'gtkcssnode.c',
-  'gtkcsscalcvalue.c',
   'gtkcalendar.c',
   'gtkcellarea.c',
   'gtkcellareabox.c',
@@ -66,7 +80,6 @@ gtk_sources = files([
   'gtkcellrenderertext.c',
   'gtkcellrenderertoggle.c',
   'gtkcellview.c',
-  'gtkcenterbox.c',
   'gtkcheckbutton.c',
   'gtkcheckmenuitem.c',
   'gtkcolorbutton.c',
@@ -74,44 +87,45 @@ gtk_sources = files([
   'gtkcolorchooserwidget.c',
   'gtkcolorchooserdialog.c',
   'gtkcoloreditor.c',
+  'gtkcolorpicker.c',
+  'gtkcolorpickerkwin.c',
+  'gtkcolorpickerportal.c',
+  'gtkcolorpickershell.c',
   'gtkcolorplane.c',
   'gtkcolorscale.c',
   'gtkcolorswatch.c',
   'gtkcolorutils.c',
   'gtkcombobox.c',
   'gtkcomboboxtext.c',
+  'gtkcomposetable.c',
   'gtkcontainer.c',
   'gtkcssanimation.c',
-  'gtkcssgadget.c',
-  'gtkcsscustomgadget.c',
-  'gtkboxgadget.c',
-  'gtkimagedefinition.c',
-  'gtkprogresstracker.c',
-  'gtkcssimageradial.c',
-  'gtkcssimagerecolor.c',
-  'gtkcssimagefallback.c',
-  'gtkbuiltinicon.c',
-  'gtkcssstylechange.c',
-  'gtkcsspalettevalue.c',
   'gtkcssanimatedstyle.c',
   'gtkcssarrayvalue.c',
   'gtkcssbgsizevalue.c',
   'gtkcssbordervalue.c',
+  'gtkcsscalcvalue.c',
   'gtkcsscolorvalue.c',
   'gtkcsscornervalue.c',
+  'gtkcsscustomgadget.c',
   'gtkcsscustomproperty.c',
+  'gtkcssdimensionvalue.c',
   'gtkcsseasevalue.c',
   'gtkcssenumvalue.c',
   'gtkcssenginevalue.c',
+  'gtkcssgadget.c',
   'gtkcssiconthemevalue.c',
   'gtkcssimage.c',
   'gtkcssimagebuiltin.c',
   'gtkcssimagecrossfade.c',
+  'gtkcssimagefallback.c',
   'gtkcssimagegradient.c',
   'gtkcssimageicontheme.c',
   'gtkcssimagelinear.c',
+  'gtkcssimageradial.c',
   'gtkcssimagesurface.c',
   'gtkcssimageurl.c',
+  'gtkcssimagerecolor.c',
   'gtkcssimagescaled.c',
   'gtkcssimagevalue.c',
   'gtkcssimagewin32.c',
@@ -122,7 +136,9 @@ gtk_sources = files([
   'gtkcssmatcher.c',
   'gtkcssnode.c',
   'gtkcssnodedeclaration.c',
+  'gtkcssnodestylecache.c',
   'gtkcssnumbervalue.c',
+  'gtkcsspalettevalue.c',
   'gtkcssparser.c',
   'gtkcsspathnode.c',
   'gtkcsspositionvalue.c',
@@ -133,12 +149,10 @@ gtk_sources = files([
   'gtkcssselector.c',
   'gtkcssstringvalue.c',
   'gtkcssstyle.c',
+  'gtkcssstylechange.c',
   'gtkcssshadowsvalue.c',
   'gtkcssshadowvalue.c',
   'gtkcssshorthandproperty.c',
-  'gtkshortcutlabel.c',
-  'gtkfilechoosernativeportal.c',
-  'gtkdragsource.c',
   'gtkcssshorthandpropertyimpl.c',
   'gtkcssstaticstyle.c',
   'gtkcssstylefuncs.c',
@@ -152,29 +166,29 @@ gtk_sources = files([
   'gtkcsstypes.c',
   'gtkcssvalue.c',
   'gtkcsswidgetnode.c',
-  'gtkcssnodestylecache.c',
-  'gtkapplicationaccels.c',
-  'gtkcssdimensionvalue.c',
-  'gtkshortcutsgroup.c',
-  'gtkshortcutsshortcut.c',
-  'gtkfilechoosernative.c',
-  'gtknativedialog.c',
+  'gtkcsswin32sizevalue.c',
   'gtkdialog.c',
+  'gtkdragsource.c',
   'gtkdrawingarea.c',
-  'gtkutils.c',
-  'gtktooltipwindow.c',
   'gtkeditable.c',
+  'gtkemojichooser.c',
+  'gtkemojicompletion.c',
   'gtkentry.c',
   'gtkentrybuffer.c',
   'gtkentrycompletion.c',
   'gtkeventbox.c',
   'gtkeventcontroller.c',
+  'gtkeventcontrollerkey.c',
+  'gtkeventcontrollermotion.c',
+  'gtkeventcontrollerscroll.c',
   'gtkexpander.c',
   'gtkfilechooser.c',
   'gtkfilechooserbutton.c',
   'gtkfilechooserdialog.c',
   'gtkfilechooserembed.c',
   'gtkfilechooserentry.c',
+  'gtkfilechoosernative.c',
+  'gtkfilechoosernativeportal.c',
   'gtkfilechooserutils.c',
   'gtkfilechooserwidget.c',
   'gtkfilefilter.c',
@@ -185,15 +199,9 @@ gtk_sources = files([
   'gtkfontbutton.c',
   'gtkfontchooser.c',
   'gtkfontchooserdialog.c',
-  'gtkcsswin32sizevalue.c',
   'gtkfontchooserutils.c',
-  'gtkwin32theme.c',
-  'gtkwin32draw.c',
-  'gtkcomposetable.c',
-  'gdkpixbufutils.c',
   'gtkfontchooserwidget.c',
   'gtkframe.c',
-  'gtkprintoperation-portal.c',
   'gtkgladecatalog.c',
   'gtkgesture.c',
   'gtkgesturedrag.c',
@@ -202,21 +210,21 @@ gtk_sources = files([
   'gtkgesturepan.c',
   'gtkgesturerotate.c',
   'gtkgesturesingle.c',
+  'gtkgesturestylus.c',
   'gtkgestureswipe.c',
   'gtkgesturezoom.c',
-  'gtkgizmo.c',
-  'gtkgladecatalog.c',
   'gtkglarea.c',
   'gtkgrid.c',
   'gtkheaderbar.c',
-  'gtkdragdest.c',
   'gtkhsla.c',
+  'gtkicon.c',
   'gtkiconcache.c',
   'gtkiconcachevalidator.c',
   'gtkiconhelper.c',
   'gtkicontheme.c',
   'gtkiconview.c',
   'gtkimage.c',
+  'gtkimagedefinition.c',
   'gtkimcontext.c',
   'gtkimcontextsimple.c',
   'gtkimmodule.c',
@@ -250,6 +258,7 @@ gtk_sources = files([
   'gtkmodifierstyle.c',
   'gtkmodules.c',
   'gtkmountoperation.c',
+  'gtknativedialog.c',
   'gtknotebook.c',
   'gtkoffscreenwindow.c',
   'gtkorientable.c',
@@ -270,6 +279,7 @@ gtk_sources = files([
   'gtkprintutils.c',
   'gtkprivate.c',
   'gtkprogressbar.c',
+  'gtkprogresstracker.c',
   'gtkpixelcache.c',
   'gtkpopover.c',
   'gtkpopovermenu.c',
@@ -302,6 +312,11 @@ gtk_sources = files([
   'gtkseparatormenuitem.c',
   'gtkseparatortoolitem.c',
   'gtksettings.c',
+  'gtkshortcutsgroup.c',
+  'gtkshortcutlabel.c',
+  'gtkshortcutsshortcut.c',
+  'gtkshortcutssection.c',
+  'gtkshortcutswindow.c',
   'gtksidebarrow.c',
   'gtksizegroup.c',
   'gtksizerequest.c',
@@ -347,6 +362,7 @@ gtk_sources = files([
   'gtktoolpalette.c',
   'gtktoolshell.c',
   'gtktooltip.c',
+  'gtktooltipwindow.c',
   'gtktrashmonitor.c',
   'gtktreedatalist.c',
   'gtktreednd.c',
@@ -359,28 +375,26 @@ gtk_sources = files([
   'gtktreestore.c',
   'gtktreeview.c',
   'gtktreeviewcolumn.c',
+  'gtkutils.c',
   'gtkvolumebutton.c',
   'gtkviewport.c',
   'gtkwidget.c',
-  'gtkwidgetfocus.c',
   'gtkwidgetpath.c',
   'gtkwindow.c',
   'gtkwindowgroup.c',
+  'gtkwin32draw.c',
   'gtkwin32theme.c',
-  'fallback-c89.c'
-])
+  'gdkpixbufutils.c',
+  'language-names.c',
+  'script-names.c',
+)
 
-gtk_private_type_headers = files([
+gtk_private_type_headers = files(
   'gtkcsstypesprivate.h',
   'gtktexthandleprivate.h',
-])
-
-gtk_private_h_sources = gtk_private_type_headers + files([
-  'gtkrecentchooserutils.h',
-  'gtkrbtree.h',
-])
+)
 
-gtk_public_h_sources = files([
+gtk_public_headers = files(
   'gtk.h',
   'gtk-autocleanups.h',
   'gtkx.h',
@@ -452,6 +466,9 @@ gtk_public_h_sources = files([
   'gtkenums.h',
   'gtkeventbox.h',
   'gtkeventcontroller.h',
+  'gtkeventcontrollerkey.h',
+  'gtkeventcontrollermotion.h',
+  'gtkeventcontrollerscroll.h',
   'gtkexpander.h',
   'gtkfilechooser.h',
   'gtkfilechooserbutton.h',
@@ -473,6 +490,7 @@ gtk_public_h_sources = files([
   'gtkgesturepan.h',
   'gtkgesturerotate.h',
   'gtkgesturesingle.h',
+  'gtkgesturestylus.h',
   'gtkgestureswipe.h',
   'gtkgesturezoom.h',
   'gtkglarea.h',
@@ -602,52 +620,14 @@ gtk_public_h_sources = files([
   'gtkwidgetpath.h',
   'gtkwindow.h',
   'gtkwindowgroup.h',
-])
+)
 
-gtk_deprecated_type_headers = files([
-  'deprecated/gtkactivatable.h',
-  'deprecated/gtkaction.h',
-  'deprecated/gtkactiongroup.h',
-  'deprecated/gtkalignment.h',
-  'deprecated/gtkarrow.h',
-  'deprecated/gtkcolorsel.h',
-  'deprecated/gtkcolorseldialog.h',
-  'deprecated/gtkfontsel.h',
-  'deprecated/gtkgradient.h',
-  'deprecated/gtkhandlebox.h',
-  'deprecated/gtkhbbox.h',
-  'deprecated/gtkhbox.h',
-  'deprecated/gtkhpaned.h',
-  'deprecated/gtkhscale.h',
-  'deprecated/gtkhscrollbar.h',
-  'deprecated/gtkhseparator.h',
-  'deprecated/gtkhsv.h',
-  'deprecated/gtkiconfactory.h',
-  'deprecated/gtkimagemenuitem.h',
-  'deprecated/gtkmisc.h',
-  'deprecated/gtknumerableicon.h',
-  'deprecated/gtkradioaction.h',
-  'deprecated/gtkrc.h',
-  'deprecated/gtkrecentaction.h',
-  'deprecated/gtkstatusicon.h',
-  'deprecated/gtkstock.h',
-  'deprecated/gtkstyle.h',
-  'deprecated/gtkstyleproperties.h',
-  'deprecated/gtksymboliccolor.h',
-  'deprecated/gtktable.h',
-  'deprecated/gtktearoffmenuitem.h',
-  'deprecated/gtkthemingengine.h',
-  'deprecated/gtktoggleaction.h',
-  'deprecated/gtkuimanager.h',
-  'deprecated/gtkvbbox.h',
-  'deprecated/gtkvbox.h',
-  'deprecated/gtkvscale.h',
-  'deprecated/gtkvscrollbar.h',
-  'deprecated/gtkvseparator.h',
-  'deprecated/gtkvpaned.h',
-])
+# Installed headers without compatibility guarantees that are not included in gtk/gtk.h
+gtk_semi_private_headers = files('gtktextlayout.h')
+
+install_headers(gtk_public_headers + gtk_semi_private_headers, subdir: 'gtk-3.0/gtk')
 
-gtk_unix_sources = files([
+gtk_unix_sources = files(
   'gtkcustompaperunixdialog.c',
   'gtkpagesetupunixdialog.c',
   'gtkprinter.c',
@@ -656,20 +636,57 @@ gtk_unix_sources = files([
   'gtkprinteroptionwidget.c',
   'gtkprintjob.c',
   'gtkprintoperation-unix.c',
+  'gtkprintoperation-portal.c',
   'gtkprintunixdialog.c',
   'gtkprintbackend.c',
   'gtksearchenginetracker.c',
-])
+)
+
+if os_unix
+  gtk_sources += gtk_unix_sources
+endif
 
-gtkresources = gnome.compile_resources(
-  'gtkresources',
-  'gtk.gresource.xml',
-  source_dir: '.',
-  c_name: '_gtk',
-  extra_args: '--manual-register'
+gtk_win32_sources = files(
+  'gtkprint-win32.c',
+       'gtkprintoperation-win32.c',
+       'gtkfilechoosernativewin32.c',
+       'gtkwin32.c',
 )
 
-gtk_x11_sources = files([
+if os_win32
+  gtk_sources += gtk_win32_sources
+endif
+
+gen_gtk_gresources_xml = find_program('gen-gtk-gresources-xml.py')
+gtk_gresources_xml = configure_file(output: 'gtk.gresources.xml',
+                                    command: [
+                                      gen_gtk_gresources_xml,
+                                      meson.current_source_dir(),
+                                      '@OUTPUT@'
+                                    ])
+
+# Re-build the theme files if sassc is available
+theme_deps = []
+sassc = find_program('sassc', required: false)
+if sassc.found()
+  sassc_opts = [ '-a', '-M', '-t', 'compact' ]
+
+  subdir('theme/Adwaita')
+  subdir('theme/HighContrast')
+endif
+
+gtkresources = gnome.compile_resources('gtkresources',
+                                       gtk_gresources_xml,
+                                       dependencies: theme_deps,
+                                       source_dir: [
+                                         # List in order of preference
+                                         meson.current_build_dir(),
+                                         meson.current_source_dir(),
+                                       ],
+                                       c_name: '_gtk',
+                                       extra_args: '--manual-register')
+
+gtk_use_x11_sources = files([
   'gtkplug.c',
   'gtksocket.c',
   'gtkxembed.c',
@@ -678,122 +695,120 @@ gtk_x11_sources = files([
   'gtkmountoperation-x11.c',
 ])
 
-gtk_wayland_sources = files([
+gtk_use_wayland_sources = files([
   'gtkapplication-wayland.c'
 ])
 
-dnd_sources = files([
-  'gtkclipboard.c',
-  'gtkdnd.c'
-])
+if quartz_enabled
+  gtk_sources += files(
+    'gtkclipboard-quartz.c',
+    'gtkdnd-quartz.c',
+  )
+else
+  gtk_sources += files(
+    'gtkclipboard.c',
+    'gtkdnd.c',
+    'gtkdragdest.c',
+  )
+endif
 
-gtk_use_wayland_or_x11_c_sources = files([
-  'gtkapplication-dbus.c'
-])
+gtk_use_wayland_or_x11_sources = files( 'gtkapplication-dbus.c')
+
+gtk_use_win32_sources = files(
+       'gtkwin32embed.c',
+       'gtkwin32embedwidget.c',
+       'gtkmountoperation-stub.c',
+)
+
+gtk_use_quartz_sources = files(
+  'gtksearchenginequartz.c',
+  'gtkmountoperation-stub.c',
+  'gtkapplication-quartz.c',
+  'gtkapplication-quartz-menu.c',
+  'gtkfilechoosernativequartz.c',
+  'gtkquartz.c',
+)
+
+gtk_stub_sources = files('gtkmountoperation-stub.c')
 
 gtk_dbus_src = gnome.gdbus_codegen('gtkdbusgenerated', 'gtkdbusinterfaces.xml',
                                    interface_prefix: 'org.Gtk.',
                                    namespace: '_Gtk')
 
-gtkmarshal_h = custom_target(
-  'gtkmarshal_h',
-  output  : 'gtkmarshalers.h',
-  input   : 'gtkmarshalers.list',
-  command : [mkmarshal, glib_marshal, '_gtk_marshal', '@INPUT@', '@OUTPUT@']
-)
+gtkmarshalers = gnome.genmarshal('gtkmarshalers',
+                                 sources: 'gtkmarshalers.list',
+                                 prefix: '_gtk_marshal',
+                                 valist_marshallers: true)
 
-gtkmarshal_c = custom_target(
-  'gtkmarshal_c',
-  output  : 'gtkmarshalers.c',
-  input   : 'gtkmarshalers.list',
-  command : [mkmarshal, glib_marshal, '_gtk_marshal', '@INPUT@', '@OUTPUT@']
-)
+gtkmarshal_h = gtkmarshalers[1]
 
+gtktypebuiltins = gnome.mkenums('gtktypebuiltins',
+                                sources: gtk_public_headers + gtk_deprecated_headers + a11y_headers,
+                                c_template: 'gtktypebuiltins.c.template',
+                                h_template: 'gtktypebuiltins.h.template',
+                                install_dir: join_paths(gtk_includedir, 'gtk-3.0/gtk'),
+                                install_header: true)
 
+gtktypebuiltins_h = gtktypebuiltins[1]
 
-gtktypebuiltins_h = custom_target(
-  'gtkypebuiltins_h',
-  output  : 'gtktypebuiltins.h',
-  input   : gtk_public_h_sources + gtk_deprecated_type_headers,
-  command : [mkenum, perl, glib_mkenums, meson.current_source_dir() + '/gtktypebuiltins.h.template', 
'@OUTPUT@', '@INPUT@']
-)
+gtkprivatetypebuiltins = gnome.mkenums('gtkprivatetypebuiltins',
+                                       sources: gtk_private_type_headers,
+                                       c_template: 'gtkprivatetypebuiltins.c.template',
+                                       h_template: 'gtkprivatetypebuiltins.h.template')
 
-gtktypebuiltins_c = custom_target(
-  'gtkypebuiltins_c',
-  output  : 'gtktypebuiltins.c',
-  input   : gtk_public_h_sources +  gtk_deprecated_type_headers,
-  depends : gtktypebuiltins_h,
-  command : [mkenum, perl, glib_mkenums, meson.current_source_dir() + '/gtktypebuiltins.c.template', 
'@OUTPUT@', '@INPUT@']
-)
+gtkprivatetypebuiltins_h = gtkprivatetypebuiltins[1]
 
-gtkprivatetypebuiltins_h = custom_target(
-  'gtkprivateypebuiltins_h',
-  output  : 'gtkprivatetypebuiltins.h',
-  input   : gtk_private_type_headers,
-  command : [mkenum, perl, glib_mkenums, meson.current_source_dir() + '/gtkprivatetypebuiltins.h.template', 
'@OUTPUT@', '@INPUT@']
-)
+# Generate gtktypefuncs.inc
+typefuncs = custom_target('gtktypefuncs.inc',
+                          depends: [ gdkenum_h ],
+                          output: 'gtktypefuncs.inc',
+                          input: gdk_headers +
+                            gtk_public_headers +
+                            gtk_deprecated_headers +
+                            [ gtktypebuiltins_h, gdkenum_h ],
+                          command: [
+                            find_program('gentypefuncs.py'),
+                            '@OUTPUT@',
+                            '@INPUT@',
+                          ],
+                          install: false)
 
-gtkprivatetypebuiltins_c = custom_target(
-  'gtkprivateypebuiltins_c',
-  output  : 'gtkprivatetypebuiltins.c',
-  input   : gtk_private_type_headers,
-  depends : [gtkprivatetypebuiltins_h, gtktypebuiltins_h],
-  command : [mkenum, perl, glib_mkenums, meson.current_source_dir() + '/gtkprivatetypebuiltins.c.template', 
'@OUTPUT@', '@INPUT@']
-)
 
-gentypefuncs_prog = find_program('gentypefuncs.py')
-# Generate gtktypefuncs.c
-typefuncs = custom_target(
-  'typefuncs',
-  depends: gdkenum_h,
-  output : 'gtktypefuncs.c',
-  input  : gdk_headers + gtk_public_h_sources + gtk_deprecated_type_headers + gtk_private_h_sources + 
[gtktypebuiltins_h] + [gdkenum_h],
-  command: [gentypefuncs_prog, '@OUTPUT@', '@INPUT@'],
-  install: false,
-)
+gtkversion_cdata = configuration_data()
+gtkversion_cdata.set('GTK_MAJOR_VERSION', gtk_major_version)
+gtkversion_cdata.set('GTK_MINOR_VERSION', gtk_minor_version)
+gtkversion_cdata.set('GTK_MICRO_VERSION', gtk_micro_version)
+gtkversion_cdata.set('GTK_BINARY_AGE', gtk_binary_age)
+gtkversion_cdata.set('GTK_INTERFACE_AGE', gtk_interface_age)
 
-cdata = configuration_data()
-cdata.set('GTK_MAJOR_VERSION', gtk_major_version)
-cdata.set('GTK_MINOR_VERSION', gtk_minor_version)
-cdata.set('GTK_MICRO_VERSION', gtk_micro_version)
-cdata.set('GTK_BINARY_AGE', gtk_binary_age)
-cdata.set('GTK_INTERFACE_AGE', gtk_interface_age)
-
-gtkversion = configure_file(
-  input  : 'gtkversion.h.in',
-  output : 'gtkversion.h',
-  configuration: cdata
-)
+gtkversion = configure_file(input: 'gtkversion.h.in',
+                            output: 'gtkversion.h',
+                            configuration: gtkversion_cdata,
+                            install_dir: join_paths(gtk_includedir, 'gtk-3.0/gtk'))
 
-gtk_cargs = [
-  '-DGTK_COMPILATION',
-  '-DGTK_PRINT_BACKEND_ENABLE_UNSUPPORTED',
-  '-DGTK_BINARY_VERSION="' + gtk_binary_version + '"',
-  '-DGTK_HOST="' + host_machine.system() + '"',
-  '-DGTK_SYSCONFDIR="' + get_option('prefix') + '/etc"',
-  '-DGTK_DATADIR="' + get_option('datadir') + '"',
-  '-DGTK_DATA_PREFIX="'+ get_option('prefix') + '"',
-  '-DGTK_PRINT_BACKENDS="null"',
+gtk_gen_headers = [
+  gtkmarshalers,
+  gtkprivatetypebuiltins,
+  gtktypebuiltins,
+  gtkversion,
 ]
 
 gtk_sources += [
   gtk_dbus_src,
-  gtk_unix_sources,
-  gtk_deprecated_c_sources,
-  dnd_sources,
+  gtk_deprecated_sources,
   inspector_sources,
   a11y_sources,
   gtkresources,
-  gtkmarshal_c,
-  gtkprivatetypebuiltins_c,
-  gtktypebuiltins_c,
+  gtkmarshalers,
+  gtkprivatetypebuiltins,
+  gtktypebuiltins,
 ]
 
 gtk_deps = [
   gmodule_dep,
-  giounix_dep,
   glib_dep,
-  atkbridge_dep,
+  gobject_dep,
+  platform_gio_dep,
   pangocairo_dep,
   pango_dep,
   cairogobj_dep,
@@ -802,68 +817,194 @@ gtk_deps = [
   pixbuf_dep,
   atk_dep,
   epoxy_dep,
-  mlib,
+  libm,
 ]
 
 if x11_enabled
-  runcmd = run_command('pkg-config', '--variable=prefix', 'x11')
-  if runcmd.returncode() == 0
-      gtk_cargs += '-DX11_DATA_PREFIX="' + runcmd.stdout().strip() + '"'
-  else
-    error('Could not get x11 data prefix via pkg-config.')
-  endif
+  x11_data_prefix = dependency('x11').get_pkgconfig_variable('prefix')
 
-  gtk_sources += [
-    gtk_x11_sources,
-    gtk_use_wayland_or_x11_c_sources
-  ]
-  gtk_deps += [
-    xi_dep,
-    x11_dep,
-    pangoft_dep
-  ]
+  gtk_cargs += [ '-DX11_DATA_PREFIX="@0@"'.format(x11_data_prefix), ]
+  gtk_sources += gtk_use_x11_sources
+  gtk_deps += [ xi_dep, x11_dep, ]
 endif
 
 if wayland_enabled
-  gtk_sources += [
-    gtk_wayland_sources,
-    gtk_use_wayland_or_x11_c_sources
-  ]
-  gtk_deps += [
-    pangoft_dep
-  ]
+  gtk_sources += gtk_use_wayland_sources
 endif
 
-gnome.compile_schemas()
+if broadway_enabled
+  gtk_sources += ['gtkimcontextbroadway.c']
+endif
 
-libgtk = shared_library('gtk',
-  gtk_sources,
-  gtkmarshal_h,
-  c_args: gtk_cargs,
-  include_directories: [confinc, gdkinc, gtkinc],
-  dependencies: [gtk_deps, libgdk_dep],
-  install: true
-)
+if win32_enabled
+  gtk_cargs += []
+  gtk_sources += gtk_use_win32_sources
+  gtk_deps += [ giowin32_dep, pangowin32_dep ]
+else
+  gtk_deps += [ atkbridge_dep, ]
+endif
 
-libgtk_dep = declare_dependency(
-  sources: [
-    'gtk.h',
-    gtkversion,
-    gtktypebuiltins_c,
+if quartz_enabled
+  gtk_sources += gtk_use_quartz_sources
+  gtk_cargs += ['-xobjective-c']  # FIXME? maybe add_languages() instead?
+endif
+
+# So we don't add these twice
+if x11_enabled or wayland_enabled
+  gtk_sources += gtk_use_wayland_or_x11_sources
+  gtk_deps += pangoft_dep
+endif
+
+if not (x11_enabled or win32_enabled or quartz_enabled)
+  gtk_sources += gtk_stub_sources
+endif
+
+if cloudproviders_enabled
+  gtk_deps += cloudproviders_dep
+endif
+
+# Unconditional. If libintl isn't found,
+# the object just does nothing being in the deplist
+gtk_deps += libintl_dep
+
+gtk_settings_schemas = [
+  'org.gtk.Settings.FileChooser.gschema.xml',
+  'org.gtk.Settings.ColorChooser.gschema.xml',
+  'org.gtk.Settings.EmojiChooser.gschema.xml',
+  'org.gtk.Settings.Debug.gschema.xml',
+]
+install_data(gtk_settings_schemas, install_dir: gtk_schemasdir)
+gnome.compile_schemas(depend_files: files(gtk_settings_schemas),
+                      build_by_default: true)
+gtk_schema_build_dir = meson.current_build_dir()
+
+# Check for more things
+if cc.has_header('langinfo.h')
+  foreach nl_enum: [ '_NL_MEASUREMENT_MEASUREMENT',
+                     '_NL_PAPER_HEIGHT',
+                     '_NL_PAPER_WIDTH',
+                     '_NL_TIME_FIRST_WEEKDAY', ]
+    cdata.set('HAVE_' + nl_enum, cc.has_header_symbol('langinfo.h', nl_enum))
+  endforeach
+endif
+
+# Library
+libgtk = shared_library('gtk-3',
+                        soversion: gtk_soversion,
+                        sources: [typefuncs, gtk_sources, gtkmarshal_h, gtkprivatetypebuiltins_h],
+                        c_args: gtk_cargs + common_cflags,
+                        include_directories: [confinc, gdkinc, gtkinc],
+                        dependencies: gtk_deps + [libgdk_dep],
+                        link_with: libgdk,
+                        link_args: common_ldflags,
+                        install: true)
+
+gtk_dep_sources = [gtkversion, gtktypebuiltins_h]
+# Introspection
+build_gir = get_option('introspection')
+if build_gir
+  gir_args = [
+    '--quiet',
+  ]
+
+  # We may build some of the dependencies as sub-projects; this means
+  # that we need to depend on the built introspection data, instead of
+  # the installed one
+  gdk_gir_inc = [ 'cairo-1.0', 'Gio-2.0', ]
+
+  if pixbuf_dep.type_name() == 'internal'
+    gdk_gir_inc += subproject('gdk-pixbuf').get_variable('gdkpixbuf_gir').get(0)
+  else
+    gdk_gir_inc += 'GdkPixbuf-2.0'
+  endif
+
+  if pango_dep.type_name() == 'internal'
+    gdk_gir_inc += subproject('pango').get_variable('pango_gir').get(0)
+  else
+    gdk_gir_inc += 'Pango-1.0'
+  endif
+
+  gdk_gir = gnome.generate_gir(libgtk,
+                               sources: gdk_public_headers + gdk_sources + [ gdkenum_h ],
+                               namespace: 'Gdk',
+                               nsversion: gtk_api_version,
+                               identifier_prefix: 'Gdk',
+                               symbol_prefix: 'gdk',
+                               export_packages: 'gtk+-3.0',
+                               includes: gdk_gir_inc,
+                               header: 'gdk/gdk.h',
+                               install: true,
+                               extra_args: gir_args + [
+                                 '-DGDK_COMPILATION',
+                               ])
+  gdk_gir_dep = declare_dependency(sources: gdk_gir)
+  gtk_dep_sources += gdk_gir
+
+  if x11_enabled
+    gdk_x11_gir = gnome.generate_gir(libgtk,
+                                     sources: gdk_x11_public_headers + gdk_x11_sources,
+                                     namespace: 'GdkX11',
+                                     nsversion: gtk_api_version,
+                                     identifier_prefix: 'Gdk',
+                                     symbol_prefix: 'gdk',
+                                     export_packages: 'gtk+-x11-3.0',
+                                     includes: [ gdk_gir[0], 'xlib-2.0', ],
+                                     install: true,
+                                     dependencies: gdk_gir_dep,
+                                     header: 'gdk/gdkx.h',
+                                     extra_args: gir_args + [
+                                       '-DGDK_COMPILATION',
+                                     ])
+    gtk_dep_sources += gdk_x11_gir
+  endif
+
+  gtk_introspection_sources = [
+    gtk_public_headers,
+    gtk_sources,
+    a11y_headers,
+    a11y_sources,
     gtktypebuiltins_h,
-  ],
-  dependencies: gtk_deps,
-  link_with: [libgtk, libgdk],
-  link_args: ['-Bsymbolic'],
-  include_directories: [confinc, gtkinc]
-)
+    gtkversion,
+  ]
 
+  gtk_gir = gnome.generate_gir(libgtk,
+                               sources: gtk_introspection_sources,
+                               namespace: 'Gtk',
+                               nsversion: gtk_api_version,
+                               identifier_prefix: 'Gtk',
+                               symbol_prefix: 'gtk',
+                               export_packages: 'gtk+-3.0',
+                               includes: [ gdk_gir[0], 'Atk-1.0', ],
+                               header: 'gtk/gtk.h',
+                               install: true,
+                               dependencies: gdk_gir_dep,
+                               extra_args: gir_args + [
+                                 '-DGTK_COMPILATION',
+                                 '--c-include=gtk/gtk-a11y.h',
+                               ])
+  gtk_dep_sources += gtk_gir
+endif
 
+libgtk_dep = declare_dependency(sources: gtk_dep_sources,
+                                include_directories: [confinc, gtkinc],
+                                dependencies: gtk_deps + [libgdk_dep],
+                                link_with: libgtk,
+                                link_args: common_ldflags)
+
+if quartz_enabled
+  # HACK: install_data() doesn't allow installing under a different name (#1487)
+  # FIXME: or maybe just rename it to gtk-keys.css in the src tree?
+  configure_file(input: 'gtk-keys.css.mac',
+                 output: 'gtk-keys.css',
+                 copy: true,
+                 install_dir: join_paths(get_option('datadir'), 'themes/Mac/gtk-4.0'))
+endif
 
 ####### Utils ######
 gtk_query_settings = executable(
   'gtk-query-settings',
   'gtk-query-settings.c',
+  c_args: gtk_cargs,
   dependencies: libgtk_dep,
   install: true
 )
@@ -871,6 +1012,7 @@ gtk_query_settings = executable(
 gtk_builder_tool = executable(
   'gtk-builder-tool',
   'gtk-builder-tool.c',
+  c_args: gtk_cargs,
   dependencies: libgtk_dep,
   install: true
 )
@@ -878,21 +1020,24 @@ gtk_builder_tool = executable(
 gtk_update_icon_cache = executable(
   'gtk-update-icon-cache',
   'updateiconcache.c',
+  c_args: gtk_cargs,
   dependencies: libgtk_dep,
   install: true
 )
 
-# gtk_query_immodules = executable(
-  # 'gtk-query-immodules-3.0',
-  # 'queryimmodules.c',
-  # 'gtkutils.c',
-  # dependencies: libgtk_dep,
-  # install: true
-# )
+ gtk_query_immodules = executable(
+  'gtk-query-immodules-3.0',
+  'queryimmodules.c',
+  'gtkutils.c',
+  c_args: gtk_cargs,
+  dependencies: libgtk_dep,
+  install: true
+)
 
 gtk_encode_symbolic_svg = executable(
   'gtk-encode-symbolic-svg',
   'encodesymbolic.c',
+  c_args: gtk_cargs,
   dependencies: libgtk_dep,
   install: true
 )
@@ -900,6 +1045,7 @@ gtk_encode_symbolic_svg = executable(
 gtk_launch = executable(
   'gtk-launch',
   'gtk-launch.c',
+  c_args: gtk_cargs,
   dependencies: libgtk_dep,
   install: true
 )
diff --git a/gtk/theme/Adwaita/meson.build b/gtk/theme/Adwaita/meson.build
new file mode 100644
index 0000000000..7a799f947d
--- /dev/null
+++ b/gtk/theme/Adwaita/meson.build
@@ -0,0 +1,30 @@
+scss_files = files([
+  '_colors-public.scss',
+  '_colors.scss',
+  '_common.scss',
+  '_drawing.scss',
+])
+
+theme_variants = [
+  'dark',
+]
+
+theme_deps += custom_target('Adwaita',
+                            input: 'gtk-contained.scss',
+                            output: 'gtk-contained.css',
+                            command: [
+                              sassc, sassc_opts, '@INPUT@', '@OUTPUT@',
+                            ],
+                            depend_files: scss_files,
+                            build_by_default: true)
+
+foreach variant: theme_variants
+  theme_deps += custom_target('Adwaita-' + variant,
+                              input: 'gtk-contained-@0@.scss'.format(variant),
+                              output: 'gtk-contained-@0@.css'.format(variant),
+                              command: [
+                                sassc, sassc_opts, '@INPUT@', '@OUTPUT@',
+                              ],
+                              depend_files: scss_files,
+                              build_by_default: true)
+endforeach
diff --git a/gtk/theme/HighContrast/meson.build b/gtk/theme/HighContrast/meson.build
new file mode 100644
index 0000000000..f3230353ef
--- /dev/null
+++ b/gtk/theme/HighContrast/meson.build
@@ -0,0 +1,29 @@
+scss_files = files([
+  '_colors.scss',
+  '_common.scss',
+  '_drawing.scss',
+])
+
+theme_variants = [
+  'inverse',
+]
+
+theme_deps += custom_target('HighContrast',
+                            input: 'gtk-contained.scss',
+                            output: 'gtk-contained.css',
+                            command: [
+                              sassc, sassc_opts, '@INPUT@', '@OUTPUT@',
+                            ],
+                            depend_files: scss_files,
+                            build_by_default: true)
+
+foreach variant: theme_variants
+  theme_deps += custom_target('HighContrast-' + variant,
+                              input: 'gtk-contained-@0@.scss'.format(variant),
+                              output: 'gtk-contained-@0@.css'.format(variant),
+                              command: [
+                                sassc, sassc_opts, '@INPUT@', '@OUTPUT@',
+                              ],
+                              depend_files: scss_files,
+                              build_by_default: true)
+endforeach
diff --git a/meson.build b/meson.build
index e3d9ec4eca..f253213bc3 100644
--- a/meson.build
+++ b/meson.build
@@ -1,24 +1,73 @@
 project('gtk+-3.0', 'c',
-        version: '3.22.0',
+        version: '3.24.1',
         default_options: [
           'buildtype=debugoptimized',
           'c_std=gnu89',
           'warning_level=1'
         ],
+        meson_version : '>= 0.43.0',
         license: 'LGPLv2.1+')
 
-gnome = import('gnome')
+glib_major_req = 2
+glib_minor_req = 53
+glib_micro_req = 4
+
+if glib_minor_req.is_odd()
+  glib_min_required = 'GLIB_VERSION_@0@_@1@'.format(glib_major_req, glib_minor_req - 1)
+else
+  glib_min_required = 'GLIB_VERSION_@0@_@1@'.format(glib_major_req, glib_minor_req)
+endif
 
-add_global_arguments('-DG_LOG_USE_STRUCTURED=1', language: 'c')
-add_global_arguments('-DG_ENABLE_DEBUG', language: 'c')
-add_global_arguments('-DG_ENABLE_CONSISTENCY_CHECKS', language: 'c')
+if glib_minor_req.is_odd()
+  glib_max_allowed = 'GLIB_VERSION_@0@_@1@'.format(glib_major_req, glib_minor_req + 1)
+else
+  glib_max_allowed = 'GLIB_VERSION_@0@_@1@'.format(glib_major_req, glib_minor_req)
+endif
+
+glib_req           = '>= @0@.@1@.@2@'.format(glib_major_req, glib_minor_req, glib_micro_req)
+pango_req          = '>= 1.41.0'
+atk_req            = '>= 2.15.1'
+cairo_req          = '>= 1.14.0'
+gdk_pixbuf_req     = '>= 2.30.0'
+introspection_req  = '>= 1.39.0'
+wayland_proto_req  = '>= 1.12'
+wayland_req        = '>= 1.9.91'
+epoxy_req          = '>= 1.4'
+cloudproviders_req = '>= 0.2.5'
+xkbcommon_req      = '>= 0.2.0'
+
+gnome = import('gnome')
 
-gtk_version       = meson.project_version().split('.')
-gtk_major_version = gtk_version[0].to_int()
-gtk_minor_version = gtk_version[1].to_int()
-gtk_micro_version = gtk_version[2].to_int()
+add_project_arguments('-DG_LOG_USE_STRUCTURED=1', language: 'c')
+add_project_arguments('-DGLIB_MIN_REQUIRED_VERSION=' + glib_min_required, language: 'c')
+add_project_arguments('-DGLIB_MAX_ALLOWED_VERSION=' + glib_max_allowed, language: 'c')
+
+# Making releases:
+#  1. gtk_micro_version += 1;
+#  2. gtk_interface_age += 1;
+#  3. if any functions have been added, set gtk_interface_age to 0.
+#  4. if backwards compatibility has been broken, we're in trouble
+gtk_version       = meson.project_version()
+gtk_major_version = gtk_version.split('.')[0].to_int()
+gtk_minor_version = gtk_version.split('.')[1].to_int()
+gtk_micro_version = gtk_version.split('.')[2].to_int()
 gtk_interface_age = 0
-add_global_arguments('-DGTK_VERSION="' + meson.project_version() + '"', language: 'c')
+add_project_arguments('-DGTK_VERSION="@0@"'.format(meson.project_version()), language: 'c')
+
+add_project_arguments('-D_GNU_SOURCE', language: 'c')
+
+gtk_debug_cflags = []
+buildtype = get_option('buildtype')
+if buildtype.startswith('debug')
+  gtk_debug_cflags += '-DG_ENABLE_DEBUG'
+  if buildtype == 'debug'
+    gtk_debug_cflags += '-DG_ENABLE_CONSISTENCY_CHECKS'
+  endif
+elif buildtype == 'release'
+  gtk_debug_cflags += '-DG_DISABLE_CAST_CHECKS'
+endif
+
+add_project_arguments(gtk_debug_cflags, language: 'c')
 
 # Define a string for the earliest version that this release has
 # backwards binary compatibility with for all interfaces a module
@@ -28,167 +77,344 @@ add_global_arguments('-DGTK_VERSION="' + meson.project_version() + '"', language
 gtk_binary_version = '3.0.0'
 
 gtk_binary_age = 100 * gtk_minor_version + gtk_micro_version
-gtk_api_version = '@0@.0'.format(gtk_major_version)
 
-x11_enabled      = get_option('enable-x11-backend')
-wayland_enabled  = get_option('enable-wayland-backend')
-broadway_enabled = get_option('enable-broadway-backend')
+gtk_soversion = '0.@0@.@1@'.format(gtk_binary_age - gtk_interface_age, gtk_interface_age)
 
+gtk_api_version = '@0@.0'.format(gtk_major_version)
 
-mkmarshal    = find_program('build_marshal.py')
-glib_marshal = find_program('glib-genmarshal')
-mkenum       = find_program('build_enum.py')
-perl         = find_program('perl')
-glib_mkenums = find_program('glib-mkenums')
+x11_enabled            = get_option('x11-backend')
+wayland_enabled        = get_option('wayland-backend')
+broadway_enabled       = get_option('broadway-backend')
+quartz_enabled         = get_option('quartz-backend')
+win32_enabled          = get_option('win32-backend')
 
 os_unix   = false
 os_linux  = false
 os_win32  = false
 os_darwin = false
 
-if host_machine.system().contains('darwin')
+# Some windowing system backends depend on the platform we're
+# building for, so we need to ensure they are disabled; in other
+# cases, they are the only windowing system available, so we need
+# to ensure they are enabled
+if host_machine.system() == 'darwin'
   os_darwin = true
-elif host_machine.system().contains('mingw')
+elif host_machine.system() == 'windows'
   os_win32 = true
-elif host_machine.system().contains('linux')
+elif host_machine.system() == 'linux'
   os_linux = true
 endif
-
 os_unix = not os_win32
 
+if os_darwin
+  wayland_enabled = false
+else
+  quartz_enabled = false
+endif
+
+if os_win32
+  wayland_enabled = false
+  x11_enabled = false
+else
+  win32_enabled = false
+endif
+
+gtk_prefix = get_option('prefix')
+gtk_includedir = join_paths(gtk_prefix, get_option('includedir'))
+gtk_libdir = join_paths(gtk_prefix, get_option('libdir'))
+gtk_datadir = join_paths(gtk_prefix, get_option('datadir'))
+gtk_localedir = join_paths(gtk_prefix, get_option('localedir'))
+gtk_sysconfdir = join_paths(gtk_prefix, get_option('sysconfdir'))
+gtk_applicationsdir = join_paths(gtk_datadir, 'applications')
+gtk_schemasdir = join_paths(gtk_datadir, 'glib-2.0/schemas')
+gtk_appdatadir = join_paths(gtk_datadir, 'metainfo')
 
 cc = meson.get_compiler('c')
+
 cdata = configuration_data()
-cdata.set('PACKAGE_VERSION', '"'+meson.project_version()+'"')
-cdata.set('GTK_LOCALEDIR', '"'+get_option('localedir')+'"')
-cdata.set('GTK_DATADIR', '"'+get_option('datadir')+'"')
-cdata.set('GTK_LIBDIR', '"'+get_option('libdir')+'"')
-cdata.set('GETTEXT_PACKAGE', '"gtk30"')
+cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
+cdata.set_quoted('GTK_LOCALEDIR', gtk_localedir)
+cdata.set_quoted('GTK_DATADIR', gtk_datadir)
+cdata.set_quoted('GTK_LIBDIR', gtk_libdir)
+cdata.set_quoted('GTK_SYSCONFDIR', gtk_sysconfdir)
+cdata.set_quoted('GETTEXT_PACKAGE', 'gtk30')
 cdata.set('GTK_MAJOR_VERSION', gtk_major_version)
 cdata.set('GTK_MINOR_VERSION', gtk_minor_version)
 cdata.set('GTK_MICRO_VERSION', gtk_micro_version)
 cdata.set('GTK_BINARY_AGE', gtk_binary_age)
 cdata.set('GTK_INTERFACE_AGE', gtk_interface_age)
+
 check_headers = [
-  ['HAVE_CRT_EXTERNS_H', 'crt/externs.h'],
-  ['HAVE_DLFCN_H', 'dlfcn.h'],
-  ['HAVE_FTW_H', 'ftw.h'],
-  ['HAVE_INTTYPES_H', 'inttypes.h'],
-  ['HAVE_LOCALE_H', 'locale.h'],
-  ['HAVE_MEMORY_H', 'memory.h'],
-  ['HAVE_STDINT_H', 'stdint.h'],
-  ['HAVE_STDLIB_H', 'stdlib.h'],
-  ['HAVE_STRINGS_H', 'strings.h'],
-  ['HAVE_STRING_H', 'string.h'],
-  ['HAVE_SYS_MMAN_H', 'sys/mman.h'],
-  ['HAVE_SYS_PARAM_H', 'sys/param.h'],
-  ['HAVE_SYS_STAT_H', 'sys/stat.h'],
-  ['HAVE_SYS_SYSINFO_H', 'sys/sysinfo.h'],
-  ['HAVE_SYS_SYSTEMINFO_H', 'sys/systeminfo.h'],
-  ['HAVE_SYS_TIME_H', 'sys/time.h'],
-  ['HAVE_SYS_TYPES_H', 'sys/types.h'],
-  ['HAVE_UNISTD_H', 'unistd.h'],
-  ['HAVE_LINUX_MEMFD_H', 'linux/memfd.h'],
+  'crt/externs.h',
+  'dlfcn.h',
+  'ftw.h',
+  'inttypes.h',
+  'linux/memfd.h',
+  'linux/input.h',
+  'dev/evdev/input.h',
+  'locale.h',
+  'memory.h',
+  'stdint.h',
+  'stdlib.h',
+  'string.h',
+  'strings.h',
+  'sys/mman.h',
+  'sys/param.h',
+  'sys/stat.h',
+  'sys/sysinfo.h',
+  'sys/systeminfo.h',
+  'sys/time.h',
+  'sys/types.h',
+  'unistd.h',
 ]
 
 foreach h : check_headers
-  if cc.has_header(h.get(1))
-    cdata.set(h.get(0), 1)
+  if cc.has_header(h)
+    cdata.set('HAVE_' + h.underscorify().to_upper(), 1)
   endif
 endforeach
 
+# Maths functions might be implemented in libm
+libm = cc.find_library('m', required: false)
+
 check_functions = [
-# check token HAVE_BIND_TEXTDOMAIN_CODESET
-# check token HAVE_CUPS_API_1_6
-  ['HAVE_DCGETTEXT', 'dcgettext', '#include<libintl.h>'],
-  ['HAVE_DECL_ISINF', 'isinf', '#include<math.h>'],
-  ['HAVE_DECL_ISNAN', 'isnan', '#include<math.h>'],
-  ['HAVE_GETPAGESIZE', 'getpagesize', '#include<unistd.h>'],
-  ['HAVE_GETRESUID', 'getresuid', '#include<unistd.h>'],
-# check token HAVE_GETTEXT
-# check token HAVE_GIO_UNIX
-# check token HAVE_GNU_FTW
-# check token HAVE_HTTPGETAUTHSTRING
-# check token HAVE_HTTP_AUTHSTRING
-# check token HAVE_IPRINTDIALOGCALLBACK
-# check token HAVE_LC_MESSAGES
-# check token HAVE_LOCALTIME_R
-  ['HAVE_LSTAT', 'lstat', '#include<sys/stat.h>'],
-  ['HAVE_MMAP', 'mmap', '#include<sys/mman.h>'],
-  ['HAVE_NEARBYINT', 'nearbyint', '#include<math.h>'],
-  ['HAVE_POSIX_FALLOCATE', 'posix_fallocate', '#include<fcntl.h>'],
-  ['HAVE__LOCK_FILE', '_lock_file', '#include<stdio.h>'],
-  ['HAVE_FLOCKFILE', 'flockfile', '#include<stdio.h>'],
-  ['HAVE_MKSTEMP', 'mkstemp', '#include<stdlib.h>'],
-  ['HAVE_MALLINFO', 'mallinfo', '#include<malloc.h>'],
-  ['HAVE_ROUND', 'round', '#include<math.h>'],
-  ['HAVE_RINT', 'rint', '#include<math.h>'],
-  ['HAVE_LOG2', 'log2', '#include<math.h>'],
-  ['HAVE_EXP2', 'exp2', '#include<math.h>'],
-  ['HAVE_SINCOS', 'sincos', '#include<math.h>'],
-  ['HAVE_XKB', 'XkbQueryExtension', '#include<X11/XKBlib.h>'],
-# check token HAVE_SOCKADDR_UN_SUN_LEN
-# check token HAVE_SOLARIS_XINERAMA
-# check token HAVE_XFREE_XINERAMA
-# check token HAVE_XINERAMA
-# check token HAVE__NL_MEASUREMENT_MEASUREMENT
-# check token HAVE__NL_PAPER_HEIGHT
-# check token HAVE__NL_PAPER_WIDTH
-# check token HAVE__NL_TIME_FIRST_WEEKDAY
-# check token HAVE__NSGETENVIRON
-]
-if x11_enabled
-check_functions += [
-  ['HAVE_XGENERICEVENTS', 'XGetEventData', '#include<X11/Xlib.h>'],
-  ['HAVE_XSYNC', 'XSyncQueryExtension', '#include<X11/Xlib.h>\n#include</usr/include/X11/extensions/sync.h>']
+  'dcgettext',
+  'getpagesize',
+  'getresuid',
+  'lstat',
+  'mmap',
+  'nearbyint',
+  'posix_fallocate',
+  '_lock_file',
+  'flockfile',
+  'mkstemp',
+  'mallinfo',
+  'round',
+  'rint',
+  'log2',
+  'exp2',
+  'sincos',
+  'trunc',
 ]
-endif
 
-foreach f : check_functions
-  if cc.has_function(f.get(1), prefix : f.get(2))
-    cdata.set(f.get(0), 1)
+foreach func : check_functions
+  if cc.has_function(func, dependencies: libm)
+    cdata.set('HAVE_' + func.underscorify().to_upper(), 1)
   endif
 endforeach
 
-#
+cdata.set('HAVE_DECL_ISINF', cc.has_header_symbol('math.h', 'isinf'))
+cdata.set('HAVE_DECL_ISNAN', cc.has_header_symbol('math.h', 'isnan'))
+
 # Disable deprecation checks for all libraries we depend on on stable branches.
 # This is so newer versions of those libraries don't cause more warnings with
 # a stable GTK version.
 # We don't ever want to turn off deprecation warnings for master however, because
 # that's where we get rid of deprecated API we use.
-if gtk_minor_version % 2 == 0
+if gtk_minor_version.is_even()
   cdata.set('GLIB_DISABLE_DEPRECATION_WARNINGS', 1)
 endif
 
+# Compiler flags
+if cc.get_id() == 'msvc'
+  # Compiler options taken from msvc_recommended_pragmas.h
+  # in GLib, based on _Win32_Programming_ by Rector and Newcomer
+  test_cflags = []
+  add_project_arguments('-FImsvc_recommended_pragmas.h', language: 'c')
+  add_project_arguments('-D_USE_MATH_DEFINES', language: 'c')
+elif cc.get_id() == 'gcc' or cc.get_id() == 'clang'
+  test_cflags = [
+    '-fno-strict-aliasing',
+    '-Wpointer-arith',
+    '-Wimplicit-function-declaration',
+    '-Wformat=2',
+    '-Wformat-security',
+    '-Wnested-externs',
+    '-Wold-style-definition',
+    '-Wundef',
+    '-Wunused',
+    '-Wcast-align',
+    '-Wmissing-noreturn',
+    '-Wmissing-format-attribute',
+    '-Wmissing-include-dirs',
+    '-Wlogical-op',
+    '-Wignored-qualifiers',
+    '-Werror=implicit',
+    '-Werror=nonnull',
+    '-Werror=init-self',
+    '-Werror=main',
+    '-Werror=missing-braces',
+    '-Werror=sequence-point',
+    '-Werror=return-type',
+    '-Werror=trigraphs',
+    '-Werror=array-bounds',
+    '-Werror=write-strings',
+    '-Werror=address',
+    '-Werror=int-to-pointer-cast',
+    '-Werror=pointer-to-int-cast',
+    '-Werror=empty-body',
+    '-Werror=write-strings',
+  ]
+else
+  test_cflags = []
+endif
+
+common_cflags = cc.get_supported_arguments(test_cflags)
+
+# Symbol visibility
+if get_option('default_library') != 'static'
+  if os_win32
+    cdata.set('DLL_EXPORT', true)
+    cdata.set('_GDK_EXTERN', '__declspec(dllexport) extern')
+    if cc.get_id() != 'msvc'
+      common_cflags += ['-fvisibility=hidden']
+    endif
+  else
+    cdata.set('_GDK_EXTERN', '__attribute__((visibility("default"))) extern')
+    common_cflags += ['-fvisibility=hidden']
+  endif
+endif
+
+common_ldflags = []
+
+if os_unix and not os_darwin
+  foreach ldflag: [ '-Wl,-Bsymbolic', '-Wl,-z,relro', '-Wl,-z,now', ]
+    if cc.links('int main () { return 0; }', name: ldflag, args: ldflag)
+      common_ldflags += [ ldflag ]
+    endif
+  endforeach
+endif
+
+# Maintain compatibility with autotools
+if os_darwin
+  common_ldflags += [ '-compatibility_version 1', '-current_version 1.0', ]
+endif
+
 
 confinc = include_directories('.')
 gdkinc = include_directories('gdk')
 gtkinc = include_directories('gtk')
+testinc = include_directories('tests')
+
+# Dependencies
+glib_dep       = dependency('glib-2.0', version: glib_req,
+                            fallback : ['glib', 'libglib_dep'])
+gobject_dep    = dependency('gobject-2.0', version: glib_req,
+                            fallback : ['glib', 'libgobject_dep'])
+if os_win32
+  giowin32_dep = dependency('gio-windows-2.0', version: glib_req, required: win32_enabled,
+                            fallback : ['glib', 'libgio_dep'])
+endif
+if os_unix
+  giounix_dep  = dependency('gio-unix-2.0', version: glib_req, required: false,
+                            fallback : ['glib', 'libgio_dep'])
+endif
+gmodule_dep    = dependency('gmodule-2.0', version: glib_req,
+                            fallback : ['glib', 'libgmodule_dep'])
+cairo_dep      = dependency('cairo', version: cairo_req, required : cc.get_id() != 'msvc')
+cairogobj_dep  = dependency('cairo-gobject', version: cairo_req, required : cc.get_id() != 'msvc')
+pango_dep      = dependency('pango', version: pango_req,
+                            fallback : ['pango', 'libpango_dep'])
+
+# Require PangoFT2 if on X11 or wayland
+require_pangoft2 = wayland_enabled or x11_enabled
+pangoft_dep    = dependency('pangoft2', required: require_pangoft2,
+                            fallback : ['pango', 'libpangoft2_dep'])
+
+if pangoft_dep.found()
+  # Need at least 2.7.1 for FT_Get_Var_Design_Coordinates()
+  # We get the dependency itself from pango, but pango doesn't care
+  # about ft2 version, so an extra check is needed.
+  ft2_dep      = dependency('freetype2', version: '>= 2.7.1', required: require_pangoft2)
+endif
+
+if win32_enabled
+  # for GTK_IM_CONTEXT_IME
+  pangowin32_dep  = dependency('pangowin32')
+endif
+
+pangocairo_dep = dependency('pangocairo', version: cairo_req,
+                            fallback : ['pango', 'libpangocairo_dep'])
+pixbuf_dep     = dependency('gdk-pixbuf-2.0', version: gdk_pixbuf_req,
+                            fallback : ['gdk-pixbuf', 'gdkpixbuf_dep'])
+epoxy_dep      = dependency('epoxy', version: epoxy_req,
+                            fallback: ['libepoxy', 'libepoxy_dep'])
+atk_dep        = dependency('atk', version: atk_req)
+harfbuzz_dep   = dependency('harfbuzz', version: '>= 0.9', required: false,
+                            fallback: ['harfbuzz', 'libharfbuzz_dep'])
+xkbdep         = dependency('xkbcommon', version: xkbcommon_req, required: wayland_enabled)
+iso_codes_dep  = dependency('iso-codes', required: false)
+
+fontconfig_dep = [] # only used in x11 backend
+atkbridge_dep  = [] # only used in x11 backend
+
+if os_win32
+  platform_gio_dep = giowin32_dep
+endif
+if os_unix
+  platform_gio_dep = giounix_dep
+endif
+
+if iso_codes_dep.found()
+  cdata.set_quoted('ISO_CODES_PREFIX', iso_codes_dep.get_pkgconfig_variable('prefix'))
+else
+  cdata.set_quoted('ISO_CODES_PREFIX', '/usr')
+endif
+
+backend_immodules = []
+
+pc_gdk_extra_libs = []
+
+cairo_backends = []
+foreach backend: [ ['cairo-xlib', cairo_req, x11_enabled],
+                   ['cairo-win32', cairo_req, win32_enabled],
+                   ['cairo-quartz', cairo_req, quartz_enabled],
+                   ['cairo', cairo_req, broadway_enabled or wayland_enabled], ]
+ backend_enabled = backend.get(2)
+ cairo_backend_req = backend.get(1)
+ cairo_backend = backend.get(0)
+ if backend_enabled
+   if dependency(cairo_backend, version: cairo_backend_req, required : cc.get_id() != 'msvc').found()
+     cairo_backends += [ cairo_backend ]
+   endif
+ endif
+endforeach
+
+cairo_pkg_found = false
+cairogobj_pkg_found = false
 
-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', required: wayland_enabled or x11_enabled)
-cairo_dep      = dependency('cairo', version: '>= 1.14.0')
-pangocairo_dep = dependency('pangocairo')
-cairogobj_dep  = dependency('cairo-gobject')
-pixbuf_dep     = dependency('gdk-pixbuf-2.0', version: '>= 2.30.0')
-epoxy_dep      = dependency('epoxy', version: '>= 1.0')
-atk_dep        = dependency('atk', version: '>= 2.15.1')
-atkbridge_dep  = dependency('atk-bridge-2.0')
-gmodule_dep    = dependency('gmodule-2.0')
-colord_dep     = dependency('colord', version: '>= 0.1.9', required: false)
-fontconfig_dep = dependency('fontconfig')
-harfbuzz_dep   = dependency('harfbuzz', version: '>= 0.9', required: false)
-xkbdep         = dependency('xkbcommon', version: '>= 0.2.0')
+if cairo_dep.found()
+  cairo_pkg_found = true
+endif
+if cairogobj_dep.found()
+  cairogobj_pkg_found = true
+endif
+
+cairo_libs = []
+
+cdata.set('HAVE_HARFBUZZ', harfbuzz_dep.found())
+cdata.set('HAVE_PANGOFT', pangoft_dep.found())
 
+atk_pkgs = ['atk']
+
+wayland_pkgs = []
 if wayland_enabled
-  wlclientdep    = dependency('wayland-client', version:  '>= 1.9.91')
-  wlprotocolsdep = dependency('wayland-protocols', version: '>= 1.7')
-  wlcursordep    = dependency('wayland-cursor', version: '>= 1.9.91')
+  wlclientdep    = dependency('wayland-client', version:  wayland_req)
+  wlprotocolsdep = dependency('wayland-protocols', version: wayland_proto_req)
+  wlcursordep    = dependency('wayland-cursor', version: wayland_req)
   wlegldep       = dependency('wayland-egl')
+  backend_immodules += ['wayland']
+
+  wayland_pkgs = [
+    'wayland-client', wayland_req,
+    'wayland-protocols', wayland_proto_req,
+    'xkbcommon', xkbcommon_req,
+    'wayland-cursor', wayland_req,
+    'wayland-egl',
+  ]
 endif
 
+x11_pkgs = []
 if x11_enabled
   xrandr_dep     = dependency('xrandr', version: '>= 1.2.99')
   xrandr15_dep   = dependency('xrandr', version: '>= 1.5', required: false)
@@ -200,67 +426,276 @@ if x11_enabled
   xdamage_dep    = dependency('xdamage', required: false)
   xfixes_dep     = dependency('xfixes', required: false)
   xcomposite_dep = dependency('xcomposite', required: false)
+  fontconfig_dep = dependency('fontconfig')
+  atkbridge_dep  = dependency('atk-bridge-2.0', version: atk_req)
 
+  backend_immodules += ['xim']
 
-  if xdamage_dep.found()
-    cdata.set('HAVE_XDAMAGE', 1)
-  endif
+  x11_pkgs = ['fontconfig', 'x11', 'xext', 'xi', 'xrandr']
 
   if xcursor_dep.found()
-    cdata.set('HAVE_XCURSOR', 1)
+    x11_pkgs += ['xcursor']
+  endif
+  if xfixes_dep.found()
+    x11_pkgs += ['xfixes']
   endif
-
   if xcomposite_dep.found()
-    cdata.set('HAVE_XCOMPOSITE', 1)
+    x11_pkgs += ['xcomposite']
+  endif
+  if xdamage_dep.found()
+    x11_pkgs += ['xdamage']
   endif
 
-  if xfixes_dep.found()
-    cdata.set('HAVE_XFIXES', 1)
+  atk_pkgs += ['atk-bridge-2.0']
+
+  cdata.set('HAVE_XDAMAGE', xdamage_dep.found())
+  cdata.set('HAVE_XCURSOR', xcursor_dep.found())
+  cdata.set('HAVE_XCOMPOSITE', xcomposite_dep.found())
+  cdata.set('HAVE_XFIXES', xfixes_dep.found())
+
+  if cc.has_function('XkbQueryExtension', dependencies: x11_dep,
+                     prefix : '#include <X11/XKBlib.h>')
+    cdata.set('HAVE_XKB', 1)
   endif
 
+  if cc.has_function('XSyncQueryExtension', dependencies: xext_dep,
+                     prefix: '''#include <X11/Xlib.h>
+                                #include <X11/extensions/sync.h>''')
+    cdata.set('HAVE_XSYNC', 1)
+  endif
 
+  if cc.has_function('XGetEventData', dependencies: x11_dep)
+    cdata.set('HAVE_XGENERICEVENTS', 1)
+  endif
 
-  if xi_dep.found() and cc.has_header('X11/extensions/XInput2.h')
+  if xi_dep.found() and cc.has_header('X11/extensions/XInput2.h', dependencies: xi_dep)
     cdata.set('XINPUT_2', 1)
-    prefix = '#include<X11/Xlib.h>\n#include<X11/extensions/XInput2.h>'
-    if cc.has_function('XIAllowTouchEvents', prefix: prefix) and cc.has_member('XIScrollClassInfo', 
'number', prefix: prefix)
+    # Note that we also check that the XIScrollClassInfo struct is defined,
+    # because at least Ubuntu Oneiric seems to have XIAllowTouchEvents(),
+    # but not the XIScrollClassInfo struct
+    has_allow_touch_evens = cc.has_function('XIAllowTouchEvents', dependencies: xi_dep)
+    has_scroll_class_info = cc.has_member('XIScrollClassInfo', 'number', dependencies: xi_dep,
+                                          prefix: '''#include <X11/Xlib.h>
+                                                     #include <X11/extensions/XInput2.h>''')
+    if has_allow_touch_evens and has_scroll_class_info
       cdata.set('XINPUT_2_2', 1)
     endif
   endif
 
-  if xrandr_dep.found()
-    cdata.set('HAVE_RANDR', 1)
-
-    if xrandr15_dep.found()
-      cdata.set('HAVE_RANDR15', 1)
+  enable_xinerama = get_option('xinerama')
+  if enable_xinerama != 'no'
+    want_xinerama = enable_xinerama == 'yes'
+    xinerama_dep = dependency('xinerama', required: want_xinerama)
+    if xinerama_dep.found() and cc.has_header_symbol('X11/extensions/Xinerama.h', 'XineramaQueryExtension', 
dependencies: xinerama_dep)
+      cdata.set('HAVE_XFREE_XINERAMA', 1)
+      x11_pkgs += ['xinerama']
     endif
+  else
+    xinerama_dep = []
   endif
+
+  cdata.set('HAVE_RANDR', xrandr_dep.found())
+  cdata.set('HAVE_RANDR15', xrandr15_dep.found())
 endif
 
-mlib   = cc.find_library('m', required: false)
-shmlib = cc.find_library('rt')
+if broadway_enabled
+  pc_gdk_extra_libs += ['-lz']
+  backend_immodules += ['broadway']
+endif
 
-if giounix_dep.found()
-  cdata.set('HAVE_GIO_UNIX', 1)
+if quartz_enabled
+  pc_gdk_extra_libs += ['-framework Cocoa', '-framework Carbon']
+  backend_immodules += ['quartz']
 endif
 
-if colord_dep.found()
-  cdata.set('HAVE_COLORD', 1)
+extra_demo_ldflags = []
+if win32_enabled
+  pc_gdk_extra_libs += ['-lgdi32', '-limm32', '-lshell32', '-lole32']
+  if cc.get_id() == 'msvc'
+    # Since the demo programs are now built as pure GUI programs, we
+    # need to pass in /entry:mainCRTStartup so that they will properly
+    # link on Visual Studio builds
+    extra_demo_ldflags = ['/entry:mainCRTStartup']
+  else
+    pc_gdk_extra_libs += ['-Wl,-luuid']
+  endif
+  pc_gdk_extra_libs += ['-lwinmm', '-ldwmapi', '-lsetupapi', '-lcfgmgr32']
+  backend_immodules += ['ime']
+endif
+
+# Check for bind_textdomain_codeset, including -lintl if GLib brings it in by
+# doing the same check as glib. We can't check that by linking to glib because
+# it might be a subproject and hence not built yet.
+if cc.has_function('ngettext')
+  libintl_dep = []
+  cdata.set('HAVE_BIND_TEXTDOMAIN_CODESET', 1)
+else
+  libintl_dep = cc.find_library('intl', required : false)
+  if cc.has_function('bind_textdomain_codeset', dependencies: libintl_dep)
+    cdata.set('HAVE_BIND_TEXTDOMAIN_CODESET', 1)
+  else
+    # Don't use subproject('proxy-libintl').get_variable('intl_dep') because that
+    # makes the dependency unconditional. This way, people have the option of
+    # either not providing the subproject or disabling it entirely with
+    # --wrap-mode=nodownload or nofallback.
+    libintl_dep = dependency('', required : false,
+                             fallback: ['proxy-libintl', 'intl_dep'])
+    if libintl_dep.found()
+      cdata.set('HAVE_BIND_TEXTDOMAIN_CODESET', 1)
+    endif
+  endif
 endif
 
-if mlib.found()
-  cdata.set('HAVE_LIBM', 1)
+if os_unix
+  cdata.set('HAVE_GIO_UNIX', giounix_dep.found())
 endif
 
-configure_file(
-  input : 'config.h.meson',
-  output: 'config.h',
-  configuration: cdata
-)
+cloudproviders_enabled = get_option('cloudproviders')
+if cloudproviders_enabled
+  cloudproviders_dep = dependency('cloudproviders', required: true)
+  if cloudproviders_dep.found()
+    cdata.set('HAVE_CLOUDPROVIDERS', cloudproviders_dep.found())
+  else
+    error('Cloudproviders support not found, but was explicitly requested.')
+  endif
+endif
 
 subdir('gdk')
 subdir('gtk')
-subdir('demos')
-subdir('tests')
-subdir('testsuite')
-subdir('examples')
+subdir('modules')
+if get_option('demos')
+  subdir('demos')
+endif
+if get_option('build-tests')
+  subdir('tests')
+  subdir('testsuite')
+endif
+if get_option('build-examples')
+  subdir('examples')
+endif
+
+# config.h
+configure_file(input: 'config.h.meson',
+               output: 'config.h',
+               configuration: cdata)
+
+# pkg-config files - bit of a mess all of this
+pkgconf = configuration_data()
+
+pkgconf.set('prefix', get_option('prefix'))
+pkgconf.set('exec_prefix', '${prefix}')
+pkgconf.set('libdir', '${prefix}/@0@'.format(get_option('libdir')))
+pkgconf.set('includedir', '${prefix}/@0@'.format(get_option('includedir')))
+pkgconf.set('GTK_API_VERSION', gtk_api_version)
+pkgconf.set('VERSION', meson.project_version())
+pkgconf.set('GTK_BINARY_VERSION', gtk_binary_version)
+pkgconf.set('host', '@0@-@1@'.format(host_machine.cpu_family(), host_machine.system())) # FIXME
+
+# Requires
+pango_pkgname = win32_enabled ? 'pangowin32' : 'pango'
+gdk_packages = ' '.join([ pango_pkgname, pango_req,
+                       'pangocairo', pango_req,
+                       'gdk-pixbuf-2.0', gdk_pixbuf_req ])
+
+if cairo_pkg_found
+  gdk_packages += ' '.join([ ' cairo', cairo_req ])
+endif
+if cairogobj_pkg_found
+  gdk_packages += ' '.join([ ' cairo-gobject', cairo_req ])
+endif
+
+pkgconf.set('GDK_PACKAGES', gdk_packages)
+pkgconf.set('GTK_PACKAGES',
+            ' '.join([ 'atk', atk_req,
+                       'gio-2.0', glib_req ]))
+
+# Requires.private
+pc_gdk_extra_libs += cairo_libs
+
+gio_pkgname = os_unix ? 'gio-unix-2.0' : 'gio-2.0'
+pkgconf.set('GDK_PRIVATE_PACKAGES',
+            ' '.join([ gio_pkgname, glib_req,
+                       'epoxy', epoxy_req ] + x11_pkgs + wayland_pkgs + cairo_backends))
+pangoft2_pkgs = (wayland_enabled or x11_enabled) ? ['pangoft2'] : []
+pkgconf.set('GTK_PRIVATE_PACKAGES', ' '.join(atk_pkgs + pangoft2_pkgs))
+
+pkgconf.set('GDK_EXTRA_LIBS', ' '.join(pc_gdk_extra_libs))
+pkgconf.set('GSK_EXTRA_LIBS', '')
+pkgconf.set('GTK_EXTRA_LIBS', '')
+
+pkgconf.set('GDK_EXTRA_CFLAGS', '')
+pkgconf.set('GSK_EXTRA_CFLAGS', '')
+pkgconf.set('GTK_EXTRA_CFLAGS', '')
+
+pkg_install_dir = join_paths(get_option('libdir'), 'pkgconfig')
+
+pkgs = [ 'gtk+-3.0.pc' ]
+
+pkg_targets = ''
+foreach backend: [ 'broadway', 'quartz', 'wayland', 'win32', 'x11', ]
+  if get_variable('@0@_enabled'.format(backend))
+    pkgs += ['gtk+-@0 -3 0 pc'.format(backend)]
+    pkg_targets += ' ' + backend
+  endif
+endforeach
+pkgconf.set('GDK_BACKENDS', pkg_targets.strip())
+
+configure_file(input: 'gdk-3.0.pc.in',
+               output: 'gdk-3.0.pc',
+               configuration: pkgconf,
+               install_dir: pkg_install_dir)
+
+foreach pkg: pkgs
+  configure_file(input: 'gtk+-3.0.pc.in',
+                 output: pkg,
+                 configuration: pkgconf,
+                 install_dir: pkg_install_dir)
+endforeach
+
+if os_unix
+  configure_file(input: 'gtk+-unix-print-3.0.pc.in',
+                 output: 'gtk+-unix-print-3.0.pc',
+                 configuration: pkgconf,
+                 install_dir: pkg_install_dir)
+endif
+
+# TODO
+#subdir('po')
+#subdir('po-properties')
+
+if get_option('documentation')
+  subdir('docs/tools')
+  subdir('docs/reference')
+endif
+
+# Keep this in sync with post-install.sh expected arguments
+meson.add_install_script('build-aux/meson/post-install.sh',
+                         gtk_api_version,
+                         gtk_binary_version,
+                         gtk_libdir,
+                         gtk_datadir)
+
+summary = [
+  '',
+  '------',
+  'GTK+ @0@ (@1@)'.format(gtk_version, gtk_api_version),
+  '',
+  '  Display backends: @0@'.format(pkg_targets.strip()),
+  '    Print backends: @0@'.format(' '.join(print_backends)),
+  '     Cloud support: @0@'.format(get_option('cloudproviders')),
+  '    Colord support: @0@'.format(get_option('colord')),
+  '     Introspection: @0@'.format(get_option('introspection')),
+  '     Documentation: @0@'.format(get_option('documentation')),
+  '       Build tests: @0@'.format(get_option('build-tests')),
+  '             Demos: @0@'.format(get_option('demos')),
+  '          Examples: @0@'.format(get_option('build-examples')),
+  'Directories:',
+  '            prefix: @0@'.format(gtk_prefix),
+  '        includedir: @0@'.format(gtk_includedir),
+  '            libdir: @0@'.format(gtk_libdir),
+  '           datadir: @0@'.format(gtk_datadir),
+  '------',
+  ''
+]
+
+message('\n'.join(summary))
diff --git a/meson_options.txt b/meson_options.txt
index e8f8ee60e9..79aca2aa66 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,39 @@
-option('enable-x11-backend', type: 'boolean', value: 'true')
-option('enable-wayland-backend', type: 'boolean', value: 'true')
-option('enable-broadway-backend', type: 'boolean', value: 'false')
+# GDK backends
+option('x11-backend', type: 'boolean', value: true,
+  description : 'Enable the X11 gdk backend (only when building on Unix)')
+option('wayland-backend', type: 'boolean', value: true,
+  description : 'Enable the wayland gdk backend (only when building on Unix except for macOS)')
+option('broadway-backend', type: 'boolean', value: false,
+  description : 'Enable the broadway (HTML5) gdk backend')
+option('win32-backend', type: 'boolean', value: true,
+  description : 'Enable the Windows gdk backend (only when building on Windows)')
+option('quartz-backend', type: 'boolean', value: true,
+  description : 'Enable the macOS gdk backend (only when building on macOS)')
+
+# Optional dependencies
+option('xinerama', type: 'combo', choices : ['yes', 'no', 'auto'], value : 'auto',
+  description : 'Enable support for the Xinerama extension')
+option('cloudproviders', type: 'boolean', value: false,
+  description : 'Enable the cloudproviders support')
+
+# Print backends
+option('print-backends', type : 'string', value : 'cups,file',
+  description : 'Build the specified print backends (comma-separated list, "all", or "none")')
+option('colord', type: 'combo', choices : ['yes', 'no', 'auto'], value : 'auto',
+  description : 'Build colord support for the CUPS printing backend')
+
+# Documentation and introspection
+option('documentation', type: 'boolean', value: 'false',
+  description : 'Build API reference and tools documentation')
+option('man-pages', type: 'boolean', value: 'false',
+  description : 'Build man pages for installed tools')
+option('introspection', type: 'boolean', value: 'true',
+  description : 'Build introspection data (requires gobject-introspection)')
+
+# Demos and binaries
+option('demos', type: 'boolean', value: 'true',
+  description : 'Build demo programs')
+option('build-examples', type: 'boolean', value: 'true',
+  description : 'Build examples')
+option('build-tests', type: 'boolean', value: 'true',
+  description : 'Build tests')
diff --git a/modules/meson.build b/modules/meson.build
new file mode 100644
index 0000000000..9779ee6ae8
--- /dev/null
+++ b/modules/meson.build
@@ -0,0 +1,8 @@
+# TODO
+#if os_unix
+#  subdir('printbackends')
+#else
+  print_backends = []
+#endif
+
+#subdir('input')
diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build
index 6c33c5e165..326c6545a8 100644
--- a/testsuite/gdk/meson.build
+++ b/testsuite/gdk/meson.build
@@ -1,24 +1,24 @@
 
-test_cairo = executable('cairo', 'cairo.c', dependencies: libgdk_dep)
+test_cairo = executable('cairo', 'cairo.c', dependencies: libgtk_dep)
 test('gdk/cairo', test_cairo)
 
-test_display = executable('display', 'display.c', dependencies: libgdk_dep)
+test_display = executable('display', 'display.c', dependencies: libgtk_dep)
 test('gdk/display', test_display)
 
-test_encoding = executable('encoding', 'encoding.c', dependencies: libgdk_dep)
+test_encoding = executable('encoding', 'encoding.c', dependencies: libgtk_dep)
 test('gdk/encoding', test_encoding)
 
-test_keysyms = executable('keysyms', 'keysyms.c', dependencies: libgdk_dep)
+test_keysyms = executable('keysyms', 'keysyms.c', dependencies: libgtk_dep)
 test('gdk/keysyms', test_keysyms)
 
-test_rectangle = executable('rectangle', 'rectangle.c', dependencies: libgdk_dep)
+test_rectangle = executable('rectangle', 'rectangle.c', dependencies: libgtk_dep)
 test('gdk/rectangle', test_rectangle)
 
-test_rgba = executable('rgba', 'rgba.c', dependencies: libgdk_dep)
+test_rgba = executable('rgba', 'rgba.c', dependencies: libgtk_dep)
 test('gdk/rgba', test_rgba)
 
-test_seat = executable('seat', 'seat.c', dependencies: libgdk_dep)
+test_seat = executable('seat', 'seat.c', dependencies: libgtk_dep)
 test('gdk/seat', test_seat)
 
-test_visual = executable('visual', 'visual.c', dependencies: libgdk_dep)
+test_visual = executable('visual', 'visual.c', dependencies: libgtk_dep)
 test('gdk/visual', test_visual)
diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build
index a11db7be76..ad1789c48c 100644
--- a/testsuite/gtk/meson.build
+++ b/testsuite/gtk/meson.build
@@ -1,150 +1,109 @@
-test_accel = executable('accel', 'accel.c', dependencies: libgtk_dep)
-test('gtk/accel test', test_accel)
-
-test_accessible = executable('accessible', 'accessible.c', dependencies: libgtk_dep)
-test('gtk/accessible test', test_accessible)
-
-test_action = executable('action', 'action.c', dependencies: libgtk_dep)
-test('gtk/action test', test_action)
-
-
-test_adjustment = executable('adjustment', 'adjustment.c', dependencies: libgtk_dep)
-test('gtk/adjustment test', test_adjustment)
-
-test_bitmask = executable('bitmask', 'bitmask.c', dependencies: libgtk_dep)
-test('gtk/bitmask test', test_bitmask)
-
-test_builder = executable('builder', 'builder.c', dependencies: libgtk_dep)
-test('gtk/builder test', test_builder)
-
-test_builderparser = executable(
-  'builderparser',
-  'builderparser.c',
-  dependencies: libgtk_dep,
-  link_with: libgtk,
-
-)
-test(
-  'gtk/builderparser test',
-  test_builderparser,
-  env: [
-      'G_TEST_SRCDIR='+meson.source_root(),
-      'G_TEST_BUILDDIR='+meson.build_root()
+gtk_tests_export_dynamic_ldflag = []
+
+if cc.get_id() != 'msvc'
+  gtk_tests_export_dynamic_ldflag = ['-Wl,--export-dynamic']
+endif
+
+tests = [
+  ['accel'],
+  ['accessible'],
+  ['action'],
+  ['adjustment'],
+  ['bitmask', ['../../gtk/gtkallocatedbitmask.c'], ['-DGTK_COMPILATION', '-UG_ENABLE_DEBUG']],
+  ['builder', [], [], gtk_tests_export_dynamic_ldflag],
+  ['builderparser'],
+  ['cellarea'],
+  ['check-icon-names'],
+  ['check-cursor-names'],
+  ['cssprovider'],
+  ['defaultvalue'],
+  ['entry'],
+  ['firefox-stylecontext'],
+  ['floating'],
+  ['focus'],
+  ['gestures'],
+  ['grid'],
+  ['gtkmenu'],
+  ['icontheme'],
+  ['keyhash', ['../../gtk/gtkkeyhash.c', gtkresources, '../../gtk/gtkprivate.c'], gtk_cargs],
+  ['listbox'],
+  ['notify'],
+  ['no-gtk-init'],
+  ['object'],
+  ['papersize'],
+  ['rbtree', ['../../gtk/gtkrbtree.c'], ['-DGTK_COMPILATION', '-UG_ENABLE_DEBUG']],
+  ['recentmanager'],
+  ['regression-tests'],
+  ['scrolledwindow'],
+  ['spinbutton'],
+  ['stylecontext'],
+  ['templates'],
+  ['textbuffer'],
+  ['textiter'],
+  ['treemodel', ['treemodel.c', 'liststore.c', 'treestore.c', 'filtermodel.c',
+                 'modelrefcount.c', 'sortmodel.c', 'gtktreemodelrefcount.c']],
+  ['treepath'],
+  ['treeview'],
+  ['typename'],
+  ['window'],
+  ['displayclose'],
+  ['revealer-size'],
+]
+
+test_cargs = []
+
+if os_unix
+  # tests += [['defaultvalue']]  # disabled in Makefile.am as well
+  test_cargs += ['-DHAVE_UNIX_PRINT_WIDGETS']
+endif
+
+if x11_enabled
+  tests += [
+    ['clipboard'],
+    ['objects-finalize', ['../../gdk/x11/gdkdisplaymanager-x11.c'], ['-DGDK_COMPILATION', 
'-UG_ENABLE_DEBUG']],
   ]
-)
-
-test_cellarea = executable('cellarea', 'cellarea.c', dependencies: libgtk_dep)
-test('gtk/cellarea test', test_cellarea)
-
-test_check_icon_names = executable('check_icon_names', 'check-icon-names.c', dependencies: libgtk_dep)
-test('gtk/check_icon_names test', test_check_icon_names)
-
-test_check_cursor_names = executable('check_cursor_names', 'check-cursor-names.c', dependencies: libgtk_dep)
-test('gtk/check_cursor_names test', test_check_cursor_names)
-
-test_clipboard = executable('clipboard', 'clipboard.c', dependencies: libgtk_dep)
-test('gtk/clipboard test', test_clipboard)
-
-test_cssprovider = executable('cssprovider', 'cssprovider.c', dependencies: libgtk_dep)
-test('gtk/cssprovider test', test_cssprovider)
-
-test_defaultvalue = executable('defaultvalue', 'defaultvalue.c', dependencies: libgtk_dep)
-test('gtk/defaultvalue test', test_defaultvalue)
-
-test_entry = executable('entry', 'entry.c', dependencies: libgtk_dep)
-test('gtk/entry test', test_entry)
-
-test_firefox_stylecontext = executable('firefox_stylecontext', 'firefox-stylecontext.c', dependencies: 
libgtk_dep)
-test('gtk/firefox_stylecontext test', test_firefox_stylecontext)
-
-test_floating = executable('floating', 'floating.c', dependencies: libgtk_dep)
-test('gtk/floating test', test_floating)
-
-test_focus = executable('focus', 'focus.c', dependencies: libgtk_dep)
-test('gtk/focus test', test_focus)
-
-test_gestures = executable('gestures', 'gestures.c', dependencies: libgtk_dep)
-test('gtk/gestures test', test_gestures)
-
-test_grid = executable('grid', 'grid.c', dependencies: libgtk_dep)
-test('gtk/grid test', test_grid)
-
-test_gtkmenu = executable('gtkmenu', 'gtkmenu.c', dependencies: libgtk_dep)
-test('gtk/gtkmenu test', test_gtkmenu)
-
-test_icontheme = executable('icontheme', 'icontheme.c', dependencies: libgtk_dep)
-test('gtk/icontheme test', test_icontheme)
-
-test_keyhash = executable('keyhash', 'keyhash.c', dependencies: libgtk_dep)
-test('gtk/keyhash test', test_keyhash)
-
-test_listbox = executable('listbox', 'listbox.c', dependencies: libgtk_dep)
-test('gtk/listbox test', test_listbox)
-
-test_notify = executable('notify', 'notify.c', dependencies: libgtk_dep)
-test('gtk/notify test', test_notify)
-
-test_no_gtk_init = executable('no_gtk_init', 'no-gtk-init.c', dependencies: libgtk_dep)
-test('gtk/no_gtk_init test', test_no_gtk_init)
-
-test_object = executable('object', 'object.c', dependencies: libgtk_dep)
-test('gtk/object test', test_object)
-
-test_objects_finalize = executable('objects_finalize', 'objects-finalize.c', dependencies: libgtk_dep)
-test('gtk/objects_finalize test', test_objects_finalize)
-
-test_papersize = executable('papersize', 'papersize.c', dependencies: libgtk_dep)
-test('gtk/papersize test', test_papersize)
-
-test_rbtree = executable('rbtree', 'rbtree.c', dependencies: libgtk_dep)
-test('gtk/rbtree test', test_rbtree)
-
-test_recentmanager = executable('recentmanager', 'recentmanager.c', dependencies: libgtk_dep)
-test('gtk/recentmanager test', test_recentmanager)
-
-test_regression_tests = executable('regression_tests', 'regression-tests.c', dependencies: libgtk_dep)
-test('gtk/regression_tests test', test_regression_tests)
-
-test_scrolledwindow = executable('scrolledwindow', 'scrolledwindow.c', dependencies: libgtk_dep)
-test('gtk/scrolledwindow test', test_scrolledwindow)
-
-test_spinbutton = executable('spinbutton', 'spinbutton.c', dependencies: libgtk_dep)
-test('gtk/spinbutton test', test_spinbutton)
-
-test_stylecontext = executable('stylecontext', 'stylecontext.c', dependencies: libgtk_dep)
-test('gtk/stylecontext test', test_stylecontext)
-
-test_templates = executable('templates', 'templates.c', dependencies: libgtk_dep)
-test('gtk/templates test', test_templates)
-
-test_textbuffer = executable('textbuffer', 'textbuffer.c', dependencies: libgtk_dep)
-test('gtk/textbuffer test', test_textbuffer)
-
-test_textiter = executable('textiter', 'textiter.c', dependencies: libgtk_dep)
-test('gtk/textiter test', test_textiter)
-
-test_treemodel = executable(
-  'treemodel',
-  'treemodel.c', 'liststore.c', 'treestore.c', 'filtermodel.c',
-  'modelrefcount.c', 'sortmodel.c', 'gtktreemodelrefcount.c',
-  dependencies: libgtk_dep
-)
-test('gtk/treemodel test', test_treemodel)
-
-test_treepath = executable('treepath', 'treepath.c', dependencies: libgtk_dep)
-test('gtk/treepath test', test_treepath)
-
-test_treeview = executable('treeview', 'treeview.c', dependencies: libgtk_dep)
-test('gtk/treeview test', test_treeview)
-
-test_typename = executable('typename', 'typename.c', dependencies: libgtk_dep)
-test('gtk/typename test', test_typename)
-
-test_window = executable('window', 'window.c', dependencies: libgtk_dep)
-test('gtk/window test', test_window)
-
-test_displayclose = executable('displayclose', 'displayclose.c', dependencies: libgtk_dep)
-test('gtk/displayclose test', test_displayclose)
-
-test_revealer_size = executable('revealer_size', 'revealer-size.c', dependencies: libgtk_dep)
-test('gtk/revealer_size test', test_revealer_size)
+endif
+
+foreach t : tests
+  test_name = t.get(0)
+  test_srcs = ['@0@.c'.format(test_name)] + t.get(1, [])
+  test_extra_cargs = t.get(2, [])
+  test_extra_ldflags = t.get(3, [])
+
+  test_exe = executable(test_name, test_srcs,
+    c_args : test_cargs + test_extra_cargs,
+    link_args : test_extra_ldflags,
+    dependencies : libgtk_dep)
+
+  test(test_name, test_exe,
+       args: [ '--tap', '-k' ],
+       env: [ 'GIO_USE_VOLUME_MONITOR=unix',
+              'GSETTINGS_BACKEND=memory',
+              'GTK_CSD=1',
+              'G_ENABLE_DIAGNOSTIC=0',
+              'GSK_RENDERER=cairo',
+              'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
+              'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+              'GSETTINGS_SCHEMA_DIR=@0@'.format(gtk_schema_build_dir),
+            ],
+       suite: 'gtk')
+endforeach
+
+# FIXME: if objc autotestkeywords_CPPFLAGS += -DHAVE_OBJC=1 -x objective-c++
+if add_languages('cpp', required: false)
+  test_exe = executable('autotestkeywords',
+                        'autotestkeywords.cc',
+                        c_args : test_cargs + ['-Idummy-headers'],
+                        dependencies : libgtk_dep)
+  test('c++ keywords', test_exe,
+       args: [ '--tap', '-k' ],
+       env: [ 'GIO_USE_VOLUME_MONITOR=unix',
+              'GSETTINGS_BACKEND=memory',
+              'GTK_CSD=1',
+              'G_ENABLE_DIAGNOSTIC=0',
+              'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
+              'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+              'GSETTINGS_SCHEMA_DIR=@0@'.format(gtk_schema_build_dir),
+            ],
+       suite: 'gtk')
+endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]