[QBS] Dynamic libraries built with qmake

Lars Ivar Igesund larsivi at gmail.com
Fri May 8 15:43:05 CEST 2015


Hi,

I'm in the process of converting a largish QMake based project to QBS. Part
of the project are two 3rd party libraries that we have to build ourselves,
but that comes with .pro files. With QMake this was very simple, just
subdirs them, but with QBS things are a bit more cumbersome.

What I have done is to create a Module that can do the building, and then
define a product that depends on that module with the pro-file in the
files-list.

One feature I wanted, was that when our part of the project depends on
these qmake-products, then the resulting library files should be picked up
and automatically linked (as if they were built with qbs).

Currently it works in fresh builds, but there are some quirks and issues.
1) I was not able to make the automatic linking work unless I set output
fileTags to be dynamiclibrary_copy (rather than dynamiclibrary), which
seems wrong as long as I had to dig in the source to find that particular
tag.
2) When running clean and/or rebuild, things fails for some reason. The
built libraries are cleaned, but they are not rebuilt. Looking at the
output, it shows that make says "Nothing to be done". Maybe this is because
I don't scan or otherwise set up proper dependencies for these projects as
a whole? But I would think that since make generates the actual library, it
should also figure out that its end target is missing.

I hope to get some feedback on how to improve on this and/or solve the
above quirks.

Here is the module, and below a sample product:


import qbs
import qbs.File
import qbs.PathTools

Module {
  FileTagger {
    patterns: ["*.pro"]
    fileTags: ["qmake-pro"]
  }

  Rule {
    inputs: ["qmake-pro"]

    Artifact {
      // NOTE: Use a subdirectory to avoid default install behaviour of
moving then deleting potentially
      // causing product itself to be deleted
      filePath: product.destinationDirectory + "/.build/" +
PathTools.dynamicLibraryFilePath(product)
      fileTags: ["dynamiclibrary_copy"]
    }

    prepare: {
      var cmds = [];
      if (!File.exists(product.destinationDirectory))
      {
        var mkdirCmd = new Command("mkdir", ["-p",
product.destinationDirectory + "/.build"]);
        mkdirCmd.description = "Creating directory " +
product.destinationDirectory;
        cmds.push(mkdirCmd);
      }

      var qmakeCmd = new Command("qmake", [input.filePath, "DESTDIR=" +
product.destinationDirectory + "/.build",
"-r", "-spec", "linux-g++", "-o", "Makefile"]);
      var makeCmd = new Command("make", ["-f", "Makefile"]);
      qmakeCmd.description = "Run qmake on " + input.filePath;
      qmakeCmd.workingDirectory = product.destinationDirectory;
      makeCmd.description = "Run make on make file generated from " +
 input.filePath;
      makeCmd.workingDirectory = product.destinationDirectory;

      cmds.push(qmakeCmd);
      cmds.push(makeCmd);
      return cmds;
    }
  }
}

import qbs
Product {
  name: "LibFoo"
  Depends { name: "qmakeBuilder" }
  Depends { name: "cpp" }
  // target specified in .pro file
  targetName: "foo"
  files: [
    "libfoo/foo.pro"
  ]
  type: "dynamiclibrary_copy"
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20150508/6c0307d5/attachment.html>


More information about the Qbs mailing list