diff --git a/swig/python/CMakeLists.txt b/swig/python/CMakeLists.txt index c453a9e5..ee9b0b22 100644 --- a/swig/python/CMakeLists.txt +++ b/swig/python/CMakeLists.txt @@ -124,8 +124,13 @@ function(BUILD_PYTHON_MODULE PYTHON_VERSION) target_include_directories(${SWIG_MODULE_SoapySDR${PYTHON_VERSION}_REAL_NAME} PRIVATE ${python_includes}) SWIG_LINK_LIBRARIES(SoapySDR${PYTHON_VERSION} ${python_libraries}) + set(get_python_lib ${SOAPYSDR_PYTHON_DIR}/get_python_lib.py) + if (${PYTHON_VERSION} EQUAL 2) + set(get_python_lib ${SOAPYSDR_PYTHON_DIR}/get_python2_lib.py) + endif() + execute_process( - COMMAND ${Python${PYTHON_VERSION}_EXECUTABLE} ${SOAPYSDR_PYTHON_DIR}/get_python_lib.py ${CMAKE_INSTALL_PREFIX} + COMMAND ${Python${PYTHON_VERSION}_EXECUTABLE} ${get_python_lib} ${CMAKE_INSTALL_PREFIX} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE PYTHON_INSTALL_DIR) diff --git a/swig/python/get_python2_lib.py b/swig/python/get_python2_lib.py new file mode 100644 index 00000000..0c716529 --- /dev/null +++ b/swig/python/get_python2_lib.py @@ -0,0 +1,19 @@ +import os +import sys +import site +from distutils.sysconfig import get_python_lib + +if __name__ == '__main__': + prefix = sys.argv[1] + + #ask distutils where to install the python module + install_dir = get_python_lib(plat_specific=True, prefix=prefix) + + #use sites when the prefix is already recognized + try: + paths = [p for p in site.getsitepackages() if p.startswith(prefix)] + if len(paths) == 1: install_dir = paths[0] + except AttributeError: pass + + #strip the prefix to return a relative path + print(os.path.relpath(install_dir, prefix))