# Slicer cmake-configuration fails with VTK 9 on Ubuntu 20.04

**URL:** <https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643>\
**Category:** Development\
**Tags:** vtk\
**Created:** [May 16, 2021, 11:49pm UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643 "2021-05-16T23:49:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 16, 2021, 11:49pm UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/1 "2021-05-16T23:49:03Z")

</div>

Hi,

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

```cmake
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:

```cmake
  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](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/f/0febbc495d8f071fc7d30e54ba418afd145210c7.png)

With VTK 8.2.0 there was no such error

**My Slicer GIT tag:**

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

```

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 17, 2021, 11:24am UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/2 "2021-05-17T11:24:59Z")

</div>

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

```auto
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:

```auto
-- 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?

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 17, 2021, 1:01pm UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/3 "2021-05-17T13:01:24Z")

</div>

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:

```auto
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:

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 17, 2021, 8:06pm UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/4 "2021-05-17T20:06:11Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [May 17, 2021, 11:50pm UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/5 "2021-05-17T23:50:07Z")

</div>

> [@lassoan](#):
>
> How can you set the VTK version for a Slicer custom application?

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

```auto
# 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_

> <https://github.com/BICCN/cell-locator/blob/acf3fa31eb30358c724fec71c86a534cb7799a05/CMakeLists.txt#L116-L118>

### References

> <https://github.com/Slicer/Slicer/blob/7d9c2f2488dbbc050baef22aedfd4d83bae6cc48/SuperBuild/External_VTK.cmake#L169-L190>

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 17, 2021, 11:58pm UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/6 "2021-05-17T23:58:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [May 18, 2021, 12:07am UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/7 "2021-05-18T00:07:54Z")

</div>

> [@lassoan](#):
>
> 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:

```cmake
# 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

> <https://github.com/KitwareMedical/SlicerQReads/blob/d40ce875aa49f396fc8fe2b578e477d6cd02894f/CMakeLists.txt#L108>

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 18, 2021, 12:47am UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/8 "2021-05-18T00:47:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [May 18, 2021, 8:45am UTC](https://discourse.slicer.org/t/slicer-cmake-configuration-fails-with-vtk-9-on-ubuntu-20-04/17643/9 "2021-05-18T08:45:11Z")

</div>

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

> [@lassoan](#):
>
> As far as I remember you had a similar issue. What did you end up doing?

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).
