Re: [Qbs] Generating a c++ class with Q_OBJECT

2019-08-28 Thread Christian Kandeler
On Wed, 28 Aug 2019 12:56:56 +0200
Raphael Cotty  wrote:

> I've created a module:
> Module {
> FileTagger {
> patterns: "*.wsdl"
> fileTags: ["wsdl"]
> }
> Depends { name: "kdsoap" }
> Rule {
> multiplex: false
> inputs: ["wsdl"]
> Artifact {
> filePath: input.baseName + ".cpp";
> fileTags: "cpp"
> }
> Artifact {
> filePath: input.baseName + ".h";
> fileTags: "hpp"
> }
> 
> prepare: {
> var file = input.filePath;
> var cmd = new Command("kdwsdl2cpp", ["-both", input.baseName,
> file]);
> cmd.description = input.fileName + "->" + outputs.cpp[0];
> cmd.highlight = "kdwsdl2cpp codegen";
> cmd.workingDirectory = product.buildDirectory;
> return cmd;
> }
> }
> }
> 
> My project file:
> Project {
> minimumQbsVersion: "1.5"
> qbsSearchPaths: "qbs"
> 
> CppApplication {
> name: "Test"
> cpp.includePaths: sourceDirectory
> files: [
> "main.cpp",
> "wsdl/WsAnnuaire.wsdl"
> ]
> Depends { name: "Qt"; submodules: ["core", "xml"] }
> Depends { name: "wsdl" }
> }
> }
> 
> So my module generates the cpp/h files according to the input using the
> baseName. Perfect.
> 
> I've no found a simple way to export the output directory of the module. I
> guess I have to create a property in the module and assign to it the output
> directory.
> But the outputs variable is only available in the Rule:
> Rule {
> property path outputPath: FileInfo.path( outputs.cpp[0].filePath )
> ...
> }
> 
> Or should the module depends on cpp and export the path?

Yes: 
cpp.includePaths: product.buildDirectory
at the Module level.


Christian
___
Qbs mailing list
Qbs@qt-project.org
https://lists.qt-project.org/listinfo/qbs


Re: [Qbs] Generating a c++ class with Q_OBJECT

2019-08-27 Thread Richard Weickelt
> CppApplication {
> name: "test"
> cpp.includePaths: sourceDirectory
> files: [
> "main.cpp",
> ]
> Depends { name: "Qt"; submodules: ["core", "xml"] }
> Depends { name: "kdsoap" }
> Rule {
> multiplex: true
> Artifact { filePath: "wsdl.cpp"; fileTags: "cpp" }
> Artifact { filePath: "wsdl.h"; fileTags: "cpp" }
> prepare: {
> var file = product.sourceDirectory +
> "/wsdl/WsAnnuaire.wsdl";
> var cmd = new Command("kdwsdl2cpp", ["-both", "wsdl",
> file]);
> cmd.description = "generating " + outputs;
> cmd.workingDirectory = product.buildDirectory;
> return cmd;
> }
> }
> }
> 
> Adding the second artifact makes qbs call moc on the wsdl.h and generates
> the qt.headers/wsdl.moc file.
> But how can I add this file to the link?

What do you mean by "link"? That the resulting .cpp file is compiled and
linked into your application? AFAIK, this should happen automatically. But
your rule above does not look kosher to me:

1. Your rule should specify a filetag as input. That might be "wsdl".
Otherwise Qbs will not (re-)run the rule upon changes in the wsdl file.

2. Consider to add a FileTagger for "wsdl" files or at least, put the wsdl
file into a group item and assign the "wsdl" filetag.

3. Why do you set multiplex true? Can the tool handle multiple wsdl input
files and creates one single large .h and .cpp file? Otherwise, consider to
set it to false (default) and generate one cpp+hpp file per wsdl file input.

4. I think you should use "hpp" as filetag for the wsdl header artifact.

5. Consider to add the output directory of the rule to cpp.includePaths if
you want to easily include them into your source files, for instance via
#include .

7. If you are going to use this generator in multiple products, consider to
write a module.
https://doc-snapshots.qt.io/qbs-master/custom-modules.html#custom-modules

The documentation about writing rules has recently been updated. Have a look
at:
https://doc-snapshots.qt.io/qbs-master/qml-qbslanguageitems-rule.html#a-complete-example

Does this maybe solve your problem?

Richard
___
Qbs mailing list
Qbs@qt-project.org
https://lists.qt-project.org/listinfo/qbs