[amtk/wip/swilmet/meson: 1/5] meson: start to port the build system to Meson




commit 4db20ed889122493adca3449d0bad1844da3ab24
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Sep 3 14:47:20 2020 +0200

    meson: start to port the build system to Meson
    
    Thanks to Xavier Claessens for an initial patch and having more reasons
    to migrate to Meson.

 .gitignore            |   1 +
 amtk/meson.build      | 123 ++++++++++++++++++++++++++++++++++++++++++
 amtk/symbol.map       |   6 +++
 meson.build           | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++
 po/meson.build        |   4 ++
 tests/meson.build     |  12 +++++
 testsuite/meson.build |  14 +++++
 7 files changed, 307 insertions(+)
---
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..84c048a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/build/
diff --git a/amtk/meson.build b/amtk/meson.build
new file mode 100644
index 0000000..d0471a9
--- /dev/null
+++ b/amtk/meson.build
@@ -0,0 +1,123 @@
+amtk_public_headers = [
+  'amtk.h',
+  'amtk-action-info-central-store.h',
+  'amtk-action-info.h',
+  'amtk-action-info-store.h',
+  'amtk-action-map.h',
+  'amtk-application-window.h',
+  'amtk-factory.h',
+  'amtk-gmenu.h',
+  'amtk-init.h',
+  'amtk-menu-item.h',
+  'amtk-menu-shell.h',
+  'amtk-shortcuts.h',
+  'amtk-types.h',
+  'amtk-utils.h',
+]
+
+amtk_public_c_files = [
+  'amtk-action-info.c',
+  'amtk-action-info-central-store.c',
+  'amtk-action-info-store.c',
+  'amtk-action-map.c',
+  'amtk-application-window.c',
+  'amtk-factory.c',
+  'amtk-gmenu.c',
+  'amtk-init.c',
+  'amtk-menu-item.c',
+  'amtk-menu-shell.c',
+  'amtk-shortcuts.c',
+  'amtk-utils.c',
+]
+
+headers_install_dir = get_option('includedir') / 'amtk-@0@/amtk/'.format(AMTK_API_VERSION)
+install_headers(
+  amtk_public_headers,
+  install_dir: headers_install_dir
+)
+
+amtk_enum_types = GNOME.mkenums_simple(
+  'amtk-enum-types',
+  decorator: '_AMTK_EXTERN',
+  header_prefix: '#include <amtk/amtk-types.h>',
+  sources: amtk_public_headers,
+  install_header: true,
+  install_dir: headers_install_dir
+)
+
+amtk_static_lib_c_args = [ '-DAMTK_COMPILATION' ]
+if meson.get_compiler('c').get_argument_syntax() == 'msvc'
+  amtk_static_lib_c_args += '-D_AMTK_EXTERN=__declspec(dllexport) extern'
+endif
+
+amtk_static_lib = static_library(
+  'amtk-static',
+  [amtk_public_c_files,
+   amtk_enum_types],
+  pic: true, # amtk_static_lib is linked in a shared library.
+  include_directories: ROOT_INCLUDE_DIR,
+  dependencies: AMTK_DEPS,
+  c_args: amtk_static_lib_c_args
+)
+
+# For unit tests, to be able to test private functions.
+AMTK_STATIC_DEP = declare_dependency(
+  include_directories: ROOT_INCLUDE_DIR,
+  link_with: amtk_static_lib,
+  sources: amtk_enum_types[1],
+  dependencies: AMTK_DEPS
+)
+
+amtk_lib_link_args = []
+amtk_lib_link_depends = []
+
+if meson.get_compiler('c').get_argument_syntax() != 'msvc'
+  symbol_map = meson.current_source_dir() / 'symbol.map'
+  amtk_lib_link_args = '-Wl,--version-script,' + symbol_map
+  amtk_lib_link_depends = symbol_map
+endif
+
+amtk_lib = library(
+  'amtk-@0@'.format(AMTK_API_VERSION),
+  dependencies: AMTK_DEPS,
+  link_args: amtk_lib_link_args,
+  link_depends: amtk_lib_link_depends,
+  # link_whole is not supported with MSVC, so we use extract_all_objects().
+  objects: amtk_static_lib.extract_all_objects(),
+  version: AMTK_LT_VERSION,
+  install: true
+)
+
+AMTK_LIB_DEP = declare_dependency(
+  include_directories: ROOT_INCLUDE_DIR,
+  link_with: amtk_lib,
+  sources: amtk_enum_types[1],
+  dependencies: AMTK_DEPS
+)
+
+PKG_CONFIG.generate(amtk_lib,
+  filebase: 'amtk-@0@'.format(AMTK_API_VERSION),
+  name: 'Amtk',
+  description: 'Actions, Menus and Toolbars Kit',
+  subdirs: 'amtk-@0@'.format(AMTK_API_VERSION),
+  libraries: AMTK_DEPS,
+)
+
+GNOME.generate_gir(
+  amtk_lib,
+  export_packages: 'amtk-@0@'.format(AMTK_API_VERSION),
+  header: 'amtk/amtk.h',
+  identifier_prefix: 'Amtk',
+  include_directories: ROOT_INCLUDE_DIR,
+  includes: ['Gtk-3.0'],
+  install: true,
+  namespace: 'Amtk',
+  nsversion: AMTK_API_VERSION,
+  sources: [
+    amtk_public_headers,
+    amtk_public_c_files,
+    amtk_enum_types
+  ],
+  # Support for deps being built as subprojects:
+  dependencies: AMTK_DEPS,
+)
diff --git a/amtk/symbol.map b/amtk/symbol.map
new file mode 100644
index 0000000..6459bce
--- /dev/null
+++ b/amtk/symbol.map
@@ -0,0 +1,6 @@
+{
+global:
+  amtk_*;
+local:
+  *;
+};
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..011d2b4
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,147 @@
+# Convention:
+# - Local variables in lower_case.
+# - Global variables in UPPER_CASE.
+# See: https://github.com/mesonbuild/meson/issues/2607
+
+project(
+  'amtk', 'c',
+  meson_version: '>= 0.53',
+  version: '5.1.2',
+  default_options: ['warning_level=2']
+)
+
+GNOME = import('gnome')
+PKG_CONFIG = import('pkgconfig')
+I18N = import('i18n')
+
+# Libtool versioning
+#
+# For development releases (if the minor package version is odd), keep the same
+# Libtool version.
+#
+# For a new minor stable release (when incrementing the minor package version
+# to an even number), apply the following algorithm step by step:
+# 1. If the library source code has changed at all since the last
+#    update, then increment REVISION.
+# 2. If any exported functions or data have been added, removed, or
+#    changed since the last update, increment CURRENT and set REVISION
+#    to 0.
+# 3. If any exported functions or data have been added since the last
+#    public release, increment AGE.
+# 4. If any exported functions or data have been removed since the last
+#    public release, set AGE to 0.
+#
+# When incrementing the API version (usually for a new major package version),
+# set CURRENT, REVISION and AGE to 0 since it's like a new library.
+lt_current = 0
+lt_revision = 0
+lt_age = 0
+AMTK_LT_VERSION = '@0@.@1@.@2@'.format(lt_current, lt_revision, lt_age)
+
+# API version, used for parallel installability.
+AMTK_API_VERSION = '5'
+
+AMTK_DEPS = [
+  dependency('gio-2.0', version: '>= 2.56'),
+  dependency('gtk+-3.0', version: '>= 3.22')
+]
+
+# config.h
+
+config_data = configuration_data()
+GETTEXT_PACKAGE_NAME = 'amtk-' + AMTK_API_VERSION
+config_data.set_quoted('GETTEXT_PACKAGE', GETTEXT_PACKAGE_NAME)
+config_data.set_quoted('DATADIR', get_option('prefix') / get_option('datadir'))
+
+configure_file(
+  output: 'config.h',
+  configuration: config_data
+)
+
+# Misc
+
+ROOT_INCLUDE_DIR = include_directories('.')
+
+add_project_arguments(
+  '-DG_LOG_DOMAIN="@0@"'.format(meson.project_name()),
+  language: 'c'
+)
+
+#####
+# CFLAGS
+# Some flags are missing when using only the builtin warning_level meson option,
+# even at the maximum level.
+# The following warning_cflags suppose that warning_level=2.
+
+c_compiler = meson.get_compiler('c')
+warning_cflags = []
+
+if c_compiler.get_id() == 'msvc'
+  # Use GLib's msvc_recommended_pragmas.h to filter out
+  # the warnings we don't really need to worry about,
+  # but do make the ones we want to be wary stand out
+  warning_cflags += [
+    '-FImsvc_recommended_pragmas.h',
+  ]
+else
+  # Try to mimic the AX_COMPILER_FLAGS Autotools macro.
+  warning_cflags += [
+    '-fno-strict-aliasing',
+    '-Wundef',
+    '-Wnested-externs',
+    '-Wwrite-strings',
+    '-Wpointer-arith',
+    '-Wmissing-declarations',
+    '-Wmissing-prototypes',
+    '-Wstrict-prototypes',
+    '-Wredundant-decls',
+    '-Wno-unused-parameter',
+    '-Wno-missing-field-initializers',
+    '-Wdeclaration-after-statement',
+    '-Wformat=2',
+    '-Wold-style-definition',
+    '-Wcast-align',
+    '-Wformat-nonliteral',
+    '-Wformat-security',
+    '-Wsign-compare',
+    '-Wstrict-aliasing',
+    '-Wshadow',
+    '-Winline',
+    '-Wpacked',
+    '-Wmissing-format-attribute',
+    '-Wmissing-noreturn',
+    '-Winit-self',
+    '-Wredundant-decls',
+    '-Wmissing-include-dirs',
+    '-Wunused-but-set-variable',
+    '-Warray-bounds',
+    '-Wimplicit-function-declaration',
+    '-Wreturn-type',
+    '-Wswitch-enum',
+    '-Wswitch-default',
+    '-Wduplicated-cond',
+    '-Wduplicated-branches',
+    '-Wlogical-op',
+    '-Wrestrict',
+    '-Wnull-dereference',
+    '-Wjump-misses-init',
+    '-Wdouble-promotion'
+  ]
+endif
+
+supported_warning_cflags = c_compiler.get_supported_arguments(warning_cflags)
+add_project_arguments(supported_warning_cflags, language: 'c')
+##### end CFLAGS
+
+subdir('po')
+subdir('amtk')
+subdir('tests')
+subdir('testsuite')
+
+#if get_option('gtk_doc')
+#  subdir('docs/reference')
+#endif
+
+summary('API version', AMTK_API_VERSION)
+summary('Prefix', get_option('prefix'))
+#summary('API documentation', get_option('gtk_doc'))
diff --git a/po/meson.build b/po/meson.build
new file mode 100644
index 0000000..efd359d
--- /dev/null
+++ b/po/meson.build
@@ -0,0 +1,4 @@
+I18N.gettext(
+  GETTEXT_PACKAGE_NAME,
+  preset: 'glib'
+)
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..342acaf
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,12 @@
+interactive_tests = [
+  # executable name, sources
+  ['test-headerbar', 'test-headerbar.c'],
+  ['test-traditional-ui', 'test-traditional-ui.c'],
+]
+
+foreach test : interactive_tests
+  executable(
+    test[0], test[1],
+    dependencies: AMTK_STATIC_DEP
+  )
+endforeach
diff --git a/testsuite/meson.build b/testsuite/meson.build
new file mode 100644
index 0000000..1946088
--- /dev/null
+++ b/testsuite/meson.build
@@ -0,0 +1,14 @@
+unit_tests = [
+  'test-action-info-store',
+  'test-action-map',
+  'test-utils',
+]
+
+foreach test_name : unit_tests
+  test_exe = executable(
+    test_name,
+    test_name + '.c',
+    dependencies: AMTK_STATIC_DEP
+  )
+  test(test_name, test_exe)
+endforeach


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