We're hiring!
*

Build your own application with GTK 4 as a Meson subproject!

Xavier Claessens avatar

Xavier Claessens
April 29, 2021

Share this post:

Welcome back to my blog series on GTK 4 and Visual Studio! If you're just joining us, make sure to take a look at the previous episode, where we saw how we can easily build and run GTK 4 on Windows with Visual Studio.

Now, on to the news. First up, GTK 4 now builds out of the box without applying any extra patches, thanks to the last remaining fix (!3135) being merged.

Furthermore, and more importantly, you can now build GTK 4 as a Meson subproject for your own application! This is not only useful for Windows builds, but also for many Linux distributions that do not yet package a recent enough version of GTK 4 and/or its dependencies.

To make your own application fall back to build GTK 4 as a Meson subproject in case the system does not provide it, simply add the following subprojects/gtk.wrap file. This file instructs Meson on where to fetch the gtk4 dependency if it cannot be found on the system:

[wrap-git]
directory=gtk
url=https://gitlab.gnome.org/GNOME/gtk.git
push-url=ssh://git@gitlab.gnome.org:GNOME/gtk.git
revision=master
depth=1

[provide]
dependency_names=gtk4

That's it! When your meson.build does dependency('gtk4'), Meson will automatically configure a GTK4 subproject if GTK4 is not found on the system. It will also fetch and build any GTK4 dependencies which are not found, for example glib, which could be outdated on your system as well.

Build GtkSourceView 5.0 with Visual Studio

Recently, Christian Hergert announced the release of GtkSourceView 5.0, the first application ported to GTK4.

I'm happy to report that all needed fixes to make it build on Windows with GTK4 as a Meson subproject have been merged on time!

Here is how to fetch and build the GtkSourceView master branch, including GTK4 and all of its dependencies, on Windows with Visual Studio. Note that -Dinstall_tests=true is only needed to have the test application installed, it is not needed if you're only interested in the library.

Make sure to follow instructions from the previous blog post to set up your build environment.

C:\src>git clone https://gitlab.gnome.org/GNOME/gtksourceview.git
C:\src>cd gtksourceview
C:\src\gtksourceview>meson setup build --prefix C:/gnome -Dinstall_tests=true
C:\src\gtksourceview>meson compile -C build
C:\src\gtksourceview>meson install -C build

Collabora - x64 Native Tools Command Prompt for VS 2019

Run the test application:

C:\src\gtksourceview>C:\gnome\bin\gtksourceview5-widget.exe

Collabora - GtkSourceView Test

Bonus: Build GTK4's GStreamer media backend with Visual Studio

GTK 4 has an optional dependency on GStreamer for its multimedia widgets. It is possible to also build GStreamer and all its dependencies, including FFmpeg, as Meson subprojects for GTK 4, or even your own application! Simply add gst-build as a subproject: subprojects/gst-build.wrap.

[wrap-git]
url=https://gitlab.freedesktop.org/gstreamer/gst-build.git
revision=master

[provide]
dependency_names=gstreamer-player-1.0

At the time of writing, there is still a build issue (#152) but this can easily be worked around by deleting related code in subprojects/gst-build/meson.build. A proper fix is still needed.

Collabora - GTK4's GStreamer media backend with Visual Studio

What's next?

Now that you can use GTK 4 as a subproject of a real application, and build both GtkSourceView 5.0 and GTK4's GStreamer media backend, what's next? Add Windows CI to GTK 4? Stay tuned!

And of course, if you have any questions about GTK4 and GStreamer on Windows, please get in touch!

Comments (0)


Add a Comment






Allowed tags: <b><i><br>Add a new comment:


Search the newsroom

Latest Blog Posts

Quick hack: Patching kernel modules using DKMS

05/05/2021

DKMS is a framework that is mostly used to build and install external kernel modules. It can also be used to install a specific patch to…

Build your own application with GTK 4 as a Meson subproject!

29/04/2021

Building GTK 4 as a Meson subproject for your own application is not only useful for Windows builds, but also for many Linux distributions…

Profiling virtualized GPU acceleration with Perfetto

22/04/2021

Recently, we have been using Perfetto to successfully profile Apitrace traces in crosvm through VirGL renderer. We have now added perfetto…

Continuous 3D Hand Pose Tracking using Machine Learning & Monado OpenXR

20/04/2021

As part of a project backed by INVEST-AI, a program managed by IVADO Labs, we have developed a multi-stage neural network-based solution…

An easy to use MTP implementation for your next embedded Linux project

13/04/2021

Did you know you could run a permissively-licensed MTP implementation with minimal dependencies on an embedded device? Here's a step-by-step…

Rust: integrating LLVM source-base code coverage with GitLab

24/03/2021

Earlier this year, the Rust compiler gained support for LLVM source-base code coverage. In this post we'll explain how to setup a CI job…

Open Since 2005 logo

We use cookies on this website to ensure that you get the best experience. By continuing to use this website you are consenting to the use of these cookies. To find out more please follow this link.

Collabora Ltd © 2005-2021. All rights reserved. Privacy Notice. Sitemap.

Collabora Limited is registered in England and Wales. Company Registration number: 5513718. Registered office: The Platinum Building, St John's Innovation Park, Cambridge, CB4 0DS, United Kingdom. VAT number: 874 1630 19.