diff options
author | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2014-12-02 15:28:23 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2014-12-02 15:47:43 +0100 |
commit | d83b1fabd06b23fae1ca66717d3603439317f1fd (patch) | |
tree | d6131592f120b1b0baeb73e64854207308ea2750 /examples | |
parent | 44ab9c7d41c59afdacce1747af5d567fa87b04ec (diff) |
add code generator example
Change-Id: I78c2aec4466499871bc03b7ca35a38086a1fb548
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/code-generator/code-generator.qbs | 70 | ||||
-rw-r--r-- | examples/code-generator/hwgen.cpp | 15 | ||||
-rw-r--r-- | examples/examples.qbs | 1 |
3 files changed, 86 insertions, 0 deletions
diff --git a/examples/code-generator/code-generator.qbs b/examples/code-generator/code-generator.qbs new file mode 100644 index 000000000..feebfee33 --- /dev/null +++ b/examples/code-generator/code-generator.qbs @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Build Suite. +** +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +****************************************************************************/ +import qbs + +Project { + // A code generator that outputs a "Hello World" C++ program. + CppApplication { + name: "hwgen" + files: ["hwgen.cpp"] + } + + // Generate and build a hello-world application. + CppApplication { + name: "hello-world" + Depends { name: "hwgen" } + Rule { + inputs: ["qbs"] // needed to trigger this rule + Artifact { + filePath: "main.cpp" + fileTags: ["cpp"] + } + prepare: { + var hwgen; + for (var i in product.dependencies) { + var dep = product.dependencies[i]; + if (dep.name != "hwgen") + continue; + hwgen = dep.buildDirectory + "/" + dep.targetName; + } + var cmd = new Command(hwgen, [output.filePath]); + cmd.description = "generating C++ source"; + return cmd; + } + } + } +} diff --git a/examples/code-generator/hwgen.cpp b/examples/code-generator/hwgen.cpp new file mode 100644 index 000000000..e71c1d9ed --- /dev/null +++ b/examples/code-generator/hwgen.cpp @@ -0,0 +1,15 @@ +#include <cstdio> + +int main(int argc, char **argv) +{ + if (argc < 2) + return 1; + FILE *f = fopen(argv[1], "w"); + if (!f) + return 2; + fprintf(f, "#include <cstdio>\n\n" + "int main()\n" + "{\n printf(\"Hello World!\\n\");\n return 0;\n}\n"); + fclose(f); + return 0; +} diff --git a/examples/examples.qbs b/examples/examples.qbs index 80b80dccb..d11b4a8a6 100644 --- a/examples/examples.qbs +++ b/examples/examples.qbs @@ -41,6 +41,7 @@ Project { references: [ "app-and-lib/app_and_lib.qbs", "cocoa-application/CocoaApplication.qbs", + "code-generator/code-generator.qbs", "collidingmice/collidingmice.qbs", "helloworld-complex/hello.qbs", "helloworld-minimal/hello.qbs", |