FindVTK.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #
  2. # Find a VTK installation or build tree.
  3. #
  4. # When VTK is found, the VTKConfig.cmake file is sourced to setup the
  5. # location and configuration of VTK. Please read this file, or
  6. # VTKConfig.cmake.in from the VTK source tree for the full list of
  7. # definitions. Of particular interest is
  8. #
  9. # VTK_USE_FILE - A CMake source file that can be included
  10. # to set the include directories, library
  11. # directories, and preprocessor macros.
  12. #
  13. # In addition to the variables read from VTKConfig.cmake, this find
  14. # module also defines
  15. #
  16. # VTK_DIR - The directory containing VTKConfig.cmake. This is either
  17. # the root of the build tree, or the lib/vtk
  18. # directory. This is the only cache entry.
  19. #
  20. # VTK_FOUND - Whether VTK was found. If this is true, VTK_DIR is okay.
  21. #
  22. # USE_VTK_FILE - The full path to the UseVTK.cmake file. This is provided
  23. # for backward compatability. Use VTK_USE_FILE instead.
  24. #
  25. # Construct consitent error messages for use below.
  26. SET(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/vtk for an installation. 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.")
  27. SET(VTK_DIR_MESSAGE "VTK not found. Set VTK_DIR to the ${VTK_DIR_DESCRIPTION}")
  28. # Search only if the location is not already known.
  29. IF(NOT VTK_DIR)
  30. # Get the system search path as a list.
  31. IF(UNIX)
  32. STRING(REGEX MATCHALL "[^:]+" VTK_DIR_SEARCH1 $ENV{PATH})
  33. ELSE(UNIX)
  34. STRING(REGEX REPLACE "\\\\" "/" VTK_DIR_SEARCH1 $ENV{PATH})
  35. ENDIF(UNIX)
  36. STRING(REGEX REPLACE "/;" ";" VTK_DIR_SEARCH2 ${VTK_DIR_SEARCH1})
  37. # Construct a set of paths relative to the system search path.
  38. SET(VTK_DIR_SEARCH "")
  39. FOREACH(dir ${VTK_DIR_SEARCH2})
  40. SET(VTK_DIR_SEARCH ${VTK_DIR_SEARCH} "${dir}/../lib/vtk")
  41. ENDFOREACH(dir)
  42. # Old scripts may set these directories in the CMakeCache.txt file.
  43. # They can tell us where to find VTKConfig.cmake.
  44. SET(VTK_DIR_SEARCH_LEGACY "")
  45. IF(VTK_BINARY_PATH AND USE_BUILT_VTK)
  46. SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH})
  47. ENDIF(VTK_BINARY_PATH AND USE_BUILT_VTK)
  48. IF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
  49. SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY}
  50. ${VTK_INSTALL_PATH}/lib/vtk)
  51. ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
  52. #
  53. # Look for an installation or build tree.
  54. #
  55. FIND_PATH(VTK_DIR UseVTK.cmake
  56. # Support legacy cache files.
  57. ${VTK_DIR_SEARCH_LEGACY}
  58. # Look in places relative to the system executable search path.
  59. ${VTK_DIR_SEARCH}
  60. # Look in standard UNIX install locations.
  61. /usr/local/lib/vtk
  62. /usr/lib/vtk
  63. # Read from the CMakeSetup registry entries. It is likely that
  64. # VTK will have been recently built.
  65. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
  66. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
  67. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
  68. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
  69. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
  70. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
  71. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
  72. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
  73. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
  74. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
  75. # Help the user find it if we cannot.
  76. DOC "The ${VTK_DIR_DESCRIPTION}"
  77. )
  78. ENDIF(NOT VTK_DIR)
  79. # If VTK was found, load the configuration file to get the rest of the
  80. # settings.
  81. IF(VTK_DIR)
  82. # Make sure the VTKConfig.cmake file exists in the directory provided.
  83. IF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
  84. # We found VTK. Load the settings.
  85. SET(VTK_FOUND 1)
  86. INCLUDE(${VTK_DIR}/VTKConfig.cmake)
  87. ELSE(EXISTS ${VTK_DIR}/VTKConfig.cmake)
  88. IF(EXISTS ${VTK_DIR}/UseVTK.cmake)
  89. # We found VTK 4.0 (UseVTK.cmake exists, but not VTKConfig.cmake).
  90. SET(VTK_FOUND 1)
  91. SET(VTK_USE_FILE ${VTK_DIR}/UseVTK.cmake)
  92. # Hard-code the version number since it isn't provided by VTK 4.0.
  93. SET(VTK_MAJOR_VERSION 4)
  94. SET(VTK_MINOR_VERSION 0)
  95. SET(VTK_BUILD_VERSION 2)
  96. # Make sure old UseVTK.cmake will work.
  97. IF(EXISTS ${VTK_DIR}/Common)
  98. # This is a VTK 4.0 build tree.
  99. SET(USE_BUILT_VTK 1)
  100. SET(VTK_BINARY_PATH ${VTK_DIR})
  101. ELSE(EXISTS ${VTK_DIR}/Common)
  102. # This is a VTK 4.0 install tree.
  103. SET(USE_INSTALLED_VTK 1)
  104. SET(VTK_INSTALL_PATH ${VTK_DIR}/../..)
  105. ENDIF(EXISTS ${VTK_DIR}/Common)
  106. ELSE(EXISTS ${VTK_DIR}/UseVTK.cmake)
  107. # We did not find VTK.
  108. SET(VTK_FOUND 0)
  109. ENDIF(EXISTS ${VTK_DIR}/UseVTK.cmake)
  110. ENDIF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
  111. ELSE(VTK_DIR)
  112. # We did not find VTK.
  113. SET(VTK_FOUND 0)
  114. ENDIF(VTK_DIR)
  115. IF(VTK_FOUND)
  116. # Set USE_VTK_FILE for backward-compatability.
  117. SET(USE_VTK_FILE ${VTK_USE_FILE})
  118. ELSE(VTK_FOUND)
  119. # VTK not found, explain to the user how to specify its location.
  120. IF(NOT VTK_FIND_QUIETLY)
  121. MESSAGE(${VTK_DIR_MESSAGE})
  122. ENDIF(NOT VTK_FIND_QUIETLY)
  123. ENDIF(VTK_FOUND)