Change configuration system from Autotools to Meson
[geeqie.git] / meson.build
1 # This file is a part of Geeqie project (https://www.geeqie.org/).
2 # Copyright (C) 2008 - 2022 The Geeqie Team
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # Meson default directories used in this project:
15 # prefix - /usr/local
16 # bindir - bin
17 # datadir - share
18
19 # Meson core options:
20 # buildtype
21 # debug
22
23 # Project expanded default directories:
24 # prefix        /usr/local/
25 # bindir        /usr/local/bin                          geeqie executable
26 # gq_bindir     /usr/local/lib/geeqie               *   plugins scripts
27 # datadir       /usr/local/share/
28 #               /usr/local/share/applications           geeqie.desktop
29 # [gq_]appdir   /usr/local/share/geeqie/            *   template.desktop
30 # desktopdir    /usr/local/share/geeqie/applications    plugin desktop files
31 # appdatadir    /usr/local/share/metainfo               org.geeqie.Geeqie.appdata.xml
32 # icondir       /usr/local/share/pixmaps                geeqie.png icon
33 # [gq_]helpdir  /usr/local/share/doc/geeqie         *   readme files etc.
34 # [gq_]htmldir  /usr/local/share/doc/geeqie/html    *   help files
35 # gq_localedir  /usr/locale/share/locale
36 # mandir1       /usr/local/share/man/man1               man page
37 # podir         project_root/po
38
39 # * See meson_options.txt file
40
41 project(
42     'geeqie',
43     'c',
44     'cpp',
45     version : run_command('./version.sh', check : true).stdout().strip(),
46     license : ['GPL-2.0-or-later'],
47     meson_version : '>= 0.60.0',
48     default_options : ['warning_level=0', 'buildtype=debugoptimized']
49 )
50
51 # Project requirements
52 project_sources = []
53 gnome = import('gnome')
54 thread_dep = dependency('threads')
55 cc = meson.get_compiler('c')
56 i18n = import('i18n')
57 configuration_inc = include_directories('.')
58
59 # External programs
60 gdk_pixbuf_csource = find_program('gdk-pixbuf-csource', required : true)
61 glib_genmarshal = find_program('glib-genmarshal', required : true)
62 gnome_doc_tool = find_program('yelp-build', required : false)
63 if not gnome_doc_tool.found()
64     message('yelp-build not found. Help files not created.')
65 endif
66
67 debug = get_option('debug')
68
69 # Note that main.c sets prefix to the directory above where the executable is run from.
70 # This is to allow AppImages to be used
71
72 # These gq_* variables are paths relative to /prefix/,
73 # and are also used in defines in the source as GQ_*
74 if get_option('gq_appdir') == ''
75     gq_appdir = join_paths(get_option('datadir'), 'geeqie')
76 else
77     gq_appdir = get_option('gq_appdir')
78 endif
79
80 # This is not the same as Meson bindir
81 if get_option('gq_bindir') == ''
82     gq_bindir = 'lib/geeqie'
83 else
84     gq_bindir = get_option('gq_bindir')
85 endif
86
87 if get_option('gq_helpdir') == ''
88     gq_helpdir = join_paths(get_option('datadir'), 'doc/geeqie')
89 else
90     gq_helpdir = get_option('gq_helpdir')
91 endif
92
93 if get_option('gq_htmldir') == ''
94     gq_htmldir = join_paths(get_option('datadir'), 'doc/geeqie/html')
95 else
96     gq_htmldir = get_option('gq_htmldir')
97 endif
98
99 if get_option('gq_localedir') == ''
100     gq_localedir = join_paths(get_option('datadir'), 'locale')
101 else
102     gq_localedir = get_option('gq_localedir')
103 endif
104
105
106 # Set up the absolute directory paths used
107 prefix = get_option('prefix')
108 datadir = join_paths(prefix, get_option('datadir'))
109
110 # Installation paths are absolute
111 appdir = join_paths(prefix, gq_appdir)
112 appdatadir = join_paths(datadir, 'metainfo')
113 desktopdir = join_paths(datadir, meson.project_name(), 'applications')
114 helpdir = join_paths(prefix, gq_helpdir)
115 htmldir = join_paths(prefix, gq_htmldir)
116 icondir = join_paths(datadir, 'pixmaps')
117 mandir1 = join_paths(datadir, 'man', 'man1')
118
119 podir = join_paths(meson.project_source_root(), 'po')
120
121 # Create the define constants used in the sources. Set via config.h.in
122 conf_data = configuration_data()
123 conf_data.set_quoted('VERSION', run_command('./version.sh', check : true).stdout())
124 conf_data.set('DEBUG', debug)
125
126 if get_option('gtk3')
127     gtk_dep = dependency('gtk+-3.0', version : '>=3.0', required: true) 
128 else
129     gtk_dep = dependency('gtk+-2.0', version : '>=2.20', required: true)
130 endif
131
132 glib_dep = dependency('glib-2.0', version: '>=2.52', required: true)
133
134 libarchive_dep = []
135 libarchive_dep = dependency('libarchive', version: '>=3.4.0', required : get_option('archive'))
136 if libarchive_dep.found()
137     conf_data.set('HAVE_ARCHIVE', 1)
138 endif
139
140 clutter_dep = []
141 clutter_gtk_dep = []
142 if get_option('gtk3')
143     clutter_dep = dependency('clutter-1.0', required : get_option('clutter'))
144     clutter_gtk_dep = dependency('clutter-gtk-1.0', required : get_option('clutter'))
145     if clutter_dep.found() and clutter_gtk_dep.found()
146         conf_data.set('HAVE_CLUTTER', 1)
147     endif
148 endif
149
150 lcms_dep = []
151 lcms_dep = dependency('lcms2', version: '>=2.0', required : get_option('cms'))
152 if lcms_dep.found()
153     conf_data.set('HAVE_LCMS', 1)
154     conf_data.set('HAVE_LCMS2', 1)
155 endif
156
157 ddjvuapi_dep = []
158 ddjvuapi_dep = dependency('ddjvuapi', version: '>=3.5.27', required : get_option('djvu'))
159 if ddjvuapi_dep.found()
160     conf_data.set('HAVE_DJVU', 1)
161 endif
162
163 exiv2_dep = []
164 exiv2_dep = dependency('exiv2', version: '>=0.11', required : get_option('exiv2'))
165 if exiv2_dep.found()
166     conf_data.set('HAVE_EXIV2', 1)
167 endif
168
169 libffmpegthumbnailer_dep = []
170 libffmpegthumbnailer_dep = dependency('libffmpegthumbnailer',
171     version: '>=2.1.0',
172     required : get_option('ffmpegthumbnailer'))
173
174 if libffmpegthumbnailer_dep.found()
175     conf_data.set('HAVE_FFMPEGTHUMBNAILER', 1)
176
177     if cc.has_member('struct video_thumbnailer_struct', 'prefer_embedded_metadata',
178         prefix : '#include <libffmpegthumbnailer/videothumbnailerc.h>')
179
180         conf_data.set('HAVE_FFMPEGTHUMBNAILER_METADATA', 1)
181     endif
182
183     if cc.has_member('struct image_data_struct', 'image_data_width',
184         prefix : '#include <libffmpegthumbnailer/videothumbnailerc.h>' )
185
186         conf_data.set('HAVE_FFMPEGTHUMBNAILER_RGB', 1)
187     endif
188
189     if cc.has_function('video_thumbnailer_set_size',
190         dependencies : libffmpegthumbnailer_dep)
191
192         conf_data.set('HAVE_FFMPEGTHUMBNAILER_WH', 1)
193     endif 
194 endif
195
196 champlain_dep = []
197 champlain_gtk_dep = []
198 if conf_data.has('HAVE_CLUTTER')
199     champlain_dep = dependency('champlain-0.12', version: '>=0.12', required : get_option('gps-map'))
200     champlain_gtk_dep = dependency('champlain-gtk-0.12', version: '>=0.12', required : get_option('gps-map'))
201     if champlain_dep.found() and champlain_gtk_dep.found()
202         conf_data.set('HAVE_LIBCHAMPLAIN', 1)
203         conf_data.set('HAVE_LIBCHAMPLAIN_GTK', 1)
204     endif
205 endif
206
207 libheif_dep = []
208 libheif_dep = dependency('libheif', version: '>=1.3.2', required : get_option('heif'))
209 if libheif_dep.found()
210     conf_data.set('HAVE_HEIF', 1)
211 endif
212
213 libopenjp2_dep = []
214 libopenjp2_dep = dependency('libopenjp2', version: '>=2.3.0', required : get_option('j2k'))
215 if libopenjp2_dep.found()
216     conf_data.set('HAVE_J2K', 1)
217 endif
218
219 libjpeg_dep = []
220 libjpeg_dep = dependency('libjpeg', required : get_option('jpeg'))
221 if libjpeg_dep.found()
222     if cc.has_function('jpeg_destroy_decompress',
223         dependencies : libjpeg_dep)
224
225         conf_data.set('HAVE_JPEG', 1)
226     endif
227 endif
228
229 libjxl_dep = []
230 libjxl_dep = dependency('libjxl', version: '>=0.3.7', required : get_option('jpegxl'))
231 if libjxl_dep.found()
232     conf_data.set('HAVE_JPEGXL', 1)
233 endif
234
235 libraw_dep = []
236 libraw_dep = dependency('libraw', version: '>=0.20', required : get_option('libraw'))
237 if libraw_dep.found()
238     conf_data.set('HAVE_RAW', 1)
239 endif
240
241 lirc_dep = []
242 lirc_dep = dependency('lirc', version: '>=0.6.1', required : get_option('lirc'))
243 if lirc_dep.found()
244     conf_data.set('HAVE_LIRC', 1)
245 endif
246
247 lua_dep = []
248 lua_dep = dependency('lua5.1', required : get_option('lua'))
249 if lua_dep.found()
250     conf_data.set('HAVE_LUA', 1)
251 endif
252
253 poppler_glib_dep = []
254 if get_option('gtk3')
255     poppler_glib_dep = dependency('poppler-glib', version: '>=0.62', required : get_option('pdf'))
256     if poppler_glib_dep.found()
257         conf_data.set('HAVE_PDF', 1)
258     endif
259 endif
260
261 gspell_dep = []
262 if get_option('gtk3')
263     gspell_dep = dependency('gspell-1', required: get_option('spell'))
264     if gspell_dep.found()
265         conf_data.set('HAVE_SPELL', 1)
266     endif
267 endif
268
269 tiff_dep = []
270 tiff_dep = cc.find_library('tiff', required: get_option('tiff'))
271 if tiff_dep.found()
272     if cc.has_function('TIFFClientOpen',
273         dependencies : tiff_dep)
274
275         conf_data.set('HAVE_TIFF', 1)
276     endif
277 endif
278
279 libwebp_dep = []
280     libwebp_dep = dependency('libwebp', version: '>=0.6.1', required : get_option('webp'))
281     if libwebp_dep.found()
282         conf_data.set('HAVE_WEBP', 1)
283     endif
284
285 # Check for nl_langinfo and _NL_TIME_FIRST_WEEKDAY
286 code = '''#include <langinfo.h>
287 #include<stdio.h>
288 int main (int argc, char ** argv) {
289     char *c;
290     c =  nl_langinfo(_NL_TIME_FIRST_WEEKDAY);
291     return 0;
292 }'''
293 if cc.links(code, name : 'nl_langinfo and _NL_TIME_FIRST_WEEKDAY')
294     conf_data.set('HAVE__NL_TIME_FIRST_WEEKDAY', 1)
295 endif
296
297 conf_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
298 conf_data.set_quoted('GQ_APPDIR', gq_appdir)
299 conf_data.set_quoted('GQ_BINDIR', gq_bindir)
300 conf_data.set_quoted('GQ_HELPDIR', gq_helpdir)
301 conf_data.set_quoted('GQ_HTMLDIR', gq_htmldir)
302 conf_data.set_quoted('GQ_LOCALEDIR', gq_localedir)
303
304 conf_data.set_quoted('PACKAGE', meson.project_name())
305 conf_data.set_quoted('PACKAGE_NAME', meson.project_name())
306 conf_data.set_quoted('PACKAGE_STRING', meson.project_version())
307 conf_data.set_quoted('PACKAGE_TARNAME', meson.project_name())
308 conf_data.set_quoted('PACKAGE_VERSION', meson.project_version())
309 conf_data.set_quoted('VERSION', meson.project_version())
310
311 configure_file(input : 'config.h.in',
312                output : 'config.h',
313                encoding : 'UTF-8',
314                configuration : conf_data)
315
316 # Process subdirs before the sources
317 subdir('po')
318 subdir('plugins')
319
320 # Generate the executable and the help files
321 subdir('src')
322 subdir('doc')
323
324 # Install other project files
325 run_command(find_program('gen_changelog.sh'), meson.project_source_root(), meson.project_build_root(), check : true)
326
327 run_command(find_program('gen_readme.sh'), meson.project_source_root(), meson.project_build_root(), check : true)
328
329 pandoc = find_program('pandoc')
330 if pandoc.found()
331     install_data('README.md', 'COPYING', join_paths(meson.project_build_root(), 'ChangeLog'), 'TODO', 'README.lirc', 'AUTHORS', join_paths(meson.project_build_root(), 'README.html'), join_paths(meson.project_build_root(), 'ChangeLog.html'), install_dir : helpdir, install_tag : 'help')
332 else
333     install_data('README.md', 'COPYING', join_paths(meson.project_build_root(), 'ChangeLog'), 'TODO', 'README.lirc', 'AUTHORS', install_dir : helpdir, install_tag : 'help')
334 endif
335
336 install_data('geeqie.png', install_dir : icondir, install_tag : 'icons')
337 install_data('geeqie.1', install_dir : mandir1, install_tag : 'man')
338
339 i18n.merge_file(
340     input : 'geeqie.desktop.in',
341     output : 'geeqie.desktop',
342     type : 'desktop',
343     po_dir : podir,
344     install : true,
345     install_dir : join_paths(datadir, 'applications'))
346
347 i18n.merge_file(
348     input : 'org.geeqie.Geeqie.appdata.xml.in',
349     output : 'org.geeqie.Geeqie.appdata.xml',
350     type : 'xml',
351     po_dir : podir,
352     install : true,
353     install_dir : appdatadir)
354
355 configure_file(input: 'geeqie.spec.in', output: 'geeqie.spec', configuration: conf_data)