How to check for python GObject Introspection modules in Autotools

When we are using compiled languages – we are usually depending on pkg-config files. For example, “PKG_CHECK_MODULES(GLIB, glib2)”, but what if we are using Python?

Autoconf Archive has AX_PYTHON_MODULE macros. We can use it very easy.

How about Python + GObject Introspection? Let’s take GTK+ as an example. I wrote special m4 file (see below), you can place it in “m4” directory. Then you just need add “AX_PYTHON_GI(Gtk, 3.0)” into “” and autoconf will check if GI works and Gtk-3.0.typelib is usable.

P.S. note that I’m not m4 expert, but it works for me.

#   AX_PYTHON_GI(gi_module, version[, python])
#   Checks for Python GObject Introspection and GI module with the given
#   version.
#    Copyright (C) 2015 Igor Gnatenko <>
#    Copying and distribution of this file, with or without modification, are
#    permitted in any medium without royalty provided the copyright notice
#    and this notice are preserved. This file is offered as-is, without any
#    warranty.

    AC_MSG_CHECKING([for bindings for GObject Introspection])
    AX_PYTHON_MODULE([gi], [required], [$3])
    AC_MSG_CHECKING([for version $2 of $1 GObject Introspection module])
    $PYTHON -c "import gi; gi.require_version('$1', '$2')" 2> /dev/null
    AS_IF([test $? -eq 0], [], [
        AC_MSG_ERROR([You need version $2 of the $1 GObject Introspection module.])

Meson and 3rd party dependencies. Only one correct way


As you know, many projects bundling libs (including source code of 3rd party libs). For example, SuperTuxKart bundles angelscript, bullet, enet, glew, irrlicht, jpeglib, libpng, wiiuse, zlib. All of this libs package in my favorite distro Fedora.

As Fedora maintainer I need to check what changed in bundled libs code, if nothing – write patch to use system lib, if few changes – write patch to use system lib and report bug against this lib in Fedora, if big changes – try to understand what changed, why it’s not in upstream, create FPC ticket and they will accept bundle – use bundle. If all devs will allow to use system libs – this will be great (0 A.D. and Xonotic does this). Yes, this is also cross-platform games.

In CMake I need to write custom FindSomething.cmake and fix some things in CMakeLists.txt. Providing switch between system and bundled sources is not easy. For example, in stuntrally to unbundle ~ 50% of libs I should Showing 49 changed files with 238 additions and 108 deletions. I hate it.

In Autotools I never tried to do this, I think I will kill myself if will try.

With Meson it’s really simple. Meson is designed to be simple for developers, maintainers and fast. Hi to m4 and that black magic.

I don’t want to write more here, please read manual at official meson wiki. Much better to see real example.


If we don’t have library in system (I renamed libenet to libent to not delete enet from my system):
Meson wrap bundled
If we have library in system:
Meson wrap system


Please do not hesitate to contact us via IRC (#mesonbuild on freenode) or send patches/issues via GitHub (

P.S. When I wrote this example I found some missing functionality and minor bugs and sent patches[1][2]. If you want to try this example – you need apply those patches.