[QBS] A Rule with more than one Artifact?

William Gallafent william at gallaf.net
Mon Sep 10 23:28:25 CEST 2012

Nothing like making a public post asking a question to make one find
the answer for oneself :)

For the record (and correct me if I've got this wrong!), if one has
multiple Artifacts in a Rule, the "output" variable is undefined in
the prepare statement. Instead there is a variable outputs which may
be referenced using outputs [X][Y] to obtain an "output" type object,
where X is the fileTag of the Artifact and Y is 0 (at least in my
experience so far). So instead of output.fileName one may say
outputs["cpp"][0].fileName for example.

So my Rule becomes:

DynamicLibrary {
  name: "foolib"
  Group {
    files: ["a.txt"]
    fileTags: ["sampleinput"]
  Depends {name: "cpp"}
  Rule {
    inputs: ["sampleinput"]
    Artifact {
      fileTags: ["cpp"]
      fileName: FileInfo.baseName (input. fileName) + ".cpp"
    Artifact {
      fileTags: ["hpp"]
      fileName: FileInfo.baseName (input. fileName) + ".hpp"
    prepare: {
      var args = [input.fileName, outputs["cpp"][0].fileName];
      var cmd = new Command ("bin/txt2cpp.rb", args);
      cmd. description = "Generating cpp and hpp from " + input. fileName;
      cmd. highlight = "codegen";
      return cmd;

This is really excellent stuff, things like this are far easier to do
with QBS than in any other build system I've used so far (once one
realises the appropriate way of thinking)! Many thanks to the authors
for their work so far. I /really/ hope that development continues
apace, I think it would be excellent if QBS became the default build
system for Qt in the near future!

Is there a wiki where little recipes like this are written down to
save neophytes like me from having to roam the wilds of
modules/cpp/msvc.js to see how it all fits together?

Anyway, more progress, thanks again for the tool :)

Bill Gallafent.

More information about the Qbs mailing list