diff options
author | Martin Braun <martin.braun@ettus.com> | 2024-05-15 11:31:18 +0200 |
---|---|---|
committer | Aki Tomita <121511582+atomita-ni@users.noreply.github.com> | 2024-05-16 14:47:30 -0500 |
commit | d8564b5a0a2548da6023f55f9c9418bdce5a272b (patch) | |
tree | d98eeb54f43c89093a9dc01bfbd9970e7e338957 /host/examples/rfnoc-example/cmake/Modules/UHDPython.cmake | |
parent | fpga: sim: Fix cast in PkgRandom (diff) | |
download | uhd-d8564b5a0a2548da6023f55f9c9418bdce5a272b.tar.xz uhd-d8564b5a0a2548da6023f55f9c9418bdce5a272b.zip |
cmake: Fix Python path corruption from pybind11
The Pybind11 CMake package uses its own underlying Python-finding calls,
which in turn can corrupt the Python include directories. This will
prevent building MPM or UHD from within a USRP OpenEmbedded SDK.
This band-aid solution will quarantine the call to
`find_package(pybind11)` and then manually export the relevant variables.
A better solution would be to update CMake minimum version to 3.12, and
use `find_package(Python ...)` further up in the file, as laid out in
the pybind11 manual.
Diffstat (limited to 'host/examples/rfnoc-example/cmake/Modules/UHDPython.cmake')
-rw-r--r-- | host/examples/rfnoc-example/cmake/Modules/UHDPython.cmake | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/host/examples/rfnoc-example/cmake/Modules/UHDPython.cmake b/host/examples/rfnoc-example/cmake/Modules/UHDPython.cmake index 4fdacc243..d8b203b91 100644 --- a/host/examples/rfnoc-example/cmake/Modules/UHDPython.cmake +++ b/host/examples/rfnoc-example/cmake/Modules/UHDPython.cmake @@ -20,14 +20,6 @@ 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 ######################################################################## message(STATUS "") @@ -56,7 +48,7 @@ endif(NOT PYTHONINTERP_FOUND) # If that fails, try using the build-in find program routine. if(NOT PYTHONINTERP_FOUND) message(STATUS "Attempting to find Python without CMake...") - find_program(PYTHON_EXECUTABLE NAMES python3 python3.6 python3.7 python3.8 python3.9) + find_program(PYTHON_EXECUTABLE NAMES python3 python3.7 python3.8 python3.9 python3.10) if(PYTHON_EXECUTABLE) set(PYTHONINTERP_FOUND TRUE) endif(PYTHON_EXECUTABLE) @@ -367,4 +359,27 @@ if(NOT PYTHON_INCLUDE_DIR) mark_as_advanced(PYTHON_INCLUDE_DIRS) endif(NOT PYTHON_INCLUDE_DIR) +######################################################################## +# Setup Python Part 3: Pybind11 +# +# Note that find_package(pybind11) breaks all sorts of stuff because it +# uses its own Python-finding CMake code. We therefore limit its scope. +# When we switch to CMake 3.12, we can probably simplify this by calling +# find_package(Python ...) above. +######################################################################## +function(FIND_PYBIND11) + set(PYBIND11_FINDPYTHON ON) + find_package(pybind11 ${PYBIND11_MIN_VERSION} QUIET) + if(DEFINED pybind11_INCLUDE_DIR) + set(pybind11_INCLUDE_DIR ${pybind11_INCLUDE_DIR} PARENT_SCOPE) + set(pybind11_INCLUDE_DIRS ${pybind11_INCLUDE_DIRS} PARENT_SCOPE) + set(pybind11_FOUND ${pybind11_FOUND} PARENT_SCOPE) + set(pybind11_DEFINITIONS ${pybind11_DEFINITIONS} PARENT_SCOPE) + set(pybind11_LIBRARIES ${pybind11_LIBRARIES} PARENT_SCOPE) + set(pybind11_LIBRARY ${pybind11_LIBRARY} PARENT_SCOPE) + endif() +endfunction() + +FIND_PYBIND11() + endif(NOT DEFINED INCLUDED_UHD_PYTHON_CMAKE) |