From 8f29fabf315f1f1b20a2caaafc424a5b3c287e29 Mon Sep 17 00:00:00 2001 From: Ben Webb <ben@salilab.org> Date: Wed, 30 Oct 2019 14:29:39 -0700 Subject: [PATCH] Add CMake script to help find IMP out of tree When building outside of the main IMP source tree, we need to find an existing IMP installation. The FindIMP.cmake script helps CMake to do this. --- tools/FindIMP.cmake | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tools/FindIMP.cmake diff --git a/tools/FindIMP.cmake b/tools/FindIMP.cmake new file mode 100644 index 0000000..1b11f97 --- /dev/null +++ b/tools/FindIMP.cmake @@ -0,0 +1,80 @@ +# +# The following module is based on FindVTK.cmake +# + +# - Find an IMP installation or binary tree. +# The following variables are set if IMP is found. If IMP is not +# found, IMP_FOUND is set to false. +# +# IMP_FOUND - Set to true when IMP is found. +# IMP_USE_FILE - CMake file to use IMP. +# + +# Construct consistent error messages for use below. +set(IMP_DIR_DESCRIPTION "directory containing IMPConfig.cmake. This is either the cmake binary directory where IMP was configured or PREFIX/lib/cmake/IMP if you installed IMP.") +set(IMP_DIR_MESSAGE "IMP not found. Set the IMP_DIR cmake variable or environment variable to the ${IMP_DIR_DESCRIPTION}") + +if ( NOT IMP_DIR ) + + # Get the system search path as a list. + if(UNIX) + string(REGEX MATCHALL "[^:]+" IMP_DIR_SEARCH1 "$ENV{PATH}") + else() + string(REGEX REPLACE "\\\\" "/" IMP_DIR_SEARCH1 "$ENV{PATH}") + endif() + + string(REGEX REPLACE "/;" ";" IMP_DIR_SEARCH2 "${IMP_DIR_SEARCH1}") + + # Construct a set of paths relative to the system search path. + set(IMP_DIR_SEARCH "") + + foreach(dir ${IMP_DIR_SEARCH2}) + + set(IMP_DIR_SEARCH ${IMP_DIR_SEARCH} ${dir}/../lib/cmake/IMP ) + + endforeach() + + + # + # Look for an installation or build tree. + # + find_path(IMP_DIR IMPConfig.cmake + + # Look for an environment variable IMP_DIR. + $ENV{IMP_DIR} + + # Look in places relative to the system executable search path. + ${IMP_DIR_SEARCH} + + # Look in standard UNIX install locations. + /usr/local/lib/IMP + /usr/local/lib/cmake/IMP + /usr/lib64/IMP + /usr/lib64/cmake/IMP + /usr/lib/IMP + /usr/lib/cmake/IMP + + # Help the user find it if we cannot. + DOC "The ${IMP_DIR_DESCRIPTION}" + ) + +endif() + +if ( IMP_DIR ) + + if ( EXISTS "${IMP_DIR}/IMPConfig.cmake" ) + include( "${IMP_DIR}/IMPConfig.cmake" ) + set( IMP_FOUND TRUE ) + endif() + +endif() + +if( NOT IMP_FOUND) + if(IMP_FIND_REQUIRED) + MESSAGE(FATAL_ERROR ${IMP_DIR_MESSAGE}) + else() + if(NOT IMP_FIND_QUIETLY) + MESSAGE(STATUS ${IMP_DIR_MESSAGE}) + endif() + endif() +endif() -- GitLab