OpenCVDetectVTK.cmake 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. if(NOT VTK_FOUND)
  2. find_package(VTK QUIET NAMES vtk VTK)
  3. if(VTK_FOUND)
  4. if(NOT (VTK_VERSION VERSION_LESS "9.0.0") AND (VTK_VERSION VERSION_LESS "10.0.0")) # VTK 9.x
  5. find_package(VTK 9 QUIET NAMES vtk COMPONENTS
  6. FiltersExtraction
  7. FiltersSources
  8. FiltersTexture
  9. IOExport
  10. IOGeometry
  11. IOPLY
  12. InteractionStyle
  13. RenderingCore
  14. RenderingLOD
  15. RenderingOpenGL2
  16. NO_MODULE)
  17. elseif(VTK_VERSION VERSION_GREATER "5") # VTK 6.x components
  18. find_package(VTK QUIET COMPONENTS vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
  19. IF(VTK_FOUND)
  20. IF(VTK_RENDERING_BACKEND) #in vtk 7, the rendering backend is exported as a var.
  21. find_package(VTK QUIET COMPONENTS vtkRendering${VTK_RENDERING_BACKEND} vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport vtkIOGeometry NO_MODULE)
  22. ELSE(VTK_RENDERING_BACKEND)
  23. find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
  24. ENDIF(VTK_RENDERING_BACKEND)
  25. ENDIF(VTK_FOUND)
  26. elseif(VTK_VERSION VERSION_EQUAL "5") # VTK 5.x components
  27. find_package(VTK QUIET COMPONENTS vtkCommon NO_MODULE)
  28. else()
  29. set(VTK_FOUND FALSE)
  30. endif()
  31. endif()
  32. endif()
  33. if(NOT VTK_FOUND)
  34. set(HAVE_VTK OFF)
  35. 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")
  36. return()
  37. endif()
  38. # Don't support earlier VTKs
  39. if(VTK_VERSION VERSION_LESS "5.8.0")
  40. message(STATUS "VTK support is disabled. VTK ver. 5.8.0 is minimum required, but found VTK ver. ${VTK_VERSION}")
  41. return()
  42. endif()
  43. # Different Qt versions can't be linked together
  44. if((HAVE_QT AND VTK_USE_QT)
  45. AND NOT DEFINED FORCE_VTK # deprecated
  46. AND NOT DEFINED OPENCV_FORCE_VTK
  47. )
  48. message(STATUS "VTK support is disabled. Possible incompatible combination: OpenCV+Qt, and VTK ver.${VTK_VERSION} with Qt")
  49. message(STATUS "If it is known that VTK was compiled without Qt4, please define '-DOPENCV_FORCE_VTK=TRUE' flag in CMake")
  50. return()
  51. endif()
  52. try_compile(VTK_COMPILE_STATUS
  53. "${OpenCV_BINARY_DIR}"
  54. "${OpenCV_SOURCE_DIR}/cmake/checks/vtk_test.cpp"
  55. CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${VTK_INCLUDE_DIRS}"
  56. LINK_LIBRARIES ${VTK_LIBRARIES}
  57. OUTPUT_VARIABLE OUTPUT
  58. )
  59. if(NOT ${VTK_COMPILE_STATUS})
  60. message(STATUS "VTK support is disabled. Compilation of the sample code has failed.")
  61. return()
  62. endif()
  63. set(HAVE_VTK ON)
  64. if (VTK_VERSION VERSION_LESS "8.90.0")
  65. message(STATUS "Found VTK ${VTK_VERSION} (${VTK_USE_FILE})")
  66. else()
  67. message(STATUS "Found VTK ${VTK_VERSION}")
  68. endif()