[CMake] Qt-Sources and non Qt-Source

John Drescher drescherjm at gmail.com
Tue Aug 12 11:54:27 EDT 2008


On Tue, Aug 12, 2008 at 11:48 AM, Jan Dinger <dinger.jan at googlemail.com> wrote:
> Thats right. So, I ignore this.
>
> Can I disable this warning in my release version? This warning looks not so
> good.
>
Yes. The warning is that you are unnecessarily running moc on that
file. If you are not going to derive any classes from QObject in this
file then you do not need to be running moc on the file you can put
this in a section of headers that do not need moc.

Here is an application that I am working on that uses (ITK, VTK, Qt and boost):

PROJECT(LungAnalysis)

IF(WIN32)
    CMAKE_MINIMUM_REQUIRED(VERSION 2.5 FATAL_ERROR)
    SET(CMAKE_CXX_FLAGS "/WL /GR /EHsc" )
ENDIF(WIN32)

ADD_DEFINITIONS(-DNEED_WL_FILTER)
#ADD_DEFINITIONS(-DNEED_SHIFT_SCALE_FILTER)

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

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( Boost REQUIRED )
FIND_PACKAGE( Qt4 REQUIRED )
FIND_PACKAGE( ITK REQUIRED )
FIND_PACKAGE( VTK REQUIRED )
#FIND_PACKAGE( WrapITK  REQUIRED )

INCLUDE( ${ITK_USE_FILE} )
INCLUDE( ${VTK_USE_FILE} )

FIND_PATH(ITK_VTK_GLUE_DIR "CMakeLists.txt" PATHS
${ITK_SOURCE_DIR}/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue)
INCLUDE_DIRECTORIES(${ITK_VTK_GLUE_DIR}/src)

INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} . Include)

INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )

INCLUDE( ${QT_USE_FILE} )
SET( UPMC_LA_SRCS
	./src/main.cxx
	./src/mainwindow.cxx
	./src/textwidget.cxx
	./src/VTK2dWidget.cpp
    ./src/itkQtProgressBar.cxx
    ./src/ImageSliceViewer.cxx
    ./src/DicomImageReaderBase.cxx
    ./src/InteractorObserver.cxx
    ./src/GenericVTKViewer.cxx
    ./src/upmcView.cxx
    ./src/upmcDocument.cxx
    ./src/upmcDocumentMgr.cxx
  )

SET( UPMC_LA_MOC_HDR
	./Include/mainwindow.h
	./Include/textwidget.h
	./Include/VTK2dWidget.h
	./Include/itkQtAdaptor.h
	./Include/itkQtLightIndicator.h
	./Include/itkQtProgressBar.h
	./Include/upmcView.h
	./Include/upmcDocument.h
	./Include/upmcDocumentMgr.h
)

SET( UPMC_LA_HDRS
	./Include/ImageSliceViewer.h
	./Include/DicomSeries.h
	./Include/DicomSeries.txx
	./Include/DicomSeriesBase.h
	./Include/DicomSeriesBase.txx
	./Include/DicomImageReader.h
	./Include/DicomImageReader.txx
	./Include/DicomImageReaderBase.h
	./Include/InteractorObserver.h
	./Include/ClickedPointEvent.h
	./Include/GenericVTKViewer.h
)

# some .ui files
SET( UPMC_LA_UIS
	./rc/vtk2dWidget.ui
)

# 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} )

# this will run uic on .ui files:
QT4_WRAP_UI( UPMC_LA_UI_HDRS ${UPMC_LA_UIS} )

LINK_LIBRARIES ( LungAnalysis ${QT_LIBRARIES} ITKCommon
ITKBasicFilters ITKIO QVTK vtkCommon
)

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

You can see that I have MOC headers and also regular headers.

John


More information about the CMake mailing list