[kdesrc-build] /: Add support for Meson build system.

Michael Pyne null at kde.org
Sat May 4 21:17:12 BST 2019


Git commit 6385f5e429dd11393b48690a33d67a66edeacfd2 by Michael Pyne.
Committed on 04/05/2019 at 20:15.
Pushed by mpyne into branch 'master'.

Add support for Meson build system.

New/updated config file options:

* 'configure-flags', reused as the way to pass cmdline options to the
meson setup command.
* 'ninja-options', a new option to pass cmdline options to the `ninja`
command. Note that ninja is mandated by Meson as the underlying build
tool.

Tested with https://github.com/plibither8/2048.cpp

Fixes #27, reviewed in !8.

Test suite passes and I continue to be able to build 2048.cpp. I've also
validated that ninja-options is passed to ninja when building 2048.cpp,
though this was a manual verification.

CCBUG:406268

M  +1    -0    CMakeLists.txt
M  +43   -2    doc/index.docbook
M  +1    -0    modules/ksb/Application.pm
M  +2    -1    modules/ksb/BuildSystem.pm
A  +71   -0    modules/ksb/BuildSystem/Meson.pm
M  +8    -0    modules/ksb/Module.pm
M  +3    -2    vim/syntax/kdesrc-buildrc.vim

https://invent.kde.org/kde/kdesrc-build/commit/6385f5e429dd11393b48690a33d67a66edeacfd2

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 28c5183..171890e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,6 +58,7 @@ if (KDESRC_BUILD_INSTALL_MODULES)
 
     install(FILES
         modules/ksb/BuildSystem/Autotools.pm
+        modules/ksb/BuildSystem/Meson.pm
         modules/ksb/BuildSystem/CMakeBootstrap.pm
         modules/ksb/BuildSystem/KDE4.pm
         modules/ksb/BuildSystem/QMake.pm
diff --git a/doc/index.docbook b/doc/index.docbook
index 409b927..bae5759 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -2438,10 +2438,15 @@ please be careful while dealing with root privileges.</entry>
 <row id="conf-make-options">
 <entry>make-options</entry>
 <entry>Module setting overrides global (build system option)</entry>
-<entry>Set this variable in order to pass command line options to the
+<entry><para>Set this variable in order to pass command line options to the
 <command>make</command> command. This is useful for programs such as <ulink
 url="https://github.com/distcc/distcc"><application>distcc</application></ulink> or
-systems with more than one processor core.
+systems with more than one processor core.</para>
+<para>Note that not all supported build systems use <command>make</command>. For
+build systems that use <command>ninja</command> for build (such as the
+<link linkend="conf-override-build-system"><application>Meson</application>
+build system</link>), see the <link linkend="conf-ninja-options">ninja-options</link>
+setting.</para>
 </entry>
 </row>
 
@@ -2499,6 +2504,36 @@ number, the "nicer" the program is. The default is 10.
 </entry>
 </row>
 
+<row id="conf-ninja-options">
+<entry>ninja-options</entry>
+<entry>Module setting overrides global (build system option)</entry>
+<entry><para>Set this variable in order to pass command line options to the
+
+<command>ninja</command> build command. This can be useful to enable <quote>verbose</quote> output
+or to manually reduce the number of parallel build jobs that <command>ninja</command> would
+use.</para>
+
+<note><para>Note that this setting only controls ninja when used by &kdesrc-build;.
+The &Qt; <quote>webengine</quote> module uses <command>ninja</command> indirectly, but
+only officially supports being built by <command>make</command>.
+In this situation, you can set <literal>NINJAFLAGS</literal> as a way to have
+<command>make</command> pass the appropriate flags when it later calls
+<command>ninja</command>, by using
+<link linkend="conf-make-options">make-options</link>.</para>
+
+<informalexample>
+<programlisting>
+options <replaceable>qtwebengine</replaceable>
+    # Restrict make and ninja to using no more than 6 separate compile jobs even
+    # when more CPU is available, to avoid running out of memory
+    <option><link linkend="conf-make-options">make-options</link></option> -j<replaceable>6</replaceable> NINJAFLAGS=-j<replaceable>6</replaceable>
+end options
+</programlisting>
+</informalexample>
+</note>
+</entry>
+</row>
+
 <row id="conf-no-svn">
 <entry>no-svn</entry>
 <entry>Module setting overrides global</entry>
@@ -2554,6 +2589,12 @@ the auto-detection. In this case you can manually specify the correct build type
         <listitem><para>This is the standard configuration tool used for most Free and
             open-source software not in any of the other categories.</para></listitem>
     </varlistentry>
+    <varlistentry>
+        <term>meson</term>
+        <listitem><para>This is a <ulink url="https://mesonbuild.com">relatively new
+            tool</ulink> gaining popularity as a replacement for the autotools and may
+            be required for some non-&kde; modules.</para></listitem>
+    </varlistentry>
 </variablelist>
 
 </entry>
diff --git a/modules/ksb/Application.pm b/modules/ksb/Application.pm
index 1ae55df..1a3d579 100644
--- a/modules/ksb/Application.pm
+++ b/modules/ksb/Application.pm
@@ -2531,6 +2531,7 @@ sub _checkForEssentialBuildPrograms
         my %requiredPackages = (
             qmake => 'Qt',
             cmake => 'CMake',
+            meson => 'Meson',
         );
 
         my $preferredPath = absPathToExecutable($prog, @preferred_paths);
diff --git a/modules/ksb/BuildSystem.pm b/modules/ksb/BuildSystem.pm
index 2053f3b..d67a79e 100644
--- a/modules/ksb/BuildSystem.pm
+++ b/modules/ksb/BuildSystem.pm
@@ -134,12 +134,13 @@ sub buildCommands
 sub buildInternal
 {
     my $self = shift;
+    my $optionsName = shift // 'make-options';
 
     return $self->safe_make({
         target => undef,
         message => 'Compiling...',
         'make-options' => [
-            split(' ', $self->module()->getOption('make-options')),
+            split(' ', $self->module()->getOption($optionsName)),
         ],
         logbase => 'build',
         subdirs => [
diff --git a/modules/ksb/BuildSystem/Meson.pm b/modules/ksb/BuildSystem/Meson.pm
new file mode 100644
index 0000000..3a93a25
--- /dev/null
+++ b/modules/ksb/BuildSystem/Meson.pm
@@ -0,0 +1,71 @@
+package ksb::BuildSystem::Meson 0.10;
+
+# This is a module used to support configuring with Meson.
+# This is required for modules like telepathy-accounts-signon
+
+use strict;
+use warnings;
+use 5.014;
+
+use parent qw(ksb::BuildSystem);
+
+use ksb::BuildException;
+use ksb::Debug;
+use ksb::Util;
+
+sub name
+{
+    return 'meson';
+}
+
+# Override
+# Return value style: boolean
+sub configureInternal
+{
+    my $self = assert_isa(shift, 'ksb::BuildSystem::Meson');
+    my $module = $self->module();
+    my $sourcedir = $module->fullpath('source');
+    my $installdir = $module->installationPath();
+
+    # 'module'-limited option grabbing can return undef, so use //
+    # to convert to empty string in that case.
+    my @setupOptions = split_quoted_on_whitespace(
+        $module->getOption('configure-flags', 'module') // '');
+
+    my $buildDir = $module->fullpath('build');
+    p_chdir($module->fullpath('source'));
+
+    return log_command($module, 'meson-setup', [
+            'meson', 'setup', $buildDir,
+            '--prefix', $installdir,
+            @setupOptions,
+        ]) == 0;
+}
+
+# Override
+sub buildInternal
+{
+    my $self = shift;
+
+    return $self->SUPER::buildInternal('ninja-options');
+}
+
+# Override
+sub buildCommands
+{
+    return 'ninja';
+}
+
+# Override
+sub requiredPrograms
+{
+    return ('meson', 'ninja');
+}
+
+# Override
+sub configuredModuleFileName
+{
+    return 'build.ninja';
+}
+
+1;
diff --git a/modules/ksb/Module.pm b/modules/ksb/Module.pm
index ff0d9c6..c53e6d5 100644
--- a/modules/ksb/Module.pm
+++ b/modules/ksb/Module.pm
@@ -34,6 +34,7 @@ use ksb::BuildSystem::Qt4;
 use ksb::BuildSystem::Qt5;
 use ksb::BuildSystem::KDE4;
 use ksb::BuildSystem::CMakeBootstrap;
+use ksb::BuildSystem::Meson;
 
 use ksb::ModuleSet::Null;
 
@@ -295,6 +296,7 @@ sub buildSystemFromName
         'qt'              => 'ksb::BuildSystem::Qt4',
         'qt5'             => 'ksb::BuildSystem::Qt5',
         'autotools'       => 'ksb::BuildSystem::Autotools',
+        'meson'           => 'ksb::BuildSystem::Meson',
     );
 
     my $class = $buildSystemClasses{lc $name} // undef;
@@ -357,6 +359,12 @@ sub buildSystem
         $buildType = ksb::BuildSystem::Autotools->new($self);
     }
 
+    # Someday move this up, but for now ensure that Meson happens after
+    # configure/autotools support is checked for.
+    if (!$buildType && -e "$sourceDir/meson.build") {
+        $buildType = ksb::BuildSystem::Meson->new($self);
+    }
+
     # Don't just assume the build system is KDE-based...
     $buildType //= ksb::BuildSystem->new($self);
 
diff --git a/vim/syntax/kdesrc-buildrc.vim b/vim/syntax/kdesrc-buildrc.vim
index 6cd4808..b55fdcc 100644
--- a/vim/syntax/kdesrc-buildrc.vim
+++ b/vim/syntax/kdesrc-buildrc.vim
@@ -1,9 +1,9 @@
 " Vim syntax file
 " Language: kdesrc-build configuration file
 " Maintainer: Michael Pyne <mpyne at kde.org>
-" Latest Revision: 23 July 2017
+" Latest Revision: 30 April 2019
 
-" Copyright (c) 2014-2017 Michael Pyne <mpyne at kde.org>
+" Copyright (c) 2014-2019 Michael Pyne <mpyne at kde.org>
 " Redistribution and use in source and binary forms, with or without
 " modification, are permitted provided that the following conditions
 " are met:
@@ -39,6 +39,7 @@ syn keyword ksbrcOption contained skipwhite nextgroup=ksbrcStringValue
             \ binpath branch build-dir checkout-only cmake-options configure-flags
             \ custom-build-command cxxflags dest-dir do-not-compile kdedir
             \ libpath log-dir make-install-prefix make-options module-base-path
+            \ ninja-options
             \ override-build-system override-url prefix qtdir repository
             \ revision source-dir svn-server tag remove-after-install
             \ qmake-options git-user


More information about the kde-doc-english mailing list