mirror of
https://develop.openfoam.com/Development/ThirdParty-common.git
synced 2025-12-08 06:57:50 +00:00
COMP: improve support for non-system python locations (issue #17)
This commit is contained in:
@ -27,6 +27,18 @@
|
||||
# Description
|
||||
# ParaView make/install helper functions
|
||||
#
|
||||
# Note
|
||||
# Obtainining paths via 'python-config' is possible, but may not always
|
||||
# resolve properly:
|
||||
#
|
||||
# python-config --includes
|
||||
# >>
|
||||
# -I/usr/include/python2.7 -I/usr/include/python2.7
|
||||
#
|
||||
# python-config --libs
|
||||
# >>
|
||||
# -lpython2.7 -lpthread -ldl -lutil -lm
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# Variables referenced by the functions. Initialization at the end of the file.
|
||||
@ -159,68 +171,91 @@ addMpiSupport()
|
||||
#
|
||||
addPythonSupport()
|
||||
{
|
||||
if [ "${withPYTHON:=false}" != true ]
|
||||
if [ "${withPYTHON:-false}" != true ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
|
||||
if pythonBin=$(which python 2>/dev/null)
|
||||
then
|
||||
if [ -n "$PYTHON_LIBRARY" ]
|
||||
then
|
||||
# Check $PYTHON_LIBRARY if it has been set
|
||||
if [ ! -e "$PYTHON_LIBRARY" ]
|
||||
then
|
||||
echo "*** Error: libpython not found at location specified " \
|
||||
"by -pythnon-lib input: PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
||||
fi
|
||||
else
|
||||
# Try to get $PYTHON_LIBRARY from dynamically linked binary
|
||||
PYTHON_LIBRARY=$(ldd $pythonBin | \
|
||||
sed -ne '/libpython/s/.* => \(.*\) (.*/\1/p')
|
||||
local pythonBin pythonConfig pythonMajor
|
||||
|
||||
[ -e "$PYTHON_LIBRARY" ] || {
|
||||
echo "*** Error: Unable to determine path to python library."
|
||||
}
|
||||
fi
|
||||
|
||||
[ -e "$PYTHON_LIBRARY" ] || {
|
||||
echo " Please set the full path to the python library "
|
||||
echo " (including libpython) using the -python-lib option, "
|
||||
echo " or deactivate python support by not using the -python "
|
||||
echo " option"
|
||||
exit 1
|
||||
}
|
||||
|
||||
pythonMajor=$(echo $PYTHON_LIBRARY | sed 's/.*libpython\(.*\)\.so.*/\1/')
|
||||
pythonInclude=/usr/include/python$pythonMajor
|
||||
|
||||
# Note - we could also allow for a PYTHON_INCLUDE variable ...
|
||||
[ -d "$pythonInclude" -a -f "$pythonInclude/Python.h" ] || {
|
||||
echo " No python headers found in $pythonInclude/"
|
||||
echo " Please install python headers or deactivate "
|
||||
echo " python support by not using the -python option"
|
||||
exit 1
|
||||
}
|
||||
|
||||
addCMakeVariable "PARAVIEW_ENABLE_PYTHON=ON"
|
||||
addCMakeVariable "PYTHON_INCLUDE_DIRS=$pythonInclude"
|
||||
addCMakeVariable "PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
||||
|
||||
echo "----"
|
||||
echo "Python information:"
|
||||
echo " executable : $pythonBin"
|
||||
echo " version : $pythonMajor"
|
||||
echo " include path : $pythonInclude"
|
||||
echo " library : $PYTHON_LIBRARY"
|
||||
|
||||
unset pythonBin pythonInclude pythonMajor
|
||||
else
|
||||
pythonBin=$(which python 2>/dev/null) || {
|
||||
echo "*** Error: python not found"
|
||||
echo "*** Deactivate python support by not using the -python "
|
||||
echo "*** option"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -n "$PYTHON_LIBRARY" ]
|
||||
then
|
||||
|
||||
# PYTHON_LIBRARY set:
|
||||
[ -e "$PYTHON_LIBRARY" ] || \
|
||||
echo "*** Error: libpython not found at location specified " \
|
||||
"by -python-lib : PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
||||
|
||||
else
|
||||
|
||||
# Fallback: get PYTHON_LIBRARY from dynamically linked binary
|
||||
|
||||
PYTHON_LIBRARY=$(ldd $pythonBin | \
|
||||
sed -ne '/libpython/s/^.* => \(.*\) (.*/\1/p')
|
||||
|
||||
[ -e "$PYTHON_LIBRARY" ] || {
|
||||
echo "*** Error: Unable to determine path to python library."
|
||||
}
|
||||
|
||||
fi
|
||||
|
||||
[ -e "$PYTHON_LIBRARY" ] || {
|
||||
echo " Please set the full path to the python library "
|
||||
echo " (including libpython) using the -python-lib option, "
|
||||
echo " or deactivate python support by not using the -python "
|
||||
echo " option"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Guess major from library
|
||||
pythonMajor=$(echo $PYTHON_LIBRARY | sed 's/.*libpython\(.*\)\.so.*/\1/')
|
||||
|
||||
if [ -n "$PYTHON_INCLUDE" ]
|
||||
then
|
||||
|
||||
# PYTHON_INCLUDE set:
|
||||
[ -d "$PYTHON_INCLUDE" -a -f "$PYTHON_INCLUDE/Python.h" ] || \
|
||||
echo "*** Error: Python.h not found at location specified " \
|
||||
"by -python-include : PYTHON_INCLUDE=$PYTHON_INCLUDE"
|
||||
|
||||
elif pythonConfig=$(which python-config 2>/dev/null)
|
||||
then
|
||||
# Guess from python-config
|
||||
# parse '-I/usr/include/python2.7 -I/usr/include/python2.7'
|
||||
# -> '/usr/include/python2.7'
|
||||
PYTHON_INCLUDE=$(python-config --includes | sed -ne 's/^-I\([^ ][^ ]*\).*$/\1/p')
|
||||
|
||||
else
|
||||
|
||||
# Fallback to system headers
|
||||
PYTHON_INCLUDE=/usr/include/python$pythonMajor
|
||||
|
||||
fi
|
||||
|
||||
[ -d "$PYTHON_INCLUDE" -a -f "$PYTHON_INCLUDE/Python.h" ] || {
|
||||
echo " No python headers found in $PYTHON_INCLUDE/"
|
||||
echo " Please install python headers or deactivate "
|
||||
echo " python support by not using the -python option"
|
||||
exit 1
|
||||
}
|
||||
|
||||
addCMakeVariable "PARAVIEW_ENABLE_PYTHON=ON"
|
||||
addCMakeVariable "PYTHON_INCLUDE_DIRS=$PYTHON_INCLUDE"
|
||||
addCMakeVariable "PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
||||
|
||||
echo "----"
|
||||
echo "Python information:"
|
||||
echo " executable : $pythonBin"
|
||||
echo " version : $pythonMajor"
|
||||
echo " include path : $PYTHON_INCLUDE"
|
||||
echo " library : $PYTHON_LIBRARY"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -78,6 +78,8 @@ options:
|
||||
-mpi with mpi
|
||||
-mpi=N with max 'N' mpi processes. N=0 for no upper-limit.
|
||||
-python with python
|
||||
-python-include DIR
|
||||
location of python headers (current: ${PYTHON_INCLUDE:-none})
|
||||
-python-lib PATH path to python library (current: ${PYTHON_LIBRARY:-none})
|
||||
-cmake PATH with cmake from the path given
|
||||
-qmake PATH with the Qt version corresponding to the qmake path given
|
||||
@ -233,6 +235,12 @@ do
|
||||
-no-python)
|
||||
withPYTHON=false
|
||||
;;
|
||||
-python-include)
|
||||
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
||||
withPYTHON=true
|
||||
PYTHON_INCLUDE="${2%%/}"
|
||||
shift
|
||||
;;
|
||||
-python-lib)
|
||||
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
||||
withPYTHON=true
|
||||
|
||||
Reference in New Issue
Block a user