[glibmm] Meson build: Make it possible to use glibmm as a subproject



commit 3ec8bdad019572c518d2fee17040b46a161d6f40
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Mar 12 17:03:03 2021 +0100

    Meson build: Make it possible to use glibmm as a subproject
    
    glib and sigc++ can be subprojects of glibmm.

 Makefile.am                      |  2 ++
 docs/reference/meson.build       |  8 ++---
 examples/meson.build             |  4 +--
 gio/giomm/meson.build            |  8 ++---
 glib/glibmm/meson.build          |  8 ++---
 meson.build                      | 67 +++++++++++++++++++++++++++++++++++++++-
 subprojects/glib.wrap            |  8 +++++
 subprojects/sigc++-3.0.wrap      |  8 +++++
 tests/meson.build                |  4 +--
 tools/extra_defs_gen/meson.build | 16 +++++++++-
 tools/meson.build                |  3 +-
 11 files changed, 117 insertions(+), 19 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 902243e3..ea59ff69 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,6 +67,8 @@ EXTRA_DIST = \
   gio/meson.build \
   gio/giommconfig.h.meson \
   gio/giomm/meson.build \
+  subprojects/glib.wrap \
+  subprojects/sigc++-3.0.wrap \
   tests/meson.build \
   tools/meson.build \
   tools/build_scripts/compile-schemas.py \
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index 2ea2cc71..1c3e7579 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -5,7 +5,7 @@
 #        glibmm_extra_h_files, giomm_extra_h_files, glibmm_built_h_file_targets,
 #        giomm_built_h_file_targets, glibmm_h_m4_files, install_datadir,
 #        python3, doc_reference_py
-# Output: install_docdir, install_devhelpdir
+# Output: install_docdir, install_devhelpdir, tag_file
 
 tag_file_modules = [
   'mm-common-libstdc++',
@@ -16,9 +16,9 @@ docinstall_flags = []
 foreach module : tag_file_modules
   depmod = dependency(module, required: false)
   if depmod.found()
-    doxytagfile = depmod.get_pkgconfig_variable('doxytagfile')
-    htmlrefpub = depmod.get_pkgconfig_variable('htmlrefpub', default: '')
-    htmlrefdir = depmod.get_pkgconfig_variable('htmlrefdir', default: '')
+    doxytagfile = depmod.get_variable(pkgconfig: 'doxytagfile', internal: 'doxytagfile')
+    htmlrefpub = depmod.get_variable(pkgconfig: 'htmlrefpub', internal: 'htmlrefpub', default_value: '')
+    htmlrefdir = depmod.get_variable(pkgconfig: 'htmlrefdir', internal: 'htmlrefdir', default_value: '')
     if htmlrefpub == ''
       htmlrefpub = htmlrefdir
     elif htmlrefdir == ''
diff --git a/examples/meson.build b/examples/meson.build
index 43e79d4a..802a1bf8 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -1,6 +1,6 @@
 # examples
 
-# input: glibmm_dep, giomm_dep, build_examples, compile_schemas_py
+# input: glibmm_own_dep, giomm_own_dep, build_examples, compile_schemas_py
 
 examples = [
 # [[dir-name], exe-name, [sources], giomm-example (not just glibmm-example)]
@@ -63,7 +63,7 @@ foreach ex : examples
   endforeach
 
   is_multithread = ex[0][0] == 'network' or ex[0][0] == 'thread'
-  mm_dep = ex[3] ? giomm_dep : glibmm_dep
+  mm_dep = ex[3] ? giomm_own_dep : glibmm_own_dep
 
   executable(ex_name, ex_sources,
     cpp_args: ['-DGLIBMM_DISABLE_DEPRECATED', '-DGIOMM_DISABLE_DEPRECATED'],
diff --git a/gio/giomm/meson.build b/gio/giomm/meson.build
index 94b32eb3..ecb7efa8 100644
--- a/gio/giomm/meson.build
+++ b/gio/giomm/meson.build
@@ -6,7 +6,7 @@
 #        is_host_windows, gmmproc, generate_wrap_init_pl, giomm_libname,
 #        macos_darwin_versions
 # Output: giomm_hg_ccg_basenames, giomm_extra_h_files, built_files_root,
-#         giomm_built_h_file_targets, giomm_dep
+#         giomm_built_h_file_targets, giomm_own_dep
 
 giomm_defs_basefiles = [
   'gio.defs',
@@ -390,9 +390,9 @@ if not meson.is_subproject()
   )
 endif
 
-# This is useful in the main project when giomm is used as a subproject.
-# It's also used when building example programs and test programs.
-giomm_dep = declare_dependency(
+# This is used when building example programs and test programs.
+# It's also a part of giomm_dep, when glibmm is a subproject.
+giomm_own_dep = declare_dependency(
   sources: glibmm_built_h_file_targets + giomm_used_built_h_file_targets,
   link_with: [glibmm_library, giomm_library],
   include_directories: extra_include_dirs,
diff --git a/glib/glibmm/meson.build b/glib/glibmm/meson.build
index 4bd78c9e..72370378 100644
--- a/glib/glibmm/meson.build
+++ b/glib/glibmm/meson.build
@@ -6,7 +6,7 @@
 #        is_host_windows, gmmproc, generate_wrap_init_pl, glibmm_libname,
 #        macos_darwin_versions
 # Output: glibmm_hg_ccg_basenames, glibmm_extra_h_files, built_files_root,
-#         glibmm_built_h_file_targets, glibmm_h_m4_files, glibmm_dep
+#         glibmm_built_h_file_targets, glibmm_h_m4_files, glibmm_own_dep
 
 glibmm_defs_basefiles = [
   'glib.defs',
@@ -343,9 +343,9 @@ if not meson.is_subproject()
   )
 endif
 
-# This is useful in the main project when glibmm is used as a subproject.
-# It's also used when building example programs and test programs.
-glibmm_dep = declare_dependency(
+# This is used when building example programs and test programs.
+# It's also a part of glibmm_dep, when glibmm is a subproject.
+glibmm_own_dep = declare_dependency(
   sources: glibmm_built_h_file_targets,
   link_with: glibmm_library,
   include_directories: extra_include_dirs,
diff --git a/meson.build b/meson.build
index 97976457..fdc59966 100644
--- a/meson.build
+++ b/meson.build
@@ -6,7 +6,7 @@ project('glibmm', 'cpp',
   default_options: [
     'cpp_std=c++17'
   ],
-  meson_version: '>= 0.50.0', # required for python3.path()
+  meson_version: '>= 0.54.0', # required for meson.override_dependency()
 )
 
 glibmm_api_version = '2.68'
@@ -254,6 +254,71 @@ if not meson.is_subproject()
     project_source_root,
     'untracked' / 'build_scripts',
   )
+else
+  # This is a subproject.
+
+  # A version of gmmproc that can be executed uninstalled by a main project.
+  conf_data_subproj = configuration_data()
+  conf_data_subproj.merge_from(gmmproc_conf_data)
+  conf_data_subproj.set('configure_input', 'tools/gmmproc (for execution uninstalled).  Generated from 
gmmproc.in')
+  conf_data_subproj.set('libdir', project_build_root)
+  gmmproc_subproj = configure_file(
+    input: 'tools' / 'gmmproc.in',
+    output: '@BASENAME@',
+    configuration: conf_data_subproj,
+    install: false,
+  )
+  gmmproc_subproj_dir = project_build_root / glibmm_pcname / 'proc'
+  run_command(
+    python3, handle_built_files_py, 'copy_built_files',
+    project_build_root,
+    gmmproc_subproj_dir,
+    'gmmproc',
+  )
+  run_command(
+    python3, handle_built_files_py, 'copy_built_files',
+    project_build_root / 'tools',
+    gmmproc_subproj_dir,
+    'generate_wrap_init.pl',
+  )
+
+  # Copy files needed by gmmproc from source dir to build dir.
+  # The directory structure must be the same as in the installation directory.
+  run_command(
+    python3, handle_built_files_py, 'copy_built_files',
+    project_source_root / 'tools' / 'm4',
+    gmmproc_subproj_dir / 'm4',
+    m4_basefiles,
+  )
+  run_command(
+    python3, handle_built_files_py, 'copy_built_files',
+    project_source_root / 'tools' / 'pm',
+    gmmproc_subproj_dir / 'pm',
+    pm_basefiles,
+  )
+
+  glibmm_dep = declare_dependency(
+    dependencies: glibmm_own_dep,
+    variables: {
+      'gmmprocdir': gmmproc_subproj_dir,
+      'doxytagfile': tag_file.full_path(),
+      'htmlrefdir': install_prefix / install_docdir / 'reference' / 'html',
+      'htmlrefpub': 'http://library.gnome.org/devel/' + pkg_conf_data.get_unquoted('PACKAGE_TARNAME') + 
'/unstable/'
+    }
+  )
+  giomm_dep = declare_dependency(
+    dependencies: giomm_own_dep,
+    variables: {
+      'doxytagfile': tag_file.full_path(),
+      'htmlrefdir': install_prefix / install_docdir / 'reference' / 'html',
+      'htmlrefpub': 'http://library.gnome.org/devel/' + pkg_conf_data.get_unquoted('PACKAGE_TARNAME') + 
'/unstable/'
+    }
+  )
+
+  # A main project that looks for glibmm_pcname.pc and giomm_pcname.pc
+  # shall find glibmm_dep and giomm_dep.
+  meson.override_dependency(glibmm_pcname, glibmm_dep)
+  meson.override_dependency(giomm_pcname, giomm_dep)
 endif
 
 # Print a summary.
diff --git a/subprojects/glib.wrap b/subprojects/glib.wrap
new file mode 100644
index 00000000..a6827389
--- /dev/null
+++ b/subprojects/glib.wrap
@@ -0,0 +1,8 @@
+[wrap-git]
+directory=glib
+url=https://gitlab.gnome.org/GNOME/glib.git
+revision=master
+depth=1
+
+[provide]
+dependency_names = glib-2.0, gobject-2.0, gmodule-2.0, gio-2.0, gio-unix-2.0
diff --git a/subprojects/sigc++-3.0.wrap b/subprojects/sigc++-3.0.wrap
new file mode 100644
index 00000000..8d8c543c
--- /dev/null
+++ b/subprojects/sigc++-3.0.wrap
@@ -0,0 +1,8 @@
+[wrap-git]
+directory=libsigcplusplus
+url=https://github.com/libsigcplusplus/libsigcplusplus.git
+revision=master
+depth=1
+
+[provide]
+dependency_names = sigc++-3.0
diff --git a/tests/meson.build b/tests/meson.build
index 07985851..814bce83 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,6 +1,6 @@
 # tests
 
-# input: glibmm_dep, giomm_dep
+# input: glibmm_own_dep, giomm_own_dep
 
 test_programs = [
 # [[dir-name], exe-name, [sources], giomm-example (not just glibmm-example)]
@@ -54,7 +54,7 @@ foreach ex : test_programs
   endforeach
 
   is_multithread = ex[0][0] == 'glibmm_mainloop'
-  mm_dep = ex[3] ? giomm_dep : glibmm_dep
+  mm_dep = ex[3] ? giomm_own_dep : glibmm_own_dep
 
   exe_file = executable(ex_name, ex_sources,
     cpp_args: ['-DGLIBMM_DISABLE_DEPRECATED', '-DGIOMM_DISABLE_DEPRECATED'],
diff --git a/tools/extra_defs_gen/meson.build b/tools/extra_defs_gen/meson.build
index 0cc3cfba..df4ca5a2 100644
--- a/tools/extra_defs_gen/meson.build
+++ b/tools/extra_defs_gen/meson.build
@@ -2,7 +2,7 @@
 
 # Input: glibmm_build_dep, giomm_build_dep, glibmm_api_version,
 #        glibmm_libversion, glibmm_pcname, msvc14x_toolset_ver,
-#        macos_darwin_versions
+#        macos_darwin_versions, handle_built_files_py, project_build_root
 # Output: -
 
 glibmm_generate_extra_defs_library = library(
@@ -15,6 +15,20 @@ glibmm_generate_extra_defs_library = library(
   install: true,
 )
 
+if meson.is_subproject()
+  glibmm_generate_extra_defs_dep = declare_dependency(
+    link_with: glibmm_generate_extra_defs_library,
+  )
+
+  # Copy the header file to a place where a main project can find it.
+  run_command(
+    python3, handle_built_files_py, 'copy_built_files',
+    meson.current_source_dir(),
+    project_build_root / 'glib' / 'glibmm_generate_extra_defs',
+    'generate_extra_defs.h',
+  )
+endif
+
 install_headers('generate_extra_defs.h', subdir: glibmm_pcname / 'glibmm_generate_extra_defs')
 
 executable('generate_defs_glib', 'generate_defs_glib.cc',
diff --git a/tools/meson.build b/tools/meson.build
index ed7443dd..370c8f3f 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -1,7 +1,8 @@
 # tools
 
 # Input: perl, m4, install_prefix, install_libdir, glibmm_pcname
-# Output: install_procdir, m4_files, pm_files, gmmproc, generate_wrap_init_pl
+# Output: install_procdir, m4_basefiles, m4_files, pm_basefiles, pm_files,
+#         gmmproc_conf_data, gmmproc, generate_wrap_init_pl
 
 subdir('extra_defs_gen')
 


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