Salome HOME
update merge Coreflows and CDMATH compilation
[tools/solverlab.git] / cmake_files / 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 distributed 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(UseVTKConfig40) # 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(VTK_BINARY_PATH AND USE_BUILT_VTK)
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(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
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(UseVTKConfig40) # 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(VTK_FOUND)
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(VTK_FIND_REQUIRED)
137     IF(NOT VTK_FIND_QUIETLY)
138       MESSAGE(STATUS ${VTK_DIR_MESSAGE})
139     ENDIF(NOT VTK_FIND_QUIETLY)
140   ENDIF(VTK_FIND_REQUIRED)
141 ENDIF(VTK_FOUND)
142