[CMake] Headers for VC project files

John Drescher drescherjm at gmail.com
Wed Oct 29 19:11:57 EDT 2008


On Wed, Oct 29, 2008 at 7:07 PM, Powei Feng <poweif at gmail.com> wrote:
> Hi,
> This is probably yet another noob question.  When I use
> cmake to generate Visual Studio project files, only the
> sources (cpp's) show up in the project.  Is there a flag I
> can set to include the headers (h's) as well.
> Thanks in advance,
>

Include the headers in the target. Here is an example project that I
am working on:

INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})

IF(WIN32)
    SET(CMAKE_CXX_FLAGS "/WL /GR /EHsc" )
	ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(WIN32)

ADD_DEFINITIONS(-DNEED_WL_FILTER)
#ADD_DEFINITIONS(-DNEED_SHIFT_SCALE_FILTER)

IF(USE_BZ_AIRWAY_ANALYSIS)
    ADD_DEFINITIONS(-DUSE_BZ_AIRWAY_ANALYSIS)
	include_directories("${PROJECT_SOURCE_DIR}/External/WrapCT_COPD/LungProcessing")
	set (UPMC_EXTERNAL_LIBS ${UPMC_EXTERNAL_LIBS} LungProcessing)
ENDIF (USE_BZ_AIRWAY_ANALYSIS)

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

#The following finds WrapITK
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 ${UPMC_EXTERNAL_LIBS} ${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}
)


More information about the CMake mailing list