[Qbs] How to pass information to custom module via Depends ?

Glenn Coombs glenn.coombs at gmail.com
Wed Feb 15 02:51:37 CET 2017


I have created a custom module to help wrap a dependency on the
Qt5GStreamerUi library.  To use it I add a line like this:

    Depends { name: "Qt5GStreamerUi" }

to any project that needs to link against Qt5GStreamerUi.  It works fine
but I would like to make the module more generic so that I can add a
dependency on any library that pkg-config knows about.  I can't work out
how to pass the name of the library through to the custom module.  I want
to be able to write something like this:

    Depends { name: "PkgConfig"; packageName = "Qt5GStreamerUi" }

where PkgConfig would be the renamed and modified version of my existing
Qt5GStreamerUi module.  Is there a way to do this ?

The contents of my qbs/modules/Qt5GStreamerUi/Qt5GStreamerUiModule.qbs file
look like this:

import qbs 1.0
import qbs.File
import qbs.FileInfo
import qbs.Probes

// TODO: turn this into more generic item (maybe called DependsPkg) that
could be used
// to depend on any pkg-config dependency, so that we could write something
like this:
// DependsPkg { name = "Qt5GStreamerUi-1.0" }

    Depends { name: "cpp" }

    property string pkgConfigExecutable

        id:         pkgConfig
        name:       "Qt5GStreamerUi-1.0"   //  <== this is the bit that
needs to be passed through
        executable: pkgConfigExecutable

    condition: !qbs.targetOS.contains("windows")

        var exe = "pkg-config";
        print("CHECKING cpp.compilerPath:", cpp.compilerPath);
        if (cpp.compilerPath)
            var path = FileInfo.path(cpp.compilerPath);
            if (File.exists(path + "/" + exe))
                exe = path + "/" + exe;
        print("=== USING pkg-config:", exe);
        return exe;

        print("PKGCONFIG: IN VALIDATE product =", product.name);
        print("PKGCONFIG: IN VALIDATE cflags =", pkgConfig.cflags);
        print("PKGCONFIG: IN VALIDATE libs =", pkgConfig.libs);

    property stringList myIncs:
        print("PKGCONFIG: cflags =", pkgConfig.cflags);
        if (!pkgConfig.cflags) return [];
        return pkgConfig.cflags.filter(function(value, index, array) {
            return array.indexOf(value) == index;  // remove duplicates
        }).filter(function(value) {
            return value.startsWith("-I");         // ignore if not include
        }).map(function(value) {
            return value.substring(2);             // remove initial "-I"

    property stringList myLibs:
        print("PKGCONFIG: libs =", pkgConfig.libs);
        if (!pkgConfig.libs) return [];
        return pkgConfig.libs.filter(function(value) {
            return value.startsWith("-l");         // ignore if not library
        }).map(function(value) {
            return value.substring(2);             // remove initial "-l"

    property var debug:
        print("Qt5GStreamerUi, INCS =", myIncs);
        print("Qt5GStreamerUi, LIBS =", myLibs);

    cpp.includePaths:     myIncs
    cpp.dynamicLibraries: myLibs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20170215/b80af4f0/attachment.html>

More information about the Qbs mailing list