ENH: New implementation of FindVTK to take advantage of VTKConfig.cmake. Also provides more powerful search path mechanism, and requires only one cache entry in user project.

This commit is contained in:
Brad King 2002-11-20 13:37:52 -05:00
parent c96c3c382f
commit e3f76e9367

View File

@ -1,28 +1,75 @@
# #
# Find the native VTK includes and library # Find a VTK installation or build tree.
# #
# This module defines: # When VTK is found, the VTKConfig.cmake file is sourced to setup the
# location and configuration of VTK. Please read this file, or
# VTKConfig.cmake.in from the VTK source tree for the full list of
# definitions. Of particular interest is
# #
# VTK_INSTALL_PATH - Where is the installed version of VTK. # VTK_USE_FILE - A CMake source file that can be included
# USE_BUILT_VTK - Should a built-from-source version of VTK be used. # to set the include directories, library
# directories, and preprocessor macros.
# #
# VTK_BINARY_PATH - Where is (one of) the binary tree(s). # In addition to the variables read from VTKConfig.cmake, this find
# USE_INSTALLED_VTK - Should an installed version of VTK be used # module also defines
# #
# USE_VTK_FILE - (internal) # VTK_DIR - The directory containing VTKConfig.cmake. This is either
# Full path and location to the UseVTK.cmake file. # the root of the build tree, or the lib/vtk
# This value changes each time USE_BUILT_VTK or # directory. This is the only cache entry.
# USE_INSTALLED_VTK is modified, and only if ONE of
# these setting is set to ON.
# #
# If VTK is not found, an error is displayed unless VTK_FIND_QUIETLY # VTK_FOUND - Whether VTK was found. If this is true, VTK_DIR is okay.
# is on. #
# USE_VTK_FILE - The full path to the UseVTK.cmake file. This is provided
# for backward compatability. Use VTK_USE_FILE instead.
# #
# # Construct consitent error messages for use below.
# Look for a binary tree (built from source) SET(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/vtk for an installation.")
# SET(VTK_DIR_MESSAGE "VTK not found. Set VTK_DIR to the ${VTK_DIR_DESCRIPTION}")
FIND_PATH(VTK_BINARY_PATH UseVTK.cmake
# Search only if the location is not already known.
IF(NOT VTK_DIR)
# Get the system search path as a list.
IF(UNIX)
STRING(REGEX MATCHALL "[^:]+" VTK_DIR_SEARCH1 $ENV{PATH})
ELSE(UNIX)
STRING(REGEX REPLACE "\\\\" "/" VTK_DIR_SEARCH1 $ENV{PATH})
ENDIF(UNIX)
STRING(REGEX REPLACE "/;" ";" VTK_DIR_SEARCH2 ${VTK_DIR_SEARCH1})
# Construct a set of paths relative to the system search path.
SET(VTK_DIR_SEARCH "")
FOREACH(dir ${VTK_DIR_SEARCH2})
SET(VTK_DIR_SEARCH ${VTK_DIR_SEARCH} "${dir}/../lib/vtk")
ENDFOREACH(dir)
# Old scripts may set these directories in the CMakeCache.txt file.
# They can tell us where to find VTKConfig.cmake.
SET(VTK_DIR_SEARCH_LEGACY "")
IF(VTK_BINARY_PATH)
SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH})
ENDIF(VTK_BINARY_PATH)
IF(VTK_INSTALL_PATH)
SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY}
${VTK_INSTALL_PATH}/lib/vtk)
ENDIF(VTK_INSTALL_PATH)
#
# Look for an installation or build tree.
#
FIND_PATH(VTK_DIR VTKConfig.cmake
# Support legacy cache files.
${VTK_DIR_SEARCH_LEGACY}
# Look in places relative to the system executable search path.
${VTK_DIR_SEARCH}
# Look in standard UNIX install locations.
/usr/local/lib/vtk
/usr/lib/vtk
# Read from the CMakeSetup registry entries. It is likely that
# VTK will have been recently built.
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1] [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2] [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3] [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
@ -33,109 +80,37 @@ FIND_PATH(VTK_BINARY_PATH UseVTK.cmake
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8] [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9] [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10] [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
VTKBIN
../VTKBIN
../../VTKBIN
$ENV{HOME}/VTKBIN
VTK-bin
../VTK-bin
../../VTK-bin
$ENV{HOME}/VTK-bin
vtkbin
../vtkbin
../../vtkbin
$ENV{HOME}/vtkbin
VTK-vc
../VTK-vc
../../VTK-vc
$ENV{HOME}/VTK-vc
VTK-nmake
../VTK-nmake
../../VTK-nmake
$ENV{HOME}/VTK-nmake
)
# # Help the user find it if we cannot.
# If we found a built tree, USE_BUILT_VTK allows the user to DOC "The ${VTK_DIR_DESCRIPTION}"
# use it or not. Defaults to ON. )
# ENDIF(NOT VTK_DIR)
IF (VTK_BINARY_PATH)
SET (USE_BUILT_VTK 1 CACHE BOOL
"Use a built (versus installed) version of VTK. Be sure that VTK_BINARY_PATH is correct.")
ENDIF (VTK_BINARY_PATH)
# # If VTK was found, load the configuration file to get the rest of the
# Look for an installed tree # settings.
# IF(VTK_DIR)
FIND_PATH(VTK_INSTALL_PATH include/vtk/UseVTK.cmake # Make sure the VTKConfig.cmake file exists in the directory provided.
/usr/local IF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
/usr
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\VTK\\Nightly]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\VTK\\43]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\VTK\\42]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\VTK\\41]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\VTK\\40]
)
# # We found VTK. Load the settings.
# If we found an installed tree, USE_INSTALLED_VTK allows the user to SET(VTK_FOUND 1)
# use it or not. INCLUDE(${VTK_DIR}/VTKConfig.cmake)
#
# Defaults to OFF if a built tree was found before (see above), ON otherwise.
#
IF (VTK_INSTALL_PATH)
IF (USE_BUILT_VTK)
SET (USE_INSTALLED_VTK 0 CACHE BOOL
"Use an installed (versus built from source) version of VTK. Be sure that VTK_INSTALL_PATH is correct.")
ELSE (USE_BUILT_VTK)
SET (USE_INSTALLED_VTK 1 CACHE BOOL
"Use an installed (versus built from source) version of VTK. Be sure that VTK_INSTALL_PATH is correct.")
ENDIF (USE_BUILT_VTK)
ENDIF (VTK_INSTALL_PATH)
# # Set USE_VTK_FILE for backward-compatability.
# Set the USE_VTK_FILE only if one of USE_BUILT_VTK or USE_INSTALLED_VTK SET(USE_VTK_FILE ${VTK_USE_FILE})
# is ON. ELSE(EXISTS ${VTK_DIR}/VTKConfig.cmake)
# # We did not find VTK.
IF (USE_BUILT_VTK) SET(VTK_FOUND 0)
IF (NOT USE_INSTALLED_VTK) ENDIF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
IF (EXISTS "${VTK_BINARY_PATH}/UseVTK.cmake") ELSE(VTK_DIR)
SET (USE_VTK_FILE "${VTK_BINARY_PATH}/UseVTK.cmake") # We did not find VTK.
ENDIF (EXISTS "${VTK_BINARY_PATH}/UseVTK.cmake") SET(VTK_FOUND 0)
ENDIF (NOT USE_INSTALLED_VTK) ENDIF(VTK_DIR)
ELSE (USE_BUILT_VTK)
IF (USE_INSTALLED_VTK)
IF (EXISTS "${VTK_INSTALL_PATH}/include/vtk/UseVTK.cmake")
SET (USE_VTK_FILE "${VTK_INSTALL_PATH}/include/vtk/UseVTK.cmake")
ENDIF (EXISTS "${VTK_INSTALL_PATH}/include/vtk/UseVTK.cmake")
ENDIF (USE_INSTALLED_VTK)
ENDIF (USE_BUILT_VTK)
# # If it was not found, explain to the user how to specify its
# Display a warning if both settings are set to ON. # location.
# Otherwise display a warning if VTK was not found. IF (NOT VTK_FOUND)
#
IF (USE_BUILT_VTK AND USE_INSTALLED_VTK)
MESSAGE ("Warning. Please make sure that only ONE of the USE_INSTALLED_VTK or USE_BUILT_VTK setting is set to ON.")
ELSE (USE_BUILT_VTK AND USE_INSTALLED_VTK)
IF (NOT USE_VTK_FILE)
IF (NOT VTK_FIND_QUIETLY) IF (NOT VTK_FIND_QUIETLY)
MESSAGE ("Warning. VTK might be found on your system as different flavours: installed VTK or built VTK. Please make sure that the VTK_INSTALL_PATH or VTK_BINARY_PATH setting reflects which VTK you are planning to use, then set ONE of the USE_INSTALLED_VTK or USE_BUILT_VTK setting to ON.") MESSAGE(${VTK_DIR_MESSAGE})
ENDIF (NOT VTK_FIND_QUIETLY) ENDIF (NOT VTK_FIND_QUIETLY)
ENDIF (NOT USE_VTK_FILE) ENDIF (NOT VTK_FOUND)
ENDIF (USE_BUILT_VTK AND USE_INSTALLED_VTK)
# Note:
#
# If you use that module then you are probably relying on VTK to be found
# on your system. Here is the CMake code you might probably want to use to
# work hand-in-hand with that module (in that example CAN_BUILD is a var
# that is set to 0 if your project can not be build):
#
# INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake)
#
# IF (USE_VTK_FILE)
# INCLUDE (${USE_VTK_FILE})
# ELSE (USE_VTK_FILE)
# SET (CAN_BUILD 0)
# ENDIF (USE_VTK_FILE)