Using the return objects from custom_target to generate names of another custom_target
A problem currently blocking me from using meson is that I can't use foreach loops to generate custom_targets based on the output of custom_targets.
We have a number of standard "transforms" which take a type of file in and create a given output file. We also have other targets which generate new files. See the following example;
ntemplate_cfgs = ['ntemplate.blah.xml']
xml_files = ['a.xml', 'b.xml']
foreach cfg : ntemplate_cfgs
t = custom_target(
cfg.underscorify(),
command : [
find_program('utils/n.py'),
'@INPUT@',
'@OUTPUT@',
],
input : cfg,
output : '@BASENAME@',
)
xml_files += [t]
endforeach
foreach f : xml_files
t = custom_target(
f.underscorify() + '_deps',
command : [
find_program('utils/deps_xml.py'),
'--output',
'@DEPFILE@',
'@INPUT@',
],
depfile : '.@[email protected]',
input : f,
)
endforeach
This fails because you can't use the custom_target output from ntemplate_cfgs to generate a name for the xml_files_deps custom target. Meson complains about no such method being found.
This also happens when you have multiple output files, neither of these examples work either;
muxgen_cmd = find_program(join_paths('utils', 'mux_gen.py'))
foreach cfg : muxgen_cfgs
t = custom_target(
cfg.underscorify(),
command : [
muxgen_cmd,
'--out_dir=@OUTDIR@',
'@INPUT@',
],
input : cfg,
output : ['@[email protected]_type.xml', '@[email protected]'],
)
if t.full_path().contains('/ntemplate.')
ntemplate_cfgs += [t[0], t[1]]
else
xml_files += [t[0], t[1]]
endif
endforeach
nor
muxgen_cmd = find_program(join_paths('utils', 'mux_gen.py'))
foreach cfg : muxgen_cfgs
t = custom_target(
cfg.underscorify(),
command : [
muxgen_cmd,
'--out_dir=@OUTDIR@',
'@INPUT@',
],
input : cfg,
output : ['@[email protected]_type.xml', '@[email protected]'],
)
if t.full_path().contains('/ntemplate.')
ntemplate_cfgs += [t]
else
xml_files += [t]
endif
endforeach
For the first problem, just don't use two loops? Get the name of the second target from the same source you had originally (+_deps). The name is just a shortcut for you in the end, so it doesn't really matter much.
ntemplate_cfgs = ['ntemplate.blah.xml']
xml_files = ['a.xml', 'b.xml']
n = find_program('utils/n.py')
deps_xml = find_program('utils/deps_xml.py')
foreach f : xml_files
t = custom_target(
f.underscorify() + '_deps',
command : [deps_xml, '--output', '@DEPFILE@', '@INPUT@'],
depfile : '.@[email protected]',
input : f,
)
endforeach
foreach cfg : ntemplate_cfgs
t = custom_target(
cfg.underscorify(),
command : [n, '@INPUT@', '@OUTPUT@'],
input : cfg,
output : '@BASENAME@',
)
xml_files += [t]
custom_target(
cfg.underscorify() + '_deps',
command : [deps_xml, '--output', '@DEPFILE@', '@INPUT@'],
depfile : '.@[email protected]',
input : t,
)
endforeach
@QuLogic This requires me to duplicate the _deps generation logic and in my real example I would have to duplicate this logic about ~5 times.
The first example can be solved by using full_path().
xml_files += t.full_path()
The last two examples work for me.
Fixed by full_path().