[cmake-developers] Current deficiencies of automoc

Sebastian Holtermann seblist at xwmw.org
Sat Oct 22 13:49:44 EDT 2016


Am 21.10.2016 um 13:39 schrieb Alan W. Irwin:
> On 2016-10-21 09:42+0200 Sebastian Holtermann wrote:
>
> [...]
>> Hi!
>>
>> I tried your example.
>> It isn't complete, test_q_object.h needs an
>>    #include <QObject>
>> and a constructor/destructor definition, e.g.:
>>    MyClass(QObject *parent = 0) {;}
>>    ~MyClass(){;}
>
> Hi Sebastian:
>
> Thanks for that fix which indeed solves the linking issue.
>
>>
>> With regards to automoc the
>>    #include "moc_test_q_object.cpp"
>> in the end should not be neccessary since
>>    #include "test_q_object.h"
>> already references to the header.
>> The problem is that this reference is not a direct path from the
>> source file but relies on include_directories.
>> CMake does not seem to populate automoc's scan list with files
>> from include_directories.
>> I tried to figure out why but this is quite complex.
>
> I hope you are able to fix this along the lines I have mentioned
> (which includes putting all generated results in the build tree
> corresponding to the header) since using #include
> "moc_test_q_object.cpp" in main.cpp is currently the only documented
> way to use automoc (see, e.g.,
> <https://cmake.org/cmake/help/v3.6/prop_tgt/AUTOMOC.html>).

As Sascha Cunz pointed out well, it is problematic to simply automoc any 
header found in the include_directories. I think the current behaviour 
is reasonable good. The documentation could be improved though to 
mention the fullpath method.

>
> In sum, I hope you are willing to fix the currently documented automoc
> "#include" method so it puts all generated results in the build tree
> corresponding to the header, update the automoc documentation so you
> also mention the "fullpath" alternative, and also similarly fix that
> method so the location of the two generated files is in the build
> directory corresponding to the header rather than the build directory
> corresponding to the source file.

Actually I made an implementation in 3.6.0 that generated the moc files
in the a build tree subdirectory correspoding to the header path.
But that blew up on some projects because the generated paths got too 
long for some compiĺers. That implementation was theefore reverted.
In 3.7  there is a new approatch that generates the moc files in
${CMAKE_BINARY_DIR}/
     ${TARGETNAME}_automoc.dir/
         ${HEADERNAME}_${HEADERPATHCHECKSUM}.cpp
This ensures that the paths don't get too long and that there won't be 
any name collisions.

> My apologies for making suggestions for improvement without being able
> to help you with the implementation (except testing of results), but
> my C++ skills and CMake developer skills are just not up to it (as you
> could probably tell from the required test_q_object.h fix you had to
> suggest.)

We'll I'm just a spare time contributor but it's motivating to see that 
someone cares about these issues as well.

-Sebastian




More information about the cmake-developers mailing list