• Uncategorized

About linux : Project-structure-for-meson

Question Detail

With the following project structure

pj
|-src
   |-pj.c
   |-meson.build
|-meson.build

where pj/meson.build is

project('pj', 'c', version : '0.1')
subdir('src')
library('pj', sources : srcs)

and pj/src/meson.build is

srcs = 'pj.c'

then running

pj$ meson build
pj$ ninja -C build

gives the ninja error

File pj.c does not exist.

The only way I can get it to work is by setting pj/src/meson.build to

srcs='src/pj.c'

Easy enough when there’s only 1 file but suppose there was 1,000.I found this earlier

Meson targets that depend on subdir siblings

and I’d like to do it the way rellenberg’s answer suggested however I can’t see why my code won’t work.

Question Answer

The problem is that you’re using a plain string to enumerate your source files. It becomes clear when you just do a plain variable substitution in your toplevel meson.build: that now gives library('pj', sources : 'pj.c'), so Meson doesn’t know about it.

To mitigate this, you can use the files() function to enumerate your source files.

In other words, you can do the following:

srcs = files('pj.c')
# and later: files('pj1.c', 'pj2.c', ...)

And it will work again

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.