diff options
author | schneider <schneider@blinkenlichts.net> | 2021-10-06 23:32:40 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-10-13 09:35:05 -0400 |
commit | 8868bfadc3cb2eb01083c4abb8b97c741d26b8fa (patch) | |
tree | 161dd5c7c0bd80f26ba4cdc18ba5491b6b613124 /cmake | |
parent | 68e618bce4fda1e827868d515d9df1653c485ad2 (diff) |
cmake: reliably determine python prefix
Signed-off-by: schneider <schneider@blinkenlichts.net>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Modules/GrPython.cmake | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/cmake/Modules/GrPython.cmake b/cmake/Modules/GrPython.cmake index ef49b56c92..776ac55906 100644 --- a/cmake/Modules/GrPython.cmake +++ b/cmake/Modules/GrPython.cmake @@ -139,27 +139,33 @@ endmacro(GR_PYTHON_CHECK_MODULE) ######################################################################## # Sets the python installation directory GR_PYTHON_DIR +# From https://github.com/pothosware/SoapySDR/tree/master/python +# https://github.com/pothosware/SoapySDR/blob/master/LICENSE_1_0.txt ######################################################################## if(NOT DEFINED GR_PYTHON_DIR) -execute_process(COMMAND ${PYTHON_EXECUTABLE} -c " -from distutils import sysconfig -print(sysconfig.get_python_lib(plat_specific=True, prefix='')) -" OUTPUT_VARIABLE GR_PYTHON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE -) -endif() -file(TO_CMAKE_PATH ${GR_PYTHON_DIR} GR_PYTHON_DIR) +execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "import os +import site +from distutils.sysconfig import get_python_lib -######################################################################## -# Sets the python relative installation directory GR_PYTHON_RELATIVE -######################################################################## -if(NOT DEFINED GR_PYTHON_RELATIVE) -execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c " -from distutils import sysconfig as sc -print(sc.get_python_lib(prefix='', plat_specific=True)) -" - OUTPUT_VARIABLE GR_PYTHON_RELATIVE OUTPUT_STRIP_TRAILING_WHITESPACE +prefix = '${CMAKE_INSTALL_PREFIX}' + +#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))" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE GR_PYTHON_DIR ) endif() +file(TO_CMAKE_PATH ${GR_PYTHON_DIR} GR_PYTHON_DIR) ######################################################################## |