Two questions about new module system

Hi all,

Having a first look at porting our application to VTK 9.0.0.

First question is about vtkRenderingContextOpenGL2. With 9.0.0 it seems we no longer get that library? What should I link against to pick the OpenGL2 backend for context views? Or has the library been removed and they are now using OpenGL2 by default?

Second question: CMake of our project finishes successfully, but VTK_INCLUDE_DIRS is now empty. I’m guessing this has to do with the VTK CMake changes/new module system? How do I get the VTK include directories added nowadays? I looked at @ben.boeckel’s post at under the “For consumers of VTK” section but couldn’t find any info about changes in how to consume VTK include directories.

I guess I have a third question :slight_smile:

The mail also mentions

  • For object factories to work, vtk_module_autoinit should be used.
    This generates the proper -D flags for getting initialization to

Will the CMake machinery still add automatic compile flags like -DvtkRenderingContext2D_AUTOINIT="1(vtkRenderingContextOpenGL2)", or must I do something manually with vtk_module_autoinit myself?

Nevermind this question, I see I sort of already asked it back in Bill’s ML thread “vtk_module_autoinit in new module system” ( So I will have to make a call to that function.

I should have done some more digging. I got everything working by 1) Adding the vtk_module_autoinit calls for our targets. 2) Fixing to use VTK::Foo instead of vtkFoo in some places.

Or well, I still have uses of deprecated stuff to take care of, but at least now the compile/link lines are all good :slight_smile:

First question is about vtkRenderingContextOpenGL2 . With 9.0.0 it seems we no longer get that library? What should I link against to pick the OpenGL2 backend for context views? Or has the library been removed and they are now using OpenGL2 by default?

Hm, now that I got the program built, it crashes at runtime with:

2020-03-22 11:51:44.120 (   0,477s) [        F002EC40] vtkContextDevice2D.cxx:32    WARN| Error: no override found for 'vtkContextDevice2D'.

So I’m guessing there’s something missing after all. In VTK 8 I could link against vtkRenderingContextOpenGL2 to pick an implementation. What should I link against in VTK 9?

In VTK 8 I had:

estan@edison:~$ ls /opt/VTK8/lib/*OpenGL2*
/opt/VTK8/lib/                 /opt/VTK8/lib/                 /opt/VTK8/lib/
/opt/VTK8/lib/             /opt/VTK8/lib/             /opt/VTK8/lib/
/opt/VTK8/lib/           /opt/VTK8/lib/           /opt/VTK8/lib/
/opt/VTK8/lib/        /opt/VTK8/lib/        /opt/VTK8/lib/
/opt/VTK8/lib/    /opt/VTK8/lib/    /opt/VTK8/lib/
/opt/VTK8/lib/  /opt/VTK8/lib/  /opt/VTK8/lib/
/opt/VTK8/lib/                         /opt/VTK8/lib/                   /opt/VTK8/lib/
/opt/VTK8/lib/                     /opt/VTK8/lib/               /opt/VTK8/lib/
/opt/VTK8/lib/                   /opt/VTK8/lib/             /opt/VTK8/lib/
/opt/VTK8/lib/                /opt/VTK8/lib/          /opt/VTK8/lib/
/opt/VTK8/lib/            /opt/VTK8/lib/      /opt/VTK8/lib/
/opt/VTK8/lib/          /opt/VTK8/lib/    /opt/VTK8/lib/

But in VTK 9 I only have:

estan@edison:~$ ls /opt/VTK9/lib/*OpenGL2*
/opt/VTK9/lib/        /opt/VTK9/lib/        /opt/VTK9/lib/
/opt/VTK9/lib/    /opt/VTK9/lib/    /opt/VTK9/lib/
/opt/VTK9/lib/  /opt/VTK9/lib/  /opt/VTK9/lib/

My CMake line for VTK 8 had:

	-DVTK_Group_Qt=ON \
	-DVTK_Group_Imaging=ON \
	-DVTK_Group_Views=ON \
	-DModule_vtkRenderingFreeTypeFontConfig=ON \
	-DPYTHON_EXECUTABLE=/usr/bin/python3 \
	-DPYTHON_INCLUDE_DIR=/usr/include/python3.6 \
	-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/ \

While my CMake line for VTK 9 had:

	-DVTK_MODULE_ENABLE_VTK_RenderingFreeTypeFontConfig=YES \

I see that, unlike e.g. VolumeOpenGL2, the ContextOpenGL2 module is not part of the Rendering group.

I do wonder how come we got that library built when using VTK 8 though, but not with VTK 9. Is VTK 9 in general building less stuff by default?

Must I enable the ContextOpenGL2 module explicity?

It’s still there. Is it just disabled in your build?

Yes, this is gone. Use the targets (VTK::CommonCore) instead.

It is no longer automatic because that gave you one autoinit set per find_package. Now it is done per target. You should do:

target_link_libraries(my_vtk_using_lib ${visibility}VTK::CommonCore ${other_vtk_libs})
vtk_module_autoinit(TARGETS my_vtk_using_lib MODULES VTK::CommonCore ${other_vtk_libs})

The latter call generates the required -D flags for the module set but just for the targets listed.

This is possible. I did end up fixing a lot of bogus dependencies when I went through with the build system.

Thanks a lot for all the answers. Makes perfect sense.

I must have gotten the RenderingContextOpenGL2 by “luck” in my earlier VTK 8 build due to some dependency.

Since RenderingContextOpenGL2, unlike e.g. RenderingVolumeOpenGL2, is not part of the Rendering group (should it be?), I guess I must enable that module explicitly to get it?

Edit: Running a VTK build now with:

                -DVTK_GROUP_ENABLE_Rendering=YES \
                -DVTK_GROUP_ENABLE_Imaging=YES \
                -DVTK_GROUP_ENABLE_Views=YES \
                -DVTK_GROUP_ENABLE_Qt=YES \
                -DVTK_MODULE_ENABLE_VTK_RenderingContextOpenGL2=YES \
                -DVTK_MODULE_ENABLE_VTK_RenderingFreeTypeFontConfig=YES \

to check. Then I think I should get it for sure.

Looking back at the CMake output from my old VTK 8 build, it lists vtkRenderingContextOpenGL2 under “Backend OpenGL2 modules:”:

Backend OpenGL2 modules: vtkDomainsChemistryOpenGL2;vtkIOExportOpenGL2;vtkImagingOpenGL2;vtkRenderingContextOpenGL2;vtkRenderingGL2PSOpenGL2;vtkRenderingLICOpenGL2;vtkRenderingOpenGL2;vtkRenderingOpenVR;vtkRenderingVolumeOpenGL2

So there seems to have been a mechanism that brought in all these *OpenGL2 modules in one go according to the chosen backend. I did not specify the OpenGL2 backend in that CMake run explicitly (I.e. did not pass -DVTK_RENDERING_BACKEND), so it was picked by default.

In VTK 9, with the old OpenGL backend gone (right?), should not (for example) RenderingContext depend on RenderingContextOpenGL2, because it won’t function without it?

Looking at the old module.cmake file, it was never part of the Rendering group. It was probably dragged in by IMPLEMENTATION_REQUIRED_BY_BACKEND (your newest reply seems to confirm that) which is…hairy logic to say the least. It’s tough to say what should be done here because the logic to implement that flag would be extremely difficult to get right.

That’s gone now. Hopefully, the Vulkan backend will be a runtime selection, not a compile-time selection thing.

Alright thanks. I’ll pretend the hairy IMPLEMENTATION_REQUIRED_BY_BACKEND never existed and enable the module explicitly :slight_smile: I wonder though why RenderingVolumeOpenGL2 is part of the Rendering group while RenderingContextOpenGL2 is not.

Everything works fine now with the flags I used in Two questions about new module system :+1: