Search code examples
buildbuild-systemmeson-build

In meson can you test for presence of a directory in your project?


Using meson build, is it possible to test for the existence of a directory in my project?

For example, I typically put acceptance tests next to my unit tests in a folder structure like this:

library/
        header.hp
        src/
            lib.cpp
        tests/
              acceptance_test/
              unit_test/ 

I don't always have acceptance tests, and I'd like to avoid having to have a meson.build file there if it isn't necessary. I'd much rather have a conditional subdir('acceptance_test') if the directory acceptance_test/ exists.


Solution

  • Update: Starting with Meson v0.53.0, you can use the Filesystem module:

    fs = import('fs')
    if fs.is_dir('<dirname>')
      message('directory exists')
    endif
    

    This is portable, and does not depend on a shell.