After I wrote Calitko Coding Conventions I wanted to try and apply all these recommendations for a single package. According to Calitko’s architecture, which is not yet documented, all network and protocol related stuff goes to the Networks package, the lowest layer of which is presented by the Networks::Transports package. There should be all Connection and related classes.
What I actually had to do was rename the Gnutella::Connections package to Networks::Transports and apply our coding conventions, which I did only partially. I also created qmake project files for building the package as a library and a test application (although nothing is being tested now). I have not figured it out exactly how to organize the project file(s), so that not only Calitko could be built, but also the test apps for each component.
Initially I created Imports.{h|cpp} and Exports.{h|cpp} exactly following our coding conventions. The idea behind these files is that the h only provides (forward) declarations, which would be necessary for a header file, whereas the cpp files provide the full declarations to be included in source files. Well, I saw the result and thought how easier it would be to only have Imports.h and Exports.h included ONLY in the source file – very much like a precompiled file. You never include a precompiled file in other header files and since it is always include first in each source file, you do NOT need to explicitly include type declarations in your headers. In this way header files will only have dependencies within a package. If a package is ever built separately as a library, then Imports.h would be the precompiled header.
The only problem with the idea occurs with moc generates source files. These files will by default not include our Imports.h. I found out from the source code of moc that if you give the option -f”Imports.h” on the command line when you run moc then the file will be included in the generated file. However, if you do this the corresponding header file for which moc was called is not included anymore. Well, the solution is easy – add following two options: -f”Imports.h” –f”YourHeader.h”. Additionally, the generated file should be created in the same directory with its header.
So far, so good! Now how to make this work in qmake? I checked and it will be necessary to modify moc.prf located in QTDIR/mkspecs/features. Patching the standard file coming with Qt is a bad idea, because everybody who wants to build Calitko would need to patch it too. What we need is a workaround to automatically replace moc.prf only when building Calitko. I have already done some progress there and I hope I will soon be able to provide the full results in a separate post.
