app_version_header.qbs 1.75 KB
Newer Older
1
import qbs
Christian Kandeler's avatar
Christian Kandeler committed
2
import qbs.TextFile
3 4 5 6 7 8 9 10 11

Product {
    name: "app_version_header"
    type: "hpp"
    files: "app_version.h.in"

    Transformer {
        inputs: ["app_version.h.in"]
        Artifact {
Joerg Bornemann's avatar
Joerg Bornemann committed
12
            filePath: "app/app_version.h"
13 14 15 16 17 18
            fileTags: "hpp"
        }
        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "generating app_version.h";
            cmd.highlight = "codegen";
19
            cmd.onWindows = (product.moduleProperty("qbs", "targetOS").contains("windows"));
20
            cmd.sourceCode = function() {
21
                var file = new TextFile(input.filePath);
22 23 24 25 26 27 28
                var content = file.readAll();
                // replace quoted quotes
                content = content.replace(/\\\"/g, '"');
                // replace Windows line endings
                if (onWindows)
                    content = content.replace(/\r\n/g, "\n");
                // replace the magic qmake incantations
29 30 31 32
                content = content.replace(/(\n#define IDE_VERSION) .+\n/, "$1 " + project.qtcreator_version + "\n");
                content = content.replace(/(\n#define IDE_VERSION_MAJOR) .+\n/, "$1 " + project.ide_version_major + "\n")
                content = content.replace(/(\n#define IDE_VERSION_MINOR) .+\n/, "$1 " + project.ide_version_minor + "\n")
                content = content.replace(/(\n#define IDE_VERSION_RELEASE) .+\n/, "$1 " + project.ide_version_release + "\n")
33
                file = new TextFile(output.filePath, TextFile.WriteOnly);
34 35 36 37 38 39 40 41 42 43 44 45 46
                file.truncate();
                file.write(content);
                file.close();
            }
            return cmd;
        }
    }

    Export {
        Depends { name: "cpp" }
        cpp.includePaths: product.buildDirectory
    }
}