[vtk-developers] find_package( VTK ) and relative path

David Cole david.cole at kitware.com
Mon Sep 19 10:20:47 EDT 2011


On Mon, Sep 19, 2011 at 10:17 AM, David Cole <david.cole at kitware.com> wrote:
> On Mon, Sep 19, 2011 at 9:22 AM, Arnaud Gelas
> <arnaud_gelas at hms.harvard.edu> wrote:
>> Hi all,
>>
>> In one CMakeLists.txt, I have
>>
>> find_package( VTK REQUIRED )
>> if( VTK_FOUND )
>>        include( ${VTK_USE_FILE} )
>> endif()
>>
>> if I provide VTK_DIR by using a relative path, it does not work (see error
>> message below); if I enter the full path it works.
>>
>> This is the error message:
>>
>> CMake Error at /opt/local/share/cmake-2.8/Modules/FindVTK.cmake:135
>>  (MESSAGE):
>>   VTK not found.  Set the VTK_DIR cmake cache entry to the directory
>>   containing VTKConfig.cmake.  This is either the root of the build tree, or
>>   PREFIX/lib/vtk for an installation.  For VTK 4.0, this is the location of
>>   UseVTK.cmake.  This is either the root of the build tree or
>>   PREFIX/include/vtk for an installation.
>>  Call Stack (most recent call first):
>>   Exercises/LevelSets/Source/CMakeLists.txt:13 (find_package)
>>
>>
>> This could have been fine and understandable if it was the same behavior for
>> ITK, but it's not...
>>
>> i.e.
>>
>> find_package( ITK REQUIRED )
>> if( ITK_FOUND )
>>        include( ${ITK_USE_FILE} )
>> endif()
>>
>> if a relative path is provided, it does work.
>>
>> I use CMake 2.8.5, I build the master branch of VTK myself with the same
>> version of CMake...
>>
>> Can someone explain to me what's the difference in between ITK and VTK with
>> respect to find_package? why is it working for one and not the other one?
>> If relative paths are not supported, why doesn't it warn users?
>>
>> Thanks,
>> Arnaud
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtk-developers
>>
>>
>
> You should use absolute full paths for VTK_DIR, ITK_DIR, or any other
> variable that is supposed to tell find_package where something is.
>
> Think about it: what would it *relative to* ...?
>
> In the context of a CMakeLists.txt file, sometimes a relative path
> expression is interpreted as relative to CMAKE_CURRENT_SOURCE_DIR,
> sometimes to CMAKE_CURRENT_BINARY_DIR, and sometimes simply as
> relative to whatever the current working directory is.
>
> Which one is it for a find_package call? It's indeterminate, so you
> should always specify VTK_DIR and ITK_DIR (and similar) variables as
> full paths.
>
> We probably should warn about this, but it hasn't been a widespread
> problem (to the best of my knowledge).
>
> File a bug report / feature request for CMake to warn about it if you
> feel strongly about it.
>
>
> Thanks,
> David C.
>

And to answer your question about the difference between ITK and VTK:
all projects may have project-specific find_package behavior, since
the find_package command simply loads either a project-config file or
a FindProject.cmake file... Whatever is in the config or find file is
the thing that determines what the behavior is.

One of them probably does a get_filename_component call to convert a
relative path into an absolute path inside the project-specific files.
That plus you're getting lucky that it's interpreting the relative
path correctly and finding the one you want it to find...


HTH,
David



More information about the vtk-developers mailing list