[gnome-autoar] build: Port to meson build system



commit 9ad4d7c9d0f8996f2fc4867868a730d9772f1748
Author: Iñigo Martínez <inigomartinez gmail com>
Date:   Wed Feb 10 11:56:27 2021 +0100

    build: Port to meson build system
    
    meson is a build system focused on speed an ease of use, which
    helps speeding up the software development.
    
    Co-authored-by: Peter Keresztes Schmidt <carbenium outlook com>

 docs/reference/meson.build               |  22 ++++
 docs/reference/xml/gtkdocentities.ent.in |   7 ++
 docs/reference/xml/meson.build           |  18 +++
 gnome-autoar/meson.build                 | 181 +++++++++++++++++++++++++++++++
 meson.build                              | 150 +++++++++++++++++++++++++
 meson_options.txt                        |   8 ++
 tests/meson.build                        |  29 +++++
 7 files changed, 415 insertions(+)
---
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
new file mode 100644
index 0000000..0e9831a
--- /dev/null
+++ b/docs/reference/meson.build
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Copyright (C) 2021 Iñigo Martinez <inigomartinez gmail com>
+
+subdir('xml')
+
+private_headers = [
+  'autoar-gtk.h',
+  'autoar-private.h',
+  'gnome-autoar.h',
+]
+
+gnome.gtkdoc(
+  gnome_autoar_name,
+  main_xml: f'@gnome_autoar_name -docs xml',
+  src_dir: src_inc,
+  dependencies: libgnome_autoar_dep,
+  scan_args: '--rebuild-types',
+  gobject_typesfile: f'@gnome_autoar_name@.types',
+  ignore_headers: private_headers,
+  fixxref_args: '--html-dir=' + (gnome_autoar_prefix / gnome.gtkdoc_html_dir(gnome_autoar_name)),
+  install: true,
+)
diff --git a/docs/reference/xml/gtkdocentities.ent.in b/docs/reference/xml/gtkdocentities.ent.in
new file mode 100644
index 0000000..fd86c16
--- /dev/null
+++ b/docs/reference/xml/gtkdocentities.ent.in
@@ -0,0 +1,7 @@
+<!ENTITY package "@PACKAGE@">
+<!ENTITY package_bugreport "@PACKAGE_BUGREPORT@">
+<!ENTITY package_name "@PACKAGE_NAME@">
+<!ENTITY package_string "@PACKAGE_STRING@">
+<!ENTITY package_tarname "@PACKAGE_TARNAME@">
+<!ENTITY package_url "@PACKAGE_URL@">
+<!ENTITY package_version "@PACKAGE_VERSION@">
diff --git a/docs/reference/xml/meson.build b/docs/reference/xml/meson.build
new file mode 100644
index 0000000..fb9dfce
--- /dev/null
+++ b/docs/reference/xml/meson.build
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Copyright (C) 2021 Iñigo Martinez <inigomartinez gmail com>
+
+ent_conf = {
+  'PACKAGE': gnome_autoar_name,
+  'PACKAGE_BUGREPORT': f'https://gitlab.gnome.org/GNOME/@gnome_autoar_name@',
+  'PACKAGE_NAME': gnome_autoar_name,
+  'PACKAGE_STRING': f'@gnome_autoar_name@ @gnome_autoar_version@',
+  'PACKAGE_TARNAME': gnome_autoar_name,
+  'PACKAGE_URL': '',
+  'PACKAGE_VERSION': gnome_autoar_version,
+}
+
+gtkdocentities_ent = configure_file(
+  input: 'gtkdocentities.ent.in',
+  output: '@BASENAME@',
+  configuration: ent_conf,
+)
diff --git a/gnome-autoar/meson.build b/gnome-autoar/meson.build
new file mode 100644
index 0000000..30533a1
--- /dev/null
+++ b/gnome-autoar/meson.build
@@ -0,0 +1,181 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Copyright (C) 2021 Iñigo Martinez <inigomartinez gmail com>
+
+src_inc = include_directories('.')
+
+libname = f'@gnome_autoar_name@-@gnome_autoar_api_version@'
+
+headers = files(
+  'autoar-compressor.h',
+  'autoar-extractor.h',
+  'autoar-format-filter.h',
+  'autoar-mime-types.h',
+  'autoar-misc.h',
+)
+
+install_headers(
+  headers + files('gnome-autoar.h'),
+  install_dir: gnome_autoar_includedir / libname / gnome_autoar_name,
+)
+
+sources = files(
+  'autoar-compressor.c',
+  'autoar-extractor.c',
+  'autoar-format-filter.c',
+  'autoar-mime-types.c',
+  'autoar-misc.c',
+)
+
+enum_types = 'autoar-enum-types'
+
+enum_sources = gnome.mkenums(
+  enum_types,
+  sources: headers,
+  h_template: f'@enum_types@.h.template',
+  c_template: f'@enum_types@.c.template',
+  install_header: true,
+  install_dir: gnome_autoar_includedir / libname / gnome_autoar_name,
+)
+
+deps = [
+  gio_dep,
+  glib_dep,
+  libarchive_dep,
+]
+
+libgnome_autoar = shared_library(
+  libname,
+  version: gnome_autoar_libversion,
+  sources: sources + enum_sources + files('autoar-private.c'),
+  include_directories: top_inc,
+  dependencies: deps,
+  install: true,
+)
+
+libgnome_autoar_dep = declare_dependency(
+  sources: enum_sources[1],
+  include_directories: src_inc,
+  dependencies: deps,
+  link_with: libgnome_autoar,
+)
+
+pkg.generate(
+  libraries: libgnome_autoar,
+  name: gnome_autoar_name,
+  description: 'Archives integration support for GNOME',
+  filebase: libname,
+  subdirs: libname,
+  requires: deps,
+  variables: 'exec_prefix=${prefix}',
+)
+
+if enable_introspection
+  api_ns = 'GnomeAutoar'
+
+  incs = [
+    'Gio-2.0',
+    'GLib-2.0',
+    'GObject-2.0',
+  ]
+
+  libgnome_autoar_gir = gnome.generate_gir(
+    libgnome_autoar,
+    sources: sources + headers,
+    includes: incs,
+    header: 'gnome-autoar/gnome-autoar.h',
+    namespace: api_ns,
+    nsversion: gnome_autoar_api_ns_version,
+    identifier_prefix: gnome_autoar_api_prefix,
+    export_packages: f'@api_ns@-@gnome_autoar_api_ns_version@',
+    install: true,
+  )
+
+  if enable_vapi
+    libgnome_autoar_vapi = gnome.generate_vapi(
+      libname,
+      sources: libgnome_autoar_gir[0],
+      packages: 'gio-2.0',
+      install: true,
+    )
+  endif
+endif
+
+if not enable_gtk
+  subdir_done()
+endif
+
+libname_gtk = f'@gnome_autoar_name@-gtk-@gnome_autoar_api_version@'
+
+headers = files(
+  'autoar-gtk-chooser.h',
+  'autoar-gtk.h',
+)
+
+install_headers(
+  headers,
+  install_dir: gnome_autoar_includedir / libname / gnome_autoar_name,
+)
+
+sources = files('autoar-gtk-chooser.c')
+
+deps = [gtk_dep]
+
+libgnome_autoar_gtk = shared_library(
+  libname_gtk,
+  version: gnome_autoar_libversion,
+  sources: sources,
+  include_directories: top_inc,
+  dependencies: deps + [libgnome_autoar_dep],
+  install: true,
+)
+
+libgnome_autoar_gtk_dep = declare_dependency(
+  include_directories: src_inc,
+  dependencies: deps + [libgnome_autoar_dep],
+  link_with: libgnome_autoar_gtk,
+)
+
+pkg.generate(
+  libraries: libgnome_autoar_gtk,
+  name: gnome_autoar_name,
+  description: 'GTK+ widgets for gnome-autoar library',
+  filebase: libname_gtk,
+  subdirs: libname,
+  requires: deps,
+  variables: 'exec_prefix=${prefix}',
+)
+
+if enable_introspection
+  api_ns = 'GnomeAutoarGtk'
+
+  incs = [
+    libgnome_autoar_gir[0],
+    'Gtk-3.0',
+  ]
+
+  libgnome_autoar_gtk_gir = gnome.generate_gir(
+    libgnome_autoar_gtk,
+    sources: sources + headers,
+    includes: incs,
+    header: 'gnome-autoar/autoar-gtk.h',
+    namespace: api_ns,
+    nsversion: gnome_autoar_api_ns_version,
+    identifier_prefix: 'AutoarGtk',
+    export_packages: f'@api_ns@-@gnome_autoar_api_ns_version@',
+    install: true,
+  )
+
+  if enable_vapi
+    packages = [
+      libgnome_autoar_vapi,
+      'gtk+-3.0',
+    ]
+
+    gnome.generate_vapi(
+      libname_gtk,
+      sources: libgnome_autoar_gtk_gir[0],
+      packages: packages,
+      install: true,
+    )
+  endif
+endif
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..90a3fbf
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,150 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Copyright (C) 2021 Iñigo Martinez <inigomartinez gmail com>
+
+project(
+  'gnome-autoar', 'c',
+  version: '0.3.3',
+  license: 'LGPL2.1+',
+  default_options: 'buildtype=debugoptimized',
+  meson_version: '>= 0.58.0',
+)
+
+gnome_autoar_name = meson.project_name()
+
+gnome_autoar_version = meson.project_version()
+version_array = gnome_autoar_version.split('.')
+gnome_autoar_major_version = version_array[0].to_int()
+gnome_autoar_minor_version = version_array[1].to_int()
+gnome_autoar_micro_version = version_array[2].to_int()
+
+# Before making a release, the libversion string should be modified.
+#
+#  * Bump the first component if binary compatibility has been broken; or
+#  * Bump the second component if new APIs are added; or
+#  * Bump the third component otherwise.
+#
+# When bumping the first component version, set the second and third components
+# to 0. When bumping the second version, set the third one to zero.
+gnome_autoar_libversion = '0.0.0'
+
+gnome_autoar_api_version = 0
+
+gnome_autoar_api_prefix = 'Autoar'
+gnome_autoar_api_ns_version = '0.1'
+
+gnome_autoar_prefix = get_option('prefix')
+gnome_autoar_datadir = get_option('datadir')
+gnome_autoar_includedir = get_option('includedir')
+
+gnome = import('gnome')
+pkg = import('pkgconfig')
+
+source_root = meson.current_source_dir()
+
+top_inc = include_directories('.')
+
+cc = meson.get_compiler('c')
+
+config_h = configuration_data()
+
+# functions
+check_functions = [
+  'getgrnam',
+  'getpwnam',
+  'link',
+  'mkfifo',
+  'mknod',
+  'stat',
+]
+
+foreach func: check_functions
+  config_h.set('HAVE_' + func.to_upper(), cc.has_function(func))
+endforeach
+
+common_flags = ['-DHAVE_CONFIG_H']
+
+compiler_flags = []
+if get_option('buildtype').contains('debug')
+  compiler_flags += cc.get_supported_arguments([
+    '-Werror=format=2',
+    '-Werror=implicit-function-declaration',
+    '-Werror=init-self',
+    '-Werror=missing-prototypes',
+    '-Werror=missing-include-dirs',
+    '-Werror=pointer-arith',
+    '-Werror=return-type',
+    '-Wnested-externs',
+    '-Wstrict-prototypes',
+  ])
+endif
+
+add_project_arguments(common_flags + compiler_flags, language: 'c')
+
+glib_req_version = '>= 2.35.6'
+gio_dep = dependency('gio-2.0', version: glib_req_version)
+glib_dep = dependency('glib-2.0', version: glib_req_version)
+gobject_dep = dependency('gobject-2.0', version: glib_req_version)
+
+libarchive_dep = dependency('libarchive', version: '>= 3.4.0')
+if not libarchive_dep.found()
+  libarchive_dep = cc.find_library('archive')
+  cc.has_function('archive_entry_is_encrypted', dependencies: libarchive_dep)
+endif
+
+gtk_req_version = '>= 3.2'
+gtk_dep = dependency(
+  'gtk+-3.0',
+  version: gtk_req_version,
+  required: get_option('gtk'),
+  not_found_message: f'GTK+ support requested but gtk+-3.0 @gtk_req_version@ could not be found',
+)
+enable_gtk = gtk_dep.found()
+
+enable_introspection = dependency('gobject-introspection-1.0', version: '>= 1.30.0', required: 
get_option('introspection')).found()
+
+enable_vapi = get_option('vapi')
+assert(not enable_vapi or enable_introspection, 'GObject introspection support must be enabled to build VALA 
bindings')
+
+gio_schemasdir = gio_dep.get_variable(
+  'schemasdir',
+  pkgconfig_define: ['datadir', gnome_autoar_datadir],
+  default_value: gnome_autoar_datadir / 'glib-2.0/schemas',
+)
+
+subdir('gnome-autoar')
+
+enable_tests = get_option('tests')
+if enable_tests
+  subdir('tests')
+endif
+
+enable_gtk_doc = get_option('gtk_doc')
+if enable_gtk_doc
+  assert(enable_gtk, 'GTK+ widgets support must be enabled to build API documentation.')
+  subdir('docs/reference')
+endif
+
+configure_file(
+  output: 'config.h',
+  configuration: config_h,
+)
+
+summary(
+  {
+    'Source code location': source_root,
+    'Prefix': gnome_autoar_prefix,
+    'Compiler': cc.get_id(),
+    'CFLAGS': compiler_flags,
+  },
+  section: 'Configuration',
+)
+summary(
+  {
+    'Build API documentation': enable_gtk_doc,
+    'GTK+ widgets': enable_gtk,
+    'Introspection': enable_introspection,
+    'VALA bindings': enable_vapi,
+    'Tests': enable_tests,
+  },
+  section: 'Optional features',
+)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..d83d5f5
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,8 @@
+option('gtk', type: 'boolean', value: true, description: 'build some common GTK+ widgets support')
+
+option('introspection', type: 'feature', value: 'auto', description: 'build introspection support')
+option('vapi', type: 'boolean', value: false, description: 'build vala bindings')
+
+option('tests', type: 'boolean', value: false, description: 'build tests')
+
+option('gtk_doc', type: 'boolean', value: false, description: 'build GTK Doc reference')
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..5da28d2
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Copyright (C) 2021 Iñigo Martinez <inigomartinez gmail com>
+
+test_units = [
+  ['test-extract', libgnome_autoar_dep, false],
+  ['test-extract-unit', libgnome_autoar_dep, true],
+  ['test-create', libgnome_autoar_dep, false],
+]
+
+if enable_gtk
+  test_units += [['test-ui', libgnome_autoar_gtk_dep, false]]
+endif
+
+foreach test_unit: test_units
+  exe = executable(
+    test_unit[0],
+    test_unit[0] + '.c',
+    include_directories: top_inc,
+    dependencies: test_unit[1],
+  )
+
+  if test_unit[2]
+    test(
+      test_unit[0],
+      exe,
+      should_fail: true,
+    )
+  endif
+endforeach


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]