[Qbs] Same precompiled headers for multiple CppApplications

Christian Kandeler christian.kandeler at qt.io
Mon Oct 1 11:46:05 CEST 2018


On Fri, 28 Sep 2018 09:45:54 +0200
Mitja Schmakeit <mitja.schmakeit at aucos.de> wrote:

> is it possible to have a single
> 
>              Group {
>                  name: "Precompiled Headers"
>                  files: ["precompiled-header.h"]
>                  fileTags: ["cpp_pch_src"]
>              }
> 
> where the precompiled-header.h is only compiled once for multiple 
> CppApplication-products? This would be nice for our unit test applications.

The compiler rules only consider precompiled headers in the same product, because different products potentially use different compiler flags, leading to incompatibilities. I think the only way to share them between products is to have a rule that makes a copy. For instance:
Product {
    name: "pch_provider"
    type: "cpp_pch"
    Group {
        name: "Precompiled Headers"
        files: "precompiled-header.h"
        fileTags: "cpp_pch_src"
    }
    Export {
        Rule {
            inputsFromDependencies: "cpp_pch"
            Artifact { filePath: input.fileName; fileTags: "cpp_pch" }
            prepare: {
                var cmd = new JavaScriptCommand();
                cmd.description = "pulling in pch file";
                cmd.sourceCode = function() { File.copy(input.filePath, output.filePath); };
                return cmd;
            }
    }
}
Then add a dependency to this product to all the applications.
It's probably only worth it if compilation of the precompiled header is particularly expensive.


Christian



More information about the Qbs mailing list