From 12e6cab66abdf648346ab5497bd395166f014f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= Date: Sat, 15 Feb 2025 17:36:07 +0100 Subject: [PATCH] Add meson build --- Makefile.am | 6 +- configure.ac | 1 + icons/Makefile.am | 4 + icons/meson.build | 13 ++++ meson.build | 183 +++++++++++++++++++++++++++++++++++++++++++++ meson_options.txt | 13 ++++ po/meson.build | 1 + src/Makefile.am | 4 +- src/main.c | 2 +- src/main_window.c | 2 +- src/meson.build | 103 +++++++++++++++++++++++++ src/util.h | 7 +- xfce-revision.h.in | 15 ++++ 13 files changed, 349 insertions(+), 5 deletions(-) create mode 100644 icons/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 po/meson.build create mode 100644 src/meson.build create mode 100644 xfce-revision.h.in diff --git a/Makefile.am b/Makefile.am index ecc77bc3..3f7f9f09 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,11 @@ appdata_in_files = org.xfce.ristretto.appdata.xml.in EXTRA_DIST = \ $(desktop_in_files) \ - $(appdata_in_files) + $(appdata_in_files) \ + meson_options.txt \ + meson.build \ + xfce-revision.h.in \ + $(NULL) DISTCLEANFILES = \ $(desktop_DATA) \ diff --git a/configure.ac b/configure.ac index eaa377f6..17040b14 100644 --- a/configure.ac +++ b/configure.ac @@ -31,6 +31,7 @@ AC_INIT([ristretto], [xdt_version], [https://gitlab.xfce.org/apps/ristretto]) AC_PREREQ([2.69]) AC_CONFIG_MACRO_DIRS([m4]) AC_REVISION([xdt_version_build]) +AC_DEFINE([VERSION_FULL], [PACKAGE_VERSION], [Alias for VERSION and PACKAGE_VERSION for meson compatibility]) AM_INIT_AUTOMAKE([1.8 no-dist-gzip dist-bzip2 tar-ustar foreign]) AC_CONFIG_HEADERS([config.h]) diff --git a/icons/Makefile.am b/icons/Makefile.am index b8755a0a..14757196 100644 --- a/icons/Makefile.am +++ b/icons/Makefile.am @@ -25,3 +25,7 @@ uninstall-hook: echo "*** $(gtk_update_icon_cache)"; \ echo "***"; \ fi + +EXTRA_DIST = \ + meson.build \ + $(NULL) diff --git a/icons/meson.build b/icons/meson.build new file mode 100644 index 00000000..b4e92173 --- /dev/null +++ b/icons/meson.build @@ -0,0 +1,13 @@ +sizes = [16, 24, 32, 48, 64, 96, 128] + +foreach size : sizes + install_data( + '@0@x@0@'.format(size) / 'org.xfce.ristretto.png', + install_dir: get_option('prefix') / get_option('datadir') / 'icons' / 'hicolor' / '@0@x@0@'.format(size) / 'apps', + ) +endforeach + +install_data( + 'scalable' / 'org.xfce.ristretto.svg', + install_dir: get_option('prefix') / get_option('datadir') / 'icons' / 'hicolor' / 'scalable' / 'apps', +) diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..d0ba371a --- /dev/null +++ b/meson.build @@ -0,0 +1,183 @@ +project( + 'ristretto', + 'c', +version : '0.13.3-dev', + license : 'GPL-2.0-or-later', + meson_version : '>= 0.54.0', + default_options : ['c_std=gnu11', 'buildtype=debugoptimized', 'warning_level=2'] +) + +project_namespace = 'apps' +pkgdatadir = get_option('prefix') / get_option('datadir') / meson.project_name() + +cc = meson.get_compiler('c') +pkgconfig = import('pkgconfig') +gnome = import('gnome') +i18n = import('i18n') + +dependency_versions = { + 'glib': '>= 2.56.0', + 'gtk': '>= 3.22.0', + 'cairo': '>= 1.10.0', + 'libexif': '>= 0.6.0', + 'exo': '>= 4.16.0', + 'libxfce4ui': '>= 4.16.0', + 'libxfce4util': '>= 4.16.0', + 'xfconf': '>= 4.12.1', + + 'libx11': '>= 1.6.7', +} + +glib = dependency('glib-2.0', version: dependency_versions['glib']) +gio = dependency('gio-2.0', version: dependency_versions['glib']) +gio_unix = dependency('gio-unix-2.0', version: dependency_versions['glib']) +gtk = dependency('gtk+-3.0', version: dependency_versions['gtk']) +cairo = dependency('cairo', version: dependency_versions['cairo']) +libexif = dependency('libexif', version: dependency_versions['libexif']) +exo = dependency('exo-2', version: dependency_versions['exo']) +libxfce4ui = dependency('libxfce4ui-2', version: dependency_versions['libxfce4ui']) +libxfce4util = dependency('libxfce4util-1.0', version: dependency_versions['libxfce4util']) +xfconf = dependency('libxfconf-0', version: dependency_versions['xfconf']) + +xdt_csource = find_program('xdt-csource', required: true) + +feature_cflags = [] + +libx11 = dependency('x11', version: dependency_versions['libx11'], required: get_option('libx11')) +if libx11.found() + feature_cflags += '-DHAVE_LIBX11=1' +endif + +tumbler_service_name_prefix = get_option('service-name-prefix') +if tumbler_service_name_prefix == '' + tumbler_service_name_prefix = 'org.freedesktop.thumbnails' +endif +tumbler_service_path_prefix = '/@0@'.format('/'.join(tumbler_service_name_prefix.split('.'))) + +headers = [ + 'math.h', + 'string.h', +] +foreach header : headers + if cc.check_header(header) + feature_cflags += '-DHAVE_@0@=1'.format(header.underscorify().to_upper()) + endif +endforeach + +libmagic = cc.find_library('magic', required: false) +if libmagic.found() and cc.check_header('magic.h') and cc.has_function('magic_open', dependencies: libmagic) + feature_cflags += '-DHAVE_MAGIC_H=1' +endif + +libm = cc.find_library('m', required: true) + +extra_cflags = [] +extra_cflags_check = [ + '-Wmissing-declarations', + '-Wmissing-noreturn', + '-Wold-style-definition', + '-Wredundant-decls', + '-Wpointer-arith', + '-Wcast-align', + '-Winit-self', + '-Wshadow', + '-Wmissing-include-dirs', + '-Wundef', + '-Wformat', + '-Wformat-security', + '-Wformat-y2k', + '-Wnested-externs', + '-Wno-unused-parameter', + '-Wno-declaration-after-statement', + '-Wno-missing-field-initializers', + '-Werror=implicit-function-declaration', + '-Wno-error=deprecated-declarations', +] + +optimization = get_option('optimization') +if get_option('debug') and optimization in ['0', 'g'] + extra_cflags_check += '-fstack-protector-strong' + extra_cflags += [ + '-DDEBUG=1', + '-DDEBUG_TRACE=1', + '-DG_ENABLE_DEBUG', + ] +elif optimization in ['3', 'minsize'] + extra_cflags += [ + '-DNDEBUG', + '-DG_DISABLE_CAST_CHECKS', + '-DG_DISABLE_ASSERT', + ] +endif + +if dependency_versions.has_key('glib') + glib_version_parts = dependency_versions['glib'].split(' ') + glib_min_version_parts = glib_version_parts[1].split('.') + glib_min_version_define = 'GLIB_VERSION_@0@_@1@'.format(glib_min_version_parts[0], glib_min_version_parts[1]) + extra_cflags += [ + '-DGLIB_VERSION_MIN_REQUIRED=@0@'.format(glib_min_version_define), + '-DGLIB_VERSION_MAX_ALLOWED=@0@'.format(glib_min_version_define), + '-DG_LOG_USE_STRUCTURED=1', + ] +endif + +version_parts = meson.project_version().split('-dev')[0].split('.') +version_short = '@0@.@1@'.format(version_parts[0], version_parts[1]) + +extra_cflags += [ + '-DPACKAGE="@0@"'.format(meson.project_name()), + '-DPACKAGE_NAME="@0@"'.format(meson.project_name()), + '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()), + '-DVERSION="@0@"'.format(meson.project_version()), + '-DVERSION_SHORT="@0@"'.format(version_short), + '-DPACKAGE_STRING="@0@ @1@"'.format(meson.project_name(), meson.project_version()), + '-DPACKAGE_DATADIR="@0@"'.format(pkgdatadir), + '-DPACKAGE_LOCALE_DIR="@0@"'.format(get_option('prefix') / get_option('localedir')), + '-DPACKAGE_BUGREPORT="https://gitlab.xfce.org/@0@/@1@/-/issues"'.format(project_namespace, meson.project_name()), + '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()), + '-DPREFIX="@0@"'.format(get_option('prefix')), + '-DBINDIR="@0@"'.format(get_option('prefix') / get_option('bindir')), + '-DDATADIR="@0@"'.format(get_option('prefix') / get_option('datadir')), + '-DINCLUDEDIR="@0@"'.format(get_option('prefix') / get_option('includedir')), + '-DLIBDIR="@0@"'.format(get_option('prefix') / get_option('libdir')), + '-DLIBEXECDIR="@0@"'.format(get_option('prefix') / get_option('libexecdir')), + '-DLOCALEDIR="@0@"'.format(get_option('prefix') / get_option('localedir')), + '-DLOCALSTATEDIR="@0@"'.format(get_option('prefix') / get_option('localstatedir')), + '-DSBINDIR="@0@"'.format(get_option('prefix') / get_option('sbindir')), + '-DSYSCONFDIR="@0@"'.format(get_option('prefix') / get_option('sysconfdir')), + '-DHAVE_XFCE_REVISION_H=1', +] + +add_project_arguments(cc.get_supported_arguments(extra_cflags_check), language: 'c') +add_project_arguments(extra_cflags, language: 'c') +add_project_arguments(feature_cflags, language: 'c') + +xfce_revision_h = vcs_tag( + command: ['git', 'rev-parse', '--short', 'HEAD'], + fallback: 'UNKNOWN', + input: 'xfce-revision.h.in', + output: 'xfce-revision.h', + replace_string: '@REVISION@', +) + +i18n.merge_file( + input: 'org.xfce.ristretto.desktop.in', + output: 'org.xfce.ristretto.desktop', + po_dir: 'po', + type: 'desktop', + install: true, + install_dir: get_option('prefix') / get_option('datadir') / 'applications', +) + +i18n.merge_file( + input: 'org.xfce.ristretto.appdata.xml.in', + output: 'org.xfce.ristretto.appdata.xml', + po_dir: 'po', + type: 'xml', + install: true, + install_dir: get_option('prefix') / get_option('datadir') / 'metainfo', +) + +subdir('icons') +subdir('po') +subdir('src') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..26ef6e60 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,13 @@ +option( + 'libx11', + type: 'feature', + value: 'auto', + description: 'Libx11 support', +) + +option( + 'service-name-prefix', + type: 'string', + value: '', + description: 'Alternative prefix to org.freedesktop.thumbnails for Tumbler services', +) diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 00000000..e9b77d79 --- /dev/null +++ b/po/meson.build @@ -0,0 +1 @@ +i18n.gettext(meson.project_name(), preset: 'glib') diff --git a/src/Makefile.am b/src/Makefile.am index cef65976..b6e39d0c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -135,4 +135,6 @@ DISTCLEANFILES += \ EXTRA_DIST = \ main_window_ui.xml \ - tumbler-service-dbus.xml.in + tumbler-service-dbus.xml.in \ + meson.build \ + $(NULL) diff --git a/src/main.c b/src/main.c index 570bbbf1..1c8337b0 100644 --- a/src/main.c +++ b/src/main.c @@ -94,7 +94,7 @@ main (int argc, if (version) { - g_print ("%s\n", PACKAGE_STRING); + g_print ("%s %s\n", PACKAGE_NAME, VERSION_FULL); return 0; } diff --git a/src/main_window.c b/src/main_window.c index 6edeafdd..32deff7f 100644 --- a/src/main_window.c +++ b/src/main_window.c @@ -2827,7 +2827,7 @@ cb_rstto_main_window_about (GtkWidget *widget, GtkWidget *about_dialog = gtk_about_dialog_new (); - gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about_dialog), PACKAGE_VERSION); + gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about_dialog), VERSION_FULL); gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (about_dialog), _("Ristretto is an image viewer for the Xfce desktop environment.")); diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 00000000..4f51f1de --- /dev/null +++ b/src/meson.build @@ -0,0 +1,103 @@ +ristretto_sources = [ + 'app_menu_item.c', + 'app_menu_item.h', + 'file.c', + 'file.h', + 'gnome_wallpaper_manager.c', + 'gnome_wallpaper_manager.h', + 'icon_bar.c', + 'icon_bar.h', + 'image_list.c', + 'image_list.h', + 'image_viewer.c', + 'image_viewer.h', + 'main.c', + 'main_window.c', + 'main_window.h', + 'mime_db.c', + 'mime_db.h', + 'monitor_chooser.c', + 'monitor_chooser.h', + 'preferences_dialog.c', + 'preferences_dialog.h', + 'print.c', + 'print.h', + 'privacy_dialog.c', + 'privacy_dialog.h', + 'properties_dialog.c', + 'properties_dialog.h', + 'settings.c', + 'settings.h', + 'thumbnailer.c', + 'thumbnailer.h', + 'util.c', + 'util.h', + 'wallpaper_manager.c', + 'wallpaper_manager.h', + 'xfce_wallpaper_manager.c', + 'xfce_wallpaper_manager.h', +] + +service_file = configure_file( + configuration: configuration_data({ + 'TUMBLER_SERVICE_NAME_PREFIX': tumbler_service_name_prefix, + 'TUMBLER_SERVICE_PATH_PREFIX': tumbler_service_path_prefix, + }), + input: 'tumbler-service-dbus.xml.in', + output: 'tumbler-service-dbus.xml', + install: false, +) + +ristretto_sources += gnome.gdbus_codegen( + 'tumbler', + sources: service_file, + interface_prefix: tumbler_service_name_prefix, + namespace: 'Tumbler', + install_header: false, +) + +ristretto_sources += gnome.genmarshal( + 'marshal', + sources: 'marshal.list', + prefix: '_rstto_marshal', + internal: true, + install_header: false, +) + +ristretto_sources += custom_target( + 'main_window_ui.h', + input: 'main_window_ui.xml', + output: 'main_window_ui.h', + command: [xdt_csource, '--static', '--strip-comments', '--strip-content', '--name=main_window_ui', '--output=@OUTPUT@', '@INPUT@'], +) + +executable( + 'ristretto', + ristretto_sources, + sources: xfce_revision_h, + c_args: [ + '-DG_LOG_DOMAIN="@0@"'.format('ristretto'), + '-DTUMBLER_SERVICE_NAME_PREFIX="@0@"'.format(tumbler_service_name_prefix), + '-DTUMBLER_SERVICE_PATH_PREFIX="@0@"'.format(tumbler_service_path_prefix), + ], + include_directories: [ + include_directories('..'), + ], + dependencies: [ + glib, + gio, + gio_unix, + gtk, + cairo, + libexif, + exo, + libxfce4ui, + libxfce4util, + xfconf, + libx11, + libmagic, + libm, + ], + install: true, + install_dir: get_option('prefix') / get_option('bindir'), +) diff --git a/src/util.h b/src/util.h index 1cdb477f..b9e3d65c 100644 --- a/src/util.h +++ b/src/util.h @@ -26,7 +26,12 @@ #define __RISTRETTO_UTIL_H__ /* our config header */ -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_XFCE_REVISION_H +#include "xfce-revision.h" +#endif /* standard headers */ #include diff --git a/xfce-revision.h.in b/xfce-revision.h.in new file mode 100644 index 00000000..0b9bb885 --- /dev/null +++ b/xfce-revision.h.in @@ -0,0 +1,15 @@ +/* + * The file xfce-revision.h is auto-generated and should not be modified + * directly. Modify the xfce-revision.h.in file and re-run the build + * instead. + */ + +#ifndef INC_XFCE_REVISION_H +#define INC_XFCE_REVISION_H + +#define REVISION "@REVISION@" + +#define VERSION_FULL VERSION "-" REVISION +#define PACKAGE_STRING_FULL PACKAGE " " VERSION_FULL + +#endif /* INC_XFCE_REVISION_H */