[CMake] moc not being run successfully (every time) in Visual Studio 2003

John Drescher drescherjm at gmail.com
Tue Apr 22 10:00:25 EDT 2008


I am running CMake-2.7.2008.04.21 and under Visual Studio moc does not
run correctly all the time for my QT4 projects.

Here is the  error:

------ Build started: Project: LungAnalysis, Configuration: Debug Win32 ------

Generating qrc_LungAnalysis.cxx
Generating moc_textwidget.cxx
moc: Cannot open options file specified with @
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
Project : error PRJ0019: A tool returned an error code from
"Generating moc_textwidget.cxx"

Build log was saved at
"file://x:\VC.NET\Libraries\MyCode\LungAnalysis\LungAnalysis.dir\Debug\BuildLog.htm"
LungAnalysis - 1 error(s), 0 warning(s)


------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------

Project configuration skipped because it is not selected in this
solution configuration


---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 1 skipped

If I run moc directly from the project directory all is fine:

[x:\vc.net\libraries\mycode\lunganalysis]moc @moc_textwidget.cxx_parameters

[x:\vc.net\libraries\mycode\lunganalysis]moc @moc_mainwindow.cxx_parameters

I ran through the Qt tutorial building everything (in my own folder)
using CMake to generate Visual Studio 2003 projects. For the 14
projects in the tutorial 3 or 4 of them failed with this error. Some
of the times exiting Visual C++ and restarting it caused it to work
correctly but others it failed the same way.

Here is an example CMakeLists.txt (Please note I just started using
CMake, QT and ITK last week ...)

PROJECT(LungAnalysis)

IF(WIN32)
    CMAKE_MINIMUM_REQUIRED(VERSION 2.5 FATAL_ERROR)
ENDIF(WIN32)

SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all executables.")

FIND_PACKAGE( Qt4 REQUIRED )
FIND_PACKAGE( ITK REQUIRED )

INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )

INCLUDE( ${QT_USE_FILE} ${ITK_USE_FILE} )

SET( UPMC_LA_SRCS
	./main.cxx
	./mainwindow.cxx
	./textwidget.cxx
)

SET( UPMC_LA_MOC_HDR
	./mainwindow.h
	./textwidget.h
)

# and finally an resource file
SET( UPMC_LA_RCS
	./rc/LungAnalysis.qrc
)

# this command will generate rules that will run rcc on all files from
UPMC_LA_RCS
# in result UPMC_LA_RC_SRCS variable will contain paths to files produced by rcc
QT4_ADD_RESOURCES( UPMC_LA_RC_SRCS ${UPMC_LA_RCS} )

# and finally this will run moc:
QT4_WRAP_CPP( UPMC_LA_MOC_SRCS ${UPMC_LA_MOC_HDR} )

LINK_LIBRARIES ( LungAnalysis ${QT_LIBRARIES} )

IF(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

ADD_EXECUTABLE( LungAnalysis ${UPMC_LA_SRCS} ${UPMC_LA_MOC_SRCS}
${UPMC_LA_MOC_HDR} ${UPMC_LA_RC_SRCS} )


Thanks in Advance,
John


More information about the CMake mailing list