Skip to content

Commit 1f0f4a5

Browse files
author
Roberto Di Remigio
committed
Work on detection of python libs from python interp
1 parent 3f1286b commit 1f0f4a5

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,37 @@ FortranCInterface_VERIFY(CXX)
4545
init_FCMangle()
4646

4747
find_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()
4979
find_package(ZLIB REQUIRED)
5080

5181
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

0 commit comments

Comments
 (0)