Merge remote-tracking branch 'upstream/3.4' into merge-3.4
[platform/upstream/opencv.git] / cmake / OpenCVDetectVTK.cmake
1 # VTK 6.x components
2 find_package(VTK QUIET COMPONENTS vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
3 IF(VTK_FOUND)
4   IF(VTK_RENDERING_BACKEND) #in vtk 7, the rendering backend is exported as a var.
5       find_package(VTK QUIET COMPONENTS vtkRendering${VTK_RENDERING_BACKEND} vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport vtkIOGeometry NO_MODULE)
6   ELSE(VTK_RENDERING_BACKEND)
7       find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
8   ENDIF(VTK_RENDERING_BACKEND)
9 ENDIF(VTK_FOUND)
10
11 # VTK 5.x components
12 if(NOT VTK_FOUND)
13   find_package(VTK QUIET COMPONENTS vtkCommon NO_MODULE)
14 endif()
15
16 if(NOT VTK_FOUND)
17   set(HAVE_VTK OFF)
18   message(STATUS "VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file")
19   return()
20 endif()
21
22 # Don't support earlier VTKs
23 if(VTK_VERSION VERSION_LESS "5.8.0")
24   message(STATUS "VTK support is disabled. VTK ver. 5.8.0 is minimum required, but found VTK ver. ${VTK_VERSION}")
25   return()
26 endif()
27
28 # Different Qt versions can't be linked together
29 if(HAVE_QT5 AND VTK_VERSION VERSION_LESS "6.0.0")
30   if(VTK_USE_QT)
31     message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4")
32   endif()
33 endif()
34
35 # Different Qt versions can't be linked together. VTK 6.0.0 doesn't provide a way to get Qt version it was linked with
36 if(HAVE_QT5 AND VTK_VERSION VERSION_EQUAL "6.0.0" AND NOT DEFINED FORCE_VTK)
37   message(STATUS "VTK support is disabled. Possible incompatible combination: OpenCV+Qt5, and VTK ver.${VTK_VERSION} with Qt4")
38   message(STATUS "If it is known that VTK was compiled without Qt4, please define '-DFORCE_VTK=TRUE' flag in CMake")
39   return()
40 endif()
41
42 # Different Qt versions can't be linked together
43 if(HAVE_QT AND VTK_VERSION VERSION_GREATER "6.0.0" AND NOT ${VTK_QT_VERSION} STREQUAL "")
44   if(HAVE_QT5 AND ${VTK_QT_VERSION} EQUAL "4")
45     message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4")
46     return()
47   endif()
48
49   if(NOT HAVE_QT5 AND ${VTK_QT_VERSION} EQUAL "5")
50     message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt4 and VTK ver.${VTK_VERSION} + Qt5")
51     return()
52   endif()
53 endif()
54
55 try_compile(VTK_COMPILE_STATUS
56     "${OpenCV_BINARY_DIR}"
57     "${OpenCV_SOURCE_DIR}/cmake/checks/vtk_test.cpp"
58     CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${VTK_INCLUDE_DIRS}"
59     LINK_LIBRARIES ${VTK_LIBRARIES}
60     OUTPUT_VARIABLE OUTPUT
61 )
62
63 if(NOT ${VTK_COMPILE_STATUS})
64   message(STATUS "VTK support is disabled. Compilation of the sample code has failed.")
65   return()
66 endif()
67
68 set(HAVE_VTK ON)
69 message(STATUS "Found VTK ${VTK_VERSION} (${VTK_USE_FILE})")