[vtkusers] CMake best practice for using VTK?

Elvis Stansvik elvis.stansvik at orexplore.com
Sat Jul 2 07:09:05 EDT 2016


2016-06-27 22:10 GMT+02:00 David Gobbi <david.gobbi at gmail.com>:

>
>
> On Mon, Jun 27, 2016 at 1:44 PM, Elvis Stansvik <
> elvis.stansvik at orexplore.com> wrote:
>
>> I'm using the trio
>>
>> find_package(VTK REQUIRED)
>>
>> include(${VTK_USE_FILE})
>>
>> target_link_libraries(myapp ${VTK_LIBRARIES})
>>
>> in my CMakeLists.txt, to find and link against VTK, like is done in the
>> VTK examples.
>>
>> I'm surprised by two things:
>>
>> 1. The shear amount of libraries that are linked against. Are all these
>> really necessary, or is it possible to more selective somehow? Is there
>> something like Qt's CMake system, where you can pull in just a certain Qt
>> module with target_link_libraries(myapp Qt5::Widgets) ?
>>
>> 2. How come the .so files are specified directly as inputs, with their
>> full paths? Isn't the common method to just add the appropriate -l (and
>> possibly -L if needed) flags?
>>
>
> I build my own list that contains only the libraries that I need, and I
> also try to be careful about public vs. private linkage.  For example:
>
>     set(VTK_LIBS vtkCommonCore vtkCommonDataModel vtkImagingCore
> vtkIOImage)
>     # Also link vtkIOMPIImage if present, it has factories for vtkIOImage
>     list(FIND VTK_LIBRARIES vtkIOMPIImage TMP_INDEX)
>     if(TMP_INDEX GREATER -1)
>       set(VTK_LIBS ${VTK_LIBS} vtkIOMPIImage)
>     endif()
>
>     target_link_libraries(${LIB_NAME} LINK_PUBLIC ${VTK_LIBS})
>     # target_link_libraries(${LIB_NAME} LINK_PRIVATE <other libs>)
>
> To find out what modules you need to link, the script
> VTK/Utilities/Maintenance/WhatModulesVTK.py can be of some use.
>

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?

Elvis


> I know this doesn't cover all of your points, but unfortunately this is as
> complete an answer as I have time to give right now.  Hopefully someone
> else can jump in and provide more details.
>
>  - David
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160702/dbfa1713/attachment.html>


More information about the vtkusers mailing list