Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Feneck91 on June 12, 2012, 02:55:15 pm

Title: Custom Build file to execute MOC for a file
Post by: Feneck91 on June 12, 2012, 02:55:15 pm
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"
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]
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 ?
Title: Re: Custom Build file to execute MOC for a file
Post by: MortenMacFly on June 12, 2012, 03:58:58 pm
Do you have an idea ?
Can you setup a dependency on that file in the project/target settings?
Title: Re: Custom Build file to execute MOC for a file
Post by: Feneck91 on June 12, 2012, 05:25:00 pm
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...
Title: Re: Custom Build file to execute MOC for a file
Post by: MortenMacFly on June 12, 2012, 05:45:04 pm
Where ?
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.
Title: Re: Custom Build file to execute MOC for a file
Post by: MortenMacFly on June 12, 2012, 05:53:21 pm
I am doing this with Bison generated code and it works pretty well - it should be the same with *.moc files.
I've just updated the WiKi article so you see how I did things.
Title: Re: Custom Build file to execute MOC for a file
Post by: Feneck91 on June 12, 2012, 07:32:12 pm
I have already read your article and try it...
But the file that need to be generated (source file) are C++ header files (.h) and so, some header need to be compiled as QT moc executable (all header that contains signal / slot / QObject) and some other header files don't need... (grrrr I Hate QT but have no choice to use wxWidgets).

.... But for my own project, I think this wiki will help me a lot (auto-generation of wrapper class to simplify using sqllite3 database !).
Like your wiki explain, I have duplicate gcc compiler to put MOC compiler and after I have tryed to set the compiler as MOC compiler into custom build but it don't remember it, each time I re-open this custom build, it is always gcc compiler (default one).
Title: Re: Custom Build file to execute MOC for a file
Post by: Feneck91 on June 14, 2012, 07:19:50 am
No more idea ? Nobody use QT with custom build ?
Title: Re: Custom Build file to execute MOC for a file
Post by: xunxun on June 14, 2012, 12:18:24 pm
I usually use QtCreator.

BTW, can you try it in the command line?
Title: Re: Custom Build file to execute MOC for a file
Post by: scarphin on June 14, 2012, 12:27:17 pm
Do you mean you can't change the build output of 'moc_$file_name.cpp' in your case?

I also use custom compilation for qobject files with moc compiler. And I include the moc compiled file say 'file_with_qobject_moc.cpp' in the file 'file_with_qobject.cpp'. It works fine besides the fact that you are including a .cpp file in a .cpp file. That's how I manage qt.
Title: Re: Custom Build file to execute MOC for a file
Post by: MortenMacFly on June 14, 2012, 04:22:58 pm
No more idea ? Nobody use QT with custom build ?
In wonder why you don't use one of these QT helper plugins available... They should do the job, too.

I still believe it is possible with a custom build, too. Just I don't have time to try for myself.
Title: Re: Custom Build file to execute MOC for a file
Post by: Feneck91 on June 14, 2012, 06:46:38 pm
In wonder why you don't use one of these QT helper plugins available... They should do the job, too.

I still believe it is possible with a custom build, too. Just I don't have time to try for myself.
It's possible and it's work but it re-compile each time, even if the source code is not modified...
I'm at home this evening, I'll try tomorow QT Workbench (http://code.google.com/p/qtworkbench/) but it seems to be outdated.
QT Helper (http://code.google.com/p/qthelper/) is avalaible only in Win32, not for linux...

Quote
In wonder why you don't use one of these QT helper plugins available
Wich one ? This problems seems to be not as simple at it seeing...