[QBS] Generate pre compiled headers

olivier musse olivier.musse at sfr.fr
Wed May 21 11:37:36 CEST 2014


Hi Christian,

Thanks for the answer but I do not understand it. Of course I see that 
cpp module is handling a precompile header since i'm using the 
cpp.cxxPrecompiledHeader in my example.
But except if I missed something this property if of path type so that 
you can specify only one file containing the list of headers you want to 
be precompiled in a format like

#if  defined  __cplusplus
#include "myfirstfile.h"
#include "mysecondfile.h"
#endif

If you look at my rule, what I want is to automatically generate this 
file (as a precompilation rules) from a filetag "pch" . This enable to 
defines group of files that can be precompiled in a simpler and more 
efficient way.

Regards

Olivier


> On 05/21/2014 12:08 AM, olivier musse wrote:
>> 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
> Why? The cpp module supports this already; see
> http://qt-project.org/doc/qbs-1.2/cpp-module.html#precompiledheader. If
> you are interested in the implementation, you can find it under
> share/qbs/modules/cpp/ in the qbs sources.
>
>
> Christian
>
>
>> ----- generatePCH.qbs
>> importqbs
>>
>> import  qbs.TextFile
>>
>> import  qbs.FileInfo
>>
>> Module  {
>>
>>       Rule  {
>>
>>           inputs:  ['
> ']
>>           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
>>
>>
>>
>>
>> _______________________________________________
>> QBS mailing list
>> QBS at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/qbs
>>
> _______________________________________________
> QBS mailing list
> QBS at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qbs
>



More information about the Qbs mailing list