Commit 6385f5e4 authored by Michael Pyne's avatar Michael Pyne

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

Tested with

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.

parent e54200ee
Pipeline #3087 passed with stage
in 1 minute and 14 seconds
......@@ -58,6 +58,7 @@ if (KDESRC_BUILD_INSTALL_MODULES)
......@@ -2438,10 +2438,15 @@ please be careful while dealing with root privileges.</entry>
<row id="conf-make-options">
<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=""><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>
......@@ -2499,6 +2504,36 @@ number, the "nicer" the program is. The default is 10.
<row id="conf-ninja-options">
<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
<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>
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
<row id="conf-no-svn">
<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>
<listitem><para>This is a <ulink url="">relatively new
tool</ulink> gaining popularity as a replacement for the autotools and may
be required for some non-&kde; modules.</para></listitem>
......@@ -2531,6 +2531,7 @@ sub _checkForEssentialBuildPrograms
my %requiredPackages = (
qmake => 'Qt',
cmake => 'CMake',
meson => 'Meson',
my $preferredPath = absPathToExecutable($prog, @preferred_paths);
......@@ -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 => [
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');
return log_command($module, 'meson-setup', [
'meson', 'setup', $buildDir,
'--prefix', $installdir,
]) == 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 '';
......@@ -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/") {
$buildType = ksb::BuildSystem::Meson->new($self);
# Don't just assume the build system is KDE-based...
$buildType //= ksb::BuildSystem->new($self);
" Vim syntax file
" Language: kdesrc-build configuration file
" Maintainer: Michael Pyne <>
" Latest Revision: 23 July 2017
" Latest Revision: 30 April 2019
" Copyright (c) 2014-2017 Michael Pyne <>
" Copyright (c) 2014-2019 Michael Pyne <>
" 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment