[pangomm] Meson build: Avoid some recompilations, and other changes



commit b5a1739fbc7bcbdcdadadb822343a0479789839b
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sun Mar 29 15:22:16 2020 +0200

    Meson build: Avoid some recompilations, and other changes
    
    * MSVC_NMake/filelist.am: Remove pangomm/copy-pangommconfig-h.py.
    * MSVC_NMake/pangomm/copy-pangommconfig-h.py: Removed file.
    * MSVC_NMake/pangomm/meson.build: Copy pangommconfig.h with configure_file().
    * Makefile.am: Distribute tools/dummy-header.py instead of tools/dist-cmd.py.
    * docs/reference/meson.build: Rename a variable.
    * meson.build: Rename some variables. Always set gmmproc_dir.
    In maintainer-mode, show its value in the summary.
    * pango/meson.build: Set pangommconfig_h.
    * pango/pangomm/meson.build: Create dummy_header.h, depending on all
    generated headers. It guarantees that all generated headers are built
    before pangomm_library is built, at the same time avoiding unnecessary
    recompilations.
    * tools/dist-cmd.py: Removed file. It's not necessary in add_dist_script()
    when the first parameter is python3.path().
    * tools/dummy-header.py: New file.

 MSVC_NMake/filelist.am                     |  1 -
 MSVC_NMake/pangomm/copy-pangommconfig-h.py | 13 -----------
 MSVC_NMake/pangomm/meson.build             | 12 +++++-----
 Makefile.am                                |  4 ++--
 docs/reference/meson.build                 | 11 ++++-----
 meson.build                                | 33 +++++++++++++++-----------
 pango/meson.build                          |  4 ++--
 pango/pangomm/meson.build                  | 37 ++++++++++++++++++++++--------
 tools/dist-cmd.py                          | 12 ----------
 tools/dummy-header.py                      | 15 ++++++++++++
 10 files changed, 76 insertions(+), 66 deletions(-)
---
diff --git a/MSVC_NMake/filelist.am b/MSVC_NMake/filelist.am
index c3cee01..7e77f51 100644
--- a/MSVC_NMake/filelist.am
+++ b/MSVC_NMake/filelist.am
@@ -11,5 +11,4 @@ msvc_nmake_data =             \
        install.mak             \
        Makefile.vc             \
        pangomm/pangomm.rc      \
-       pangomm/copy-pangommconfig-h.py \
        pangomm/pangommconfig.h
diff --git a/MSVC_NMake/pangomm/meson.build b/MSVC_NMake/pangomm/meson.build
index 7ccc189..d7c88d2 100644
--- a/MSVC_NMake/pangomm/meson.build
+++ b/MSVC_NMake/pangomm/meson.build
@@ -1,7 +1,7 @@
 # MSVC_NMake/pangomm
 
-# Input: pkg_conf_data, project_build_root
-# Output: -
+# Input: pkg_conf_data, pangommconfig_h
+# Output: pangomm_rc
 
 pangomm_rc = configure_file(
   input: 'pangomm.rc.in',
@@ -10,8 +10,8 @@ pangomm_rc = configure_file(
 )
 
 # Copy the generated configuration header into the MSVC project directory.
-meson.add_postconf_script(
-  'copy-pangommconfig-h.py',
-  project_build_root,
-  meson.current_build_dir(),
+configure_file(
+  input: pangommconfig_h,
+  output: 'pangommconfig.h',
+  copy: true,
 )
diff --git a/Makefile.am b/Makefile.am
index f5bb023..f6b6551 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -48,7 +48,7 @@ dist_noinst_SCRIPTS = autogen.sh
 
 DISTCLEANFILES = MSVC_NMake/pangomm/pangommconfig.h
 
-# Distribute files needed when building mm-common with meson.
+# Distribute files needed when building pangomm with Meson.
 EXTRA_DIST = \
   meson.build \
   meson_options.txt \
@@ -57,7 +57,7 @@ EXTRA_DIST = \
   pango/meson.build \
   pango/pangomm/meson.build \
   pango/pangommconfig.h.meson \
-  tools/dist-cmd.py \
+  tools/dummy-header.py \
   tools/extra_defs_gen/meson.build \
   untracked/README
 
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index 49ce4fd..217d0b2 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -2,7 +2,7 @@
 
 # Input: built_files_root, project_source_root, pangomm_pcname, perl,
 #        hg_ccg_basenames, extra_h_files, built_h_file_targets, install_datadir,
-#        dist_cmd, python3
+#        python3, doc_reference_py
 # Output: install_docdir, install_devhelpdir
 
 tag_file_modules = [
@@ -100,7 +100,7 @@ tag_file = custom_target('html_and_tag',
   input: doc_h_files,
   output: book_name + '.tag',
   command: [
-    python3, doc_reference, 'doxygen',
+    python3, doc_reference_py, 'doxygen',
     doctool_dir,
     '@OUTPUT@',
     src_h_files,
@@ -115,7 +115,7 @@ devhelp_file = custom_target('devhelp',
   input: tag_file,
   output: book_name + '.devhelp2',
   command: [
-    python3, doc_reference, 'devhelp',
+    python3, doc_reference_py, 'devhelp',
     doctool_dir,
     '@INPUT@',
     '@OUTPUT@',
@@ -127,7 +127,7 @@ devhelp_file = custom_target('devhelp',
 
 # Install Devhelp file and html files.
 meson.add_install_script(
-  python3.path(), doc_reference, 'install_doc',
+  python3.path(), doc_reference_py, 'install_doc',
   doctool_dir,
   devhelp_file.full_path(),
   install_devhelpdir,
@@ -151,8 +151,7 @@ if not meson.is_subproject()
   # Distribute built files and files copied by mm-common-prepare.
   # (add_dist_script() is not allowed in a subproject)
   meson.add_dist_script(
-    python3.path(), dist_cmd,
-    python3.path(), doc_reference, 'dist_doc',
+    python3.path(), doc_reference_py, 'dist_doc',
     doctool_dir,
     doctool_dist_dir,
     meson.current_build_dir(),
diff --git a/meson.build b/meson.build
index ac3874d..7840759 100644
--- a/meson.build
+++ b/meson.build
@@ -183,21 +183,19 @@ doxygen = find_program('doxygen', required: build_documentation)
 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. (N/A on MSVC builds)
+# Where to find gmmproc and generate_wrap_init.pl.
 if glibmm_dep.type_name() == 'pkgconfig'
   gmmproc_dir = glibmm_dep.get_pkgconfig_variable('gmmprocdir')
 else
-  if is_msvc
-    gmmproc_dir = get_option('gmmproc-dir')
-  endif
+  gmmproc_dir = get_option('gmmproc-dir')
 endif
 
+# Script files copied to 'untracked' by mm-common-get.
 script_dir = project_source_root / 'untracked' / 'build_scripts'
-generate_binding = script_dir / 'generate-binding.py'
-doc_reference = script_dir / 'doc-reference.py'
-dist_changelog = script_dir / 'dist-changelog.py'
-dist_build_scripts = script_dir / 'dist-build-scripts.py'
-dist_cmd = project_source_root / 'tools' / 'dist-cmd.py' # Must be committed to git.
+generate_binding_py = script_dir / 'generate-binding.py'
+doc_reference_py = script_dir / 'doc-reference.py'
+dist_changelog_py = script_dir / 'dist-changelog.py'
+dist_build_scripts_py = script_dir / 'dist-build-scripts.py'
 
 if maintainer_mode and mm_common_get.found()
   # Copy files to untracked/build_scripts and untracked/docs.
@@ -205,6 +203,10 @@ if maintainer_mode and mm_common_get.found()
     project_source_root / 'untracked' / 'docs')
 endif
 
+# pangomm's own script files.
+pangomm_script_dir = project_source_root / 'tools'
+dummy_header_py = pangomm_script_dir / 'dummy-header.py'
+
 # Set compiler warnings.
 warning_flags = []
 if warning_level == 'min'
@@ -254,15 +256,13 @@ if not meson.is_subproject()
   # Add a ChangeLog file to the distribution directory.
   # (add_dist_script() is not allowed in a subproject)
   meson.add_dist_script(
-    python3.path(), dist_cmd,
-    python3.path(), dist_changelog,
+    python3.path(), dist_changelog_py,
     project_source_root,
   )
   # Add build scripts to the distribution directory, and delete .gitignore
   # files and an empty $MESON_DIST_ROOT/build/ directory.
   meson.add_dist_script(
-    python3.path(), dist_cmd,
-    python3.path(), dist_build_scripts,
+    python3.path(), dist_build_scripts_py,
     project_source_root,
     'untracked' / 'build_scripts',
   )
@@ -299,7 +299,12 @@ summary = [
   '                 datadir: @0@'.format(install_prefix / install_datadir),
   '                  docdir: @0@'.format(install_prefix / install_docdir),
   '              devhelpdir: @0@'.format(install_prefix / install_devhelpdir),
-  '------'
 ]
+if maintainer_mode
+  summary += [
+    '              gmmprocdir: @0@'.format(gmmproc_dir),
+  ]
+endif
+summary += ['------']
 
 message('\n'.join(summary))
diff --git a/pango/meson.build b/pango/meson.build
index 368bd35..4cb992b 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -4,7 +4,7 @@
 #        pangomm_pcname, pangomm_api_version, pangomm_requires,
 #        install_pkgconfigdir, install_libdir, build_deprecated_api,
 #        pangomm_major_version, pangomm_minor_version, pangomm_micro_version
-# Output: pkg_conf_data, install_includeconfigdir
+# Output: pkg_conf_data, install_includeconfigdir, pangommconfig_h
 
 pkg_conf_data = configuration_data()
 pkg_conf_data.set('prefix', install_prefix)
@@ -41,7 +41,7 @@ configure_file(
 )
 
 install_includeconfigdir = install_libdir / pangomm_pcname / 'include'
-configure_file(
+pangommconfig_h = configure_file(
   input: 'pangommconfig.h.meson',
   output: 'pangommconfig.h',
   configuration: pkg_conf_data,
diff --git a/pango/pangomm/meson.build b/pango/pangomm/meson.build
index 9e1fa29..34c68f2 100644
--- a/pango/pangomm/meson.build
+++ b/pango/pangomm/meson.build
@@ -1,8 +1,8 @@
 # pango/pangomm
 
 # Input: pangomm_build_dep, pangomm_pcname, maintainer_mode, project_source_root,
-#        generate_binding, m4_files, pangomm_libversion, install_includedir,
-#        dist_cmd, python3, pangomm_rc
+#        generate_binding_py, m4_files, pangomm_libversion, install_includedir,
+#        python3, pangomm_rc, dummy_header_py, gmmproc_dir
 # Output: hg_ccg_basenames, extra_h_files, built_h_file_targets, built_files_root,
 #         pangomm_dep
 
@@ -80,7 +80,7 @@ if maintainer_mode
 
   # Maintainer mode. Generate .h and .cc files from .hg and .ccg files in ../src.
 
-  # docs/reference/meson.build needs this.
+  # docs/reference/meson.build needs these.
   built_files_root = project_build_root
   built_h_file_targets = []
 
@@ -98,7 +98,7 @@ if maintainer_mode
     input: hg_files,
     output: 'wrap_init.cc',
     command: [
-      python3, generate_binding, 'generate_wrap_init',
+      python3, generate_binding_py, 'generate_wrap_init',
       gmmproc_dir,
       '@OUTPUT@',
       'Pango', # namespace
@@ -116,7 +116,7 @@ if maintainer_mode
       input: [hg_file, ccg_file],
       output: [file + '.stamp', file + '.cc', file + '.h'],
       command: [
-        python3, generate_binding, 'gmmproc',
+        python3, generate_binding_py, 'gmmproc',
         gmmproc_dir,
         '@OUTPUT0@',
         file,
@@ -131,10 +131,28 @@ if maintainer_mode
     built_h_file_targets += built_file_target[2]
   endforeach
 
+  # Create dummy_header.h, depending on all generated headers.
+  # It's created if it does not exist, but it's never updated.
+  # It guarantees that all generated headers are built before pangomm_library
+  # is built, at the same time avoiding unnecessary recompilations.
+  # If built_h_file_targets would be listed as sources to pangomm_library,
+  # all generated .cc files could be recompiled if one generated .h file has
+  # been changed.
+  built_dummy_h_file_target = custom_target('dummy_header.h',
+    input: built_h_file_targets,
+    output: 'dummy_header.h',
+    command: [
+      python3, dummy_header_py,
+      '@OUTPUT@',
+    ],
+    build_by_default: maintainer_mode,
+    install: false,
+  )
+
   extra_include_dirs = ['..']
 
   pangomm_library = library(pangomm_pcname, extra_pangomm_objects,
-    built_cc_file_targets, built_h_file_targets, extra_cc_files,
+    built_cc_file_targets, extra_cc_files, built_dummy_h_file_target,
     version: pangomm_libversion,
     include_directories: extra_include_dirs,
     cpp_args: pangomm_cpp_args,
@@ -163,7 +181,7 @@ else # not maintainer_mode
 
   # Try to copy built source code files to the source tree.
   run_command(
-    python3, generate_binding, 'copy_built_files',
+    python3, generate_binding_py, 'copy_built_files',
     meson.current_build_dir(),
     src_untracked_pangomm,
     hg_ccg_basenames,
@@ -191,7 +209,7 @@ endif
 
 # Install built .h and _p.h files.
 meson.add_install_script(
-  python3.path(), generate_binding, 'install_built_h_files',
+  python3.path(), generate_binding_py, 'install_built_h_files',
   built_h_cc_dir,
   install_includedir / pangomm_pcname / 'pangomm', # subdir below {prefix}
   hg_ccg_basenames
@@ -201,8 +219,7 @@ if not meson.is_subproject()
   # Distribute built files.
   # (add_dist_script() is not allowed in a subproject)
   meson.add_dist_script(
-    python3.path(), dist_cmd,
-    python3.path(), generate_binding, 'dist_built_files',
+    python3.path(), generate_binding_py, 'dist_built_files',
     built_h_cc_dir,
     untracked_pangomm,
     hg_ccg_basenames,
diff --git a/tools/dummy-header.py b/tools/dummy-header.py
new file mode 100755
index 0000000..8c61464
--- /dev/null
+++ b/tools/dummy-header.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+# External command, intended to be called with custom_target() in meson.build.
+
+# dummy-header.py <output_file>
+
+import os
+import sys
+
+output_file = sys.argv[1]
+
+# A dummy header file is created if it does not exist, but it's never updated.
+if not os.path.isfile(output_file):
+  with open(output_file, 'w') as f:
+    f.write('// Dummy header file. Created and used by meson.build\n')


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