Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Modules / FindVTK.cmake
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 #=============================================================================
31 # Copyright 2001-2009 Kitware, Inc.
32 #
33 # Distributed under the OSI-approved BSD License (the "License");
34 # see accompanying file Copyright.txt for details.
35 #
36 # This software is distributed WITHOUT ANY WARRANTY; without even the
37 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38 # See the License for more information.
39 #=============================================================================
40 # (To distribute this file outside of CMake, substitute the full
41 #  License text for the above reference.)
42
43 # Assume not found.
44 set(VTK_FOUND 0)
45
46 # VTK 4.0 did not provide VTKConfig.cmake.
47 if("${VTK_FIND_VERSION}" VERSION_LESS 4.1)
48   set(_VTK_40_ALLOW 1)
49   if(VTK_FIND_VERSION)
50     set(_VTK_40_ONLY 1)
51   endif()
52 endif()
53
54 # Construct consitent error messages for use below.
55 set(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake.  This is either the root of the build tree, or PREFIX/lib/vtk for an installation.")
56 if(_VTK_40_ALLOW)
57   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.")
58 endif()
59 set(VTK_DIR_MESSAGE "VTK not found.  Set the VTK_DIR cmake cache entry to the ${VTK_DIR_DESCRIPTION}")
60
61 # Check whether VTK 4.0 has already been found.
62 if(_VTK_40_ALLOW AND VTK_DIR)
63   if(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
64     set(VTK_FOUND 1)
65     include(${CMAKE_CURRENT_LIST_DIR}/UseVTKConfig40.cmake) # No VTKConfig; load VTK 4.0 settings.
66   endif()
67 endif()
68
69 # Use the Config mode of the find_package() command to find VTKConfig.
70 # If this succeeds (possibly because VTK_DIR is already set), the
71 # command will have already loaded VTKConfig.cmake and set VTK_FOUND.
72 if(NOT _VTK_40_ONLY AND NOT VTK_FOUND)
73   find_package(VTK QUIET NO_MODULE)
74 endif()
75
76 # Special search for VTK 4.0.
77 if(_VTK_40_ALLOW AND NOT VTK_DIR)
78   # Old scripts may set these directories in the CMakeCache.txt file.
79   # They can tell us where to find VTKConfig.cmake.
80   set(VTK_DIR_SEARCH_LEGACY "")
81   if(VTK_BINARY_PATH AND USE_BUILT_VTK)
82     set(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH})
83   endif()
84   if(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
85     set(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY}
86         ${VTK_INSTALL_PATH}/lib/vtk)
87   endif()
88
89   # Look for UseVTK.cmake in build trees or under <prefix>/include/vtk.
90   find_path(VTK_DIR
91     NAMES UseVTK.cmake
92     PATH_SUFFIXES vtk-4.0 vtk
93     HINTS ENV VTK_DIR
94
95     PATHS
96
97     # Support legacy cache files.
98     ${VTK_DIR_SEARCH_LEGACY}
99
100     # Read from the CMakeSetup registry entries.  It is likely that
101     # VTK will have been recently built.
102     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
103     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
104     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
105     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
106     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
107     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
108     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
109     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
110     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
111     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
112
113     # Help the user find it if we cannot.
114     DOC "The ${VTK_DIR_DESCRIPTION}"
115     )
116
117   if(VTK_DIR)
118     if(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
119       set(VTK_FOUND 1)
120       include(${CMAKE_CURRENT_LIST_DIR}/UseVTKConfig40.cmake) # No VTKConfig; load VTK 4.0 settings.
121     else()
122       # We found the wrong version.  Pretend we did not find it.
123       set(VTK_DIR "VTK_DIR-NOTFOUND" CACHE PATH "The ${VTK_DIR_DESCRIPTION}" FORCE)
124     endif()
125   endif()
126 endif()
127
128 #-----------------------------------------------------------------------------
129 if(VTK_FOUND)
130   # Set USE_VTK_FILE for backward-compatability.
131   set(USE_VTK_FILE ${VTK_USE_FILE})
132 else()
133   # VTK not found, explain to the user how to specify its location.
134   if(VTK_FIND_REQUIRED)
135     message(FATAL_ERROR ${VTK_DIR_MESSAGE})
136   else()
137     if(NOT VTK_FIND_QUIETLY)
138       message(STATUS ${VTK_DIR_MESSAGE})
139     endif()
140   endif()
141 endif()