summaryrefslogtreecommitdiff
path: root/meson.build
blob: 422946a647352dd3ec4d3bf6855e228a14a552a8 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
project(
    'libosinfo', 'c',
    version: '1.11.0',
    license: 'LGPLv2+',
    meson_version: '>= 0.49.0',
    default_options: [
        'buildtype=debugoptimized',
        'c_std=gnu99',
        'warning_level=1',
    ],
)

libosinfo_prefix = get_option('prefix')

# those directories have to be know by the project
libosinfo_datadir = join_paths(libosinfo_prefix, get_option('datadir'))
libosinfo_localedir = join_paths(libosinfo_prefix, get_option('localedir'))
libosinfo_pkgdatadir = join_paths(libosinfo_datadir, meson.project_name())
libosinfo_sysconfdir = join_paths(libosinfo_prefix, get_option('sysconfdir'))

# those directories will have files installed in
libsoinfo_bindir = join_paths(libosinfo_prefix, get_option('bindir'))
libsoinfo_docdir = join_paths(libosinfo_datadir, 'doc', meson.project_name())
libosinfo_includedir = join_paths(libosinfo_prefix, get_option('includedir'))
libosinfo_libdir = join_paths(libosinfo_prefix, get_option('libdir'))
libosinfo_licensedir = join_paths(libosinfo_datadir, 'license', meson.project_name())
libosinfo_mandir = join_paths(libosinfo_prefix, get_option('mandir'))
libosinfo_pkgconfdir = join_paths(libosinfo_libdir, 'pkgconfig')

# gobject introspection
gir = find_program('g-ir-scanner', required: get_option('enable-introspection'))
enable_introspection = gir.found() and not meson.is_cross_build()

# vala
vapi_opt = get_option('enable-vala')
enable_vapi = add_languages('vala', required: vapi_opt)
if enable_vapi and not enable_introspection
    enable_vapi = false
    if vapi_opt.enabled()
        error('vala support was requested, but introspection support is mandatory.')
    endif
endif

libosinfo_girdir = join_paths(libosinfo_datadir, 'gir-1.0')
libosinfo_typelibdir = join_paths(libosinfo_libdir, 'girepository-1.0')
libosinfo_pkgconfdir = join_paths(libosinfo_libdir, 'pkgconfig')

# spec files
libosinfo_spec_data = configuration_data()
libosinfo_spec_data.set('VERSION', meson.project_version())

configure_file(
    input: 'libosinfo.spec.in',
    output: 'libosinfo.spec',
    configuration: libosinfo_spec_data,
)

# ninja dist helper
meson.add_dist_script('build-aux/dist.sh', meson.source_root(), meson.build_root())

# dependencies
#  glib stuff
glib_version = '2.44'
glib_version_required = 'GLIB_VERSION_2_44'
glib_version_info = '>= @0@'.format(glib_version)
glib_dep = dependency('glib-2.0', version: glib_version_info)
gio_dep = dependency('gio-2.0', version: glib_version_info)
gobject_dep = dependency('gobject-2.0', version: glib_version_info)

#  everything else

libsoup_abi = get_option('libsoup-abi')
libsoup_dep = disabler()
if ['auto', '3.0'].contains(libsoup_abi)
  libsoup_dep = dependency('libsoup-3.0', required: libsoup_abi.contains('3.0'))
endif
if not libsoup_dep.found()
#    fallback to libsoup2
  libsoup_dep = dependency('libsoup-2.4', required: libsoup_abi.contains('2.4'))
endif
libxml_dep = dependency('libxml-2.0', version: '>= 2.6.0')
libxslt_dep = dependency('libxslt', version: '>= 1.0.0')

#  common dependencies
libosinfo_dependencies = [
    gobject_dep,
    gio_dep,
    glib_dep,
    libsoup_dep,
    libxml_dep,
    libxslt_dep,
]

libosinfo_include = [include_directories('.')]

# arguments
libosinfo_cflags = []

#  glib stuff
libosinfo_cflags += [
    '-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_44',
    '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_44'
]

#  directories used
libosinfo_cflags += [
    '-DPKG_DATA_DIR="@0@"'.format(libosinfo_pkgdatadir),
    '-DDATA_DIR="@0@"'.format(libosinfo_datadir),
    '-DSYS_CONF_DIR="@0@"'.format(libosinfo_sysconfdir),
    '-DLOCALEDIR="@0@"'.format(libosinfo_localedir),
]

#  gettext package name
libosinfo_cflags += ['-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name())]

#  cflags to check whether the compiler supports them or not
libosinfo_check_cflags = [
    '-W',
    '-Waddress',
    '-Waggressive-loop-optimizations',
    '-Wall',
    '-Warray-bounds',
    '-Wattributes',
    '-Wbuiltin-macro-redefined',
    '-Wchar-subscripts',
    '-Wclobbered',
    '-Wcomment',
    '-Wcomments',
    '-Wcoverage-mismatch',
    '-Wcpp',
    '-Wdate-time',
    '-Wdeclaration-after-statement',
    '-Wdeprecated-declarations',
    '-Wdisabled-optimization',
    '-Wdiv-by-zero',
    '-Wempty-body',
    '-Wendif-labels',
    '-Wenum-compare',
    '-Wextra',
    '-Wformat-contains-nul',
    '-Wformat-extra-args',
    '-Wformat-security',
    '-Wformat-y2k',
    '-Wformat-zero-length',
    '-Wfree-nonheap-object',
    '-Wignored-qualifiers',
    '-Wimplicit',
    '-Wimplicit-function-declaration',
    '-Wimplicit-int',
    '-Winit-self',
    '-Wno-inline',
    '-Wint-to-pointer-cast',
    '-Winvalid-memory-model',
    '-Winvalid-pch',
    '-Wjump-misses-init',
    '-Wlogical-op',
    '-Wmain',
    '-Wmaybe-uninitialized',
    '-Wmissing-braces',
    '-Wmissing-declarations',
    '-Wmissing-field-initializers',
    '-Wmissing-include-dirs',
    '-Wmissing-parameter-type',
    '-Wmissing-prototypes',
    '-Wmultichar',
    '-Wnarrowing',
    '-Wnested-externs',
    '-Wnonnull',
    '-Wold-style-declaration',
    '-Wold-style-definition',
    '-Wopenmp-simd',
    '-Woverflow',
    '-Woverlength-strings',
    '-Woverride-init',
    '-Wpacked',
    '-Wpacked-bitfield-compat',
    '-Wparentheses',
    '-Wpointer-arith',
    '-Wpointer-sign',
    '-Wpointer-to-int-cast',
    '-Wpragmas',
    '-Wreturn-local-addr',
    '-Wreturn-type',
    '-Wsequence-point',
    '-Wshadow',
    '-Wsizeof-pointer-memaccess',
    '-Wstack-protector',
    '-Wstrict-aliasing',
    '-Wstrict-overflow',
    '-Wstrict-prototypes',
    '-Wsuggest-attribute=const',
    '-Wsuggest-attribute=format',
    '-Wsuggest-attribute=noreturn',
    '-Wsuggest-attribute=pure',
    '-Wswitch',
    '-Wswitch-default',
    '-Wsync-nand',
    '-Wtrampolines',
    '-Wtrigraphs',
    '-Wtype-limits',
    '-Wuninitialized',
    '-Wunknown-pragmas',
    '-Wunused',
    '-Wunused-but-set-parameter',
    '-Wunused-but-set-variable',
    '-Wunused-function',
    '-Wunused-label',
    '-Wunused-local-typedefs',
    '-Wunused-parameter',
    '-Wunused-result',
    '-Wunused-value',
    '-Wunused-variable',
    '-Wvarargs',
    '-Wvariadic-macros',
    '-Wvector-operation-performance',
    '-Wvla',
    '-Wvolatile-register-var',
    '-Wwrite-strings',
    '-Wnormalized=nfc',
    '-Wno-sign-compare',
    '-Wno-sign-conversion',
    '-Wno-conversion',
    '-Wno-unused-parameter',
    '-Wjump-misses-init',
    '-Wframe-larger-than=4096',
    '-Wno-overlength-strings',
    '--param=ssp-buffer-size=4',
    '-fexceptions',
    '-fasynchronous-unwind-tables',
    '-fdiagnostics-show-option',
    '-funit-at-a-time',
    '-fipa-pure-const',
    '-Wno-suggest-attribute=pure',
    '-Wno-suggest-attribute=const',
    '-Wno-string-plus-int',
]

if host_machine.system() == 'linux'
    libosinfo_check_cflags += ['-fstack-protector-all']
endif

compiler = meson.get_compiler('c')

# Builds os clang  will fail without those.
if compiler.get_id() == 'clang'
    libosinfo_check_cflags += [
        '-Wno-typedef-redefinition',
        '-Wno-missing-field-initializers',
    ]
endif

if run_command('[', '-d', '.git', ']').returncode() == 0
    libosinfo_check_cflags += ['-Werror']
endif

foreach cflag: libosinfo_check_cflags
  if compiler.has_argument(cflag)
    libosinfo_cflags += [cflag]
  endif
endforeach

pci_ids_path = get_option('with-pci-ids-path')
if pci_ids_path == ''
    pci_id_files = [
        '/usr/share/pci.ids',
        '/usr/share/misc/pci.ids',
        '/usr/share/hwdata/pci.ids',
        '/usr/local/share/pciids/pci.ids',
    ]

    install_file = meson.is_cross_build()

    foreach file: pci_id_files
        if run_command('[', '-f', file, ']').returncode() == 0
            pci_ids_path = file
            break
        endif
    endforeach

    if pci_ids_path == ''
        download = find_program('build-aux/download_pci_ids')
        if download.found()
            r = run_command(download)
            if r.returncode() == 0
                file = join_paths(meson.build_root(), 'pci.ids')
                install_file = true
            endif
        endif
    endif

    if install_file
        install_data(file, install_dir: libosinfo_pkgdatadir)
        pci_ids_path = join_paths(libosinfo_pkgdatadir, 'pci.ids')
    endif
endif
if pci_ids_path != ''
    libosinfo_cflags += ['-DPCI_IDS="@0@"'.format(pci_ids_path)]
    message('Location of pci.ids: "@0@"'.format(pci_ids_path))
endif

usb_ids_path = get_option('with-usb-ids-path')
if usb_ids_path == ''
    usb_id_files = [
        '/usr/share/usb.ids',
        '/usr/share/misc/usb.ids',
        '/usr/share/hwdata/usb.ids',
        '/usr/local/share/usbids/usb.ids',
    ]

    install_file = meson.is_cross_build()

    foreach file: usb_id_files
        if run_command('[', '-f', file, ']').returncode() == 0
            usb_ids_path = file
            break
        endif
    endforeach

    if usb_ids_path == ''
        download = find_program('build-aux/download_usb_ids')
        if download.found()
            r = run_command(download)
            if r.returncode() == 0
                file = join_paths(meson.build_root(), 'usb.ids')
                install_file = true
            endif
        endif
    endif

    if install_file
        install_data(file, install_dir: libosinfo_pkgdatadir)
        usb_ids_path = join_paths(libosinfo_pkgdatadir, 'usb.ids')
    endif
endif
if usb_ids_path != ''
    libosinfo_cflags += ['-DUSB_IDS="@0@"'.format(usb_ids_path)]
    message('Location of usb.ids: "@0@"'.format(usb_ids_path))
endif

libosinfo_version = meson.project_version()
libosinfo_major_version = libosinfo_version.split('.')[0].to_int()
libosinfo_minor_version = libosinfo_version.split('.')[1].to_int()
libosinfo_micro_version = libosinfo_version.split('.')[2].to_int()

libosinfo_interface_age = 0
libosinfo_binary_age = 1000 * libosinfo_major_version + libosinfo_minor_version

# Maintain version scheme with libtool
libosinfo_soversion = 0
libosinfo_version = '@0@.@1@.@2@'.format(
    libosinfo_soversion,
    (libosinfo_binary_age - libosinfo_interface_age),
    libosinfo_interface_age)
osx_current = libosinfo_binary_age - libosinfo_interface_age + 1
libosinfo_darwin_versions = [
    osx_current,
    '@0@.@1@.0'.format(osx_current, libosinfo_interface_age)
]

subdir('osinfo')
subdir('tools')
subdir('po')
if get_option('enable-gtk-doc') and not meson.is_cross_build()
    if find_program('gtkdoc-scan', required: true).found()
        subdir('docs/reference')
    else
        message('Not building documentation as gtk-doc was not found')
    endif
endif
if get_option('enable-tests')
    subdir('tests')
endif