| 1 |
project( |
| 2 |
'cppgir_example', |
| 3 |
['c', 'cpp'], |
| 4 |
version: '2.0.0', |
| 5 |
meson_version: '>= 0.61', |
| 6 |
default_options: ['warning_level=2', 'cpp_std=c++17'], |
| 7 |
) |
| 8 |
|
| 9 |
# following example uses the Gio-2.0 gir |
| 10 |
# will generate code for that |
| 11 |
|
| 12 |
# locate cppgir, either in system or subproject |
| 13 |
# if subproject, arrange to embed ignore data |
| 14 |
# (since it will run un-installed, so data can not be found in installed location) |
| 15 |
gi = dependency( |
| 16 |
'cppgir', |
| 17 |
required: true, |
| 18 |
version: '>=2.0.0', |
| 19 |
fallback: 'cppgir', |
| 20 |
default_options: ['build_embed_ignore=true'], |
| 21 |
) |
| 22 |
cppgir = find_program('cppgir', required: true) |
| 23 |
|
| 24 |
generated_src = custom_target( |
| 25 |
'src', |
| 26 |
# actually it generates all this (and more) |
| 27 |
# output : ['gio.cpp', 'gio.hpp', 'glib.cpp', 'glib.hpp', 'gobject.cpp', 'gobject.hpp'], |
| 28 |
# but the example below will inline all of the above, so no source files are used |
| 29 |
# (though it is recommended for a real case, rather than a full inline) |
| 30 |
output: ['gio.hpp'], |
| 31 |
console: true, |
| 32 |
# output-top creates extra files in top-level (as oppposed to subdir) |
| 33 |
# since "output" paths above "must not contain a path segment" (says meson, sigh) |
| 34 |
command: [cppgir, '--output-top', '--output', '@OUTDIR@', 'Gio-2.0'], |
| 35 |
) |
| 36 |
|
| 37 |
# need the code and libs and especially GIRs |
| 38 |
gobject = dependency('gobject-2.0', required: true) |
| 39 |
gio = dependency('gio-2.0', required: true) |
| 40 |
# the Gio GIR data also covers this, so generated code references it |
| 41 |
gio_unix = dependency('gio-unix-2.0', required: true) |
| 42 |
|
| 43 |
deps = [gi, gobject, gio, gio_unix] |
| 44 |
|
| 45 |
# (actually) needs no generated code, but it needs basic libs |
| 46 |
ex_gobject = executable( |
| 47 |
'ext-gobject', |
| 48 |
['src/ext-gobject.cpp'], |
| 49 |
dependencies: deps, |
| 50 |
) |
| 51 |
|
| 52 |
# (really) needs generated code |
| 53 |
ex_gio = executable( |
| 54 |
'ext-gio', |
| 55 |
['src/ext-gio.cpp', generated_src], |
| 56 |
dependencies: deps, |
| 57 |
) |