Am 21.10.2016 um 01:29 schrieb Alan W. Irwin:
On 2016-10-20 15:08-0400 Brad King wrote:

Please construct a minimal/complete example source tree/tarball
that demonstrate the layout you'd like to have work.  That will
be helpful in constructing such a bug report.

OK. I have attached the requested minimal example to serve as the
basis for further discussion.  The files in the tarball are

test_qt5/
test_qt5/include/
test_qt5/include/test_q_object.h
test_qt5/main.cpp
test_qt5/CMakeLists.txt

include/test_q_object.h is a header that contains a minimal use of
Q_OBJECT.  (Likely too minimal so I will need help with that see below.)
main.cpp is a "hello-world" example that #includes that header.  It also
#includes
the moc-generated moc_test_q_object.cpp.

The USE_AUTOMOC option for this test project defaults to OFF.  In that
default case this test project is set up so that the qt5_wrap_cpp is
called instead of using automoc, and the
result is the compilation works fine (all headers and files generated
by moc are found with no issues) but there is a link error

CMakeFiles/helloworld.dir/main.cpp.o:(.data.rel.ro._ZTV7MyClass[_ZTV7MyClass]+0x28):

undefined reference to MyClass::~MyClass()'

which likely has to do with include/test_q_object.h being too minimal.
I would appreciate help with that issue to complete this example, but
that is a side issue and the principal result is the compile (as
opposed to the link) was a success with the default -DUSE_AUTOMOC=OFF.

However, if you try -DUSE_AUTOMOC=ON with this project the compile
step (before it even gets to the link step) fails as follows:

Automatic moc for target helloworld
/home/software/cmake/install-3.5.2/bin/cmake -E cmake_autogen
/home/software/plplot/HEAD/test_qt5/build_dir/CMakeFiles/helloworld_automoc.dir/
""
AUTOGEN: Checking /home/software/plplot/HEAD/test_qt5/main.cpp
AUTOGEN: error: /home/software/plplot/HEAD/test_qt5/main.cpp The file
includes the moc file "moc_test_q_object.cpp", but could not find header
"test_q_object{.h,.hh,.h++,.hm,.hpp,.hxx,.in,.txx}" in
/home/software/plplot/HEAD/test_qt5/

I hope a simple solution to this deficiency of the current automoc can
be found using the following ideas (copied from my previous post to
keep this self-contained).

If

#include "moc_<name>.cpp"

is found in a source file under automoc
control, then if moc_<name>.cpp could not be found in any of the
include directories for the target, then search those include
directories (including source-tree equivalents of build-tree include
directories) for <name>.h, run moc on that file and place the result
moc_<name>.cpp in the build directory corresponding to <name.h>.

So the result is moc would be run just once on the correct header file
with the moc_<name>.cpp result stored in one logical location no
matter how many different source files in different directories have
code with the above #include.

Alan
__________________________
Alan W. Irwin

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(){;}

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.

A quick fix for the example would be to explicitly add the
headers-to-moc to the sources list.
- add_executable(helloworld main.cpp)
+ add_executable(helloworld main.cpp
+       ${CMAKE_SOURCE_DIR}/include/test_q_object.h)

The #include "moc_test_q_object.cpp" in main.cpp can be removed then.

-Sebastian










--

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to