Slicer cmake-configuration fails with VTK 9 on Ubuntu 20.04

Hi,

Trying to build SlicerCAT with VTK 9 and I get this error:

CMake Error at CMakeLists.txt:813 (find_package):
  Found package configuration file:

    /home/kerim/Documents/Colada_prj/d/VTK-build/vtk-config.cmake

  but it set VTK_FOUND to FALSE so package "VTK" is considered to be NOT
  FOUND.  Reason given by package:

  Could not find the VTK package with the following required components:
  GUISupportQtOpenGL.

Can’t find a way to turn GUISupportQtOpenGL ON.
I can see that External_VTK.cmake has:

  if("${Slicer_VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
    list(APPEND EXTERNAL_PROJECT_OPTIONAL_VTK8_CMAKE_CACHE_ARGS
      -DModule_vtkGUISupportQtOpenGL:BOOL=ON
      )
    list(APPEND EXTERNAL_PROJECT_OPTIONAL_VTK9_CMAKE_CACHE_ARGS
      -DVTK_MODULE_ENABLE_VTK_GUISupportQtOpenGL:STRING=YES
      )
  endif()

i.e. it probably should set GUISupportQtOpenGL ON and in my case Slicer_VTK_RENDERING_BACKEND is equal to OpenGL2. I have checked if("${Slicer_VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2") statement returns TRUE.

image

With VTK 8.2.0 there was no such error

My Slicer GIT tag:

GIT_REPOSITORY git://github.com/Slicer/Slicer
GIT_TAG        "e7ac45bf36195dc2d676d9edca153d86b89ab77d"
GIT_PROGRESS   1

I guess the thing is that in Slicer’s CMakeLists.txt we have:

set(_default_vtk "8")
set(Slicer_VTK_VERSION_MAJOR ${_default_vtk} CACHE STRING "VTK major version (8 or 9)")
set_property(CACHE Slicer_VTK_VERSION_MAJOR PROPERTY STRINGS "8" "9")
if(NOT "${Slicer_VTK_VERSION_MAJOR}" MATCHES "^(8|9)$")
  message(FATAL_ERROR "error: Slicer_VTK_VERSION_MAJOR must be 8 or 9.")
endif()
mark_as_superbuild(Slicer_VTK_VERSION_MAJOR)

I guess this overrides my Slicer_VTK_VERSION_MAJOR that I previously set up in my main SlicerCAT’s CMakeLists.txt and I can see the output right before the error appears:

-- Configuring VTK
--   Slicer_VTK_RENDERING_BACKEND is OpenGL2
--   Slicer_VTK_SMP_IMPLEMENTATION_TYPE is Sequential
--   Slicer_VTK_VERSION_MAJOR is 8
-- Configuring Colada with Qt 5.15.2 (using modules: Core, Widgets, Multimedia, Network, OpenGL, PrintSupport, UiTools, Xml, XmlPatterns, Svg, Sql, WebEngine, WebEngineWidgets, WebChannel, )
-- Setting QT_PLUGINS_DIR: /home/kerim/Qt/5.15.2/gcc_64/plugins
-- Setting QT_BINARY_DIR: /home/kerim/Qt/5.15.2/gcc_64/bin
-- Setting ExternalData_OBJECT_STORES to '/home/kerim/Documents/Colada_prj/d/Slicer-build/ExternalData/Objects'
-- Configuring Colada for [linux-amd64]
CMake Error at CMakeLists.txt:813 (find_package):
  Found package configuration file:

    /home/kerim/Documents/Colada_prj/d/VTK-build/vtk-config.cmake

  but it set VTK_FOUND to FALSE so package "VTK" is considered to be NOT
  FOUND.  Reason given by package:

  Could not find the VTK package with the following required components:
  GUISupportQtOpenGL.



-- Configuring incomplete, errors occurred!

As you can see the Slicer_VTK_VERSION_MAJOR is equal now to 8.
Do I misunderstand something?

I’m sorry. The error was invoked by my misunderstanding of CMake CACHE variable’s behaviour.

I used to set VTK version with the code in my main SlicerCAT CMakeLists.txt:

set(Slicer_VTK_VERSION_MAJOR 9)
mark_as_superbuild(Slicer_VTK_VERSION_MAJOR)

but as I noticed in Slicer’s main CMakeLists.txt Slicer_VTK_VERSION_MAJOR is CACHE type.
So to solve my error I simply overwrote the above line with the command:

set(Slicer_VTK_VERSION_MAJOR 9 CACHE STRING "VTK major version (8 or 9)" FORCE)
mark_as_superbuild(Slicer_VTK_VERSION_MAJOR)

Now I for the first time successfully compiled SlicerCAT with VTK 9 :slight_smile:

1 Like

@jcfr @Sam_Horvath How can you set the VTK version for a Slicer custom application?
@cpinter As far as I remember you had a similar issue. What did you end up doing?

Adding a snippet like this one in the top-level CMakeLists.txt of your custom application will do it:

# Custom VTK
set(Slicer_${proj}_GIT_REPOSITORY "${EP_GIT_PROTOCOL}://github.com/myorg/VTK")
set(Slicer_${proj}_GIT_TAG "abcdef1234...")

Example

In this example, CTK is customized

References

Thank you @jcfr. Does this also set the VTK major version (8/9) or that should be set using another variable?

Doing the following will ensure proper initialization of the cache:

# Custom VTK
set(Slicer_VTK_VERSION_MAJOR 9 CACHE STRING "VTK major version")
set(Slicer_${proj}_GIT_REPOSITORY "${EP_GIT_PROTOCOL}://github.com/myorg/VTK")
set(Slicer_${proj}_GIT_TAG "abcdef1234...")

Example

1 Like

Great, thank you. @keri tried to do this but probably it failed because of a previous configuration with version 8. Your complete working example above should be sufficient for anyone who needs to use a custom VTK version.

Thanks @jcfr this could be potentially quite useful to use as well.

I did not have this specific issue. Maybe what you remember is that I tried to configure an extension used by a custom app with an additional option (still haven’t figured it out btw).