You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am a packager for openSUSE and am trying to build RPM packages for pybind11_abseil. We found that we need a few changes to the cmake scripts to improve the package finding logic, linking to the right version of Python, and installation of headers. I list the patches we use one by one in this description, so that you may have a look and see if they are right for your project. If you agree, I can submit PRs for the changes.
Pass FIND_PACKAGE_ARGS to FetchContent_Declare
This enables the detection of system absl and pybind11 and goes on to download them if they are not. Important for packaging on openSUSE because RPMs are built inside a no-network access VM.
Note: This will bump the CMake minimum version to 3.24.
This is needed in any case for our packages to avoid undefined reference to Py* errors when linking, but additionally it helps to build against the correct version of Python and Pybind11 if there are multiple ones installed in the system. On openSUSE, it is natural to have simultaneously python3.10, python3.11, and python3.12 and the corresponding pybind11, numpy, python-absl installed in the system. This helps pick the right pybind11 to go with the choice of python executable.
---
CMakeLists.txt | 3 +++
pybind11_abseil/CMakeLists.txt | 1 +
2 files changed, 4 insertions(+)
Index: pybind11_abseil-202402.0/CMakeLists.txt
===================================================================--- pybind11_abseil-202402.0.orig/CMakeLists.txt+++ pybind11_abseil-202402.0/CMakeLists.txt@@ -16,6 +16,9 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3
cmake_policy(SET CMP0135 NEW)
endif()
+# Needs to be called *before* looking for pybind11 to ensure pybind11 uses the same python+find_package(Python COMPONENTS Interpreter Development)+
FetchContent_Declare(
absl
URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.0.tar.gz
Index: pybind11_abseil-202402.0/pybind11_abseil/CMakeLists.txt
===================================================================--- pybind11_abseil-202402.0.orig/pybind11_abseil/CMakeLists.txt+++ pybind11_abseil-202402.0/pybind11_abseil/CMakeLists.txt@@ -1,5 +1,6 @@
add_subdirectory(compat)
add_subdirectory(cpp_capsule_tools)
+link_libraries(${Python_LIBRARIES})
# absl_casters ============================================================
add_library(absl_casters INTERFACE)
Install headers
Apparently the current CMake scripts do not install the headers to the system, only the libraries. Headers are nonetheless needed for devs using C++ interface of pybind11_abseil. This patch adds the necessary include dirs to the install destination.
There are apparently more issues when using an out-of-tree pybind11_abseil:
Missing implementations of ImportStatusModule. This is located in import_status_module.cc, but that is not part of any exported shared library. The easiest solution would probably be to make this an inline implementation in the header, as it is fairly small.
The INTERFACE libraries are not exported, e.g. pybind11_abseil::absl_caster.
No CMake Config file generated/installed, also no Target definititions for the interfaces.
The two python extensions (status.so, ok_status_singleton.so) should be MODULE, not SHARED libraries. This would probably covered by usage of the appropriate pybind11 CMake macro.
The status_caster and statusor_caster libraries are not actually INTERFACE libraries, as these depend on several compiled source files which are not available outside the source tree.
Makes me wonder if the *.cc files should not be just inlined into the header files. Currently, the *cc files will be compiled to static libraries, and be linked statically into any python extension making use of it.
Hi,
I am a packager for openSUSE and am trying to build RPM packages for
pybind11_abseil
. We found that we need a few changes to the cmake scripts to improve the package finding logic, linking to the right version of Python, and installation of headers. I list the patches we use one by one in this description, so that you may have a look and see if they are right for your project. If you agree, I can submit PRs for the changes.Pass
FIND_PACKAGE_ARGS
toFetchContent_Declare
This enables the detection of system
absl
andpybind11
and goes on to download them if they are not. Important for packaging on openSUSE because RPMs are built inside a no-network access VM.Note: This will bump the CMake minimum version to 3.24.
Link against the correct Python library
This is needed in any case for our packages to avoid
undefined reference to Py*
errors when linking, but additionally it helps to build against the correct version of Python and Pybind11 if there are multiple ones installed in the system. On openSUSE, it is natural to have simultaneously python3.10, python3.11, and python3.12 and the corresponding pybind11, numpy, python-absl installed in the system. This helps pick the right pybind11 to go with the choice of python executable.Install headers
Apparently the current CMake scripts do not install the headers to the system, only the libraries. Headers are nonetheless needed for devs using C++ interface of
pybind11_abseil
. This patch adds the necessary include dirs to the install destination.Suggestions, comments welcome. Thanks in advance. Thank you also for the very useful library.
Edit: Slightly improved patch for headers' installation: exclude test and requirements dirs.
The text was updated successfully, but these errors were encountered: