FindVTK.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # - Find a VTK installation or build tree.
  2. # The following variables are set if VTK is found. If VTK is not
  3. # found, VTK_FOUND is set to false.
  4. # VTK_FOUND - Set to true when VTK is found.
  5. # VTK_USE_FILE - CMake file to use VTK.
  6. # VTK_MAJOR_VERSION - The VTK major version number.
  7. # VTK_MINOR_VERSION - The VTK minor version number
  8. # (odd non-release).
  9. # VTK_BUILD_VERSION - The VTK patch level
  10. # (meaningless for odd minor).
  11. # VTK_INCLUDE_DIRS - Include directories for VTK
  12. # VTK_LIBRARY_DIRS - Link directories for VTK libraries
  13. # VTK_KITS - List of VTK kits, in CAPS
  14. # (COMMON,IO,) etc.
  15. # VTK_LANGUAGES - List of wrapped languages, in CAPS
  16. # (TCL, PYHTON,) etc.
  17. # The following cache entries must be set by the user to locate VTK:
  18. # VTK_DIR - The directory containing VTKConfig.cmake.
  19. # This is either the root of the build tree,
  20. # or the lib/vtk directory. This is the
  21. # only cache entry.
  22. # The following variables are set for backward compatibility and
  23. # should not be used in new code:
  24. # USE_VTK_FILE - The full path to the UseVTK.cmake file.
  25. # This is provided for backward
  26. # compatibility. Use VTK_USE_FILE
  27. # instead.
  28. #
  29. #=============================================================================
  30. # Copyright 2001-2009 Kitware, Inc.
  31. #
  32. # Distributed under the OSI-approved BSD License (the "License");
  33. # see accompanying file Copyright.txt for details.
  34. #
  35. # This software is distributed WITHOUT ANY WARRANTY; without even the
  36. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  37. # See the License for more information.
  38. #=============================================================================
  39. # (To distribute this file outside of CMake, substitute the full
  40. # License text for the above reference.)
  41. # Assume not found.
  42. set(VTK_FOUND 0)
  43. # VTK 4.0 did not provide VTKConfig.cmake.
  44. if("${VTK_FIND_VERSION}" VERSION_LESS 4.1)
  45. set(_VTK_40_ALLOW 1)
  46. if(VTK_FIND_VERSION)
  47. set(_VTK_40_ONLY 1)
  48. endif()
  49. endif()
  50. # Construct consistent error messages for use below.
  51. set(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/vtk for an installation.")
  52. if(_VTK_40_ALLOW)
  53. set(VTK_DIR_DESCRIPTION "${VTK_DIR_DESCRIPTION} For VTK 4.0, this is the location of UseVTK.cmake. This is either the root of the build tree or PREFIX/include/vtk for an installation.")
  54. endif()
  55. set(VTK_DIR_MESSAGE "VTK not found. Set the VTK_DIR cmake cache entry to the ${VTK_DIR_DESCRIPTION}")
  56. # Check whether VTK 4.0 has already been found.
  57. if(_VTK_40_ALLOW AND VTK_DIR)
  58. if(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
  59. set(VTK_FOUND 1)
  60. include(${CMAKE_CURRENT_LIST_DIR}/UseVTKConfig40.cmake) # No VTKConfig; load VTK 4.0 settings.
  61. endif()
  62. endif()
  63. # Use the Config mode of the find_package() command to find VTKConfig.
  64. # If this succeeds (possibly because VTK_DIR is already set), the
  65. # command will have already loaded VTKConfig.cmake and set VTK_FOUND.
  66. if(NOT _VTK_40_ONLY AND NOT VTK_FOUND)
  67. find_package(VTK QUIET NO_MODULE)
  68. endif()
  69. # Special search for VTK 4.0.
  70. if(_VTK_40_ALLOW AND NOT VTK_DIR)
  71. # Old scripts may set these directories in the CMakeCache.txt file.
  72. # They can tell us where to find VTKConfig.cmake.
  73. set(VTK_DIR_SEARCH_LEGACY "")
  74. if(VTK_BINARY_PATH AND USE_BUILT_VTK)
  75. set(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH})
  76. endif()
  77. if(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
  78. set(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY}
  79. ${VTK_INSTALL_PATH}/lib/vtk)
  80. endif()
  81. # Look for UseVTK.cmake in build trees or under <prefix>/include/vtk.
  82. find_path(VTK_DIR
  83. NAMES UseVTK.cmake
  84. PATH_SUFFIXES vtk-4.0 vtk
  85. HINTS ENV VTK_DIR
  86. PATHS
  87. # Support legacy cache files.
  88. ${VTK_DIR_SEARCH_LEGACY}
  89. # Read from the CMakeSetup registry entries. It is likely that
  90. # VTK will have been recently built.
  91. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
  92. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
  93. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
  94. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
  95. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
  96. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
  97. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
  98. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
  99. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
  100. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
  101. # Help the user find it if we cannot.
  102. DOC "The ${VTK_DIR_DESCRIPTION}"
  103. )
  104. if(VTK_DIR)
  105. if(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
  106. set(VTK_FOUND 1)
  107. include(${CMAKE_CURRENT_LIST_DIR}/UseVTKConfig40.cmake) # No VTKConfig; load VTK 4.0 settings.
  108. else()
  109. # We found the wrong version. Pretend we did not find it.
  110. set(VTK_DIR "VTK_DIR-NOTFOUND" CACHE PATH "The ${VTK_DIR_DESCRIPTION}" FORCE)
  111. endif()
  112. endif()
  113. endif()
  114. #-----------------------------------------------------------------------------
  115. if(VTK_FOUND)
  116. # Set USE_VTK_FILE for backward-compatibility.
  117. set(USE_VTK_FILE ${VTK_USE_FILE})
  118. else()
  119. # VTK not found, explain to the user how to specify its location.
  120. if(VTK_FIND_REQUIRED)
  121. message(FATAL_ERROR ${VTK_DIR_MESSAGE})
  122. else()
  123. if(NOT VTK_FIND_QUIETLY)
  124. message(STATUS ${VTK_DIR_MESSAGE})
  125. endif()
  126. endif()
  127. endif()