[mm-common] skeletonmm: Make it possible to use it as a subproject



commit 443f53589f53badf84f84a6d6395ea44f2cf9e56
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sun May 16 15:42:16 2021 +0200

    skeletonmm: Make it possible to use it as a subproject
    
    skeleton and glibmm can be subprojects of skeletonmm.

 skeletonmm/doc/reference/meson.build        | 34 +++++++++++++++--------------
 skeletonmm/examples/meson.build             |  4 ++--
 skeletonmm/meson.build                      | 32 +++++++++++++++++++++++----
 skeletonmm/skeleton/skeletonmm.pc.in        |  2 ++
 skeletonmm/skeleton/skeletonmm/meson.build  |  8 +++----
 skeletonmm/subprojects/glibmm-2.4.wrap      |  8 +++++++
 skeletonmm/subprojects/glibmm-2.68.wrap     |  8 +++++++
 skeletonmm/subprojects/skeleton-1.0.wrap    |  8 +++++++
 skeletonmm/tests/meson.build                |  4 ++--
 skeletonmm/tools/extra_defs_gen/meson.build | 10 ++++++++-
 10 files changed, 89 insertions(+), 29 deletions(-)
---
diff --git a/skeletonmm/doc/reference/meson.build b/skeletonmm/doc/reference/meson.build
index a1ee30c..fdaf840 100644
--- a/skeletonmm/doc/reference/meson.build
+++ b/skeletonmm/doc/reference/meson.build
@@ -3,7 +3,7 @@
 # Input: built_files_root, project_source_root, skeletonmm_pcname, python3,
 #        hg_ccg_basenames, extra_h_files, built_h_file_targets, install_datadir,
 #        doc_reference, can_add_dist_script
-# Output: install_docdir, install_devhelpdir
+# Output: install_docdir, install_devhelpdir, if build_documentation: tag_file
 
 tag_file_modules = [
   'mm-common-libstdc++',
@@ -19,21 +19,23 @@ docinstall_flags = []
 foreach module : tag_file_modules
   depmod = dependency(module, required: false)
   if depmod.found()
-    doxytagfile = depmod.get_variable(pkgconfig: 'doxytagfile')
-    htmlrefpub = depmod.get_variable(pkgconfig: 'htmlrefpub', default_value: '')
-    htmlrefdir = depmod.get_variable(pkgconfig: 'htmlrefdir', default_value: '')
-    if htmlrefpub == ''
-      htmlrefpub = htmlrefdir
-    elif htmlrefdir == ''
-      htmlrefdir = htmlrefpub
-    endif
-    doxygen_tagfiles += ' "' + doxytagfile + '=' + htmlrefpub + '"'
-
-    # Doxygen <= 1.8.15
-    docinstall_flags += ['-l', doxytagfile.split('/')[-1] + '@' + htmlrefdir]
-    if htmlrefpub != htmlrefdir
-      # Doxygen >= 1.8.16
-      docinstall_flags += ['-l', 's@' + htmlrefpub + '@' + htmlrefdir]
+    doxytagfile = depmod.get_variable(pkgconfig: 'doxytagfile', internal: 'doxytagfile', default_value: '')
+    if 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 == ''
+        htmlrefdir = htmlrefpub
+      endif
+      doxygen_tagfiles += ' "' + doxytagfile + '=' + htmlrefpub + '"'
+
+      # Doxygen <= 1.8.15
+      docinstall_flags += ['-l', doxytagfile.split('/')[-1] + '@' + htmlrefdir]
+      if htmlrefpub != htmlrefdir
+        # Doxygen >= 1.8.16
+        docinstall_flags += ['-l', 's@' + htmlrefpub + '@' + htmlrefdir]
+      endif
     endif
   endif
 endforeach
diff --git a/skeletonmm/examples/meson.build b/skeletonmm/examples/meson.build
index 04375fb..e76a99b 100644
--- a/skeletonmm/examples/meson.build
+++ b/skeletonmm/examples/meson.build
@@ -1,6 +1,6 @@
 # examples
 
-# input: gnome, skeletonmm_dep, build_examples
+# input: gnome, skeletonmm_own_dep, build_examples
 
 examples = [
 # [[dir-name], exe-name, [sources]]
@@ -27,7 +27,7 @@ foreach ex : examples
   endforeach
 
   exe_file = executable(ex_name, ex_sources, resources,
-    dependencies: skeletonmm_dep,
+    dependencies: skeletonmm_own_dep,
     implicit_include_directories: false,
     gui_app: true,
     build_by_default: build_examples
diff --git a/skeletonmm/meson.build b/skeletonmm/meson.build
index 982a4b1..e13a356 100644
--- a/skeletonmm/meson.build
+++ b/skeletonmm/meson.build
@@ -6,7 +6,8 @@ project('skeletonmm', 'cpp',
   default_options: [
     'cpp_std=c++17'
   ],
-  meson_version: '>= 0.51.0', # required for dep.get_variable()
+  meson_version: '>= 0.54.0', # required for meson.override_dependency()
+                              # and dep.get_variable(internal:)
 )
 
 skeletonmm_api_version = '1.0'
@@ -87,7 +88,7 @@ install_pkgconfigdir = install_libdir / 'pkgconfig'
 
 # Dependencies.
 # skeletonmm_build_dep: Dependencies when building the skeletonmm library.
-# skeletonmm_dep (created in skeleton/skeletonmm/meson.build):
+# skeletonmm_own_dep (created in skeleton/skeletonmm/meson.build):
 #   Dependencies when using the skeletonmm library.
 glibmm_req = '>= 2.68.0' # E.g. >= 2.66.0 if the dependency is glibmm-2.4
 skeleton_req = '>= 1.0.0'
@@ -106,7 +107,11 @@ gnome = import('gnome')
 # reference documentation shall be built.
 mm_common_get = find_program('mm-common-get', required: false)
 if maintainer_mode and not mm_common_get.found()
-  error('mm-common-get not found. mm-common >= 1.0.0 is required.')
+  message('Maintainer mode requires the \'mm-common-get\' command. If it is not found,\n' +
+          'install the \'mm-common\' package, version 1.0.0 or higher.')
+  # If meson --wrap-mode != forcefallback, Meson falls back to the mm-common
+  # subproject only if mm-common-get is required.
+  mm_common_get = find_program('mm-common-get', required: true)
 endif
 m4 = find_program('m4', required: maintainer_mode) # Used by gmmproc (in glibmm)
 perl = find_program('perl', required: maintainer_mode or build_documentation)
@@ -115,7 +120,7 @@ dot = find_program('dot', required: build_documentation) # Used by Doxygen
 xsltproc = find_program('xsltproc', required: build_documentation)
 
 # Where to find gmmproc and generate_wrap_init.pl.
-gmmproc_dir = glibmm_dep.get_variable(pkgconfig: 'gmmprocdir')
+gmmproc_dir = glibmm_dep.get_variable(pkgconfig: 'gmmprocdir', internal: 'gmmprocdir')
 
 # Script files copied to 'untracked' by mm-common-get.
 script_dir = project_source_root / 'untracked' / 'build_scripts'
@@ -185,6 +190,25 @@ if can_add_dist_script
   )
 endif
 
+if meson.is_subproject()
+  pkgconfig_vars = {
+    'gmmprocm4dir': project_source_root / 'tools' / 'm4',
+    'htmlrefdir': install_prefix / install_docdir / 'reference' / 'html',
+    'htmlrefpub': 'http://library.gnome.org/devel/' + pkg_conf_data.get_unquoted('PACKAGE_TARNAME') + 
'/unstable/'
+  }
+  if build_documentation
+    pkgconfig_vars += {'doxytagfile': tag_file.full_path()}
+  endif
+  skeletonmm_dep = declare_dependency(
+    dependencies: skeletonmm_own_dep,
+    variables: pkgconfig_vars,
+  )
+
+  # A main project that looks for skeletonmm_pcname.pc shall find skeletonmm_dep.
+  meson.override_dependency(skeletonmm_pcname, skeletonmm_dep)
+endif
+
+
 # Print a summary.
 real_maintainer_mode = ''
 if maintainer_mode_opt == 'if-git-build'
diff --git a/skeletonmm/skeleton/skeletonmm.pc.in b/skeletonmm/skeleton/skeletonmm.pc.in
index b92cf53..4d18a97 100644
--- a/skeletonmm/skeleton/skeletonmm.pc.in
+++ b/skeletonmm/skeleton/skeletonmm.pc.in
@@ -5,6 +5,8 @@ datarootdir=@datarootdir@
 datadir=@datadir@
 includedir=@includedir@
 
+gmmprocm4dir=${libdir}/@SKELETONMM_MODULE_NAME@/proc/m4
+
 docdir=${datarootdir}/doc/@SKELETONMM_MODULE_NAME@
 doxytagfile=${docdir}/reference/@SKELETONMM_MODULE_NAME@.tag
 htmlrefdir=${docdir}/reference/html
diff --git a/skeletonmm/skeleton/skeletonmm/meson.build b/skeletonmm/skeleton/skeletonmm/meson.build
index 8e41ba5..a0760b5 100644
--- a/skeletonmm/skeleton/skeletonmm/meson.build
+++ b/skeletonmm/skeleton/skeletonmm/meson.build
@@ -4,7 +4,7 @@
 #        generate_binding, m4_files, skeletonmm_libversion, install_includedir,
 #        macos_darwin_versions, python3, can_add_dist_script
 # Output: hg_ccg_basenames, extra_h_files, built_h_file_targets, built_files_root,
-#         skeletonmm_dep
+#         skeletonmm_own_dep
 
 defs_basefiles = [
   'skeleton.defs',
@@ -169,9 +169,9 @@ if can_add_dist_script
   )
 endif
 
-# This is useful in the main project when skeletonmm is used as a subproject.
-# It's also used when building example programs and test programs.
-skeletonmm_dep = declare_dependency(
+# This is used when building example programs and test programs.
+# It's also a part of skeletonmm_dep, when skeletonmm is a subproject.
+skeletonmm_own_dep = declare_dependency(
   sources: built_h_file_targets,
   link_with: skeletonmm_library,
   include_directories: extra_include_dirs,
diff --git a/skeletonmm/subprojects/glibmm-2.4.wrap b/skeletonmm/subprojects/glibmm-2.4.wrap
new file mode 100644
index 0000000..a7f7855
--- /dev/null
+++ b/skeletonmm/subprojects/glibmm-2.4.wrap
@@ -0,0 +1,8 @@
+[wrap-git]
+directory=glibmm-2.4
+url=https://gitlab.gnome.org/GNOME/glibmm.git
+revision=glibmm-2-66
+depth=1
+
+[provide]
+dependency_names = glibmm-2.4, giomm-2.4
diff --git a/skeletonmm/subprojects/glibmm-2.68.wrap b/skeletonmm/subprojects/glibmm-2.68.wrap
new file mode 100644
index 0000000..a0fef48
--- /dev/null
+++ b/skeletonmm/subprojects/glibmm-2.68.wrap
@@ -0,0 +1,8 @@
+[wrap-git]
+directory=glibmm
+url=https://gitlab.gnome.org/GNOME/glibmm.git
+revision=master
+depth=1
+
+[provide]
+dependency_names = glibmm-2.68, giomm-2.68
diff --git a/skeletonmm/subprojects/skeleton-1.0.wrap b/skeletonmm/subprojects/skeleton-1.0.wrap
new file mode 100644
index 0000000..6a99d13
--- /dev/null
+++ b/skeletonmm/subprojects/skeleton-1.0.wrap
@@ -0,0 +1,8 @@
+[wrap-git]
+directory=skeleton
+url=https://gitlab.gnome.org/GNOME/skeleton.git
+revision=master
+depth=1
+
+[provide]
+skeleton-1.0 = libskeleton_dep
diff --git a/skeletonmm/tests/meson.build b/skeletonmm/tests/meson.build
index c0c6864..49a5baf 100644
--- a/skeletonmm/tests/meson.build
+++ b/skeletonmm/tests/meson.build
@@ -1,6 +1,6 @@
 # tests
 
-# input: gnome, skeletonmm_dep
+# input: gnome, skeletonmm_own_dep
 
 tests = [
 # [[dir-name], exe-name, [sources]]
@@ -28,7 +28,7 @@ foreach ex : tests
   endforeach
 
   exe_file = executable(ex_name, ex_sources, resources,
-    dependencies: skeletonmm_dep,
+    dependencies: skeletonmm_own_dep,
     implicit_include_directories: false,
     gui_app: false,
     build_by_default: true
diff --git a/skeletonmm/tools/extra_defs_gen/meson.build b/skeletonmm/tools/extra_defs_gen/meson.build
index 05d0b5e..4d0ae6e 100644
--- a/skeletonmm/tools/extra_defs_gen/meson.build
+++ b/skeletonmm/tools/extra_defs_gen/meson.build
@@ -1,12 +1,20 @@
 # tools/extra_defs_gen
 
-# Input: cpp_compiler, skeletonmm_build_dep, install_libdir, skeletonmm_pcname
+# Input: cpp_compiler, skeletonmm_build_dep, install_libdir, skeletonmm_pcname,
+#        glibmm_dep
 # Output: m4_files, install_m4dir
 
 glibmm_generate_extra_defs_dep = cpp_compiler.find_library(
   'glibmm_generate_extra_defs-2.68',
 # or:  'glibmm_generate_extra_defs-2.4',
+  required: glibmm_dep.type_name() != 'internal',
 )
+if not glibmm_generate_extra_defs_dep.found()
+  glibmm_generate_extra_defs_dep = dependency(
+    '', fallback: ['glibmm-2.68', 'glibmm_generate_extra_defs_dep'],
+# or:    '', fallback: ['glibmm-2.4', 'glibmm_generate_extra_defs_dep'],
+  )
+endif
 
 executable('generate_defs_skeleton', 'generate_defs_skeleton.cc',
   dependencies: [skeletonmm_build_dep, glibmm_generate_extra_defs_dep],


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