4

Relative to my project root where meson.build is located, all of my source files are under src/.

Is it possible to specify these source files in meson.build in a way that wouldn't force me to prefix them all with src/, given that that's somewhat redundant?

sssilver
  • 2,549
  • 3
  • 24
  • 34

3 Answers3

6

Prefixing source files shouldn't be needed because meson provides special function: files() which generates file array object that "remembers" subdirectory. For example, in the root meson.build you can have:

subdir('src')
subdir('src_more')
exe = executable('test', sources)

In src/meson.build:

sources = files('a1.c', 'a2.c')

And in src_more/meson.build:

sources += files('b1.c', 'b2.c')
pmod
  • 10,450
  • 1
  • 37
  • 50
1

You really should put a meson.build file in src/ and create the list there.

TingPing
  • 2,129
  • 1
  • 12
  • 15
1

You can actually "build" an array of files using foreach statement:

raw_sources = [
    'foo.cpp',
    'foomanager.cpp',
    'foofactory.cpp'
]
sources = []

foreach file : raw_sources
    full_path = join_paths('src', file)
    sources += files(full_path)
endforeach

And now sources contains files with the desired prefix.

barsoosayque
  • 329
  • 2
  • 11