[vtkusers] CMake best practice for using VTK?

David Gobbi david.gobbi at gmail.com
Sat Jul 2 08:45:20 EDT 2016


On Sat, Jul 2, 2016 at 5:09 AM, Elvis Stansvik <elvis.stansvik at orexplore.com
> wrote:
>
>
> I'm actually a little unsure which set of modules that the script prints I
> should be using. It prints three set of modules: referenced, minimal and
> maximal. E.g:
>
> Modules and their dependencies:
> find_package(VTK COMPONENTS
>   vtkCommonColor
>   vtkCommonComputationalGeometry
>   vtkCommonCore
>   vtkCommonDataModel
>   vtkCommonExecutionModel
>   vtkCommonMath
>   vtkCommonMisc
>   vtkCommonSystem
>   vtkCommonTransforms
>   vtkFiltersCore
>   vtkFiltersGeneral
>   vtkFiltersSources
>   vtkGUISupportQt
>   vtkImagingCore
>   vtkInteractionStyle
>   vtkRenderingCore
>   vtkRenderingOpenGL
>   vtkkwiml
> )
> Your application code includes 18 of 189 vtk modules.
>
> All modules referenced in the files:
> find_package(VTK COMPONENTS
>   vtkCommonCore
>   vtkFiltersSources
>   vtkGUISupportQt
>   vtkRenderingCore
>   vtkRenderingOpenGL
> )
> Your application code includes 5 of 189 vtk modules.
>
> Minimal set of modules:
> find_package(VTK COMPONENTS
>   vtkCommonCore
>   vtkFiltersSources
>   vtkGUISupportQt
> )
> Your application code includes 3 of 189 vtk modules.
>
>
> Would it be enough to use the minimal set? When would I want to use one of
> the other two?
>

The minimal set should work.  But I always use the middle set, because I
want to directly link every library that contains a class that I directly
utilize.  If I rely on library dependencies to bring in all the libraries I
use, then I will be out of luck if a future release of VTK manages to
eliminate some of the dependencies I was relying on.

Note that the fact that this list contains an OpenGL/OpenGL2 library means
extra logic is required when building the link line.  I end up with a mess
of cmake code that looks like this:

  # Set VTK_LIBS to the libs I want to link
  set(VTK_LIBS
      vtkCommonCore vtkCommonDataModel vtkImagingCore
      vtkIOImage vtkIOSQL
      vtkRenderingImage vtkRenderingFreeType)
  # Conditionally add these libs if present in VTK_LIBRARIES
  set(VTK_FACTORY_LIBS
      vtkIOMPIImage vtkIOMySQL
      vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL
      vtkRenderingOpenGL2 vtkRenderingFreeTypeOpenGL2)
  foreach(TMP_LIB ${VTK_FACTORY_LIBS})
    list(FIND VTK_LIBRARIES ${TMP_LIB} TMP_INDEX)
    if(TMP_INDEX GREATER -1)
      set(VTK_LIBS ${VTK_LIBS} ${TMP_LIB})
    endif()
  endforeach()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160702/faadb4d6/attachment.html>


More information about the vtkusers mailing list