News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Custom Build file to execute MOC for a file

Started by Feneck91, June 12, 2012, 02:55:15 PM

Previous topic - Next topic

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 :
"$(#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 :
Quotewarning: 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 ?

MortenMacFly

Quote from: Feneck91 on June 12, 2012, 02:55:15 PM
Do you have an idea ?
Can you setup a dependency on that file in the project/target settings?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

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 ?
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

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.
I've just updated the WiKi article so you see how I did things.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Feneck91

#5
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).

Feneck91

No more idea ? Nobody use QT with custom build ?

xunxun

I usually use QtCreator.

BTW, can you try it in the command line?
Regards,
xunxun

scarphin

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.

MortenMacFly

Quote from: Feneck91 on June 14, 2012, 07:19:50 AM
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Feneck91

Quote from: MortenMacFly on June 14, 2012, 04:22:58 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 but it seems to be outdated.
QT Helper is avalaible only in Win32, not for linux...

QuoteIn 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...