Page 1 of 1

Meson build system

Posted: Wed Mar 21, 2018 3:24 pm
by lucianodato
Hello folks! I'm investigating meson build system to use it with my projects. It seems far simpler than using makefiles. Is someone experienced with it or has any opinions of it?

Re: Meson build system

Posted: Wed Mar 21, 2018 3:56 pm
by ssj71
I've been using it extensively for work and am transitioning my personal projects to it slowly. I love it and definitely recommend!

Re: Meson build system

Posted: Fri Mar 23, 2018 1:35 am
by lucianodato
I cannot agree more. It's much more simple than make. I was able to build noise-repellent with meson but I'm struggling to ensemble ttls in order to copy them as data with the installation. I might not be able to use Robins trickery for extracting version from github. Who knows... at least I'm entertained with it at least :D and for a build system that is rare.

Re: Meson build system

Posted: Sat Mar 24, 2018 12:06 pm
by Lyberta
How does it compare to CMake?

Re: Meson build system

Posted: Mon Mar 26, 2018 6:35 pm
by ssj71
Lyberta wrote: CMake?
I switched. I feel its simpler and faster.

Re: Meson build system

Posted: Mon Mar 26, 2018 7:42 pm
by lucianodato
I was able to build noise-repellent successfully using meson but I'm not sure how to handle installing and taking into account ttl files in order to copy everything into the correct system location. I saw that you could include an external script for the installation but it doesn't seem very convenient.

Re: Meson build system

Posted: Wed Mar 28, 2018 2:57 pm
by ssj71
can't you use the install_data() function on ttl? Admittedly I haven't actually used it on a desktop project that I got as far as installing yet (only on embedded systems and WIP that I just run from the build directory). So I haven't looked into it much, I'd be surprised it if takes an external script to get this done, but on the other hand I've been able to do some very custom and complex things using python3 scripts that work fully cross platform.

Re: Meson build system

Posted: Wed Mar 28, 2018 7:34 pm
by lucianodato
Yes you could use install data perfectly but I based my makefile in one from Robin Gareus and he made some tricks with sed in order to obtain versions from github and some more things. Not to mention that manifest.ttl needs to have the correct shared object extension for multiplatform build. I guess I'll have to hardcode that or make a separate script to go ahead with meson. When I got something I will report back to share.

Re: Meson build system

Posted: Thu Mar 29, 2018 2:12 am
by lucianodato
I was able to replicate my previous makefile functionality with meson. Here is how it looks:

Code: Select all

project(
    'noise-repellent',
    'c',
    default_options: 'c_std=c99'
)

#shared object name
lv2_name = 'nrepel'

#source to compile
src = 'src/nrepel.c'

#dependencies for noise repellent
fftw_dep = dependency('fftw3f')
lv2_dep = dependency('lv2')
nr_dep = [
    fftw_dep,
    lv2_dep
]

#compiler optimization flags
cflags = [
    '-msse',
    '-msse2',
    '-mfpmath=sse',
    '-ffast-math',
    '-fomit-frame-pointer',
    '-fno-finite-math-only'
]

#linking flags (besides dependencies)
largs = [
    '-lm'
]

#install destination
i_path = '/usr/local/lib/lv2/nrepel.lv2'

#Ensamble ttl files in order to be copied to install folder
current_os = build_machine.system()

if current_os == 'linux'
  extension = '.so'
endif
if current_os == 'darwin'
  extension = '.dylib'
endif
if current_os == 'windows'
  extension = '.dll'
endif
run_command('lv2ttl/generate_ttl.sh',extension)

#add generated ttl and nrepel.ttl to be installed with the shared object
install_data(
    ['lv2ttl/manifest.ttl', 'lv2ttl/nrepel.ttl'],
    install_dir : i_path
)

#build configuration for the shared object
shared_library(
    lv2_name,
    src,
    name_prefix: '',
    dependencies: nr_dep,
    c_args: cflags,
    link_args: largs,
    install: true,
    install_dir : i_path
)
And this is the ttl script to generate the manifest ttl with the correct extension

Code: Select all

#!/bin/bash
LIB_EXT=$1
sed "s/@LIB_EXT@/$LIB_EXT/" lv2ttl/manifest.ttl.in > lv2ttl/manifest.ttl
Taking into account this manifest file

Code: Select all

@prefix lv2:  <http://lv2plug.in/ns/lv2core#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.

<https://github.com/lucianodato/noise-repellent>
  a lv2:Plugin;
  lv2:binary <nrepel@LIB_EXT@> ;
rdfs:seeAlso <nrepel.ttl> .
It does the job correctly but I'm not liking the ttl part in order to support multi os build. Maybe I'm complicating myself a bit and is much easier to handle that with some other meson magic that I don't know yet. I will appreciate any input.

Re: Meson build system

Posted: Thu Mar 29, 2018 1:53 pm
by lucianodato
It turns out as obvious that I wasn't aware of the possibility of configuring a file that meson offers. With this few lines I don't need the script that used sed to replace the lib extension

Code: Select all

#Configure manifest ttl in order to be copied to install folder
manifest_conf = configuration_data()
manifest_conf.set('LIB_EXT',extension)
configure_file(input : 'lv2ttl/manifest.ttl.in',
  output : 'manifest.ttl',
  configuration : manifest_conf)
And the final meson build is as follows

Code: Select all

project(
    'noise-repellent',
    'c',
    default_options: 'c_std=c99'
)

#shared object name
lv2_name = 'nrepel'

#source to compile
src = 'src/nrepel.c'

#dependencies for noise repellent
cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : true)
fftw_dep = dependency('fftw3f', required : true)
lv2_dep = dependency('lv2', required : true)

nr_dep = [
    m_dep,
    fftw_dep,
    lv2_dep
]

#compiler optimization flags
cflags = [
    '-msse',
    '-msse2',
    '-mfpmath=sse',
    '-ffast-math',
    '-fomit-frame-pointer',
    '-fno-finite-math-only'
]

#install destination
i_path = '/usr/local/lib/lv2/nrepel.lv2'

#build of the shared object
shared_library(
    lv2_name,
    src,
    name_prefix: '',
    dependencies: nr_dep,
    c_args: cflags,
    install: true,
    install_dir : i_path
)

#get the build operating system
current_os = build_machine.system()
if current_os == 'darwin'
  extension = '.dylib' #mac
else
  extension = '.so' #linux and others
endif
if current_os == 'windows'
  extension = '.dll' #windows
endif

#Configure manifest ttl in order to replace the correct shared object extension
manifest_conf = configuration_data()
manifest_conf.set('LIB_EXT',extension)
configure_file(input : 'lv2ttl/manifest.ttl.in',
  output : 'manifest.ttl',
  configuration : manifest_conf)

#add manifest.ttl and nrepel.ttl to be installed with the shared object
install_data(
    ['build/manifest.ttl', 'lv2ttl/nrepel.ttl'],
    install_dir : i_path
)
Now I'm pretty happy with it

Re: Meson build system

Posted: Thu Mar 29, 2018 4:12 pm
by ssj71
that looks good. the only feedback I have is that i_path should probably change to something different on windows. I don't know where the standard lv2 directories are on MacOS or Windows, but I imagine they're different.

Re: Meson build system

Posted: Thu Mar 29, 2018 4:56 pm
by lucianodato
Good catch! Something like this will fix it (not sure about windows though)

Code: Select all

#get the build operating system and configure install path and shared object extension
current_os = build_machine.system()
if current_os == 'darwin' #mac
    i_path = '/Library/Audio/Plug-Ins/LV2/nrepel.lv2'
    extension = '.dylib'
else #unix like
    i_path = '/usr/local/lib/lv2/nrepel.lv2'
    extension = '.so'
endif #windows
if current_os == 'windows'
    i_path = '%COMMONPROGRAMFILES%/LV2/nrepel.lv2'
    extension = '.dll'
endif