Struktura sestavení
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.
Například si představme, že obalujeme knihovnu C nazvanou libneco a že poskytuje API na základě GObject s typy nazvanými například NecoWidget a NecoNejakeho.
- G.1.1. Kopírování kostry projektu
- G.1.2. Úprava souborů řídících sestavení
G.1.1. Kopírování kostry projektu
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
Soubory končící na .in budou použity k vygenerování souborů se stejným názvem, ale bez přípony .in. Během konfigurační fáze se v nich nahradí některé proměnné skutečnými hodnotami.
Generated files are saved in the build tree, which is separated from the source tree when meson and ninja are used.
G.1.2. Úprava souborů řídících sestavení
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.
Všechny výskyty skeleton by měly být nahrazeny správným názvem knihovny C, kterou obalujete, např. za „neco“ a „libneco“. Stejně tak všechny výskyty SKELETON by měly být nahrazeny za „NECO“ a „LIBNECO“ a všechny výskyty Skeleton za „Neco“.
Obdobně nahraďte všechny výskyty Joe Hacker za zamýšleného držitele práv, což budete nejspíše vy. To stejné proveďte s e-mailovou adresou joe@example.com.
- G.1.2.1. meson.build in the top-level directory
- G.1.2.2. Other meson.build files
- G.1.2.3. Vytváření souborů .hg a .ccg
G.1.2.1. meson.build in the top-level directory
- Pro vazební moduly je běžné, že sledují číslo verze knihovny, kterou obalují. Takže například, když knihovna C je ve verzi 1.23.4, počáteční verze vazebního modulu by byla 1.23.0. Vyhněte se ale počátku se sudým vedlejším číslem verze, protože obvykle indikuje stabilní vydání.
- 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.1.2.2. 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.1.2.3. Vytváření souborů .hg a .ccg
Měli bychom vytvořit své první soubory .hg a .ccg pro obalení některého z objektů v knihovně C. Jeden pár ukázkových zdrojových souborů již existuje: skeleton.ccg a skeleton.hg. Podle potřeby si vytvořte kopie těchto souborů.
V kapitole soubory .hg a .ccg se můžete dozvědět více o syntaxi používané v těchto souborech.