[vtkusers] CMake best practice for using VTK?
Elvis Stansvik
elvis.stansvik at orexplore.com
Mon Jun 27 16:17:16 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 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.
>
Ah, thanks for sharing! I'll have a look at that script.
Elvis
>
> - David
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160627/7b661567/attachment.html>
More information about the vtkusers
mailing list