meson-build

Prefix all sources with src/ in Meson


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?


Solution

  • 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')