[QBS] Generate pre compiled headers
olivier musse
olivier.musse at sfr.fr
Wed May 21 00:08:10 CEST 2014
Hi,
I want to create a module to automatically create and compile a pre
compile header file in my project
For that I create the following module
----- generatePCH.qbs
importqbs
import qbs.TextFile
import qbs.FileInfo
Module {
Rule {
inputs: ['pch']
multiplex:true
Artifact {
fileName: "pch_headers.h"
fileTags: [ "hpp" ]
}
prepare: {
var cmd = new JavaScriptCommand();
cmd.description = "generating precompiled header file";
cmd.sourceCode = function() {
var fileContent="#if defined __cplusplus\n";
for(var i in inputs.pch)
{
fileContent+="#include \"" +FileInfo.fileName(inputs.pch[i].filePath) + "\"\n";
}
fileContent+="#endif"
var file = new TextFile(output.filePath, TextFile.WriteOnly);
file.truncate();
file.write(fileContent);
file.close();
}
return cmd;
}
}
Depends { name : "cpp"}
cpp.cxxPrecompiledHeader:product.buildDirectory+"/pch_headers.h"
}
And In my project I can simply call
Depends { name : "generatePCH" }
Group{
name:"PchHeaders"
files:['commondefs.h','otherfile.h']
fileTags:['pch']
}
I have some questions :
1) The file pch_headers.h is well generated on the build directory if in
my PchHeaders Group I select files with extension other than .h . When
I use .h extension, the pch_headers.h is not generated as if there are
some interferences between the cpp module "hpp" tag and my "pch" tag.
Does it may be the issue? Can I do something for it to work?
2) the line
cpp.cxxPrecompiledHeader:product.buildDirectory+"/pch_headers.h" seem to
have no effect when put in the Module. I try to put it directly in the
product and then it warn me that the artifact is not in the list of
source files. For the pch_headers.h to be pre compiled, I need to put it
manually in the source directory and add to project
Group{
files:[pch_headers.h]}
cpp.cxxPrecompiledHeader:"pch_headers.h"
In that case it compiled but as soon as i'm trying to use the generated
pch_headers.h located in build directory it does nothing.
Am I doing something wrong?
Many thanks for help
Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20140521/70ed7ee5/attachment.html>
More information about the Qbs
mailing list