Skip to contentSkip to conversation

python3-pybind11: Build with -DPYBIND11_USE_CROSSCOMPILING=ON

PATCH New Khem Raj 1 participant 2 messages Mar 22, 2025

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/2 python3-pybind11: Build with -DPYBIND11_USE_CROSSCOMPILING=ON

Since we are cross-compiling this option is required with 3.13+

---
 meta-python/recipes-devtools/python/python3-pybind11_2.13.6.bb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta-python/recipes-devtools/python/python3-pybind11_2.13.6.bb +1 -1
index ee5722fbcb..e853bb33d8 100644
@@ -16,7 +16,7 @@ S = "${WORKDIR}/git"
 
 inherit cmake python_setuptools_build_meta
 
-EXTRA_OECMAKE = "-DPYBIND11_TEST=OFF"
+EXTRA_OECMAKE = "-DPYBIND11_TEST=OFF -DPYBIND11_USE_CROSSCOMPILING=ON"
 
 do_configure:append() {
     cmake_do_configure
author
#1 lore raw

PATCH 2/2 python3-pybind11-json: Specify -DPYBIND11_USE_CROSSCOMPILING=ON to support pybind11 13.x

Add support for pkgconfig
Use python-native during build to avoid host variability

---
 ...d4df929bc9d0882298fc1f85ecf589456ff6.patch | 59 +++++++++++++++++++
 .../python/python3-pybind11-json_0.2.15.bb    |  6 +-
 2 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 meta-python/recipes-devtools/python/python3-pybind11-json/d72ad4df929bc9d0882298fc1f85ecf589456ff6.patch
meta-python/recipes-devtools/python/python3-pybind11-json/d72ad4df929bc9d0882298fc1f85ecf589456ff6.patch new file +59 -0
new file mode 100644
index 0000000000..c216ce66cb
@@ -0,0 +1,59 @@
+From d72ad4df929bc9d0882298fc1f85ecf589456ff6 Mon Sep 17 00:00:00 2001
+From: Daniel Lundberg Pedersen <[email protected]>
+Date: Thu, 23 Jan 2025 11:48:16 +0100
+Subject: [PATCH] CMakeLists.txt: Add support for pkg-config
+
+Create and install pkg-config (.pc) file for dependency detection.
+Upstream-Status: Submitted [https://github.com/pybind/pybind11_json/pull/75]
+Signed-off-by: Khem Raj <[email protected]>
+---
+ CMakeLists.txt      | 24 ++++++++++++++++++++++++
+ pybind11_json.pc.in |  7 +++++++
+ 2 files changed, 31 insertions(+)
+ create mode 100644 pybind11_json.pc.in
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index c0ef675..a92240a 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -133,3 +133,27 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
+ install(EXPORT ${PROJECT_NAME}-targets
+         FILE ${PROJECT_NAME}Targets.cmake
+         DESTINATION ${PYBIND11_JSON_CMAKECONFIG_INSTALL_DIR})
++
++# pkg-config support
++if(NOT prefix_for_pc_file)
++if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}")
++  set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
++else()
++  set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}")
++  if(CMAKE_VERSION VERSION_LESS 3.20)
++    set(prefix_for_pc_file "\${pcfiledir}/..")
++    while(pc_datarootdir)
++      get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY)
++      string(APPEND prefix_for_pc_file "/..")
++    endwhile()
++  else()
++    cmake_path(RELATIVE_PATH CMAKE_INSTALL_PREFIX BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR
++               OUTPUT_VARIABLE prefix_for_pc_file)
++  endif()
++endif()
++endif()
++set(includedir_for_pc_file "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
++configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pybind11_json.pc.in"
++             "${CMAKE_CURRENT_BINARY_DIR}/pybind11_json.pc" @ONLY)
++install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11_json.pc"
++      DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
+diff --git a/pybind11_json.pc.in b/pybind11_json.pc.in
+new file mode 100644
+index 0000000..da5bfde
+--- /dev/null
++++ b/pybind11_json.pc.in
+@@ -0,0 +1,7 @@
++prefix=@prefix_for_pc_file@
++includedir=@includedir_for_pc_file@
++
++Name: @PROJECT_NAME@
++Description: Using nlohmann::json with pybind11
++Version: @PROJECT_VERSION@
++Cflags: -I${includedir}
meta-python/recipes-devtools/python/python3-pybind11-json_0.2.15.bb +4 -2
index 3667ba872c..bb2ccae794 100644
@@ -3,10 +3,12 @@ LICENSE = "BSD-3-Clause"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=0e25ff0ec476d06d366439e1120cce98"
 
 SRCREV = "32043f433ed987b2c2ce99d689ec337bcbd4ba95"
-SRC_URI = "git://github.com/pybind/pybind11_json;branch=master;protocol=https"
+SRC_URI = "git://github.com/pybind/pybind11_json;branch=master;protocol=https \
+           file://d72ad4df929bc9d0882298fc1f85ecf589456ff6.patch"
 
 DEPENDS += "nlohmann-json python3-pybind11"
 
+EXTRA_OECMAKE += "-DPYBIND11_USE_CROSSCOMPILING=ON"
 S = "${WORKDIR}/git"
 
-inherit cmake
+inherit cmake python3native python3targetconfig