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
|
# Description
|
||||||
# ParaView make/install helper functions
|
# 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.
|
# Variables referenced by the functions. Initialization at the end of the file.
|
||||||
@ -159,29 +171,39 @@ addMpiSupport()
|
|||||||
#
|
#
|
||||||
addPythonSupport()
|
addPythonSupport()
|
||||||
{
|
{
|
||||||
if [ "${withPYTHON:=false}" != true ]
|
if [ "${withPYTHON:-false}" != true ]
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if pythonBin=$(which python 2>/dev/null)
|
local pythonBin pythonConfig pythonMajor
|
||||||
then
|
|
||||||
|
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" ]
|
if [ -n "$PYTHON_LIBRARY" ]
|
||||||
then
|
then
|
||||||
# Check $PYTHON_LIBRARY if it has been set
|
|
||||||
if [ ! -e "$PYTHON_LIBRARY" ]
|
# PYTHON_LIBRARY set:
|
||||||
then
|
[ -e "$PYTHON_LIBRARY" ] || \
|
||||||
echo "*** Error: libpython not found at location specified " \
|
echo "*** Error: libpython not found at location specified " \
|
||||||
"by -pythnon-lib input: PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
"by -python-lib : PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# Try to get $PYTHON_LIBRARY from dynamically linked binary
|
|
||||||
|
# Fallback: get PYTHON_LIBRARY from dynamically linked binary
|
||||||
|
|
||||||
PYTHON_LIBRARY=$(ldd $pythonBin | \
|
PYTHON_LIBRARY=$(ldd $pythonBin | \
|
||||||
sed -ne '/libpython/s/.* => \(.*\) (.*/\1/p')
|
sed -ne '/libpython/s/^.* => \(.*\) (.*/\1/p')
|
||||||
|
|
||||||
[ -e "$PYTHON_LIBRARY" ] || {
|
[ -e "$PYTHON_LIBRARY" ] || {
|
||||||
echo "*** Error: Unable to determine path to python library."
|
echo "*** Error: Unable to determine path to python library."
|
||||||
}
|
}
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -e "$PYTHON_LIBRARY" ] || {
|
[ -e "$PYTHON_LIBRARY" ] || {
|
||||||
@ -192,35 +214,48 @@ addPythonSupport()
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Guess major from library
|
||||||
pythonMajor=$(echo $PYTHON_LIBRARY | sed 's/.*libpython\(.*\)\.so.*/\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 ...
|
if [ -n "$PYTHON_INCLUDE" ]
|
||||||
[ -d "$pythonInclude" -a -f "$pythonInclude/Python.h" ] || {
|
then
|
||||||
echo " No python headers found in $pythonInclude/"
|
|
||||||
|
# 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 " Please install python headers or deactivate "
|
||||||
echo " python support by not using the -python option"
|
echo " python support by not using the -python option"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
addCMakeVariable "PARAVIEW_ENABLE_PYTHON=ON"
|
addCMakeVariable "PARAVIEW_ENABLE_PYTHON=ON"
|
||||||
addCMakeVariable "PYTHON_INCLUDE_DIRS=$pythonInclude"
|
addCMakeVariable "PYTHON_INCLUDE_DIRS=$PYTHON_INCLUDE"
|
||||||
addCMakeVariable "PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
addCMakeVariable "PYTHON_LIBRARY=$PYTHON_LIBRARY"
|
||||||
|
|
||||||
echo "----"
|
echo "----"
|
||||||
echo "Python information:"
|
echo "Python information:"
|
||||||
echo " executable : $pythonBin"
|
echo " executable : $pythonBin"
|
||||||
echo " version : $pythonMajor"
|
echo " version : $pythonMajor"
|
||||||
echo " include path : $pythonInclude"
|
echo " include path : $PYTHON_INCLUDE"
|
||||||
echo " library : $PYTHON_LIBRARY"
|
echo " library : $PYTHON_LIBRARY"
|
||||||
|
|
||||||
unset pythonBin pythonInclude pythonMajor
|
|
||||||
else
|
|
||||||
echo "*** Error: python not found"
|
|
||||||
echo "*** Deactivate python support by not using the -python "
|
|
||||||
echo "*** option"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -78,6 +78,8 @@ options:
|
|||||||
-mpi with mpi
|
-mpi with mpi
|
||||||
-mpi=N with max 'N' mpi processes. N=0 for no upper-limit.
|
-mpi=N with max 'N' mpi processes. N=0 for no upper-limit.
|
||||||
-python with python
|
-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})
|
-python-lib PATH path to python library (current: ${PYTHON_LIBRARY:-none})
|
||||||
-cmake PATH with cmake from the path given
|
-cmake PATH with cmake from the path given
|
||||||
-qmake PATH with the Qt version corresponding to the qmake path given
|
-qmake PATH with the Qt version corresponding to the qmake path given
|
||||||
@ -233,6 +235,12 @@ do
|
|||||||
-no-python)
|
-no-python)
|
||||||
withPYTHON=false
|
withPYTHON=false
|
||||||
;;
|
;;
|
||||||
|
-python-include)
|
||||||
|
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
||||||
|
withPYTHON=true
|
||||||
|
PYTHON_INCLUDE="${2%%/}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-python-lib)
|
-python-lib)
|
||||||
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
||||||
withPYTHON=true
|
withPYTHON=true
|
||||||
|
|||||||
Reference in New Issue
Block a user