CMake linking and install improvements
Los mantenedores suelen responder en 1 día
@Mizux ya está trabajando en esto.
Desde el 24/2/2025.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
---
CMakeLists.txt | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
Index: pybind11_abseil-202402.0/CMakeLists.txt
===================================================================
--- pybind11_abseil-202402.0.orig/CMakeLists.txt
+++ pybind11_abseil-202402.0/CMakeLists.txt
@@ -17,16 +17,18 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3
endif()
FetchContent_Declare(
- abseil-cpp
+ absl
URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.0.tar.gz
URL_HASH
- SHA256=59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5)
+ SHA256=59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5
+ FIND_PACKAGE_ARGS)
FetchContent_Declare(
pybind11
- URL https://github.com/pybind/pybind11/archive/refs/heads/master.tar.gz)
+ URL https://github.com/pybind/pybind11/archive/refs/heads/master.tar.gz
+ FIND_PACKAGE_ARGS)
-FetchContent_MakeAvailable(abseil-cpp pybind11)
+FetchContent_MakeAvailable(absl pybind11)
set(TOP_LEVEL_DIR ${CMAKE_CURRENT_LIST_DIR})
include_directories(${TOP_LEVEL_DIR} ${pybind11_INCLUDE_DIRS})
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.
---
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.
---
CMakeLists.txt | 7 +++++++
1 file changed, 7 insertions(+)
Index: pybind11_abseil-202402.0/CMakeLists.txt
===================================================================
--- pybind11_abseil-202402.0.orig/CMakeLists.txt
+++ pybind11_abseil-202402.0/CMakeLists.txt
@@ -37,3 +37,11 @@ set(TOP_LEVEL_DIR ${CMAKE_CURRENT_LIST_D
include_directories(${TOP_LEVEL_DIR} ${pybind11_INCLUDE_DIRS})
add_subdirectory(pybind11_abseil)
+
+if(CMAKE_INSTALL_PYDIR)
+ install(DIRECTORY pybind11_abseil
+ TYPE INCLUDE
+ FILES_MATCHING PATTERN "*.h"
+ PATTERN tests EXCLUDE
+ PATTERN requirements EXCLUDE)
+endif()
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.
- Lenguaje dominante
- C++
- Estrellas
- 27
- Forks
- 22
- Merge medio
- 19 h
- PR fusionados (30 d)
- 45
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pybind/pybind11_abseil
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 43/100
pybind/pybind11_abseil#83 ·
Los mantenedores suelen responder en 1 día
-
Python bindings for absl::Status cause ODR violationQuizá libre de nuevo @Mizux la tomó hace 400 días y no hay ningún pull request abierto. Abiertobazel bug
pybind/pybind11_abseil#20 · 1 reacción · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bazel bug
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
pybind/pybind11_abseil#18 ·
Los mantenedores suelen responder en 1 día
-
bazel bug
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
pybind/pybind11_abseil#12 · 26 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug enhancement help wanted
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
pybind/pybind11_abseil#4 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de pybind/pybind11_abseil
Issues similares
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
patrick-hudson/put.gd-desktop#2044 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
uxlfoundation/oneDNN#6604 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Posiblemente ocupada @fmu1337 la tomó hoy. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
alliedmodders/sourcemod#2627 ·
Los mantenedores suelen responder en 1 día