Build VTK 9.3.0 Msys2/Mingw64 on Win10 with OSMESA offscreen rendering

Description / Steps to reproduce the issue

I want to compile vtk with OSMESA offscreen rendering, instead of default Win32 OpenGL.

I based on package from the official repository VTK

In the file PKGBUILD, I only added this cmake flags:

${MINGW_PREFIX}/bin/cmake \
    ...
    -DVTK_USE_WIN32_OPENGL=OFF \
    -DVTK_OPENGL_HAS_OSMESA=ON \
    -DVTK_MODULE_ENABLE_VTK_MomentInvariants=NO \
    -DVTK_MODULE_ENABLE_VTK_RenderingOpenXR=NO \
    -DVTK_MODULE_ENABLE_VTK_RenderingLookingGlass=NO \
    ...

and I added more jobs to copiler, but it shouldn’t make any difference:

${MINGW_PREFIX}/bin/cmake --build . -- -j$(nproc)

The compilation was successful, and I installed the generated package without any problems:

pacman -U mingw-w64-ucrt-x86_64-vtk-9.3.0-4-any.pkg.tar.zst

I then successfully compiled the OffScreenRendering example.

Example should produce screenshot.png file, but I got this error instead:

$ ./OffScreenRendering.exe
2024-01-12 11:28:03.616 (   0.164s) [DA4A6AE7A9E48EB7]vtkOpenGLRenderWindow.c:704    ERR| vtkOSOpenGLRenderWindow (0x22cf2c7d930): GLEW could not be initialized: Missing GL version
[1]    9031 segmentation fault  ./OffScreenRendering.exe

Windows Version

$ uname

MINGW64_NT-10.0-19045

I performed the above steps on UCRT64 MINGW environments.

Is anyone able to help me solve this problem?

I managed to solve the problem by using the internal GLEW instead of the external one.
So I had to add an extra flag to cmake:

-DVTK_MODULE_USE_EXTERNAL_VTK_glew=OFF