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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
|
project(
'libvirt-glib', 'c',
version: '5.0.0',
license: 'LGPLv2+',
meson_version: '>= 0.56.0',
default_options: [
'buildtype=debugoptimized',
'c_std=gnu99',
'warning_level=2',
],
)
python3 = find_program('python3', required: true)
# Python3 < 3.7 treats the C locale as 7-bit only. We must force env vars so
# it treats it as UTF-8 regardless of the user's locale.
runutf8 = [ 'LC_ALL=', 'LANG=C', 'LC_CTYPE=en_US.UTF-8' ]
cc = meson.get_compiler('c')
git = run_command('test', '-d', '.git', check: false).returncode() == 0
version_info = meson.project_version().split('.')
version_major = version_info[0].to_int()
version_minor = version_info[1].to_int()
version_micro = version_info[2].to_int()
libvirt_glib_interface_age = 0
libvirt_glib_binary_age = 1000 * version_major + version_minor
# Maintain version scheme with libtool
libvirt_glib_soversion = 0
libvirt_glib_version = '@0@.@1@.@2@'.format(
libvirt_glib_soversion,
(libvirt_glib_binary_age - libvirt_glib_interface_age),
libvirt_glib_interface_age)
osx_current = libvirt_glib_binary_age - libvirt_glib_interface_age + 1
libvirt_glib_darwin_versions = [
osx_current,
'@0@.@1@.0'.format(osx_current, libvirt_glib_interface_age)
]
# Keep these two definitions in agreement.
glib_version = '2.48.0'
glib_min_version_symbol='GLIB_VERSION_2_48'
glib_dep = dependency('glib-2.0', version: '>=' + glib_version)
gobject_dep = dependency('gobject-2.0', version: '>=' + glib_version)
gio_dep = dependency('gio-2.0', version: '>=' + glib_version)
libvirt_version = '2.3.0'
libvirt_dep = dependency('libvirt', version: '>=' + libvirt_version)
libxml_min_version='>=2.9.1'
libxml_dep = dependency('libxml-2.0', version: libxml_min_version)
prefix = get_option('prefix')
localedir = join_paths(prefix, get_option('localedir'))
datadir = join_paths(prefix, get_option('datadir'))
libdir = join_paths(prefix, get_option('libdir'))
includedir = join_paths(prefix, get_option('includedir'))
subdir('build-aux')
# gobject introspection
gir = find_program('g-ir-scanner', required: get_option('introspection'))
enable_introspection = gir.found() and not meson.is_cross_build()
# vala
vapi_opt = get_option('vapi')
enable_vapi = add_languages('vala', native: false, 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
# gtk-doc
if not get_option('docs').disabled()
gtk_doc = find_program('gtkdoc-scan', required: get_option('docs'))
enable_doc = gtk_doc.found() and not meson.is_cross_build()
else
enable_doc = false
endif
# Add RPATH information when building for a non-standard prefix, or
# when explicitly requested to do so
if prefix == '/usr' and not get_option('rpath').enabled()
rpathdir = ''
else
rpathdir = libdir
endif
common_link_args = []
if meson.get_compiler('c').has_link_argument('-Wl,--no-undefined')
common_link_args += ['-Wl,--no-undefined']
endif
build_tests = not get_option('tests').disabled()
girdir = join_paths(datadir, 'gir-1.0')
typelibdir = join_paths(libdir, 'girepository-1.0')
pkgconfdir = join_paths(libdir, 'pkgconfig')
conf_data = configuration_data()
conf_data.set('VERSION', meson.project_version())
conf_data.set('prefix', prefix)
conf_data.set('includedir', includedir)
conf_data.set('exec_prefix', prefix)
conf_data.set('libdir', libdir)
configure_file(
input: 'meson-config.h.in',
output: 'config.h',
configuration: conf_data
)
if git
configure_file(
input: 'libvirt-glib.spec.in',
output: 'libvirt-glib.spec',
configuration: conf_data
)
endif
configure_file(
input: 'libvirt-glib-1.0.pc.in',
output: 'libvirt-glib-1.0.pc',
configuration: conf_data,
install: true,
install_dir: pkgconfdir
)
configure_file(
input: 'libvirt-gconfig-1.0.pc.in',
output: 'libvirt-gconfig-1.0.pc',
configuration: conf_data,
install: true,
install_dir: pkgconfdir
)
configure_file(
input: 'libvirt-gobject-1.0.pc.in',
output: 'libvirt-gobject-1.0.pc',
configuration: conf_data,
install: true,
install_dir: pkgconfdir
)
cc_flags = []
git_werror = get_option('git_werror')
if git_werror.enabled() or git_werror.auto() and git
cc_flags += [ '-Werror' ]
endif
# gcc --help=warnings outputs
ptrdiff_max = cc.sizeof('ptrdiff_t', prefix: '#include <stddef.h>')
size_max = cc.sizeof('size_t', prefix: '#include <stdint.h>')
# Compute max safe object size by checking ptrdiff_t and size_t sizes.
# Ideally we would get PTRDIFF_MAX and SIZE_MAX values but it would
# give us (2147483647L) and we would have to remove the () and the suffix
# in order to convert it to numbers to be able to pick the smaller one.
alloc_max = run_command(
python3.full_path(), '-c',
'print(min(2**(@0@ * 8 - 1) - 1, 2**(@1@ * 8) - 1))'.format(ptrdiff_max, size_max),
check: true,
)
cc_flags += [
'-fasynchronous-unwind-tables',
'-fexceptions',
'-fipa-pure-const',
'-fno-common',
'-Wabsolute-value',
'-Waddress',
'-Waddress-of-packed-member',
'-Waggressive-loop-optimizations',
'-Walloc-size-larger-than=@0@'.format(alloc_max.stdout().strip()),
'-Warray-bounds=2',
'-Wattribute-alias=2',
'-Wattribute-warning',
'-Wattributes',
'-Wbool-compare',
'-Wbool-operation',
'-Wbuiltin-declaration-mismatch',
'-Wbuiltin-macro-redefined',
'-Wcannot-profile',
# We do "bad" function casts all the time for event callbacks
'-Wno-cast-function-type',
'-Wchar-subscripts',
'-Wclobbered',
'-Wcomment',
'-Wcomments',
'-Wcoverage-mismatch',
'-Wcpp',
'-Wdangling-else',
'-Wdate-time',
'-Wdeprecated-declarations',
'-Wdesignated-init',
'-Wdiscarded-array-qualifiers',
'-Wdiscarded-qualifiers',
'-Wdiv-by-zero',
'-Wduplicated-cond',
'-Wduplicate-decl-specifier',
'-Wempty-body',
'-Wendif-labels',
'-Wexpansion-to-defined',
'-Wformat-contains-nul',
'-Wformat-extra-args',
'-Wno-format-nonliteral',
'-Wformat-overflow=2',
'-Wformat-security',
# -Wformat enables this by default, and we should keep it,
# but need to rewrite various areas of code first
'-Wno-format-truncation',
'-Wformat-y2k',
'-Wformat-zero-length',
'-Wframe-address',
'-Wframe-larger-than=256',
'-Wfree-nonheap-object',
'-Whsa',
'-Wif-not-aligned',
'-Wignored-attributes',
'-Wignored-qualifiers',
'-Wimplicit',
'-Wimplicit-fallthrough=5',
'-Wimplicit-function-declaration',
'-Wimplicit-int',
'-Wincompatible-pointer-types',
'-Winit-self',
'-Winline',
'-Wint-conversion',
'-Wint-in-bool-context',
'-Wint-to-pointer-cast',
'-Winvalid-memory-model',
'-Winvalid-pch',
'-Wjump-misses-init',
'-Wlogical-not-parentheses',
'-Wlogical-op',
'-Wmain',
'-Wmaybe-uninitialized',
'-Wmemset-elt-size',
'-Wmemset-transposed-args',
'-Wmisleading-indentation',
'-Wmissing-attributes',
'-Wmissing-braces',
'-Wmissing-declarations',
'-Wmissing-field-initializers',
'-Wmissing-include-dirs',
'-Wmissing-parameter-type',
'-Wmissing-profile',
'-Wmissing-prototypes',
'-Wmultichar',
'-Wmultistatement-macros',
'-Wnarrowing',
'-Wnested-externs',
'-Wnonnull',
'-Wnonnull-compare',
'-Wnormalized=nfc',
'-Wnull-dereference',
'-Wodr',
'-Wold-style-declaration',
'-Wold-style-definition',
'-Wopenmp-simd',
'-Woverflow',
'-Woverride-init',
'-Wpacked-bitfield-compat',
'-Wpacked-not-aligned',
'-Wparentheses',
'-Wpointer-arith',
'-Wpointer-compare',
'-Wpointer-sign',
'-Wpointer-to-int-cast',
'-Wpragmas',
'-Wpsabi',
'-Wrestrict',
'-Wreturn-local-addr',
'-Wreturn-type',
'-Wscalar-storage-order',
'-Wsequence-point',
'-Wshadow',
'-Wshift-count-negative',
'-Wshift-count-overflow',
'-Wshift-negative-value',
'-Wshift-overflow=2',
# So we have -W enabled, and then have to explicitly turn off...
'-Wno-sign-compare',
'-Wsizeof-array-argument',
'-Wsizeof-pointer-div',
'-Wsizeof-pointer-memaccess',
'-Wstrict-aliasing',
'-Wstrict-prototypes',
'-Wstringop-overflow=2',
'-Wstringop-truncation',
'-Wsuggest-attribute=cold',
'-Wno-suggest-attribute=const',
'-Wsuggest-attribute=format',
'-Wsuggest-attribute=noreturn',
'-Wno-suggest-attribute=pure',
'-Wsuggest-final-methods',
'-Wsuggest-final-types',
'-Wswitch',
'-Wswitch-bool',
'-Wswitch-enum',
'-Wswitch-unreachable',
'-Wsync-nand',
'-Wtautological-compare',
'-Wtrampolines',
'-Wtrigraphs',
'-Wtype-limits',
# Clang incorrectly complains about dup typedefs win gnu99 mode
# so use this Clang-specific arg to keep it quiet
'-Wno-typedef-redefinition',
'-Wuninitialized',
'-Wunknown-pragmas',
'-Wunused',
'-Wunused-but-set-parameter',
'-Wunused-but-set-variable',
'-Wunused-const-variable=2',
'-Wunused-function',
'-Wunused-label',
'-Wunused-local-typedefs',
'-Wunused-result',
'-Wunused-value',
'-Wunused-variable',
'-Wvarargs',
'-Wvariadic-macros',
'-Wvector-operation-performance',
'-Wvla',
'-Wvolatile-register-var',
'-Wwrite-strings',
]
if get_option('warning_level') == '2'
# on aarch64 error: -fstack-protector not supported for this target
if host_machine.cpu_family() != 'aarch64'
if host_machine.system() in [ 'linux', 'freebsd', 'windows' ]
# we prefer -fstack-protector-strong but fallback to -fstack-protector-all
fstack_cflags = cc.first_supported_argument([
'-fstack-protector-strong',
'-fstack-protector-all',
])
cc_flags += fstack_cflags
# When building with mingw using -fstack-protector requires libssp library
# which is included by using -fstack-protector with linker.
if fstack_cflags.length() == 1 and host_machine.system() == 'windows'
add_project_link_arguments(fstack_cflags, language: 'c')
endif
endif
endif
# Clang complains about unused static inline functions which are common
# with G_DEFINE_AUTOPTR_CLEANUP_FUNC.
w_unused_function_args = ['-Wunused-function', '-Werror']
w_unused_function_code = '''
static inline void foo(void) {}
int main(void) { return 0; }
'''
# -Wunused-function is implied by -Wall, we must turn it off explicitly.
if not cc.compiles(w_unused_function_code, args: w_unused_function_args)
cc_flags += ['-Wno-unused-function']
endif
warning_cflags = cc.get_supported_arguments(cc_flags)
else
warning_cflags = []
endif
if host_machine.system() == 'windows'
# no machinery for generating .def files for now
version_script_flags = ''
elif host_machine.system() == 'darwin'
# macOS libraries don't support symbol versioning
version_script_flags = ''
else
version_script_flags = '-Wl,--version-script='
endif
if git
authors = run_command(python3.full_path(), gen_authors_prog.full_path(),
env: runutf8, check: true)
authors_file = 'AUTHORS.in'
authors_conf = configuration_data()
authors_conf.set('authorslist', authors.stdout())
configure_file(
input: authors_file,
output: '@BASENAME@',
configuration: authors_conf,
)
meson.add_dist_script(python3.full_path(), dist_prog.full_path(),
meson.project_build_root(), 'AUTHORS')
meson.add_dist_script(python3.full_path(), dist_prog.full_path(),
meson.project_build_root(), 'libvirt-glib.spec')
endif
common_cflags = [
'-DLOCALEDIR="@0@"'.format(localedir),
'-DDATADIR="@0@"'.format(datadir),
'-DLIBVIRT_GLIB_BUILD',
'-DGLIB_VERSION_MIN_REQUIRED=@0@'.format(glib_min_version_symbol),
'-DGLIB_VERSION_MAX_ALLOWED=@0@'.format(glib_min_version_symbol),
]
gnome = import('gnome')
i18n = import('i18n')
top_include_dir = [include_directories('.')]
subdir('libvirt-glib')
subdir('libvirt-gconfig')
subdir('libvirt-gobject')
subdir('po')
subdir('examples')
subdir('docs')
if build_tests
subdir('tests')
endif
|