如何在 Meson 中将多个文件连接成一个文件?

How can I concatenate multiple files into one in Meson?

我在 Meson 中的一项基本任务中遇到了问题,我需要在构建过程中将多个文件连接成一个文件;基本上:

cat *.txt > compiled.txt

cat foo.txt bar.txt baz.txt > compiled.txt

然而,无论我使用 custom_target()generator() 还是任何其他函数,Meson 要么无法找到 compiled.txt,要么无法处理从多个输入文件到单个输入文件的转换输出文件。

有没有简单的方法可以做到这一点?

更新:

使用 run_command() 我已经成功构建了 compiled.txt 并且它出现在源目录中。最终我希望 compiled.txt(我在 gresource.xml 中列出)由 gnome.compile_resources() 编译。有什么办法可以 运行 这个命令并将文件直接传递给那个函数来处理吗?

使用custom_target(),将输出传递给gnome.compile_resources()dependencies。请注意,您需要相当新的 glib 才能正常工作。

另请参阅:http://mesonbuild.com/Gnome-module.html#gnomecompile_resources

将解决方案从问题移至答案:

Solution:

I ended up not using gresources, but still needed this solution to concatenate files

cat_prog = find_program('cat')

parts_of_the_whole = files(
  'part1.txt',
  'part2.txt'
)

concat_parts = custom_target(
  'concat-parts',
  command: [ cat_prog, '@INPUT@' ],
  capture: true,
  input: parts_of_the_whole,
  output: 'compiled.txt',
  install_dir: appdatadir,
  install: true,
  build_by_default: true
)