From 75b7991378e3f465f9d91cba597d98ee5b9054ed Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 1 May 2020 10:53:00 -0700 Subject: python: Fix RPATH for the Python library On UNIX systems, CMake will set the RPATH of the Python library to the build directory, which is very helpful because it allows unit and other tests to be executed from within the build directory. On installation, the RPATH is removed, but only if install(TARGETS) is used, which we were not, thus resulting in incorrect RPATHs. This would surface as a bug, too. Calling uhd.get_lib_path() would always point to the build directory, thus resulting in no FPGA images being found automatically, e.g. when running a B200 through the Python API. This change installs the Python .so file separately, using the correct CMake mechanisms. --- host/python/CMakeLists.txt | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt index a4929b977..0990e2582 100644 --- a/host/python/CMakeLists.txt +++ b/host/python/CMakeLists.txt @@ -43,7 +43,11 @@ else() if(${PYTHON_EXTENSION_SUFFIX} STREQUAL "None") set(PYTHON_EXTENSION_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX}) endif() - set_target_properties(pyuhd PROPERTIES PREFIX "lib" SUFFIX ${PYTHON_EXTENSION_SUFFIX}) + set_target_properties(pyuhd + PROPERTIES + PREFIX "lib" + SUFFIX ${PYTHON_EXTENSION_SUFFIX} + ) endif(WIN32) target_include_directories(pyuhd PUBLIC ${PYTHON_NUMPY_INCLUDE_DIR} @@ -104,5 +108,22 @@ else() file(TO_CMAKE_PATH ${UHD_PYTHON_DIR} UHD_PYTHON_DIR) message(STATUS "Utilizing the python install directory: ${UHD_PYTHON_DIR}") - install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/uhd DESTINATION ${UHD_PYTHON_DIR} COMPONENT pythonapi) + # CMake will create an up-to-date copy of the entire Python module within + # the build directory. Instead of using setuptools, we use distutils (above) + # to figure out the destination path, and then we simply copy this module + # recursively into its final destination. + install(DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/uhd + DESTINATION ${UHD_PYTHON_DIR} + COMPONENT pythonapi + ) + # On Linux/Unix systems, we must properly install the library file, though. + # install(DIRECTORY) will treat the .so file like any other file, which + # means it won't update its RPATH, and thus the RPATH would be stuck to the + # build directory. + if(UNIX) + install(TARGETS pyuhd + DESTINATION ${UHD_PYTHON_DIR}/uhd + ) + endif(UNIX) endif(HAVE_PYTHON_VIRTUALENV) -- cgit v1.2.3