1project('gtksourceview', 'c',
2          version: '4.8.1',
3          license: 'LGPL-2.1-or-later',
4    meson_version: '>= 0.50.0',
5  default_options: [ 'c_std=gnu99',
6                     'buildtype=debugoptimized',
7                     'warning_level=2' ],
8)
9
10buildtype = get_option('buildtype')
11
12i18n = import('i18n')
13gnome = import('gnome')
14pkg = import('pkgconfig')
15
16# Versioning
17version = meson.project_version()
18version_arr = version.split('.')
19version_major = version_arr[0].to_int()
20version_minor = version_arr[1].to_int()
21version_micro = version_arr[2].to_int()
22
23api_version = '4'
24
25lib_version = '0.0.0'
26lib_version_arr = lib_version.split('.')
27lib_version_major = lib_version_arr[0].to_int()
28lib_version_minor = lib_version_arr[1].to_int()
29lib_version_micro = lib_version_arr[2].to_int()
30
31osx_current = lib_version_major + 1
32lib_osx_version = [osx_current, '@0@.@1@'.format(osx_current, lib_version_minor)]
33
34
35package_name = meson.project_name()
36package_string = '@0@-@1@'.format(package_name, api_version)
37
38# Paths
39rootdir = include_directories('.')
40srcdir = meson.source_root()
41builddir = meson.build_root()
42
43prefix = get_option('prefix')
44
45includedir = join_paths(prefix, get_option('includedir'))
46libdir = join_paths(prefix, get_option('libdir'))
47libexecdir = join_paths(prefix, get_option('libexecdir'))
48typelibdir = join_paths(libdir, 'girepository-1.0')
49datadir = join_paths(prefix, get_option('datadir'))
50localedir = join_paths(prefix, get_option('localedir'))
51pkgincludedir = join_paths(includedir, package_string)
52pkgconfigdir = join_paths(libdir, 'pkgconfig')
53pkgdatadir = join_paths(datadir, package_string)
54girdir = join_paths(datadir, 'gir-1.0')
55vapidir = join_paths(datadir, 'vala', 'vapi')
56mandir = join_paths(prefix, get_option('mandir'))
57testexecdir = join_paths(libexecdir, 'installed-tests', package_string)
58testdatadir = join_paths(datadir, 'installed-tests', package_string)
59docpath = join_paths(datadir, 'gtk-doc', 'html', package_string)
60
61# Options
62install_glade_catalog = get_option('glade_catalog')
63generate_gir = get_option('gir')
64generate_vapi = generate_gir and get_option('vapi')
65build_gtk_doc = get_option('gtk_doc')
66
67# Dependencies
68cc = meson.get_compiler('c')
69
70glib_req_version = '2.48'
71gtk_req_version = '3.24'
72
73libm_dep = cc.find_library('m', required: false)
74
75glib_req = '>= @0@'.format(glib_req_version)
76gtk_req = '>= @0@'.format(gtk_req_version)
77libxml_req = '>= 2.6'
78gladeui_req = '>= 3.9'
79introspection_req  = '>= 1.42.0'
80gtk_doc_req = '>= 1.25'
81fribidi_req = '>= 0.19.7'
82
83glib_dep = dependency('glib-2.0', version: glib_req)
84gobject_dep = dependency('gobject-2.0', version: glib_req)
85gio_dep = dependency('gio-2.0', version: glib_req)
86gtk_dep = dependency('gtk+-3.0', version: gtk_req)
87libxml_dep = dependency('libxml-2.0', version: libxml_req, required: cc.get_id() != 'msvc')
88fribidi_dep = dependency('fribidi', version: fribidi_req)
89
90gtk_quartz_dep = dependency('gtk+-quartz-3.0', version: gtk_doc_req, required: false)
91
92if install_glade_catalog
93  gladeui_dep = dependency('gladeui-2.0', version: gladeui_req)
94else
95  gladeui_dep = []
96endif
97
98if generate_gir
99  introspection_dep = dependency('gobject-introspection-1.0', version: introspection_req)
100else
101  introspection_dep = []
102endif
103
104if generate_vapi
105  vapigen_dep = dependency('vapigen')
106else
107  vapigen_dep = []
108endif
109
110if build_gtk_doc
111  gtk_doc_dep = dependency('gtk-doc', version: gtk_doc_req)
112else
113  gtk_doc_dep = []
114endif
115
116# Look for the libxml2 library manually on Visual Studio if
117# its pkg-config file could not be found, as the NMake
118# Makefiles of libxml2 do not generate the pkg-config files
119# for us.  Remove once Meson gains the ability to declare
120# deps in a declarative way
121if cc.get_id() == 'msvc' and not libxml_dep.found()
122  libxml_dep = cc.find_library('libxml2', has_headers: ['libxml/xmlreader.h', 'libxml/parser.h'])
123endif
124
125xmllint_prg = find_program('xmllint', required: false)
126
127glib_version_arr = glib_req_version.split('.')
128glib_major_version = glib_version_arr[0]
129glib_minor_version = glib_version_arr[1]
130
131gtk_version_arr = gtk_req_version.split('.')
132gtk_major_version = gtk_version_arr[0]
133gtk_minor_version = gtk_version_arr[1]
134
135# Configurations
136add_project_arguments([
137  '-DG_DISABLE_DEPRECATED',
138  '-DGDK_DISABLE_DEPRECATED',
139  '-DGTK_DISABLE_DEPRECATED',
140  '-DGDK_PIXBUF_DISABLE_DEPRECATED',
141  '-DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_@0@_@1@'.format(gtk_major_version, gtk_minor_version),
142  '-DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_@0@_@1@'.format(gtk_major_version, gtk_minor_version),
143  '-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_@0@_@1@'.format(glib_major_version, glib_minor_version),
144  '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_@0@_@1@'.format(glib_major_version, glib_minor_version),
145], language: 'c')
146
147config_h = configuration_data()
148config_h.set('GSV_API_VERSION', api_version)
149config_h.set_quoted('GSV_API_VERSION_S', api_version)
150config_h.set_quoted('GETTEXT_PACKAGE', package_string)
151config_h.set_quoted('DATADIR', datadir)
152
153check_headers = [
154  ['unistd.h', 'HAVE_UNISTD_H'],
155]
156
157foreach header: check_headers
158  if cc.has_header(header.get(0))
159    config_h.set(header.get(1), 1)
160  endif
161endforeach
162
163if build_machine.system() == 'darwin' and gtk_quartz_dep.found()
164  cocoa_dep = dependency('appleframeworks', modules: 'Cocoa', required: false)
165  assert(cocoa_dep.found(), 'Dependency appleframeworks not found')
166  config_h.set_quoted('OS_OSX', 'yes')
167endif
168
169# Compiler flags and warnings
170global_c_args = []
171if cc.get_id() == 'msvc'
172  test_c_args = [
173    '/FImsvc_recommended_pragmas.h',
174  ]
175else
176  test_c_args = [
177    '-Wcast-align',
178    '-Wdeclaration-after-statement',
179    '-Werror=address',
180    '-Werror=array-bounds',
181    '-Werror=empty-body',
182    '-Werror=implicit',
183    '-Werror=implicit-function-declaration',
184    '-Werror=incompatible-pointer-types',
185    '-Werror=init-self',
186    '-Werror=int-conversion',
187    '-Werror=int-to-pointer-cast',
188    '-Werror=main',
189    '-Werror=misleading-indentation',
190    '-Werror=missing-braces',
191    '-Werror=missing-include-dirs',
192    '-Werror=nonnull',
193    '-Werror=overflow',
194    '-Werror=parenthesis',
195    '-Werror=pointer-arith',
196    '-Werror=pointer-to-int-cast',
197    '-Werror=return-type',
198    '-Werror=sequence-point',
199    '-Werror=shadow',
200    '-Werror=strict-prototypes',
201    '-Werror=trigraphs',
202    '-Werror=undef',
203    '-Werror=write-strings',
204    '-Wformat-nonliteral',
205    ['-Werror=format-security', '-Werror=format=2' ],
206    '-Wignored-qualifiers',
207    '-Wimplicit-function-declaration',
208    '-Wlogical-op',
209    '-Wmissing-format-attribute',
210    '-Wmissing-include-dirs',
211    '-Wmissing-noreturn',
212    '-Wnested-externs',
213    '-Wno-cast-function-type',
214    '-Wno-missing-field-initializers',
215    '-Wno-sign-compare',
216    '-Wno-unused-parameter',
217    '-Wold-style-definition',
218    '-Wpointer-arith',
219    '-Wstrict-prototypes',
220    '-Wswitch-default',
221    '-Wswitch-enum',
222    '-Wundef',
223    '-Wuninitialized',
224    '-Wunused',
225    '-fno-strict-aliasing',
226  ]
227  if buildtype != 'plain'
228    test_c_args += '-fstack-protector-strong'
229  endif
230endif
231
232foreach arg: test_c_args
233  if cc.has_multi_arguments(arg)
234    global_c_args += arg
235  endif
236endforeach
237
238if cc.get_id() != 'msvc' and cc.has_multi_arguments('-Wmissing-declarations')
239  global_c_args += '-Wmissing-declarations'
240endif
241
242# Detect and set symbol visibility
243if get_option('default_library') != 'static'
244  if host_machine.system() == 'windows'
245    config_h.set('DLL_EXPORT', true)
246    if cc.get_id() == 'msvc'
247      config_h.set('_GTK_SOURCE_EXTERN', '__declspec(dllexport) extern')
248    elif cc.has_argument('-fvisibility=hidden')
249      config_h.set('_GTK_SOURCE_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
250    endif
251  elif cc.has_argument('-fvisibility=hidden')
252    config_h.set('_GTK_SOURCE_EXTERN', '__attribute__((visibility("default"))) extern')
253  endif
254endif
255
256add_project_arguments(global_c_args, language: 'c')
257
258# Various optimizations for non-debug builds including disabling of
259# cast checks, asserts, and additional link options.
260release_link_args = []
261test_link_args = [
262  '-Wl,-z,defs',   # Detect and reject underlinking
263  '-Wl,-z,now',    # Disable lazy binding
264  '-Wl,-z,relro',  # Read-only segments after relocation
265]
266if not buildtype.startswith('debug')
267  add_global_arguments([
268    '-DG_DISABLE_ASSERT',
269    '-DG_DISABLE_CAST_CHECKS',
270  ], language: 'c')
271  test_link_args += ['-Wl,-Bsymbolic', '-fno-plt']
272endif
273foreach link_arg: test_link_args
274  if cc.has_link_argument(link_arg)
275    release_link_args += link_arg
276  endif
277endforeach
278
279configure_file(
280         output: 'config.h',
281  configuration: config_h
282)
283
284subdir('gtksourceview')
285subdir('data')
286subdir('docs')
287subdir('po')
288subdir('tests')
289subdir('testsuite')
290
291summary = [
292  '',
293  '------',
294  'GtkSourceView @0@ (@1@)'.format(version, api_version),
295  '',
296  '  Documentation: @0@'.format(build_gtk_doc),
297  '  Glade catalog: @0@'.format(install_glade_catalog),
298  '  Install tests: @0@'.format(get_option('install_tests')),
299  '  Introspection: @0@'.format(generate_gir),
300  '      Vala vapi: @0@'.format(generate_vapi),
301  '',
302  'Directories:',
303  '         prefix: @0@'.format(prefix),
304  '     includedir: @0@'.format(includedir),
305  '         libdir: @0@'.format(libdir),
306  '        datadir: @0@'.format(datadir),
307  '------',
308]
309
310message('\n'.join(summary))
311