[CMake] Problems with Qt MOC and conditional compilation.

Tim Sutton tim at linfiniti.com
Tue Mar 13 14:16:22 EST 2007


Hi Filipe

Many thanks for your response. I altered FindQt4 to look like this:

 734   MACRO (QT4_WRAP_CPP outfiles )
 735     # get include dirs
 736     QT4_GET_MOC_INC_DIRS(moc_includes)
 737
 738     #Added by Tim at the suggestion of Filipe Sousa on the cmake
mailing list
 739     #so that compiler flags get passed to moc properly
 740     GET_DIRECTORY_PROPERTY(_flags DEFINITIONS)
 741     SEPARATE_ARGUMENTS(_flags)
 742     LIST(APPEND moc_includes ${_flags})
 743
 744     FOREACH (it ${ARGN})
 745       GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
 746       GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
 747
 748       SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/moc_${outfile}.cxx)
 749       ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
 750         COMMAND ${QT_MOC_EXECUTABLE}
 751         ARGS ${moc_includes} -o ${outfile} ${it}
 752         DEPENDS ${it})
 753       SET(${outfiles} ${${outfiles}} ${outfile})
 754     ENDFOREACH(it)
 755
 756   ENDMACRO (QT4_WRAP_CPP)

When I try to compile (using make VERBOSE=1) now I get the following error:

[ 51%] Generating moc_omgmainwindow.cxx
cd /home/timlinux/dev/cpp/openModellerDesktop/build/src/gui &&
/usr/bin/moc-qt4 -I /usr/include/qt4 -I /usr/include/qt4/Qt3Support -I
/usr/include/qt4/QtSvg -I /usr/include/qt4/QtGui -I
/usr/include/qt4/QtXml -I /usr/include/qt4/QtNetwork -I
/usr/include/qt4/QtCore -DWITH_QGIS -DOMG_NO_EXPERIMENTAL -DQT_SHARED
-DQT_3SUPPORT_LIB -DQT3_SUPPORT -DQT_SVG_LIB -DQT_GUI_LIB -DQT_XML_LIB
-DQT_NETWORK_LIB -DQT_CORE_LIB -Wall -Werror -DCORE_EXPORT=
-DPLUGIN_EXPORT= -DGUI_EXPORT= -o
/home/timlinux/dev/cpp/openModellerDesktop/build/src/gui/moc_omgmainwindow.cxx
/home/timlinux/dev/cpp/openModellerDesktop/src/gui/omgmainwindow.h
moc: Invalid argument
Usage: moc [options] <header-file>
  -o<file>           write output to file rather than stdout
  -I<dir>            add dir to the include path for header files
  -E                 preprocess only; do not generate meta object code
  -D<macro>[=<def>]  define macro, with optional definition
  -U<macro>          undefine macro
  -i                 do not generate an #include statement
  -p<path>           path prefix for included file
  -f[<file>]         force #include, optional file name
  -nw                do not display warnings
  -v                 display version of moc
make[2]: *** [src/gui/moc_omgmainwindow.cxx] Error 1
make[2]: Leaving directory `/home/timlinux/dev/cpp/openModellerDesktop/build'
make[1]: *** [src/gui/CMakeFiles/openModellerDesktop.dir/all] Error 2
make[1]: Leaving directory `/home/timlinux/dev/cpp/openModellerDesktop/build'
make: *** [all] Error 2

I tried manually editing the above and running it to include only
'-DFoo' options e.g.:

cd /home/timlinux/dev/cpp/openModellerDesktop/build/src/gui &&
/usr/bin/moc-qt4 -DWITH_QGIS -DOMG_NO_EXPERIMENTAL -DQT_SHARED
-DQT_3SUPPORT_LIB -DQT3_SUPPORT -DQT_SVG_LIB -DQT_GUI_LIB -DQT_XML_LIB
-DQT_NETWORK_LIB -DQT_CORE_LIB -DCORE_EXPORT= -DPLUGIN_EXPORT=
-DGUI_EXPORT= -o
/home/timlinux/dev/cpp/openModellerDesktop/build/src/gui/moc_omgmainwindow.cxx
/home/timlinux/dev/cpp/openModellerDesktop/src/gui/omgmainwindow.h

And moc ran successfully and when I did a make install the program
behaved correctly with slots defined in the header working as
expected.

I'm just not familiar enough with cmake to know how to adjust your
macro update so it only includes -D options and not -w etc.

Regards

Tim

-- 
-- 
Tim Sutton

Visit http://qgis.org for a great Open Source GIS
Home Page: http://linfiniti.com
Skype: timlinux
MSN: tim_bdworld at msn.com
Yahoo: tim_bdworld at yahoo.com
Jabber: timlinux
Irc: timlinux on #qgis at freenode.net


More information about the CMake mailing list