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
|
# (To distributed this file outside of CMake, substitute the full
|
||||||
# License text for the above reference.)
|
# 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.
|
# 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}")
|
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.
|
# Check whether VTK 4.0 has already been found.
|
||||||
IF(NOT VTK_DIR)
|
IF(_VTK_40_ALLOW AND VTK_DIR)
|
||||||
# Get the system search path as a list.
|
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||||
IF(UNIX)
|
SET(VTK_FOUND 1)
|
||||||
STRING(REGEX MATCHALL "[^:]+" VTK_DIR_SEARCH1 "$ENV{PATH}")
|
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||||
ELSE(UNIX)
|
ENDIF()
|
||||||
STRING(REGEX REPLACE "\\\\" "/" VTK_DIR_SEARCH1 "$ENV{PATH}")
|
ENDIF()
|
||||||
ENDIF(UNIX)
|
|
||||||
STRING(REGEX REPLACE "/;" ";" VTK_DIR_SEARCH2 "${VTK_DIR_SEARCH1}")
|
|
||||||
|
|
||||||
# Construct a set of paths relative to the system search path.
|
# Use the Config mode of the find_package() command to find VTKConfig.
|
||||||
SET(VTK_DIR_SEARCH "")
|
# If this succeeds (possibly because VTK_DIR is already set), the
|
||||||
FOREACH(dir ${VTK_DIR_SEARCH2})
|
# command will have already loaded VTKConfig.cmake and set VTK_FOUND.
|
||||||
SET(VTK_DIR_SEARCH ${VTK_DIR_SEARCH}
|
IF(NOT _VTK_40_ONLY AND NOT VTK_FOUND)
|
||||||
${dir}/../lib/vtk-5.4
|
FIND_PACKAGE(VTK QUIET NO_MODULE)
|
||||||
${dir}/../lib/vtk-5.2
|
ENDIF()
|
||||||
${dir}/../lib/vtk-5.1
|
|
||||||
${dir}/../lib/vtk-5.0
|
|
||||||
${dir}/../lib/vtk
|
|
||||||
)
|
|
||||||
ENDFOREACH(dir)
|
|
||||||
|
|
||||||
|
# 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.
|
# Old scripts may set these directories in the CMakeCache.txt file.
|
||||||
# They can tell us where to find VTKConfig.cmake.
|
# They can tell us where to find VTKConfig.cmake.
|
||||||
SET(VTK_DIR_SEARCH_LEGACY "")
|
SET(VTK_DIR_SEARCH_LEGACY "")
|
||||||
|
@ -77,23 +86,17 @@ IF(NOT VTK_DIR)
|
||||||
${VTK_INSTALL_PATH}/lib/vtk)
|
${VTK_INSTALL_PATH}/lib/vtk)
|
||||||
ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
|
ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
|
||||||
|
|
||||||
#
|
# Look for UseVTK.cmake in build trees or under <prefix>/include/vtk.
|
||||||
# Look for an installation or build tree.
|
FIND_PATH(VTK_DIR
|
||||||
#
|
NAMES UseVTK.cmake
|
||||||
FIND_PATH(VTK_DIR UseVTK.cmake
|
PATH_SUFFIXES vtk-4.0 vtk
|
||||||
|
HINTS $ENV{VTK_DIR}
|
||||||
|
|
||||||
|
PATHS
|
||||||
|
|
||||||
# Support legacy cache files.
|
# Support legacy cache files.
|
||||||
${VTK_DIR_SEARCH_LEGACY}
|
${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
|
# Read from the CMakeSetup registry entries. It is likely that
|
||||||
# VTK will have been recently built.
|
# VTK will have been recently built.
|
||||||
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
|
||||||
|
@ -109,34 +112,18 @@ IF(NOT VTK_DIR)
|
||||||
|
|
||||||
# Help the user find it if we cannot.
|
# Help the user find it if we cannot.
|
||||||
DOC "The ${VTK_DIR_DESCRIPTION}"
|
DOC "The ${VTK_DIR_DESCRIPTION}"
|
||||||
)
|
)
|
||||||
ENDIF(NOT VTK_DIR)
|
|
||||||
|
|
||||||
# If VTK was found, load the configuration file to get the rest of the
|
IF(VTK_DIR)
|
||||||
# settings.
|
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||||
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.
|
|
||||||
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)
|
SET(VTK_FOUND 1)
|
||||||
# Load settings for VTK 4.0.
|
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||||
INCLUDE(UseVTKConfig40)
|
ELSE()
|
||||||
ELSE(EXISTS ${VTK_DIR}/UseVTK.cmake)
|
# We found the wrong version. Pretend we did not find it.
|
||||||
# We did not find VTK.
|
SET(VTK_DIR "VTK_DIR-NOTFOUND" CACHE PATH "The ${VTK_DIR_DESCRIPTION}" FORCE)
|
||||||
SET(VTK_FOUND 0)
|
ENDIF()
|
||||||
ENDIF(EXISTS ${VTK_DIR}/UseVTK.cmake)
|
ENDIF()
|
||||||
ENDIF(EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
ENDIF()
|
||||||
ELSE(VTK_DIR)
|
|
||||||
# We did not find VTK.
|
|
||||||
SET(VTK_FOUND 0)
|
|
||||||
ENDIF(VTK_DIR)
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
IF(VTK_FOUND)
|
IF(VTK_FOUND)
|
||||||
|
|
Loading…
Reference in New Issue