La structure de construction

Generation of the source code for a gtkmm-style wrapper API requires use of tools such as gmmproc and generate_wrap_init.pl, which are included in glibmm. In theory you could write your own build files to use these appropriately, but a much better option is to make use of the build infrastructure provided by the mm-common module. To get started, it helps a lot to pick an existing binding module as an example to look at.

For instance, let's pretend that we are wrapping a C library called libsomething. It provides a GObject-based API with types named, for instance, SomeWidget and SomeStuff.

G.I.I. Copie du squelette du projet

Typically our wrapper library would be called libsomethingmm. We can start by copying the skeleton source tree from the mm-common module. Starting with mm-common 1.0.0 this skeleton application is built with the Meson build system.

  $ git clone https://gitlab.gnome.org/GNOME/mm-common.git
  $ cp -a mm-common/skeletonmm libsomethingmm

This provides a directory structure for the source .hg and .ccg files and the hand-written .h and .cc files, with meson.build files that can specify the various files in use, in terms of Meson variables. The directory structure usually looks like this, after we have renamed the directories appropriately:

  • libsomethingmm: The top-level directory.

    • libsomething: Contains the main include file and the pkg-config .pc file.

      • src: Contains .hg and .ccg source files.
      • libsomethingmm: Contains hand-written .h and .cc files.

As well as renaming the directories, we should rename some of the source files. For instance:

$ for f in $(find libsomethingmm -depth -name '*skeleton*'); do \
    d="${f%/*}"; b="${f##*/}"; mv "$f" "$d/${b//skeleton/libsomething}"; \
  done
A number of the skeleton files must still be filled in with project-specific content later.

Notez que les fichiers avec l'extension .in seront utilisés pour générer des fichiers de même nom, mais sans extension, en remplaçant certaines variables par leur vraie valeur pendant la phase de traitement par le script configure.

Generated files are saved in the build tree, which is separated from the source tree when meson and ninja are used.

G.I.II. Modification des fichiers de construction

Now we edit the files to adapt them to our needs. You might prefer to use a multiple-file search-replace utility for this, such as regexxer. Note that nearly all of the files provided with the skeleton source tree contain placeholder text. Thus, the substitutions should be performed globally, and not be limited to the Meson files.

Toutes les mentions de skeleton doivent être remplacées par le nom adéquat de la bibliothèque C que vous habillez, comme « something » ou « libsomething ». De la même manière, toutes les occurrences de SKELETON doivent être remplacées par « SOMETHING » ou « LIBSOMETHING » et celles de Skeleton par « Something ».

De même, remplacez toutes les occurrences de Joe Hacker par le nom du détenteur du copyright — vous, probablement. Faites de même pour l'adresse courriel joe@example.com.

G.I.II.I. meson.build in the top-level directory

  • il est courant pour les modules de liaison de garder trace du numéro de version de la bibliothèque qu'ils habillent. Ainsi, par exemple, si la bibliothèque C est à la version 1.23.4, alors la version initiale du module de liaison sera 1.23.0. Évitez toutefois de démarrer avec un numéro de version mineur pair, car il indique traditionnellement une version stable.
  • In the project() function, change the license and the C++ version, if necessary.
  • You probably need to add more required modules than glibmm and skeleton (libsomething).

G.I.II.II. Other meson.build files

Next we must adapt the other meson.build files:

  • skeleton/meson.build: Perhaps not much to change here more than the global name substitutions.

  • skeleton/skeletonmm/meson.build

    defs_basefiles

    If we have more .defs and docs.xml files, we add them here.

    hg_ccg_basenames

    We must mention all of our .hg and .ccg files here.

    extra_cc_files, extra_h_files

    Any additional hand-written .h and .cc source files go here.

G.I.II.III. Création des fichiers .hg et .ccg

Vous devez maintenant créer vos premiers fichiers .hg et .ccg pour habiller quelques objets dans la librairie C. Il y a une paire de fichiers sources à titre d'exemple : skeleton.ccg et skeleton.hg. Faites des copies de ces fichiers si nécessaire.

Dans le paragraphe Fichiers .hg et .ccg vous pouvez voir la syntaxe utilisée dans ces fichiers.