[vtk-developers] Repeated calls to find_package(VTK COMPONENTS ...)

Matt McCormick matt.mccormick at kitware.com
Thu Sep 25 12:48:11 EDT 2014


Looking at FindITK.cmake and FindVTK.cmake, they appear to not
propagate COMPONENTS [1] [2].  I think we should consider removing
these altogether.  Any version of ITK or VTK from moderately recent
history will have a Config.cmake file.

Matt

[1] http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/FindITK.cmake;h=c9d39eb981f6933d61fc6cb4e0e41f26baabdeab;hb=HEAD
[2] http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/FindVTK.cmake;h=60f48dd4063f3e0eed0f733b923ae7a83b7c76fc;hb=HEAD

On Wed, Sep 24, 2014 at 5:22 PM, Matt McCormick
<matt.mccormick at kitware.com> wrote:
> Hi Marcus,
>
> Thanks again for your feedback and information here.
>
>
> Another note for posterity: I am finding that a project that does
>
> find_package( ITK REQUIRED
>   COMPONENTS
>    [...]
>   ITKVtkGlue
> )
>
> find_package( VTK NO_MODULE
>   REQUIRED
>   COMPONENTS
>     [...]
> )
>
> the "NO_MODULE" option is required to avoid missing includes.
>
>
> In summary, to avoid issues:
>
>
> 1) Use COMPONENTS for all calls to find_package( VTK
>
> 2) Pass NO_MODULE to find_package( VTK
>
>
> Thanks,
> Matt
>
>
> On Tue, Sep 9, 2014 at 2:42 PM, Marcus D. Hanwell
> <marcus.hanwell at kitware.com> wrote:
>> Matt,
>>
>> Probably commit f915a54, made after I proposed a different change that
>> was ultimately rejected. I didn't realize you were on 6.0 - a lot has
>> changed since then. I am not entirely certain what your use case is
>> for mixed - reallyt non one should make mixed calls and you should
>> prefer to always specify COMPONENTS. It would be safer to at least
>> spit out a warning, I can look at adding something to warn.
>>
>> Marcus
>>
>> On Tue, Sep 9, 2014 at 2:37 PM, Matt McCormick
>> <matt.mccormick at kitware.com> wrote:
>>> Hi Marcus,
>>>
>>> Thanks for taking a look at this. I reproduced your output with VTK
>>> master for build a build tree and install tree.  However, I get
>>>
>>> -- LIBS: vtkChartsCore;vtkCommonColor;vtkCommonDataModel;vtkCommonMath;vtkCommonCore;vtksys;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkInfovisCore;vtkFiltersExtraction;vtkCommonExecutionModel;vtkFiltersCore;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkIOImage;vtkDICOMParser;vtkIOCore;/usr/lib64/libz.so;vtkmetaio;/usr/lib64/libjpeg.so;/usr/lib64/libpng.so;/usr/lib64/libtiff.so;vtkIOXMLParser;/usr/lib64/libexpat.so;vtkRenderingFreeType;/usr/lib64/libfreetype.so;vtkftgl;vtkRenderingOpenGL;vtkImagingHybrid
>>> -- LIBS: vtkCommonCore
>>> -- LIBS: vtkCommonMath
>>> -- LIBS: vtkChartsCore
>>> -- LIBS: vtkChartsCore
>>> -- Configuring done
>>> -- Generating done
>>> -- Build files have been written to: /tmp/vtkcomponents/build
>>>
>>> for an installed VTK 6.0.
>>>
>>>
>>> What was the fix and where it was made? We would like to have similar
>>> behavior for ITK and other CMake projects that make use of components.
>>>
>>>
>>> I hope that multiple calls, sometimes without specifying COMPONENTS,
>>> will still work. If it does not work, CMake should complain
>>> informatively that a non-COMPONENTS call cannot occur after a
>>> COMPONENTS call.
>>>
>>> Thanks,
>>> Matt
>>>
>>> On Tue, Sep 9, 2014 at 2:18 PM, Marcus D. Hanwell
>>> <marcus.hanwell at kitware.com> wrote:
>>>> Pushing this a little further, to see if we can build executables in
>>>> the same directory with multiple calls, the following worked for me
>>>> locally,
>>>>
>>>> cmake_minimum_required(VERSION 3.0)
>>>>
>>>> find_package(VTK COMPONENTS vtkChartsCore vtkRenderingContextOpenGL NO_MODULE)
>>>> message(STATUS "LIBS: ${VTK_LIBRARIES}")
>>>> message(STATUS "DEFS: ${VTK_DEFINITIONS}")
>>>> add_executable(testexe test.cxx)
>>>> set_property(TARGET testexe APPEND
>>>>   PROPERTY COMPILE_DEFINITIONS "${VTK_DEFINITIONS}")
>>>> set_property(TARGET testexe APPEND
>>>>   PROPERTY INCLUDE_DIRECTORIES ${VTK_INCLUDE_DIRS})
>>>> target_link_libraries(testexe ${VTK_LIBRARIES})
>>>>
>>>> find_package(VTK COMPONENTS vtkCommonCore NO_MODULE)
>>>> message(STATUS "LIBS: ${VTK_LIBRARIES}")
>>>> message(STATUS "DEFS: ${VTK_DEFINITIONS}")
>>>> add_executable(testexe2 test2.cxx)
>>>> set_property(TARGET testexe2 APPEND
>>>>   PROPERTY COMPILE_DEFINITIONS "${VTK_DEFINITIONS}")
>>>> set_property(TARGET testexe2 APPEND
>>>>   PROPERTY INCLUDE_DIRECTORIES ${VTK_INCLUDE_DIRS})
>>>> target_link_libraries(testexe2 ${VTK_LIBRARIES})
>>>>
>>>> Producing the output,
>>>>
>>>> -- LIBS: vtkChartsCore;vtkCommonColor;vtkCommonDataModel;vtkCommonMath;vtkCommonCore;vtksys;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkInfovisCore;vtkFiltersExtraction;vtkCommonExecutionModel;vtkFiltersCore;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;vtkfreetype;vtkzlib;vtkftgl;vtkRenderingContextOpenGL;vtkRenderingOpenGL;vtkImagingHybrid;vtkIOImage;vtkDICOMParser;vtkIOCore;vtkmetaio;vtkjpeg;vtkpng;vtktiff
>>>> -- DEFS: vtkRenderingContext2D_AUTOINIT=1(vtkRenderingContextOpenGL);vtkRenderingCore_AUTOINIT=2(vtkRenderingFreeType,vtkRenderingOpenGL)
>>>> -- LIBS: vtkCommonCore;vtksys
>>>> -- DEFS:
>>>> -- Configuring done
>>>> -- Generating done
>>>> -- Build files have been written to: /home/marcus/build/vtkcomponents
>>>>
>>>> So the definitions were empty, as you would hope, in the second call,
>>>> the mains were very simple instantiating a vtkRenderWindow in the
>>>> first which resulted in a vtkXOpenGLRenderWindow class being
>>>> instantiated as the overrides kicked in for that target. Most projects
>>>> I know of that make multiple calls tend to use directories for each
>>>> target, and make the calls in sibling directories, but it looks like
>>>> you should be able to call it multiple times in the same scope (on
>>>> Linux with VTK master at least).
>>>>
>>>> On Tue, Sep 9, 2014 at 1:53 PM, Marcus D. Hanwell
>>>> <marcus.hanwell at kitware.com> wrote:
>>>>> Adding you both to CC in case you aren't subscribed, it might also be
>>>>> worth appending NO_MODULE to the calls to ensure find modules aren't
>>>>> used, i.e. find_package(VTK COMPONENTS vtkChartsCore NO_MODULE). The
>>>>> wiki page at http://www.vtk.org/Wiki/VTK/Build_System_Migration#Finding_and_Linking_to_VTK
>>>>> contains advice I added, but didn't specifically cover multiple calls.
>>>>> Including the use file, or setting the DIRECTORY property will of
>>>>> course cause issues if you are not using separate directory scopes for
>>>>> each target.
>>>>>
>>>>> On Tue, Sep 9, 2014 at 1:23 PM, Marcus D. Hanwell
>>>>> <marcus.hanwell at kitware.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Moving this discussion from
>>>>>> http://review.source.kitware.com/#/c/16703/ to the mailing list. As I
>>>>>> was saying I do not see precisely what you see, the repeated calls
>>>>>> seem to work for me locally. I would not expect the call without
>>>>>> COMPONENTS to work, and am not sure we should support calling with and
>>>>>> without COMPONENTS.
>>>>>>
>>>>>> I have a minimal CMake script,
>>>>>>
>>>>>> cmake_minimum_required(VERSION 3.0)
>>>>>>
>>>>>> find_package(VTK COMPONENTS vtkChartsCore)
>>>>>> message(STATUS "LIBS: ${VTK_LIBRARIES}")
>>>>>>
>>>>>> find_package(VTK COMPONENTS vtkCommonCore)
>>>>>> message(STATUS "LIBS: ${VTK_LIBRARIES}")
>>>>>>
>>>>>> find_package(VTK COMPONENTS vtkCommonMath)
>>>>>> message(STATUS "LIBS: ${VTK_LIBRARIES}")
>>>>>>
>>>>>> find_package(VTK COMPONENTS vtkChartsCore)
>>>>>> message(STATUS "LIBS: ${VTK_LIBRARIES}")
>>>>>>
>>>>>> find_package(VTK)
>>>>>> message(STATUS "LIBS: ${VTK_LIBRARIES}")
>>>>>>
>>>>>> This results in the output,
>>>>>>
>>>>>> $ cmake -DVTK_DIR:PATH=/home/marcus/build/VTK .
>>>>>> -- The C compiler identification is GNU 4.9.1
>>>>>> -- The CXX compiler identification is GNU 4.9.1
>>>>>> -- Check for working C compiler: /usr/bin/cc
>>>>>> -- Check for working C compiler: /usr/bin/cc -- works
>>>>>> -- Detecting C compiler ABI info
>>>>>> -- Detecting C compiler ABI info - done
>>>>>> -- Check for working CXX compiler: /usr/bin/c++
>>>>>> -- Check for working CXX compiler: /usr/bin/c++ -- works
>>>>>> -- Detecting CXX compiler ABI info
>>>>>> -- Detecting CXX compiler ABI info - done
>>>>>> -- LIBS: vtkChartsCore;vtkCommonColor;vtkCommonDataModel;vtkCommonMath;vtkCommonCore;vtksys;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkInfovisCore;vtkFiltersExtraction;vtkCommonExecutionModel;vtkFiltersCore;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;vtkfreetype;vtkzlib;vtkftgl
>>>>>> -- LIBS: vtkCommonCore;vtksys
>>>>>> -- LIBS: vtkCommonMath;vtkCommonCore;vtksys
>>>>>> -- LIBS: vtkChartsCore;vtkCommonColor;vtkCommonDataModel;vtkCommonMath;vtkCommonCore;vtksys;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkInfovisCore;vtkFiltersExtraction;vtkCommonExecutionModel;vtkFiltersCore;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;vtkfreetype;vtkzlib;vtkftgl
>>>>>> -- LIBS: vtkChartsCore;vtkCommonColor;vtkCommonDataModel;vtkCommonMath;vtkCommonCore;vtksys;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkInfovisCore;vtkFiltersExtraction;vtkCommonExecutionModel;vtkFiltersCore;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;vtkfreetype;vtkzlib;vtkftgl
>>>>>> -- Configuring done
>>>>>> -- Generating done
>>>>>> -- Build files have been written to: /home/marcus/build/vtkcomponents
>>>>>>
>>>>>> As far as I can see this gives the libraries one would expect, i.e.
>>>>>> vtkChartsCore, vtkCommonCore, vtkCommonMath, vtkChartsCore, and the
>>>>>> final one is incorrect but I am not sure of the value in supporting
>>>>>> mixed COMPONENTS and non-components versions of find_package.
>>>>>>
>>>>>> Let me know if there is something I am missing, is this possibly with
>>>>>> an older version of VTK (I am testing with master).
>>>>>>
>>>>>> Marcus



More information about the vtk-developers mailing list