[libgweather] build: Improve chances of using libgweather as a subproject



commit 454c63f1a55e314d887ff9ade8bbf6cf9392619a
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Nov 27 13:47:04 2017 +0000

    build: Improve chances of using libgweather as a subproject
    
    Do not use add_global_arguments(), and do not reference source and build
    root directories.
    
    Instead of the former, we can use add_project_arguments(); in place of
    the latter, we should use the include_directories() object.
    
    We also want to make the dependency on libgweather include the
    introspection data, as it will be useful for projects including
    libgweather that are not written in C.

 libgweather/meson.build |   76 ++++++++++++++++++++++++----------------------
 meson.build             |    6 ++-
 2 files changed, 44 insertions(+), 38 deletions(-)
---
diff --git a/libgweather/meson.build b/libgweather/meson.build
index e41a0b6..f3d9fd2 100644
--- a/libgweather/meson.build
+++ b/libgweather/meson.build
@@ -1,27 +1,23 @@
-add_global_arguments([
+add_project_arguments([
   '-DHAVE_CONFIG_H',
-  '-I' + meson.build_root(),
-  '-I' + meson.source_root(),
   '-DGWEATHER_COMPILATION',
   '-D_XOPEN_SOURCE=700',
   '-D_DEFAULT_SOURCE',
 ], language: 'c')
 
-headerdir = join_paths(includedir, 'libgweather-3.0/libgweather')
+header_subdir = 'libgweather-3.0/libgweather'
 
 versionconf = configuration_data()
 versionconf.set('GWEATHER_MAJOR_VERSION', libgweather_version[0])
-versionconf.set('GWEATHER_MINOR_VERSION',
-libgweather_version[1])
-versionconf.set('GWEATHER_MICRO_VERSION',
-libgweather_version[2])
+versionconf.set('GWEATHER_MINOR_VERSION', libgweather_version[1])
+versionconf.set('GWEATHER_MICRO_VERSION', libgweather_version[2])
 versionconf.set_quoted('GWEATHER_VERSION', meson.project_version())
 configure_file(
   input: 'gweather-version.h.in',
   output: 'gweather-version.h',
   configuration: versionconf,
   install: true,
-  install_dir: headerdir
+  install_dir: join_paths(includedir, header_subdir),
 )
 
 gweather_new_headers = [
@@ -38,9 +34,9 @@ gweather_enum_types = gnome.mkenums('gweather-enum-types',
   c_template: 'gweather-enum-types.c.tmpl',
   h_template: 'gweather-enum-types.h.tmpl',
   install_header: true,
-  install_dir: headerdir)
+  install_dir: join_paths(includedir, header_subdir))
 install_headers(gweather_new_headers,
-  install_dir: headerdir)
+  install_dir: header_subdir)
 
 gweather_c_sources = [
   gweather_enum_types,
@@ -64,26 +60,11 @@ introspection_sources = gweather_c_sources + gweather_new_headers
 
 lib_libgweather = shared_library('gweather-3',
   gweather_c_sources,
-  dependencies : deps_libgweather,
-  version : libgweather_so_version,
-  install : true
+  include_directories: root_inc,
+  dependencies: deps_libgweather,
+  version: libgweather_so_version,
+  install: true,
 )
-libgweather_dep = declare_dependency(sources: [gweather_enum_types[1]],
-                                     dependencies: deps_libgweather,
-                                     link_with: lib_libgweather)
-
-executable('test_locations',
-  ['test_locations.c'],
-  dependencies: libgweather_dep,
-  install: false)
-#executable('test_metar',
-#  ['test_metar.c', 'weather-metar.c'],
-#  dependencies: libgweather_dep,
-#  install: false)
-#executable('test_sun_moon',
-#  ['test_sun_moon.c', 'weather-sun.c', 'weather-moon.c'],
-#  dependencies: libgweather_dep,
-#  install: false)
 
 gweather_gir = gnome.generate_gir(lib_libgweather,
   sources: introspection_sources,
@@ -94,13 +75,36 @@ gweather_gir = gnome.generate_gir(lib_libgweather,
   symbol_prefix: 'gweather',
   identifier_prefix: 'GWeather',
   export_packages: 'gweather-3.0',
-  extra_args: ['--warn-all', '--c-include=libgweather/gweather.h'],
-  install: true)
+  header: 'libgweather/gweather.h',
+  extra_args: ['--warn-all'],
+  install: true,
+)
+
+libgweather_dep = declare_dependency(
+  sources: [gweather_enum_types[1], gweather_gir],
+  dependencies: deps_libgweather,
+  link_with: lib_libgweather,
+  include_directories: root_inc,
+)
 
 if enable_vala
   gnome.generate_vapi('gweather-3.0',
-                      sources: gweather_gir[0],
-                      packages: ['gobject-2.0', 'gtk+-3.0'],
-                      metadata_dirs: '.',
-                      install: true)
+    sources: gweather_gir[0],
+    packages: ['gobject-2.0', 'gtk+-3.0'],
+    metadata_dirs: '.',
+    install: true
+  )
 endif
+
+executable('test_locations',
+  ['test_locations.c'],
+  dependencies: libgweather_dep,
+  install: false)
+#executable('test_metar',
+#  ['test_metar.c', 'weather-metar.c'],
+#  dependencies: libgweather_dep,
+#  install: false)
+#executable('test_sun_moon',
+#  ['test_sun_moon.c', 'weather-sun.c', 'weather-moon.c'],
+#  dependencies: libgweather_dep,
+#  install: false)
diff --git a/meson.build b/meson.build
index 64be305..e2cb4c1 100644
--- a/meson.build
+++ b/meson.build
@@ -74,11 +74,11 @@ if get_option('default_library') != 'static'
     config_h.set('DLL_EXPORT', true)
     config_h.set('GWEATHER_EXTERN', '__declspec(dllexport) extern')
     if cc.get_id() != 'msvc'
-      add_global_arguments(['-fvisibility=hidden'], language: 'c')
+      add_project_arguments(['-fvisibility=hidden'], language: 'c')
     endif
   else
     config_h.set('GWEATHER_EXTERN', '__attribute__((visibility("default"))) extern')
-    add_global_arguments(['-fvisibility=hidden'], language: 'c')
+    add_project_arguments(['-fvisibility=hidden'], language: 'c')
   endif
 endif
 
@@ -105,6 +105,8 @@ else
   enable_vala = enable_vala != 'false'
 endif
 
+root_inc = include_directories('.')
+
 subdir('libgweather')
 subdir('data')
 subdir('schemas')


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