summaryrefslogtreecommitdiffstats
path: root/test cases/frameworks/7 gnome/mkenums/meson.build
blob: 4cf4dcf8a01afa5bc187baad09e09196931827cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Generate both header and source via template together.

myenums = gnome.mkenums('abc1',
  sources : 'meson-sample.h',
  h_template : 'enums.h.in',
  c_template : 'enums.c.in',
  install_header : true,
  install_dir : get_option('includedir'))

enums_c1 = myenums[0]
enums_h1 = myenums[1]

conf = configuration_data()
conf.set('ENUM_FILE', 'enums.h')
main = configure_file(
  input : 'main.c',
  output : 'main1.c',
  configuration : conf)

enumexe1 = executable('enumprog1', main, enums_c1, enums_h1,
dependencies : gobj)
test('enum test 1', enumexe1)

# Generate both header and source via template individually and overriding.

enums_h2 = gnome.mkenums('abc2',
  sources : 'meson-sample.h',
  h_template : 'enums2.h.in',
  ftail : '/* trailing header file info */',
  install_header : true,
  install_dir : get_option('includedir'))

enums_c2 = gnome.mkenums('abc2',
  sources : 'meson-sample.h',
  depends : [enums_h1, enums_h2],
  c_template : 'enums2.c.in',
  ftail : '/* trailing source file info */')
# explicitly don't set install_dir here, for bug testing
# See https://github.com/mesonbuild/meson/issues/9472

conf = configuration_data()
conf.set('ENUM_FILE', 'enums2.h')
main = configure_file(
  input : 'main.c',
  output : 'main2.c',
  configuration : conf)

enumexe2 = executable('enumprog2', main, enums_c2, enums_h2,
dependencies : gobj)
test('enum test 2', enumexe2)

# Generate both header and source by options only.
# These are specified in a way that should produce the same result as above
# (modulo any filename changes.)

enums_h3 = gnome.mkenums('enums3.h',
  sources : 'meson-sample.h',
  fhead : '''#ifndef MESON_ENUMS_H
#define MESON_ENUMS_H

#include <glib-object.h>

G_BEGIN_DECLS
''',
  fprod : '''
/* enumerations from "@basename@" */
''',
  vhead : '''GType @enum_name@_get_type(void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
''',
  ftail : '''
G_END_DECLS

#endif /* MESON_ENUMS_H */
''',
  install_header : true,
  install_dir : get_option('includedir'))

enums_c3 = gnome.mkenums('enums3.c',
  sources : 'meson-sample.h',
  depends : enums_h3,
  fhead : '''#include "enums3.h"
''',
  fprod : '''

/* enumerations from "@basename@" */
#include "@basename@"
''',
  vhead : '''
GType
@enum_name@_get_type(void) {
    static gsize static_g_define_type_id = 0;

    if(g_once_init_enter(&static_g_define_type_id)) {
        static const G@Type@Value values [] = {
''',
  vprod : '''            { @VALUENAME@, "@VALUENAME@", "@valuenick@" },''',
  vtail : '''            { 0, NULL, NULL }
        };

        GType g_define_type_id =
            g_@type@_register_static(g_intern_static_string("@EnumName@"), values);
        g_once_init_leave(&static_g_define_type_id, g_define_type_id);
    }

    return static_g_define_type_id;
}
''')

conf = configuration_data()
conf.set('ENUM_FILE', 'enums3.h')
main = configure_file(
  input : 'main.c',
  output : 'main3.c',
  configuration : conf)

enumexe3 = executable('enumprog3', main, enums_c3, enums_h3,
dependencies : gobj)
test('enum test 3', enumexe3)

enums4 = gnome.mkenums_simple('enums4', sources : files('meson-sample.h'),
                              function_prefix : '_')
enumexe4 = executable('enumprog4', 'main4.c', enums4, dependencies : gobj)

enums5 = gnome.mkenums_simple('enums5', sources : 'meson-sample.h',
                              install_header : true,
                              decorator : 'MESON_EXPORT',
                              header_prefix : '#include "meson-decls.h"')

conf = configuration_data()
conf.set('ENUM_FILE', 'enums5.h')
main = configure_file(
  input : 'main.c',
  output : 'main5.c',
  configuration : conf)

enumexe5 = executable('enumprog5', main, enums5, dependencies : gobj)

# Generate template then use as input to mkenums

# Simple trick to copy the file without substitutions, can be
# removed when https://github.com/mesonbuild/meson/pull/3383 is fixed
gen_h_template = configure_file(input: 'enums.h.in',
  output: 'enums6.h.in',
  configuration: configuration_data(),
  format: 'cmake')

enums_h6 = gnome.mkenums('enums6',
  sources : 'meson-sample.h',
  h_template : gen_h_template,
  ftail : '/* trailing header file info */',
  install_header : true,
  install_dir : get_option('includedir'))

conf = configuration_data()
conf.set('ENUM_FILE', 'enums6.h')
main = configure_file(
  input : 'main.c',
  output : 'main6.c',
  configuration : conf)

enumexe6 = executable('enumprog6', main, enums_c2, enums_h6,
dependencies : gobj)
test('enum test 4', enumexe6)