Author Topic: Custom Build file to execute MOC for a file  (Read 10243 times)

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Custom Build file to execute MOC for a file
« 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 ?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Custom Build file to execute MOC for a file
« Reply #1 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?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Custom Build file to execute MOC for a file
« Reply #2 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...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Custom Build file to execute MOC for a file
« Reply #3 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Custom Build file to execute MOC for a file
« Reply #4 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Custom Build file to execute MOC for a file
« Reply #5 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).
« Last Edit: June 14, 2012, 07:19:14 am by Feneck91 »

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Custom Build file to execute MOC for a file
« Reply #6 on: June 14, 2012, 07:19:50 am »
No more idea ? Nobody use QT with custom build ?

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: Custom Build file to execute MOC for a file
« Reply #7 on: June 14, 2012, 12:18:24 pm »
I usually use QtCreator.

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

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Custom Build file to execute MOC for a file
« Reply #8 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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Custom Build file to execute MOC for a file
« Reply #9 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: Custom Build file to execute MOC for a file
« Reply #10 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 but it seems to be outdated.
QT Helper 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...