Introduce "generator expressions" to add_test()
[cmake.git] / Modules / FindVTK.cmake
blob57da7a0d7e15c94fe8d2315c55588840bdb46e4d
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.
30 # Construct consitent error messages for use below.
31 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.")
32 SET(VTK_DIR_MESSAGE "VTK not found.  Set the VTK_DIR cmake cache entry to the ${VTK_DIR_DESCRIPTION}")
34 # Search only if the location is not already known.
35 IF(NOT VTK_DIR)
36   # Get the system search path as a list.
37   IF(UNIX)
38     STRING(REGEX MATCHALL "[^:]+" VTK_DIR_SEARCH1 "$ENV{PATH}")
39   ELSE(UNIX)
40     STRING(REGEX REPLACE "\\\\" "/" VTK_DIR_SEARCH1 "$ENV{PATH}")
41   ENDIF(UNIX)
42   STRING(REGEX REPLACE "/;" ";" VTK_DIR_SEARCH2 "${VTK_DIR_SEARCH1}")
44   # Construct a set of paths relative to the system search path.
45   SET(VTK_DIR_SEARCH "")
46   FOREACH(dir ${VTK_DIR_SEARCH2})
47     SET(VTK_DIR_SEARCH ${VTK_DIR_SEARCH}
48       ${dir}/../lib/vtk-5.4
49       ${dir}/../lib/vtk-5.2
50       ${dir}/../lib/vtk-5.1
51       ${dir}/../lib/vtk-5.0
52       ${dir}/../lib/vtk
53       )
54   ENDFOREACH(dir)
56   # Old scripts may set these directories in the CMakeCache.txt file.
57   # They can tell us where to find VTKConfig.cmake.
58   SET(VTK_DIR_SEARCH_LEGACY "")
59   IF(VTK_BINARY_PATH AND USE_BUILT_VTK)
60     SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH})
61   ENDIF(VTK_BINARY_PATH AND USE_BUILT_VTK)
62   IF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
63     SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY}
64         ${VTK_INSTALL_PATH}/lib/vtk)
65   ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
67   #
68   # Look for an installation or build tree.
69   #
70   FIND_PATH(VTK_DIR UseVTK.cmake
71     # Support legacy cache files.
72     ${VTK_DIR_SEARCH_LEGACY}
74     # Look for an environment variable VTK_DIR.
75     $ENV{VTK_DIR}
77     # Look in places relative to the system executable search path.
78     ${VTK_DIR_SEARCH}
80     # Look in standard UNIX install locations.
81     /usr/local/lib/vtk
82     /usr/lib/vtk
84     # Read from the CMakeSetup registry entries.  It is likely that
85     # VTK will have been recently built.
86     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
87     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
88     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
89     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
90     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
91     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
92     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
93     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
94     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
95     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
97     # Help the user find it if we cannot.
98     DOC "The ${VTK_DIR_DESCRIPTION}"
99   )
100 ENDIF(NOT VTK_DIR)
102 # If VTK was found, load the configuration file to get the rest of the
103 # settings.
104 IF(VTK_DIR)
105   # Make sure the VTKConfig.cmake file exists in the directory provided.
106   IF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
108     # We found VTK.  Load the settings.
109     SET(VTK_FOUND 1)
110     INCLUDE(${VTK_DIR}/VTKConfig.cmake)
112   ELSE(EXISTS ${VTK_DIR}/VTKConfig.cmake)
113     IF(EXISTS ${VTK_DIR}/UseVTK.cmake)
114       # We found VTK 4.0 (UseVTK.cmake exists, but not VTKConfig.cmake).
115       SET(VTK_FOUND 1)
116       # Load settings for VTK 4.0.
117       INCLUDE(UseVTKConfig40)
118     ELSE(EXISTS ${VTK_DIR}/UseVTK.cmake)
119       # We did not find VTK.
120       SET(VTK_FOUND 0)
121     ENDIF(EXISTS ${VTK_DIR}/UseVTK.cmake)
122   ENDIF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
123 ELSE(VTK_DIR)
124   # We did not find VTK.
125   SET(VTK_FOUND 0)
126 ENDIF(VTK_DIR)
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)