How to fix: CMake Error Found relative path while evaluating include directories of

How to fix: CMake Error Found relative path while evaluating include directories of

Starting from https://examples.vtk.org/site/Cxx/PolyData/ColoredPoints/, I decided to compile VTK as a git-submodule which implies:

  • replacing find_package by git submodule add https://gitlab.kitware.com/vtk/vtk vtk; add_subdirectory(vtk)
  • replacing ${VTK_LIBRARIES} by VTK::CommonCore, VTK::CommonDataModel …).

I get CMake error: CMake Error Found relative path while evaluating include directories of ... "VTK::CommonDataModel"

Googling seems to point that this may be in connection with absolute / relative path. I tried to add set(VTK_DIR "${PROJECT_SOURCE_DIR}/vtk") in the CMakeLists.txt but I get the same error.

Setting set(VTK_DIR "${CMAKE_BINARY_DIR}/vtk") doesn’t help neither.

Reducing the example with the very minimum (just vtkPoints creation): “VTK::CommonCore” is found. But adding vtkPolyData needs VTK::CommonDataModel which is not found

Basically I do this

add_subdirectory(vtk)

set(VTK_DIR "${CMAKE_BINARY_DIR}/vtk")
set(VTK_TARGETS "VTK::CommonCore" "VTK::CommonDataModel")

vtk_module_autoinit(TARGETS ColoredPoints MODULES "${VTK_TARGETS}")
target_include_directories(ColoredPoints PRIVATE "${VTK_TARGETS}")
target_link_libraries(ColoredPoints PRIVATE "${VTK_TARGETS}")

Any clue?

But why though ?

Because I’ll likely need to change CMake options

Any clue on the problem?

For changing cmake options, using a cmake preset is a much more sane approach.

If CMake is telling you that you have relative paths, then you need to find and fix them.

Alternatively:

  1. The best approach is to check out and build VTK as in the VTK build instructions and make sure everything works. It should, if you adopt this approach. When this is done, then you can experiment.
  2. You could also look in unix_path.sh (windows_path.bat) for path settings. It is found in the top-level build directory where you build VTK.

This finally worked:

foreach(VTK_TARGET ${VTK_TARGETS})
  vtk_module_autoinit(TARGETS xx MODULES ${VTK_TARGET}")
  target_include_directories(xx PRIVATE "${VTK_TARGET}")
  target_link_libraries(xx PRIVATE "${VTK_TARGET}")
endforeach()
1 Like

vtk_module_autoinit doesn’t work this way. The problem here:

${VTK_TARGETS} is a list and should not be quoted so that it expands as distinct arguments.

Why do think this is a bad idea?
I am also think about this, where my own project is a git repo and with vtk as a submodule it would be very easy to clone it and integrate it in my project. Or am I missing something?

You should consider VTK as a dependency and use find_package instead.

Note that it is possible to vendor VTK (ParaView does it), but it is not as easy as add_subdirectory (and therefore FetchContent is not an option). Instead, ParaView “knows” what VTK does in various situations and uses its own CMake variables to control its build (e.g., VTK_USE_MPI is just set to the value of PARAVIEW_USE_MPI and not offered independently). VTK’s top-level CMakeLists.txt is set up to be the top-level and not designed to integrate as a component of another project.

1 Like