RFC: new way to handle MOC files ?
Alexander Neundorf
neundorf at kde.org
Fri Feb 21 17:51:09 GMT 2003
Hi,
I wrote a small python script to help handling moc files in Makefiles.
It's a third way additionally to the existing automagic stuff and qmake.
It can be used in a Makefile in the following way:
GLOBALMOC=mocs.cpp
GLOBALMOCOBJECT=mocs.o
SOURCES=foo.cpp main.cpp $(GLOBALMOC)
HEADERS= foo.h
OBJECTS= foo.o main.o $(GLOBALMOCOBJECT)
$(GLOBALMOC): $(SOURCES) $(HEADERS)
./create_global_moc $(SOURCES) $(HEADERS)
It works the following way: a moc file is required if a source or header
contains the Q_OBJECT macro. The create_global_moc script parses all files
given on its command line and searches checks which files contain "Q_OBJECT".
These files are remembered (e.g. foo.cpp) and a new file "mocs.cpp" is created
which will include all required moc files (e.g. foo.cpp.moc).
Additionally it does some checks whether the file mocs.cpp has to be recreated
at all.
Then this moc.cpp can be compiled as any other "normal" source file using the
normal build rules.
I see the following advantages:
-no need to insert the "#include "blah.moc" into the source files
-an explicit rule to create the moc files exists, which can be "called" by the
user in case something is fucked up (which happens from time to time)
-the script can be used to write a simple Makefile by hand with automatic mocs
without using the auto-stuff and without qmake, see the attached Makefile
-it works also for signals/slots in classes declared in the cpp files (not
only in headers, I *think* this doesn't work with the current KDE build
system)
-less hidden magic ;-)
The attached script is a first try, don't expect it be the perfect final
solution, but it works.
What do you think ?
BTW this is my very first python script ever, so I'd also be happy about
comments to the code itself.
Bye
Alex
--
Work: alexander.neundorf at jenoptik.com - http://www.jenoptik-los.de
Home: neundorf at kde.org - http://www.kde.org
alex at neundorf.net - http://www.neundorf.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: create_global_moc.py
Type: text/x-python
Size: 2641 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030221/491bce6a/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: text/x-makefile
Size: 333 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030221/491bce6a/attachment.bin>
More information about the kde-core-devel
mailing list