Re: [CMake] question about QT4_WRAP_CPP

2009-12-07 Thread Pau Garcia i Quiles
On Tue, Dec 8, 2009 at 12:21 AM, Glenn Hughes  wrote:
> Thanks Pau,
>
> Interesting! If I remove the #include "moc_main.cxx" line, then the
> generated moc file includes "main.h", so then everything will build. I guess
> moc auto-detects which method you are using, and generates its code
> accordingly.

The problem you were having is you were moc'ing files twice[*],
therefore the linker found two references to the very same methods,
one generated by automoc, the other generated by qt4_wrap_cpp.

[*] Assuming you had not cleaned your build directory

> I was trying to see if there was a way I could build the example without
> splitting the object def in main.cpp into main.h... but I guess not. So,
> this is a minor difference between CMake and qmake. In qmake its OK to have
> your object definitions in your source files, but it seems in CMake there's
> no way to do this cleanly.

There is. It's called QT4_AUTOMOC. Try the example I attached to the bugreport.

> Yes, I understand what you're saying about the bug with QT4_AUTOMOC... And
> the header not existing at all is a similar case to the header and src being
> in different directories.

You don't need to split .h and .cpp if you use QT4_AUTOMOC but until
the bug is fixed (sorry Clinton, I don't have time at the moment to
fix it), QT4_AUTOMOC will only work if .h and .cpp files are in the
same directory.

>
> Cheers
> Glenn
>
> On Mon, Dec 7, 2009 at 6:08 PM, Pau Garcia i Quiles 
> wrote:
>>
>> If you use QT4_WRAP_CPP, do not #include "blah.moc"
>>
>> If you use QT4_AUTOMOC, #include "blah.moc"
>>
>> QT4_AUTOMOC is more convenient but currently there's the bug I pointed
>> in my other e-mail: if the .h and the .cpp file for a class are in
>> different directories, QT4_AUTOMOC fails.
>>
>> --
>> Pau Garcia i Quiles
>> http://www.elpauer.org
>> (Due to my workload, I may need 10 days to answer)
>
>



-- 
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] question about QT4_WRAP_CPP

2009-12-07 Thread Pau Garcia i Quiles
On Mon, Dec 7, 2009 at 11:54 PM, Glenn Hughes  wrote:
> I'm still playing around with the states Qt example, and I've hit something
> I don't understand:
>
> I can get everything working as expected with QT4_AUTOMOC, but not if I use
> QT4_WRAP_CPP.
>
> In the QT4_WRAP_CPP case, it seems the only way to get dependencies set up
> correctly is to add the MOC output to the target, i.e.
>
> QT4_WRAP_CPP( states_MOC_files ${states_HEADERS})
> ADD_EXECUTABLE( states MACOSX_BUNDLE ${states_SRCS} ${states_MOC_files}
> ${states_RESOURCES_SOURCES} )
>
> However, if I do this CMake adds the moc files (named in the form
> moc_foo.cxx) to the project to be compiled as C++ files.
> BUT, MOC files are not designed to be compiled on their own. Typically they
> are included at the bottom of the module that contains the source for the
> objects in question. They do not include all the headers that they need, and
> so they will not build independently.
>
> So, if I include the moc files in the ADD_EXECUTABLE line, my build doesn't
> work...
> but if I remove them, the dependency is not set up, so the moc files are not
> generated at all.
>
> How can I say "these files are required by this target, but don't try to
> compile them directly?"
>
> Or is there something else I should be doing?

If you use QT4_WRAP_CPP, do not #include "blah.moc"

If you use QT4_AUTOMOC, #include "blah.moc"

QT4_AUTOMOC is more convenient but currently there's the bug I pointed
in my other e-mail: if the .h and the .cpp file for a class are in
different directories, QT4_AUTOMOC fails.

-- 
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake