From 2233b8d05e9f76f857b7a2560bc1caaac7c4bdc6 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 26 Jan 2024 16:52:07 +0100 Subject: cmake: Update UHDPython.cmake - Use find_package(pybind11) to find a system-wide Pybind11. This will take preference over the vendored version of Pybind11, unless requested otherwise. - Fix a typo. --- host/CMakeLists.txt | 1 + host/cmake/Modules/UHDPython.cmake | 10 +++++++++- host/cmake/debian/control | 3 ++- host/python/CMakeLists.txt | 27 ++++++++++++++------------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index f77d72f54..7cd8f87d4 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -40,6 +40,7 @@ set(NUMPY_MIN_VERSION "1.11") set(RUAMEL.YAML_MIN_VERSION "0.15") set(PY_MAKO_MIN_VERSION "0.4.2") set(PY_REQUESTS_MIN_VERSION "2.0") +set(PYBIND11_MIN_VERSION "2.4") ######################################################################## # Check Compiler Version diff --git a/host/cmake/Modules/UHDPython.cmake b/host/cmake/Modules/UHDPython.cmake index b68e18453..a15434b18 100644 --- a/host/cmake/Modules/UHDPython.cmake +++ b/host/cmake/Modules/UHDPython.cmake @@ -17,6 +17,14 @@ endif() if(NOT DEFINED INCLUDED_UHD_PYTHON_CMAKE) set(INCLUDED_UHD_PYTHON_CMAKE TRUE) +######################################################################## +# Setup Python Part 0: Pybind11 +# +# We do this first so it doesn't interfere with the other steps. In +# particular, searching for pybind11 will mess with PYTHON_VERSION. +######################################################################## +find_package(pybind11 ${PYBIND11_MIN_VERSION} QUIET) + ######################################################################## # Setup Python Part 1: Find the interpreters ######################################################################## @@ -211,7 +219,7 @@ exit(0) ) if(python_result EQUAL 0) if(${version_output} VERSION_GREATER_EQUAL ${min_module_version}) - message(STATUS "Python checking for ${desc} - ${version_output} satisifes minimum required version ${min_module_version}") + message(STATUS "Python checking for ${desc} - ${version_output} satisfies minimum required version ${min_module_version}") set(${have_var} TRUE) else() message(STATUS "Python checking for ${desc} - ${version_output} does not satisfy minimum required version ${min_module_version}") diff --git a/host/cmake/debian/control b/host/cmake/debian/control index 30ce701b0..2bed05304 100644 --- a/host/cmake/debian/control +++ b/host/cmake/debian/control @@ -22,7 +22,8 @@ Build-Depends: cmake, python3-numpy, python3-requests, python3-ruamel.yaml, - python3-setuptools + python3-setuptools, + pybind11-dev Build-Depends-Indep: doxygen, doxygen-latex, graphviz [!powerpcspe] diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt index fdf612747..c3ed35478 100644 --- a/host/python/CMakeLists.txt +++ b/host/python/CMakeLists.txt @@ -4,10 +4,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -######################################################################## -# This file included, use CMake directory variables -######################################################################## - PYTHON_CHECK_MODULE( "virtual environment" "sys" @@ -15,15 +11,18 @@ PYTHON_CHECK_MODULE( HAVE_PYTHON_VIRTUALENV ) +if(pybind11_FOUND) + message(STATUS "Using Pybind11 from: ${pybind11_INCLUDE_DIR}") +else() + set(pybind11_INCLUDE_DIR + "${UHD_SOURCE_DIR}/lib/deps/pybind11/include" + CACHE STRING + "Location of PyBind11 includes" + ) + message(STATUS "Using in-tree Pybind11.") +endif() + # Get include dirs -include_directories(${PYTHON_INCLUDE_DIRS}) -set(PYBIND11_INCLUDE_DIR - "${UHD_SOURCE_DIR}/lib/deps/pybind11/include" - CACHE - STRING - "Location of PyBind11 includes" -) -include_directories(${PYBIND11_INCLUDE_DIR}) execute_process( COMMAND "${PYTHON_EXECUTABLE}" -c "try:\n import numpy\n import os\n inc_path = numpy.get_include()\n if os.path.exists(os.path.join(inc_path, 'numpy', 'arrayobject.h')):\n print(inc_path, end='')\nexcept:\n pass" @@ -36,6 +35,7 @@ add_library(pyuhd SHARED ${UHD_SOURCE_DIR}/lib/device_python.cpp ${UHD_SOURCE_DIR}/lib/usrp/multi_usrp_python.cpp ) + # python expects extension modules with a particular suffix if(WIN32) set_target_properties(pyuhd PROPERTIES PREFIX "lib" SUFFIX ".pyd") @@ -56,9 +56,10 @@ else() ) endif(WIN32) target_include_directories(pyuhd PUBLIC + ${PYTHON_INCLUDE_DIRS} ${PYTHON_NUMPY_INCLUDE_DIR} ${UHD_SOURCE_DIR}/lib - ${PYBIND11_INCLUDE_DIR} + ${pybind11_INCLUDE_DIR} ) if(WIN32) -- cgit v1.2.3-59-g8ed1b