User forums > Using Code::Blocks

Custom Build file to execute MOC for a file

(1/3) > >>

Feneck91:
I'm trying to use Code::Blocks to build QT projects.
Not really a problem.

In all header files that use signal / slot / QObject, I right clic on file,
- in Build tab I check Compile File and put the priority level to 10 (compile before the other files).
- In Advanced tab I check use custom command to build this file and I put the code :

--- Code: ---"$(#qtdir)\bin\moc.exe" "$file" -o ".\GeneratedFiles\$(ConfigurationName)\moc_$file_name.cpp"
--- End code ---
Where $(ConfigurationName) is a project custom variable that is "Debug" or "Release".

All is working fine exept a warning :

--- Quote ---warning: missing whitespace after the macro name [enabled by default]
--- End quote ---
The problem is :
-> In Visual C++ when making custom build, you are allowed to indicate to compiler what file will be generated while compiling this file. In my case, indicate it generate .\GeneratedFiles\$(ConfigurationName)\moc_$file_name.cpp.
-> In Code::Blocks you cannot indicate what kind of file the build will generate.

So, when modifying the generated or source file, the compiler know that the file must be re-build (in Visual C++)
In Code::Blocks, it doesn't know that, so, even the file hase no modification the build is always run, the file re-build and all dependencies re-build again, making for a large projet a long compilation time each time the build process is executed!

Do you have an idea ?

MortenMacFly:

--- Quote from: Feneck91 on June 12, 2012, 02:55:15 pm ---Do you have an idea ?

--- End quote ---
Can you setup a dependency on that file in the project/target settings?

Feneck91:
Where ?
Where I can found project/target settings? It is certainly what I need....

In project/properties in Build Target tab I found "Build Target Files" all  the custom build files and all genrerated files but I can do nothing with this...

MortenMacFly:

--- Quote from: Feneck91 on June 12, 2012, 05:25:00 pm ---Where ?

--- End quote ---
Go to project -> properties... -> build targets -> "Dependencies"

But I guess you'd be better of if you follow the steps as described here:
http://wiki.codeblocks.org/index.php?title=Adding_support_for_non_C/C%2B%2B_files_to_the_build_system

...because this would actually do what you need: Check if (re-)generation is needed and link (re-)link if the generated file is newer. I am doing this with Bison generated code and it works pretty well - it should be the same with *.moc files.

MortenMacFly:

--- Quote from: MortenMacFly on June 12, 2012, 05:45:04 pm ---I am doing this with Bison generated code and it works pretty well - it should be the same with *.moc files.

--- End quote ---
I've just updated the WiKi article so you see how I did things.

Navigation

[0] Message Index

[#] Next page

Go to full version