diff options
Diffstat (limited to 'host/python/CMakeLists.txt')
-rw-r--r-- | host/python/CMakeLists.txt | 135 |
1 files changed, 66 insertions, 69 deletions
diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt index c3ed35478..81deb0499 100644 --- a/host/python/CMakeLists.txt +++ b/host/python/CMakeLists.txt @@ -4,12 +4,63 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -PYTHON_CHECK_MODULE( - "virtual environment" - "sys" - "sys.prefix != sys.base_prefix" - HAVE_PYTHON_VIRTUALENV -) +######################################################################## +# This file included, use CMake directory variables +######################################################################## + +# Global Python API constants +set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in") +set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py") +set(TIMESTAMP_FILE "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp") +# convert binary directory to native format to use in SETUP_PY file. +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_PYTHON_API is OFF, then we can skip most of the work and will just +# install a bunch of Python files. +if(NOT ENABLE_PYTHON_API AND ENABLE_PYMOD_UTILS) + # List of Python files that are part of the module but don't get + # generated during build time and don't require libpyuhd. + # Note: When adding Python files into uhd/, they don't get added to the + # dependency list until CMake is re-run. + file(GLOB_RECURSE PYUHD_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/uhd/dsp/*.py + ${CMAKE_CURRENT_SOURCE_DIR}/uhd/imgbuilder/*.py + ${CMAKE_CURRENT_SOURCE_DIR}/uhd/imgbuilder/*.mako + ) + # This copies the contents of host/python/uhd into the build directory. We will + # use that as a staging ground for installing the final module to the system. + # We make sure that we always have an up-to-date copy in here. + add_custom_command(OUTPUT ${TIMESTAMP_FILE} + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/uhd/ + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/uhd/__init__.py + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/uhd/imgbuilder ${CMAKE_CURRENT_BINARY_DIR}/uhd/imgbuilder + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/uhd/dsp ${CMAKE_CURRENT_BINARY_DIR}/uhd/dsp + COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} -q build + COMMAND ${CMAKE_COMMAND} -E touch ${TIMESTAMP_FILE} + DEPENDS ${PYUHD_FILES}) + add_custom_target(pyuhd_library ALL DEPENDS ${TIMESTAMP_FILE}) + PYTHON_INSTALL_MODULE( + MODULE "uhd" + ) + return() +endif() + if(pybind11_FOUND) message(STATUS "Using Pybind11 from: ${pybind11_INCLUDE_DIR}") @@ -84,29 +135,6 @@ file(GLOB_RECURSE PYUHD_FILES ${CMAKE_CURRENT_SOURCE_DIR}/uhd/*.py ) -set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in") -set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py") -set(TIMESTAMP_FILE "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp") -# convert binary directory to native format to use in SETUP_PY file. -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. @@ -168,6 +196,9 @@ if(ENABLE_SIM) set(PYUHD_FILES ${PYUHD_FILES} copy_mpm_packages) endif(ENABLE_SIM) +# This copies the contents of host/python/uhd into the build directory. We will +# use that as a staging ground for installing the final module to the system. +# We make sure that we always have an up-to-date copy in here. add_custom_command(OUTPUT ${TIMESTAMP_FILE} COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/uhd ${CMAKE_CURRENT_BINARY_DIR}/uhd COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} -q build @@ -175,43 +206,9 @@ add_custom_command(OUTPUT ${TIMESTAMP_FILE} DEPENDS ${PYUHD_FILES}) add_custom_target(pyuhd_library ALL DEPENDS ${TIMESTAMP_FILE} pyuhd) -if(HAVE_PYTHON_VIRTUALENV) - 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() - # Otherwise, use sysconfig to determine the correct relative path for Python - # 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;\ - 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 - ) - endif(NOT DEFINED UHD_PYTHON_DIR) - file(TO_CMAKE_PATH ${UHD_PYTHON_DIR} UHD_PYTHON_DIR) - - message(STATUS "Utilizing the python install directory: ${CMAKE_INSTALL_PREFIX}/${UHD_PYTHON_DIR}") - # CMake will create an up-to-date copy of the entire Python module within - # the build directory. Use sysconfig (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) + +# Now install the Python module from the build directory to the final destination. +PYTHON_INSTALL_MODULE( + MODULE "uhd" + LIBTARGET pyuhd +) |