[Insight-users] How to write CMakeLists

Gavin Baker gavinb+xtk at cs . mu . OZ . AU
Tue, 23 Sep 2003 11:52:41 +1000


Hello Chunyan,

On Mon, Sep 22, 2003 at 06:31:28PM +0200, jiang wrote:

> If I want to use VTK as visualization tool, how can I add this library to
> CMakeLists? I wrote it as
> LINK_LIBRARIES (
> ${ITK_LIBRARIES}
> ${VTK_LIBRARIES}
> )

CMake has support for packages, so that once something like VTK or ITK is
installed, a single command will pull in the correct settings.  So you first
need to call FIND_PACKAGE() which sets up the build variables for includes
and libraries.  The CMake guide has more info on this:

    http://www . cmake . org/HTML/Documentation . html

> I install vtk42 in my system.
> However it does not work. The program can not pass compiling. The error
> message is:
> fatal error C1083: Cannot open include file: 'vtkRenderWindow.h': No such
> file or directory...

This is just because the include path is not set; using FIND_PACKAGE() will
fix this by setting include and lib paths.

Here is a working example from a simple appliation of mine:



PROJECT(vgf)

# Required libraries

FIND_PACKAGE(ITK)
IF(ITK_FOUND)
   INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
   MESSAGE(FATAL_ERROR "Cannot build without ITK.  Please set ITK_DIR.")
ENDIF(ITK_FOUND)

FIND_PACKAGE(VTK)
IF (VTK_FOUND)
   INCLUDE(${VTK_USE_FILE})
ELSE(VTK_FOUND)
   MESSAGE(FATAL_ERROR "Cannot build without ITK.  Please set VTK_DIR.")
ENDIF(VTK_FOUND)

# The application

ADD_EXECUTABLE(vgf vgf.cxx)

TARGET_LINK_LIBRARIES(vgf popt ITKCommon ITKIO ITKBasicFilters vtkCommon vtkImaging vtkGraphics vtkIO vtkFiltering vtkHybrid vtkRendering)



The libraries are specified individually so as not to include every one, but
you could use ${VTK_LIBRARIES} if you wish.

Hope this helps...

  :: Gavin

-- 
Gavin Baker                                Computer Vision Lab (CVMIL)
http://www . cs . mu . oz . au/~gavinb                 University of Melbourne