Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you glob source code with meson?

Is it possible to glob source code files in a meson build?

like image 276
paxos1977 Avatar asked Feb 10 '26 22:02

paxos1977


2 Answers

Globbing source files is discouraged and is bad practice, and not only on Meson. It causes weird errors, makes it hard to have some developement files aside for development but that you don't want to build or ship, and can cause problems with incremental builds.

Explicit is better than implicit.

2021-03-02 EDIT:

Read also Why can't I specify target files with a wildcard? in the Meson FAQ.

Meson does not support this syntax and the reason for this is simple. This can not be made both reliable and fast.

If after all the warnings, you still want to do it at your own risk, the FAQ tells you how in But I really want to use wildcards!. You just use an external script to do the globbing and return the list of files (that script is called grabber.sh in that example).

c = run_command('grabber.sh')
sources = c.stdout().strip().split('\n')
e = executable('prog', sources)

like image 187
liberforce Avatar answered Feb 13 '26 12:02

liberforce


I found an example in the meson unit tests showing how to glob source, but in the comments it says this is not recommended.

if build_machine.system() == 'windows'
  c = run_command('grabber.bat')
  grabber = find_program('grabber2.bat')
else
  c = run_command('grabber.sh')
  grabber = find_program('grabber.sh')
endif


# First test running command explicitly.
if c.returncode() != 0
  error('Executing script failed.')
endif

newline = '''
'''

sources = c.stdout().strip().split(newline)

e = executable('prog', sources)

The reason this is not recommended: attempting to add files by glob'ing a directory will NOT make those files automatically appear in the build. You have to manually re-invoke meson for the files to be added to the build. Re-invoking ninja or other back-ends is not sufficient, you must reinvoke meson itself.

like image 20
paxos1977 Avatar answered Feb 13 '26 12:02

paxos1977



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!