Imported Upstream version 1.61.2
[platform/upstream/gobject-introspection.git] / meson.build
1 project('gobject-introspection', 'c',
2   version: '1.61.2',
3   meson_version: '>= 0.49.2',
4   default_options: [
5     'warning_level=1',
6     'buildtype=debugoptimized',
7   ],
8 )
9
10 host_system = host_machine.system()
11 gi_versions = meson.project_version().split('.')
12
13 configinc = include_directories('.')
14
15 pymod = import('python')
16 python = pymod.find_installation(get_option('python'))
17
18 python_version = python.language_version()
19 python_version_req = '>=3.4'
20 if not python_version.version_compare(python_version_req)
21   error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
22 endif
23
24 cc = meson.get_compiler('c')
25
26 project_c_args = []
27 if cc.get_id() != 'msvc'
28     project_c_args += [
29       '-Wall',
30       '-Warray-bounds',
31       '-Wcast-align',
32       '-Wdeclaration-after-statement',
33       '-Wduplicated-branches',
34       '-Wextra',
35       '-Wformat=2',
36       '-Wformat-nonliteral',
37       '-Wformat-security',
38       '-Wimplicit-function-declaration',
39       '-Winit-self',
40       '-Wjump-misses-init',
41       '-Wlogical-op',
42       '-Wmissing-declarations',
43       '-Wmissing-format-attribute',
44       '-Wmissing-include-dirs',
45       '-Wmissing-noreturn',
46       '-Wmissing-prototypes',
47       '-Wnested-externs',
48       '-Wnull-dereference',
49       '-Wold-style-definition',
50       '-Wpacked',
51       '-Wpointer-arith',
52       '-Wrestrict',
53       '-Wreturn-type',
54       '-Wshadow',
55       '-Wsign-compare',
56       '-Wstrict-aliasing',
57       '-Wstrict-prototypes',
58       '-Wundef',
59       '-Wunused-but-set-variable',
60       '-Wwrite-strings',
61     ]
62
63     project_c_args += [
64       '-fno-strict-aliasing',
65     ]
66 else
67     project_c_args += [
68       '-FImsvc_recommended_pragmas.h',
69     ]
70 endif
71
72 project_c_args = cc.get_supported_arguments(project_c_args)
73 add_project_arguments(project_c_args, language: 'c')
74
75 config = configuration_data()
76
77 config.set('GI_MAJOR_VERSION', gi_versions[0])
78 config.set('GI_MINOR_VERSION', gi_versions[1])
79 config.set('GI_MICRO_VERSION', gi_versions[2])
80
81 config.set_quoted('GIR_SUFFIX', 'gir-1.0')
82 gir_dir_prefix = get_option('gir_dir_prefix')
83 if gir_dir_prefix == ''
84     gir_dir_prefix = join_paths(get_option('prefix'), get_option('datadir'))
85     gir_dir_pc_prefix = '${datadir}'
86 else
87     gir_dir_prefix = join_paths(get_option('prefix'), gir_dir_prefix)
88     gir_dir_pc_prefix = join_paths('${prefix}', gir_dir_prefix)
89 endif
90 girdir = join_paths(gir_dir_prefix, 'gir-1.0')
91 config.set_quoted('GIR_DIR', girdir)
92 config.set_quoted('GOBJECT_INTROSPECTION_LIBDIR', join_paths(get_option('prefix'), get_option('libdir')))
93 config.set_quoted('UNINSTALLED_GIR_DIR', join_paths(meson.current_build_dir(), 'gir'))
94
95 foreach type : ['char', 'short', 'int', 'long']
96   size = cc.sizeof(type)
97   if size == -1
98     error('Failed to get size of @0@'.format(type))
99   endif
100   config.set('SIZEOF_@0@'.format(type.to_upper()), size)
101 endforeach
102
103 add_project_arguments(['-DHAVE_CONFIG_H'], language: 'c')
104
105 gi_hidden_visibility_cflags = []
106 if host_system == 'windows'
107   config.set('DLL_EXPORT', true)
108   config.set('_GI_EXTERN', '__declspec(dllexport) extern')
109   if cc.get_id() != 'msvc'
110     gi_hidden_visibility_cflags += '-fvisibility=hidden'
111   endif
112 else
113   config.set('_GI_EXTERN', '__attribute__((visibility("default"))) extern')
114   gi_hidden_visibility_cflags += '-fvisibility=hidden'
115 endif
116
117 configure_file(
118   configuration: config,
119   output: 'config.h'
120 )
121
122 # FIXME: Always bumped to match our version
123 #glib_version = '>=2.@0@.@1@'.format(gi_versions[1], gi_versions[2])
124 glib_version = '>= 2.58.0'
125
126 glib_dep = dependency('glib-2.0', version : glib_version,
127   fallback: ['glib', 'libglib_dep'])
128 gobject_dep = dependency('gobject-2.0', version : glib_version,
129   fallback: ['glib', 'libgobject_dep'])
130 gio_dep = dependency('gio-2.0', version : glib_version,
131   fallback: ['glib', 'libgio_dep'])
132 gmodule_dep = dependency('gmodule-2.0', version : glib_version,
133   fallback: ['glib', 'libgmodule_dep'])
134 if host_system != 'windows'
135   giounix_dep = dependency('gio-unix-2.0', version : glib_version,
136     fallback: ['glib', 'libgiounix_dep'])
137 else
138   # Don't even try to look for gio-unix-2.0 on Windows because Meson will
139   # fruitlessly try to find it in the glib subproject even when we don't want
140   # it to look in the subproject at all. Just use a not-found dependency.
141   giounix_dep = dependency('', required : false)
142   # XXX: Autotools doesn't build girs for gio-win32-2.0, but maybe we should?
143 endif
144 libffi_dep = dependency('libffi',
145   fallback : ['libffi', 'ffi_dep'])
146
147 with_cairo = get_option('cairo')
148
149 if with_cairo
150   cairo_dep = dependency('cairo', required: cc.get_id() != 'msvc')
151   cairo_gobject_dep = dependency('cairo-gobject', required: cc.get_id() != 'msvc')
152
153   if cc.get_id() == 'msvc' and (not cairo_gobject_dep.found() or not cairo_dep.found())
154     if cc.has_header('cairo.h') and cc.has_header ('cairo-gobject.h')
155       cairo_dep = cc.find_library ('cairo')
156       cairo_gobject_dep = cc.find_library ('cairo-gobject')
157     endif
158   endif
159 else
160   warning('Not building with cairo support, not all tests will be run')
161 endif
162
163 with_doctool = get_option('doctool')
164 if not with_doctool
165   warning('Not building with doctool support, not all tests will be run')
166 endif
167
168 subdir('girepository')
169 subdir('tools')
170 subdir('giscanner')
171 subdir('gir')
172 subdir('examples')
173 subdir('docs')
174 subdir('tests')
175
176 install_data('Makefile.introspection', install_dir: join_paths(get_option('datadir'), 'gobject-introspection-1.0'))
177 install_data('m4/introspection.m4', install_dir: join_paths(get_option('datadir'), 'aclocal'))
178
179 prefix = get_option('prefix')
180 pkgconfig_conf = configuration_data()
181 pkgconfig_conf.set('prefix', prefix)
182 pkgconfig_conf.set('exec_prefix', '${prefix}')
183 pkgconfig_conf.set('bindir', join_paths('${exec_prefix}', get_option('bindir')))
184 pkgconfig_conf.set('libdir', join_paths('${exec_prefix}', get_option('libdir')))
185 pkgconfig_conf.set('datarootdir', join_paths('${prefix}', get_option('datadir')))
186 pkgconfig_conf.set('datadir', '${datarootdir}')
187 pkgconfig_conf.set('includedir', join_paths('${prefix}', get_option('includedir')))
188 pkgconfig_conf.set('GIR_PC_DIR', join_paths(gir_dir_pc_prefix, 'gir-1.0'))
189 if host_system == 'windows' or host_system == 'cygwin'
190   pkgconfig_conf.set('EXEEXT', '.exe')
191 else
192   pkgconfig_conf.set('EXEEXT', '')
193 endif
194 pkgconfig_conf.set('VERSION', meson.project_version())
195 pkgconfig_conf.set('FFI_PC_PACKAGES', 'libffi')
196 if libffi_dep.type_name() == 'pkgconfig'
197   prog_pkgconfig = find_program('pkg-config')
198   pkgconfig_conf.set('FFI_PC_CFLAGS', run_command(prog_pkgconfig, ['libffi', '--cflags-only-I']).stdout())
199   pkgconfig_conf.set('FFI_PC_LIBS', run_command(prog_pkgconfig, ['libffi', '--libs-only-l']).stdout())
200 else
201   # XXX: We can't know the correct values for these, needs meson API. Maybe we
202   # should use meson's pkgconfig module to generate the whole file.
203   pkgconfig_conf.set('FFI_PC_CFLAGS', '')
204   pkgconfig_conf.set('FFI_PC_LIBS', '-lffi')
205 endif
206
207 configure_file(
208   input: 'gobject-introspection-no-export-1.0.pc.in',
209   output: 'gobject-introspection-no-export-1.0.pc',
210   configuration: pkgconfig_conf,
211   install_dir: join_paths(get_option('libdir'), 'pkgconfig'),
212 )
213
214 configure_file(
215   input: 'gobject-introspection-1.0.pc.in',
216   output: 'gobject-introspection-1.0.pc',
217   configuration: pkgconfig_conf,
218   install_dir: join_paths(get_option('libdir'), 'pkgconfig'),
219 )