From e6e659bc0563ed08726216ac13929aa164488d67 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 6 Oct 2023 20:14:06 -0400 Subject: [PATCH] + xo_pybind11_link_flags() + xo_pybind11_library() --- cmake/xo_cxx.cmake | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cmake/xo_cxx.cmake b/cmake/xo_cxx.cmake index da93eccb..37867d59 100644 --- a/cmake/xo_cxx.cmake +++ b/cmake/xo_cxx.cmake @@ -263,4 +263,46 @@ macro(xo_self_dependency target dep) endmacro() # ---------------------------------------------------------------- +# need this when linking pybind11-generated libraries # +macro(xo_pybind11_link_flags) + # see: + # 1. FAQ Build Issues Q2 + # 2. CMAKE_SHARED_LINKER_FLAGS in src/CMakeLists.txt + # 3. pybind11 cmake support, somewhere like + # [path/to/pybind11-2.9.2/ + # lib/python3.9-pybind11-2.9.2/ + # lib/python3.9/site-packages/ + # pybind11/share/cmake/ + # pybind11/pybind11Common.cmake] + # + set_property( + TARGET pybind11::python_link_helper + APPEND + PROPERTY INTERFACE_LINK_OPTIONS "$<$:LINKER:-flat_namespace>" + ) +endmacro() + +# ---------------------------------------------------------------- +# use this for a subdir that builds a python library using pybind11 +# +# expecting the following +# 1. a directory pyfoo/ -> library pyfoo +# 2. pyfoo/pyfoo.hpp.in -> pyfoo/pyfoo.hpp +# +macro(xo_pybind11_library target source_files) + configure_file(${target}.hpp.in ${target}.hpp) + + # find_package(Python..) finds python in + # /Library/Frameworks/Python.framework/... + # but we want to use python from nix + # + #find_package(Python COMPONENTS Interpreter Development REQUIRED) + # + + find_package(pybind11) + pybind11_add_module(${target} MODULE ${source_files}) + xo_pybind11_link_flags() + # use xo_install_library2() instead + #install(TARGETS ${target} DESTINATION lib) +endmacro()