The following code should do.
project('tutorial', 'c')
exec = executable('target.elf', 'main.c', build_by_default : false)
custom_target('final binary',
depends : exec,
input : exec,
output : 'fake',
command : ['chmod', '+x', '@INPUT@'],
build_by_default : true)
Note that because I want to always run the fake
target, I'm using custom_target()
. However, the command chmod + x demo
doesn't generate the file fake
specified in custom_target()
, successive ninja
command will always run the target.
If you don't want this behaviour, there are two ways:
You can write a script which chmod
the target.elf
and then copies it to target
, thus effectively creates the target file. Make sure to change the output
file in the meson.build
if you do so.
If you don't mind typing ninja chmod
instead of ninja
, you can use run_target()
.
# optional
run_target('chmod',
command : ['chmod', '+x', exec])
Another alternative is to use install_mode
for executable()
.
Also note that you should always use find_program()
instead of plain chmod
. This example doesn't use it for simplicity.
ninja
. I have more targets, and each of it will have a fake file. It's not elegant. And if someone forgot to write all targets nothing will warn him/her that something is missing. (A few scripts can solve this problem, but I don't think we should use scripts for it.) – Animated