Modernize FindVTK module
This teaches the FindVTK module to use the Config mode of find_package() to search for VTKConfig in the common case. The old search method based on find_path() and UseVTK is now used only to search for VTK 4.0. This approach avoids the need to update the module for each new VTK version because find_package(VTK) automatically searches "lib/vtk*". It also addresses issue #9105 since find_package searches lib64 paths too.
This commit is contained in:
parent
71910b3fd4
commit
2c1a01dc6d
|
@ -40,32 +40,41 @@
|
|||
# (To distributed this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
# Assume not found.
|
||||
SET(VTK_FOUND 0)
|
||||
|
||||
# VTK 4.0 did not provide VTKConfig.cmake.
|
||||
IF("${VTK_FIND_VERSION}" VERSION_LESS 4.1)
|
||||
SET(_VTK_40_ALLOW 1)
|
||||
IF(VTK_FIND_VERSION)
|
||||
SET(_VTK_40_ONLY 1)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# Construct consitent error messages for use below.
|
||||
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.")
|
||||
SET(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/vtk for an installation.")
|
||||
IF(_VTK_40_ALLOW)
|
||||
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.")
|
||||
ENDIF()
|
||||
SET(VTK_DIR_MESSAGE "VTK not found. Set the VTK_DIR cmake cache entry to the ${VTK_DIR_DESCRIPTION}")
|
||||
|
||||
# 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}")
|
||||
# Check whether VTK 4.0 has already been found.
|
||||
IF(_VTK_40_ALLOW AND VTK_DIR)
|
||||
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||
SET(VTK_FOUND 1)
|
||||
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# 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-5.4
|
||||
${dir}/../lib/vtk-5.2
|
||||
${dir}/../lib/vtk-5.1
|
||||
${dir}/../lib/vtk-5.0
|
||||
${dir}/../lib/vtk
|
||||
)
|
||||
ENDFOREACH(dir)
|
||||
# Use the Config mode of the find_package() command to find VTKConfig.
|
||||
# If this succeeds (possibly because VTK_DIR is already set), the
|
||||
# command will have already loaded VTKConfig.cmake and set VTK_FOUND.
|
||||
IF(NOT _VTK_40_ONLY AND NOT VTK_FOUND)
|
||||
FIND_PACKAGE(VTK QUIET NO_MODULE)
|
||||
ENDIF()
|
||||
|
||||
# Special search for VTK 4.0.
|
||||
IF(_VTK_40_ALLOW AND NOT VTK_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 "")
|
||||
|
@ -77,23 +86,17 @@ IF(NOT VTK_DIR)
|
|||
${VTK_INSTALL_PATH}/lib/vtk)
|
||||
ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
|
||||
|
||||
#
|
||||
# Look for an installation or build tree.
|
||||
#
|
||||
FIND_PATH(VTK_DIR UseVTK.cmake
|
||||
# Look for UseVTK.cmake in build trees or under <prefix>/include/vtk.
|
||||
FIND_PATH(VTK_DIR
|
||||
NAMES UseVTK.cmake
|
||||
PATH_SUFFIXES vtk-4.0 vtk
|
||||
HINTS $ENV{VTK_DIR}
|
||||
|
||||
PATHS
|
||||
|
||||
# Support legacy cache files.
|
||||
${VTK_DIR_SEARCH_LEGACY}
|
||||
|
||||
# Look for an environment variable VTK_DIR.
|
||||
$ENV{VTK_DIR}
|
||||
|
||||
# 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]
|
||||
|
@ -110,33 +113,17 @@ IF(NOT VTK_DIR)
|
|||
# Help the user find it if we cannot.
|
||||
DOC "The ${VTK_DIR_DESCRIPTION}"
|
||||
)
|
||||
ENDIF(NOT VTK_DIR)
|
||||
|
||||
# If VTK was found, load the configuration file to get the rest of the
|
||||
# settings.
|
||||
IF(VTK_DIR)
|
||||
# Make sure the VTKConfig.cmake file exists in the directory provided.
|
||||
IF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||
|
||||
# We found VTK. Load the settings.
|
||||
IF(VTK_DIR)
|
||||
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||
SET(VTK_FOUND 1)
|
||||
INCLUDE(${VTK_DIR}/VTKConfig.cmake)
|
||||
|
||||
ELSE(EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||
IF(EXISTS ${VTK_DIR}/UseVTK.cmake)
|
||||
# We found VTK 4.0 (UseVTK.cmake exists, but not VTKConfig.cmake).
|
||||
SET(VTK_FOUND 1)
|
||||
# Load settings for VTK 4.0.
|
||||
INCLUDE(UseVTKConfig40)
|
||||
ELSE(EXISTS ${VTK_DIR}/UseVTK.cmake)
|
||||
# We did not find VTK.
|
||||
SET(VTK_FOUND 0)
|
||||
ENDIF(EXISTS ${VTK_DIR}/UseVTK.cmake)
|
||||
ENDIF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||
ELSE(VTK_DIR)
|
||||
# We did not find VTK.
|
||||
SET(VTK_FOUND 0)
|
||||
ENDIF(VTK_DIR)
|
||||
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||
ELSE()
|
||||
# We found the wrong version. Pretend we did not find it.
|
||||
SET(VTK_DIR "VTK_DIR-NOTFOUND" CACHE PATH "The ${VTK_DIR_DESCRIPTION}" FORCE)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
IF(VTK_FOUND)
|
||||
|
|
Loading…
Reference in New Issue