Error with mocs in compiling kdevelop

Alexander Neundorf neundorf at kde.org
Sat Aug 12 22:27:34 UTC 2006


On Saturday 12 August 2006 00:04, Eric Pignet wrote:
> On 8/11/06, Alexander Neundorf <neundorf at kde.org> wrote:
> > > I use last cmake version, as given in
> > > http://developer.kde.org/build/trunk.html
> >
> > So cmake 2.4.3 ?
>
> Yes
>
> > > make[2]: *** No rule to make target « lib/weaver/Job.moc », needed by «
> > > lib/weaver/CMakeFiles/ThreadWeaver.dir/Job_moc.o ».
> > > make[2]: *** no rule to make target « lib/weaver/Thread.moc », needed
> > > by « lib/weaver/CMakeFiles/ThreadWeaver.dir/Thread_moc.o ».
> > >
> > > I added some trace messages in kde4_automoc macro and I see that
> > > includes of both missing mocs are well detected and that
> > > add_custom_commands are called. But no target is generated in
> > > makefiles...
> >
> > I had a quick look at the sources.
> > Neither Job.cpp nor Thread.cpp are listed as a source file for the
> > library. Why ?
>
> Because if Job.cpp and Thread.cpp are listed as sources in addition to
> Job_moc.cpp and Thread_moc.cpp, the link fails with many symbols
> already referenced.
> The problem is that they are needed as sources for their mocs to be
> generated, but we want to compile and link Job_moc.cpp and
> Thread_moc.cpp only.
>
> > And the generated Job_moc.cpp and Thread_moc.cpp include Job.moc and
> > Thread.moc ?
>
> Yes
>
> > Job_moc.cpp and Thread_moc.cpp do not exist yet at cmake time, so if
> > these generated files will include Thread.moc/Job.moc this cannot be
> > detected at this time.
>
> Yes, _moc files do not exist, but Job.cpp and Thread.cpp are also part
> of the list given to kde4_automoc so includes of Job.moc and
> Thread.moc are found there.
>
> To sum up:
> - We want Job.moc and Thread.moc to be generated from Job.h and
> Thread.h, and Job_moc.cpp and Thread_moc.cpp to be generated from
> Job.cpp and Thread.cpp.

Rules for generating the moc files:

QT4_GENERATE_MOC(Job.h ${CMAKE_CURRENT_BINARY_DIR}/Job.moc)
QT4_GENERATE_MOC(Thread.h ${CMAKE_CURRENT_BINARY_DIR}/Thread.moc)

QT4_GENERATE_MOC(Job.cpp ${CMAKE_CURRENT_BINARY_DIR}/Job_moc.cpp)
QT4_GENERATE_MOC(Thread.cpp ${CMAKE_CURRENT_BINARY_DIR}/Thread_moc.cpp)

Set the sources:

set(ThreadWeaver_LIB_SRCS
    DestructedState.cpp
    WeaverImpl.cpp
    InConstructionState.cpp
    State.cpp
    ShuttingDownState.cpp
    WeaverInterface.cpp
    WeaverObserver.cpp
    SuspendedState.cpp
    WorkingHardState.cpp
    DebuggingAids.cpp
    ThreadWeaver.cpp
    SuspendingState.cpp
    IncludeMocs.cpp
    JobCollection.cpp
    JobSequence.cpp
)

And then run automoc only once on the sources without the moc files:

kde4_automoc(${ThreadWeaver_LIB_SRCS})

and append the moc files to the sources:

set(ThreadWeaver_LIB_SRCS ${ThreadWeaver_LIB_SRCS}
    ${CMAKE_CURRENT_BINARY_DIR}/Job_moc.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/Thread_moc.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/Job.moc
    ${CMAKE_CURRENT_BINARY_DIR}/Thread.moc
)

With cmake 2.4.3 this will generate the required dependencies.
I'm not 100% sure this will also work with cmake 2.4.1 and 2.4.2.

If it doesn't, don't add Job.moc and Thread.moc to the list of sources, but 
add the following:

macro_add_file_dependencies(${CMAKE_CURRENT_BINARY_DIR}/Job_moc.cpp 
${CMAKE_CURRENT_BINARY_DIR}/Job.moc )
macro_add_file_dependencies(${CMAKE_CURRENT_BINARY_DIR}/Thread_moc.cpp 
${CMAKE_CURRENT_BINARY_DIR}/Thread.moc )

This will also add the dependencies, but the version given above (adding the 
moc files simply to the list of sources) works better.

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




More information about the KDevelop-devel mailing list