Search code examples
glibmeson-build

How to use meson to build glib


I need to upgrade glib for a specific project. It currently uses glib 2.28.8. I have three problems.

  1. I've never used meson and ninja before, so I checked glib's INSTALL.in and it just said to run meson _build followed by ninja -C _build. So I ran meson _build and got the following output:
$ meson _build
The Meson build system
Version: 0.47.2
Source dir: /srv/devel/build/glib-2.65.0
Build dir: /srv/devel/build/glib-2.65.0/_build
Build type: native build
meson.build:227: WARNING: Identifier 'in' will become a reserved keyword in a future release. Please rename it.

meson.build:227:14: ERROR:  Expecting eol got id.
if vs_crt_opt in ['mdd', 'mtd']

So the basic build doesn't work. Why?

  1. For our purposes, we use the following configure command:
PKG_CONFIG_PATH=$(OUTPUT_DIR)/lib/pkgconfig ./configure --prefix=$(OUTPUT_DIR) --disable-dtrace --disable-selinux ac_cv_path_MSGFMT=/bin/true CPPFLAGS="-fPIC -I$(OUTPUT_DIR)/include" LDFLAGS="-L$(OUTPUT_DIR)/lib" --enable-static --disable-shared

How do I specify that in meson?

  1. I will also need to build in Windows. Any gotchas there?

Thanks!

EDIT: I tried older versions of glib, going back to 2.62.0 and when I run meson _build I get the error meson.build:1:0: ERROR: Meson version is 0.47.2 but project requires >= 0.49.2.. So that's probably a big part of the problem for question (1). This is running on CentOS 6 & 7, so I'll probably have to get and install a current meson package.


Solution

  • So the basic build doesn't work. Why?

    You correctly figured this out in your edit: GLib 2.64 requires Meson 0.49.2, and it seems that Meson 0.47.2 is so old as to not be able to correctly parse GLib’s meson.build.

    It looks from your build output that you’re trying to build GLib 2.65.0. Note that 2.65 is an unstable release series. Even minor versions of GLib (2.62.x, 2.64.x, etc.) are stable; odd ones are unstable. Using an unstable release is fine, as long as you know what you’ve signed up for: it may contain bugs, and new APIs introduced in that unstable series may change or be removed before the first stable release (in the case of 2.65.x, the corresponding first stable release will be 2.66.0).

    For our purposes, we use the following configure command:

    You’ll want something like: meson --prefix "$(OUTPUT_DIR)" -Dselinux=disabled -Ddefault_library=static _build

    You can see from the b_staticpic option’s default value that -fPIC is the default for static libraries, so (I believe) doesn’t need to be explicitly specified.

    There should be no need to disable dtrace support since it’s disabled by default. If you did need to disable it, you’d do that with -Ddtrace=false.

    The custom -L and -I arguments should be covered by use of --prefix.

    Overriding the msgfmt tool to disable internationalisation is not a supported way of building GLib and you’re on your own with that one.

    There is some good documentation on the built-in options in Meson here and here.

    I will also need to build in Windows. Any gotchas there?

    That’s too broad a question to be answered on StackOverflow.