Moving from QMake to CMake: "VTK is designed to work with OpenGL version..."

(Paulo Carvalho) #1

Dear all,

I’ve been avoiding this for years, but I finally decided to move a Qt project from QMake to CMake. My QMake-based build works just fine, but my CMake build leads to a “VTK is designed to work with OpenGL version 3.2 but it appears it has been given a context that does not support 3.2. VTK will run in a compatibility mode designed to work with earlier versions of OpenGL but some features may not work.” whenever the programs loads, then crashes.

My CMakeLists.txt is as follows:

cmake_minimum_required (VERSION 3.7)

set(PROJECT_NAME TesteMod)
set(VERSION 1.0)

project (${PROJECT_NAME})

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

set(CMAKE_AUTOUIC ON)

add_compile_definitions( APP_VERSION="${VERSION}" )
add_compile_definitions( APP_NAME="${PROJECT_NAME}" )
add_compile_definitions( APP_NAME_VER="${PROJECT_NAME} ${VERSION}" )

set(CMAKE_PREFIX_PATH "C:/VTK64/install_release/lib/cmake"   ${CMAKE_PREFIX_PATH})

find_package(Qt5Core CONFIG REQUIRED)
find_package(Qt5Gui CONFIG REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(VTK COMPONENTS 
               vtkGUISupportQt
               vtkCommonCore
               vtkFiltersSources
               vtkRenderingCore
               vtkCommonExecutionModel
               vtkInteractionStyle
               vtkRenderingOpenGL2
               vtkRenderingAnnotation
               vtkRenderingFreeType
               vtkInteractionWidgets
               vtkCommonDataModel
               vtkFiltersGeneral
               vtkCommonTransforms
               vtkImagingSources
               vtkImagingCore
		    vtkFiltersCore
               vtkFiltersExtraction
		    vtkImagingFourier
		    vtkCommonMisc
		    vtkCommonComputationalGeometry
		    vtkCommonMath
		    vtksys
		    vtkFiltersGeometry
		    vtkCommonColor
		    vtkCommonSystem
		    vtkglew
		    vtkfreetype
		    vtkzlib
		    vtkFiltersHybrid
		    vtkFiltersModeling
		    vtkImagingGeneral
		    vtkRenderingVolume
		    vtkFiltersStatistics
               vtkalglib
               vtkImagingStencil
               vtkImagingHybrid
)

include(${VTK_USE_FILE})

set(${PROJECT_NAME}_SRCS
    widgets/focuswatcher.h
    widgets/focuswatcher.cpp
    viewer3d/view3dcolortables.cpp
    viewer3d/view3dcolortables.h
    viewer3d/view3dverticalexaggerationwidget.cpp
    viewer3d/view3dverticalexaggerationwidget.h
    viewer3d/view3dverticalexaggerationwidget.ui
    viewer3d/view3dwidget.cpp
    viewer3d/view3dwidget.h
    viewer3d/view3dwidget.ui
    viewer3d/viewer3dlistwidget.cpp
    viewer3d/viewer3dlistwidget.h
    gui/mainwindow.ui
    gui/mainwindow.cpp
    util.h
    util.cpp
    main.cpp
)

add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS})

target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Gui)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})

Please, help!

(Ben Boeckel) #2

I suspect you are missing using VTK_DEFINITIONS. Something like:

add_compile_definitions(${VTK_DEFINITIONS})
(Andras Lasso) #3

What CPU and graphics card do you have in this computer? Recent VTK versions require computers that are not older than about 6-8 years.

(Paulo Carvalho) #4

No avail :frowning:

(Paulo Carvalho) #5

Then I wonder why my QMake-based version works… same hardware, same libraries, etc. Same everything… exept the build system. I’ve been avoiding CMake for years fearing its dreaded trickery we know it does. Now I know why.

(Andras Lasso) #6

OpenGL2 rendering backend does not work on old hardware. This is not related to what build system you use. What graphics card and CPU model do you use?

If your application works with the same QVTK rendering widget and same VTK rendering backend using QtCreator then it should work when you build with CMake, too. To investigate the problem further, you can try some of the VTK Qt examples.

(Paulo Carvalho) #7

You are right. I built one of the VTK examples and they went just fine. Maybe some silent bug in my program that luckly made it work when built with QMake.