[Qbs] Generating a c++ class with Q_OBJECT

Raphael Cotty raphael.cotty at gmail.com
Wed Aug 28 12:56:56 CEST 2019


Hi,
Thanks.
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?

Thanks

Raph

Le mar. 27 août 2019 à 20:43, Richard Weickelt <richard at weickelt.de> a
écrit :

> > 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 <wsdl.h>.
>
> 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 at qt-project.org
> https://lists.qt-project.org/listinfo/qbs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20190828/b41224dd/attachment.html>


More information about the Qbs mailing list