Changed code for finding ERT Python
- Using standard python 'import ert' and introspection. - Using dist-packages (debian) and site-packages (!debian). - In separate cmake module FindERTPython.cmake
This commit is contained in:
@@ -72,24 +72,6 @@ find_path (ERT_GEN_INCLUDE_DIR
|
||||
${_no_default_path}
|
||||
)
|
||||
|
||||
find_package(PythonInterp)
|
||||
if(PYTHONINTERP_FOUND)
|
||||
execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c
|
||||
"from distutils.sysconfig import get_python_lib; print get_python_lib()"
|
||||
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
find_path (ERT_PYTHON_PATH
|
||||
NAMES "ert/__ert_lib_path.py"
|
||||
HINTS "${ERT_ROOT}"
|
||||
PATHS "${PYTHON_SITE_PACKAGES}"
|
||||
"${PROJECT_SOURCE_DIR}/../ert/build/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages"
|
||||
"${PROJECT_SOURCE_DIR}/../ert/devel/build/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages"
|
||||
"${PROJECT_BINARY_DIR}/../ert-build/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages"
|
||||
"${PROJECT_BINARY_DIR}/../ert/devel/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages")
|
||||
if(ERT_PYTHON_PATH MATCHES "NOTFOUND")
|
||||
set(ERT_PYTHON_PATH "")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# need all of these libraries
|
||||
if (CMAKE_SIZEOF_VOID_P)
|
||||
@@ -300,3 +282,7 @@ find_package_handle_standard_args (ERT
|
||||
DEFAULT_MSG
|
||||
ERT_INCLUDE_DIR ERT_LIBRARY HAVE_ERT
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
55
cmake/Modules/FindERTPython.cmake
Normal file
55
cmake/Modules/FindERTPython.cmake
Normal file
@@ -0,0 +1,55 @@
|
||||
# - Find the Python wrappers for Ensemble-based Reservoir Tool (ERT)
|
||||
#
|
||||
# Set the cache variable ERT_PYTHON_PATH to the install location of
|
||||
# the root ert package.
|
||||
|
||||
find_package(PythonInterp)
|
||||
if(PYTHONINTERP_FOUND)
|
||||
|
||||
# We try to find the ert Python distribution. This is done by running
|
||||
# Python code which tries to 'import ert' and prints out the path to
|
||||
# the module if the import succeeds.
|
||||
#
|
||||
# The normal Python import machinery is employed, so if you have
|
||||
# installed ert python in a default location, or alternatively set the
|
||||
# PYTHONPATH variable the ert Python distribution will eventually be
|
||||
# found there, independently of the alternatives which are tested with
|
||||
# the ${PATH_LIST} variable.
|
||||
|
||||
if (EXISTS "/etc/debian_version")
|
||||
set( PYTHON_PACKAGE_PATH "dist-packages")
|
||||
else()
|
||||
set( PYTHON_PACKAGE_PATH "site-packages")
|
||||
endif()
|
||||
set(PYTHON_INSTALL_PREFIX "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/${PYTHON_PACKAGE_PATH}" CACHE STRING "Subdirectory to install Python modules in")
|
||||
|
||||
if (ERT_ROOT)
|
||||
set( start_path "${ERT_ROOT}/${PYTHON_INSTALL_PREFIX}" )
|
||||
else()
|
||||
set( start_path "DEFAULT_PATH")
|
||||
endif()
|
||||
|
||||
set( PATH_LIST "${start_path}"
|
||||
"${PROJECT_SOURCE_DIR}/../ert/build/${PYTHON_INSTALL_PREFIX}"
|
||||
"${PROJECT_SOURCE_DIR}/../ert/devel/build/${PYTHON_INSTALL_PREFIX}"
|
||||
"${PROJECT_BINARY_DIR}/../ert-build/${PYTHON_INSTALL_PREFIX}"
|
||||
"${PROJECT_BINARY_DIR}/../ert/devel/${PYTHON_INSTALL_PREFIX}")
|
||||
|
||||
foreach( PATH ${PATH_LIST})
|
||||
set( python_code "import sys; sys.path.insert(0 , '${PATH}'); import os.path; import inspect; import ert; print os.path.dirname(os.path.dirname(inspect.getfile(ert)))")
|
||||
execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "${python_code}"
|
||||
RESULT_VARIABLE import_result
|
||||
OUTPUT_VARIABLE stdout_output
|
||||
ERROR_VARIABLE stderr_output
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE )
|
||||
|
||||
if (${import_result} EQUAL 0)
|
||||
set( ERT_PYTHON_PATH ${stdout_output} CACHE PATH "Python path for ERT Python" )
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
find_package_handle_standard_args("ERTPython" DEFAULT_MSG ERT_PYTHON_PATH)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user