aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2023-01-09 17:34:04 +0100
committerAki Tomita <121511582+atomita-ni@users.noreply.github.com>2023-05-10 21:39:39 -0500
commite2576cfed4b79409e6e9e3d81fc93da061888a54 (patch)
treef815956e29e37fe864ae9a84d6faee5fb01cd3da
parentextension: windows: Fixed linking extension example to uhd.lib (diff)
downloaduhd-e2576cfed4b79409e6e9e3d81fc93da061888a54.tar.xz
uhd-e2576cfed4b79409e6e9e3d81fc93da061888a54.zip
cmake: Fix auto-detection of Python install directory
This fixes an issue where on Ubuntu 22.04 (with Python 3.10), the installation of the Python module would go to $PREFIX/local/lib even if the rest goes to $PREFIX/lib. We achieve this by avoiding a) using sysconfig.get_path() to get *both* the prefix and the library path, and then also avoiding the `posix_local` install scheme. Note: This same logic fails to work for MPM, so we don't touch that, but simply force MPM to use the same path as UHD has. This means MPM is unaffected when built by itself, but follows the UHD path when built as part of UHD. Hat-tip to Johannes Demel for pointing out this solution path.
-rw-r--r--host/python/CMakeLists.txt24
1 files changed, 22 insertions, 2 deletions
diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt
index 239901387..fdf612747 100644
--- a/host/python/CMakeLists.txt
+++ b/host/python/CMakeLists.txt
@@ -90,8 +90,26 @@ set(TIMESTAMP_FILE "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR} NATIVE_CURRENT_BINARY_DIR)
configure_file(${SETUP_PY_IN} ${SETUP_PY})
+
+# If we're not in a virtual environment, then we need to figure out where to
+# install the Python module. Do this here so we can use the value for UHD_PYTHON_DIR
+# in the simulator.
+if(NOT DEFINED UHD_PYTHON_DIR)
+ execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
+ # Avoid the posix_local install scheme
+ "import os,sysconfig;\
+ install_scheme = 'posix_prefix';\
+ platlib = sysconfig.get_path('platlib', scheme=install_scheme);\
+ prefix = sysconfig.get_config_var('prefix');\
+ print(os.path.relpath(platlib, prefix));"
+ OUTPUT_VARIABLE UHD_PYTHON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+endif(NOT DEFINED UHD_PYTHON_DIR)
+
if(ENABLE_SIM)
set(MPM_DEVICE "sim")
+ # Whereever UHD Python gets installed, also install that from MPM.
+ set(USRP_MPM_PYTHON_DIR ${UHD_PYTHON_DIR})
add_subdirectory(${UHD_SOURCE_DIR}/../mpm/python simulator)
# simulator/usrp_mpm needs to be copied to usrp_mpm because setuptools only detects import packages in the working directory
add_custom_target(copy_mpm_packages ALL DEPENDS usrp_mpm)
@@ -157,7 +175,7 @@ add_custom_command(OUTPUT ${TIMESTAMP_FILE}
add_custom_target(pyuhd_library ALL DEPENDS ${TIMESTAMP_FILE} pyuhd)
if(HAVE_PYTHON_VIRTUALENV)
- message(STATUS "python virtual environment detected.")
+ message(STATUS "Python virtual environment detected -- Ignoring UHD_PYTHON_DIR.")
# In virtualenvs, let setuptools do its thing
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} -q install --force)")
else()
@@ -165,8 +183,10 @@ else()
# packages, and install to our prefix
if(NOT DEFINED UHD_PYTHON_DIR)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
+ # Avoid the posix_local install scheme
"import os,sysconfig;\
- platlib = sysconfig.get_path(name='platlib');\
+ install_scheme = 'posix_user';\
+ platlib = sysconfig.get_path('platlib', scheme=install_scheme);\
prefix = sysconfig.get_config_var('prefix');\
print(os.path.relpath(platlib, prefix));"
OUTPUT_VARIABLE UHD_PYTHON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE