@@ -45,7 +45,37 @@ FortranCInterface_VERIFY(CXX)
4545init_FCMangle()
4646
4747find_package (PythonInterp REQUIRED)
48- find_package (PythonLibs REQUIRED)
48+ # Set variables to help find Python library that is compatible with interpreter
49+ # Copied from https://bitbucket.org/fenics-project/dolfin
50+ if (PYTHONINTERP_FOUND)
51+ # Get Python include path from Python interpretter
52+ execute_process (COMMAND "${PYTHON_EXECUTABLE} " -c
53+ "import distutils.sysconfig, sys; sys.stdout.write(distutils.sysconfig.get_python_inc())"
54+ OUTPUT_VARIABLE _PYTHON_INCLUDE_PATH
55+ RESULT_VARIABLE _PYTHON_INCLUDE_RESULT)
56+
57+ # Get Python library path from interpreter
58+ execute_process (COMMAND "${PYTHON_EXECUTABLE} " -c
59+ "import os, sys, inspect; sys.stdout.write(os.path.split(os.path.split(inspect.getfile(inspect))[0])[0])"
60+ OUTPUT_VARIABLE _PYTHON_LIB_PATH
61+ RESULT_VARIABLE _PYTHON_LIB_RESULT)
62+
63+ # Set include path, if returned by interpreter
64+ if ("${_PYTHON_INCLUDE_RESULT} " STREQUAL "0" )
65+ set (PYTHON_INCLUDE_DIR ${_PYTHON_INCLUDE_PATH} )
66+ endif ()
67+
68+ # Add a search path for Python library based on output from
69+ # interpreter
70+ set (CMAKE_LIBRARY_PATH_SAVE ${CMAKE_LIBRARY_PATH} )
71+ if ("${_PYTHON_LIB_RESULT} " STREQUAL "0" )
72+ set (CMAKE_LIBRARY_PATH ${_PYTHON_LIB_PATH} )
73+ endif ()
74+
75+ # Find Pythons libs
76+ find_package (PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
77+ #set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH_SAVE})
78+ endif ()
4979find_package (ZLIB REQUIRED)
5080
5181if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
0 commit comments