summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib
diff options
context:
space:
mode:
authorRyan Volz <ryan.volz@gmail.com>2021-01-08 15:43:41 -0500
committerMartin Braun <martin@gnuradio.org>2021-01-14 04:08:21 -0800
commit51d3ad973292763a6fc0cf8e971faa3cf89029e9 (patch)
treeac7e74ccc60615b700f693241379dedd77abbd4e /gnuradio-runtime/lib
parent518dc7eda3a2575292dc67374cad62c887f83d12 (diff)
cmake: python: Fix linking when runtime py interpreter != build time.
This fixes a segmentation fault with the Pybind11 bindings when trying to load any Python module on OSX with a different interpreter than was used at build time (relevant to at least conda and homebrew). This fix was already in place for the prior Swig bindings, but the Pybind11 changes do not incorporate it since they link with ${PYTHON_LIBRARIES} instead of the (fixed) Python::Python target. For clearer separation and to adopt the approach used by the new-ish (3.12) builtin CMake FindPython module, this commit creates a separate Python::Module target to be used when creating a Python extension module (which includes "-undefined" and "dynamic_lookup" for macOS instead of linking directly to the Python library). The Python::Python target that does link to the Python library is still necessary for use as a PRIVATE target (e.g. for runtime and qtgui). For future reference and a general description of best practices for linking Python extension modules, see https://blog.tim-smith.us/2015/09/python-extension-modules-os-x. Signed-off-by: Ryan Volz <ryan.volz@gmail.com>
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r--gnuradio-runtime/lib/CMakeLists.txt9
1 files changed, 7 insertions, 2 deletions
diff --git a/gnuradio-runtime/lib/CMakeLists.txt b/gnuradio-runtime/lib/CMakeLists.txt
index ec06f3fabc..5a21a73a40 100644
--- a/gnuradio-runtime/lib/CMakeLists.txt
+++ b/gnuradio-runtime/lib/CMakeLists.txt
@@ -204,13 +204,18 @@ target_link_libraries(gnuradio-runtime PUBLIC
Boost::thread
Log4Cpp::log4cpp
MPLib::mplib
- ${PYTHON_LIBRARIES}
${libunwind_LIBRARIES}
+ # INTERFACE/PRIVATE split so users of the library can choose how to link to Python
+ # (importantly, extension modules can avoid linking against Python and resolve
+ # their own Python symbols at runtime through the Python interpreter's linking)
+ INTERFACE
+ Python::Module
+ PRIVATE
+ Python::Python
)
target_include_directories(gnuradio-runtime
PUBLIC
- ${PYTHON_INCLUDE_DIR}
${PYTHON_NUMPY_INCLUDE_DIR}
${pybind11_INCLUDE_DIR}
$<INSTALL_INTERFACE:include>