How to reuse properties of a Qbs project?

82 Views Asked by At

How two projects, a CppApplication and a DynamicLibrary, would reuse the properties defined in a base Product project? I seems inheritance is a solution but checking https://doc.qt.io/qbs/language-introduction.html#reusing-project-file-code it didn't help. I would like something like this:

// common.qbs ------------------------------------
Product
{
    Properties {
        condition: qbs.toolchain.contains("clang")
        cpp.defines: ["COMPILER_CLANG"]
    }
    Properties {
        condition: qbs.toolchain.contains("gcc")
        cpp.defines: ["COMPILER_GCC"]
    }
    Group {
        name: "Common files"
        files: [
           "common.cpp",
           "common.hpp",
        ]
    }
}

// project.qbs ------------------------------------
import "common.qbs" as Common

// app.qbs
CppApplication <inherits> Common
{
    cpp.defines: outer.concat("APP")
}

// dll.qbs
DynamicLibray <inherits> Common
{
    cpp.defines: outer.concat("DLL")
}
1

There are 1 best solutions below

1
Christian Kandeler On

There is no multiple inheritance, so basically you have two choices: Either declare the properties in a project that both products know (e.g. the top-level project), or use a project-specific module.