meson.build 4.56 KB
Newer Older
Guido Gunther's avatar
Guido Gunther committed
1
project('libhandy', 'c',
Guido Gunther's avatar
Guido Gunther committed
2
          version: '0.0.10',
Guido Gunther's avatar
Guido Gunther committed
3
          license: 'LGPL-2.1+',
4
    meson_version: '>= 0.47.0',
Guido Gunther's avatar
Guido Gunther committed
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
  default_options: [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11' ],
)

version_arr = meson.project_version().split('.')
handy_version_major = version_arr[0].to_int()
handy_version_minor = version_arr[1].to_int()
handy_version_micro = version_arr[2].to_int()

apiversion = '0.0'
soversion = 0

if handy_version_minor.is_odd()
  handy_interface_age = 0
else
  handy_interface_age = handy_version_micro
endif

# maintaining compatibility with libtool versioning
# current = minor * 100 + micro - interface
# revision = interface
current = handy_version_minor * 100 + handy_version_micro - handy_interface_age
revision = handy_interface_age
libversion = '@0@.@1@.@2@'.format(soversion, current, revision)

config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', 'libhandy')
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))

configure_file(
  output: 'config.h',
  configuration: config_h,
)

add_project_arguments([
  '-DHAVE_CONFIG_H',
  '-DHANDY_COMPILATION',
  '-I' + meson.build_root(),
], language: 'c')

root_inc = include_directories('.')
src_inc = include_directories('src')

cc = meson.get_compiler('c')

global_c_args = []
test_c_args = [
  '-Wcast-align',
52
  '-Wdate-time',
Guido Gunther's avatar
Guido Gunther committed
53 54
  '-Wdeclaration-after-statement',
  ['-Werror=format-security', '-Werror=format=2'],
55 56 57 58 59 60 61 62
  '-Wendif-labels',
  '-Werror=incompatible-pointer-types',
  '-Werror=missing-declarations',
  '-Werror=overflow',
  '-Werror=return-type',
  '-Werror=shift-count-overflow',
  '-Werror=shift-overflow=2',
  '-Werror=implicit-fallthrough=3',
Guido Gunther's avatar
Guido Gunther committed
63 64
  '-Wformat-nonliteral',
  '-Wformat-security',
65 66 67
  '-Winit-self',
  '-Wmaybe-uninitialized',
  '-Wmissing-field-initializers',
Guido Gunther's avatar
Guido Gunther committed
68
  '-Wmissing-include-dirs',
69
  '-Wmissing-noreturn',
Guido Gunther's avatar
Guido Gunther committed
70 71 72 73 74
  '-Wnested-externs',
  '-Wno-missing-field-initializers',
  '-Wno-sign-compare',
  '-Wno-strict-aliasing',
  '-Wno-unused-parameter',
75
  '-Wold-style-definition',
Guido Gunther's avatar
Guido Gunther committed
76 77 78
  '-Wpointer-arith',
  '-Wredundant-decls',
  '-Wshadow',
79
  '-Wstrict-prototypes',
Guido Gunther's avatar
Guido Gunther committed
80 81
  '-Wswitch-default',
  '-Wswitch-enum',
82
  '-Wtype-limits',
Guido Gunther's avatar
Guido Gunther committed
83
  '-Wundef',
84
  '-Wunused-function',
Guido Gunther's avatar
Guido Gunther committed
85
]
86 87 88

target_system = target_machine.system()

Guido Gunther's avatar
Guido Gunther committed
89
if get_option('buildtype') != 'plain'
90 91 92 93 94
  if target_system == 'windows'
    test_c_args += '-fstack-protector'
  else
    test_c_args += '-fstack-protector-strong'
  endif
Guido Gunther's avatar
Guido Gunther committed
95
endif
96
if get_option('profiling')
Guido Gunther's avatar
Guido Gunther committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  test_c_args += '-pg'
endif

foreach arg: test_c_args
  if cc.has_multi_arguments(arg)
    global_c_args += arg
  endif
endforeach
add_project_arguments(
  global_c_args,
  language: 'c'
)

# Setup various paths that subdirectory meson.build files need
package_subdir = get_option('package_subdir') # When used as subproject
libdir = join_paths(get_option('libdir'), package_subdir)
girdir = join_paths(get_option('datadir'), package_subdir, 'gir-1.0')
typelibdir = join_paths(get_option('libdir'), package_subdir, 'girepository-1.0')
if package_subdir != ''
  vapidir = join_paths(get_option('datadir'), package_subdir, 'vapi')
else
  vapidir = join_paths(get_option('datadir'), 'vala', 'vapi')
endif

121 122
static = get_option('static')

123 124
installable = not (static and meson.is_subproject())

125
glade_catalog_feature = get_option('glade_catalog')
126 127 128
if static and glade_catalog_feature.enabled()
  error('The Glade Catalog isn’t available for static libhandy.')
endif
129
gladeui_dep = dependency('gladeui-2.0', required : glade_catalog_feature)
130
glade_catalog = gladeui_dep.found() and not static
131 132

introspection_feature = get_option('introspection')
133 134 135 136
if static and introspection_feature.enabled()
  error('Introspection isn’t available for static libhandy.')
endif
introspection = introspection_feature.enabled() or (introspection_feature.auto() and not static)
137

Guido Gunther's avatar
Guido Gunther committed
138 139 140
gnome = import('gnome')

subdir('src')
Guido Gunther's avatar
Guido Gunther committed
141
subdir('po')
Guido Gunther's avatar
Guido Gunther committed
142 143 144
subdir('examples')
subdir('tests')
subdir('doc')
145
subdir('glade')
Guido Gunther's avatar
Guido Gunther committed
146 147 148

run_data = configuration_data()
run_data.set('ABS_BUILDDIR', meson.current_build_dir())
149
run_data.set('ABS_SRCDIR', meson.current_source_dir())
Guido Gunther's avatar
Guido Gunther committed
150 151 152 153 154 155 156 157 158 159
configure_file(
  input: 'run.in',
  output: 'run',
  configuration: run_data)

summary = [
  '',
  '------',
  'Handy @0@ (@1@)'.format(current, apiversion),
  '',
160 161 162
  '             Tests: @0@'.format(get_option('tests')),
  '          Examples: @0@'.format(get_option('examples')),
  '     Documentation: @0@'.format(get_option('gtk_doc')),
163
  '            Static: @0@'.format(static),
164
  '     Introspection: @0@'.format(introspection),
165
  '              Vapi: @0@'.format(get_option('vapi')),
166
  '     Glade Catalog: @0@'.format(glade_catalog),
Guido Gunther's avatar
Guido Gunther committed
167 168 169 170 171 172
 '------',
  ''
]

message('\n'.join(summary))