[vtkusers] CMake best practice for using VTK?

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Jun 30 07:54:49 EDT 2016


2016-06-30 13:16 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:

> 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.
>>
>
> The script seems to work fine, but has some limitations. It seems it only
> considers headers that start with "vtk", so if I include QVTKWidget.h, it
> won't pick up that I need the vtkGUISupportQt module.
>

I made this pull request to make it also consider QVTK* headers:

    https://gitlab.kitware.com/vtk/vtk/merge_requests/1604

Elvis


>
> 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/20160630/970a2105/attachment.html>


More information about the vtkusers mailing list