On Wednesday 10 May 2006 15:00, David Faure wrote: > I want to implement "Q_OBJECT in .cpp file and no .h file at all, and .cpp > includes .moc" support in kde4_automoc, for unit tests. Would be much more > convenient than having to write a .h file for each, and by having the "no > header file" condition there we avoid grepping both .h and .cpp for > Q_OBJECT in all cases, which might slow things down.
How about using Qt4_WRAP_CPP() ? Usage: set(mySrcs foo.cpp widget.cpp main.cpp) qt4_wrap_cpp(mySrcs widget.cpp) # <- all files which have to be moc'ed. ... would also not make automoc yet slower. > > But my current implementation doesn't work - no moc file, and the binary is > being linked without any source file as input... I'm stumped. > > --- KDE4Macros.cmake (revision 538918) > +++ KDE4Macros.cmake (working copy) > @@ -240,6 +240,19 @@ > get_filename_component(_basename ${_current_MOC} NAME_WE) > # set(_header ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h) > set(_header ${_abs_PATH}/${_basename}.h) > + > + # Check if the header exists > + if (NOT EXISTS ${_header}) > + # Otherwise check if the cpp file has Q_OBJECT > + string(REGEX MATCH "Q_OBJECT" _match "${_contents}") > + if (_match) Isn't it matched ? Maybe ".*Q_OBJECT.*" should work ? > + # Yes -> moc the cpp file, not the non-existing > header file. + set(_header ${_abs_FILE}) > + else (_match) > + message(FATAL_ERROR "${_abs_FILE} includes > ${_moc_INCS} but there's no ${_header} file and no Q_OBJECT in ${_abs_FILE} > either") + endif (_match) > + endif (NOT EXISTS ${_header}) > + > set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) > #set(_moc ${_abs_PATH}/${_current_MOC}) > add_custom_command(OUTPUT ${_moc} > COMMAND ${QT_MOC_EXECUTABLE} > ARGS ${_moc_INCS} ${_header} -o ${_moc} > MAIN_DEPENDENCY ${_header} > ) > > The testcase: > set(kovariabletest_SRCS kovariabletest.cpp) > kde4_automoc(${kovariabletest_SRCS}) > kde4_add_executable(kovariabletest RUN_UNINSTALLED ${kovariabletest_SRCS}) > target_link_libraries(kovariabletest kotext ${QT_QTTEST_LIBRARY}) > > with kovariabletest.cpp defining a QObject-derived class, with Q_OBJECT > macro and #include "kovariabletest.moc" > > What happens: > Linking CXX executable kovariabletest > /usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../lib64/crt1.o: In function > `_start':../sysdeps/x86_64/elf/start.S:109: undefined reference to `main' > Indeed in CMakeFiles/kovariabletest.dir/build.make, kovariabletest_OBJECTS > is empty! How could this happen, given that I checked and > ${kovariabletest_SRCS} is definitely not empty just before the call to > kde4_add_executable... Hmm, strange. I'll have a closer look later. 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 _______________________________________________ Kde-buildsystem mailing list Kde-buildsystem@kde.org https://mail.kde.org/mailman/listinfo/kde-buildsystem