projects/guix·blob python-team · refs

93 lines · 3.4 KiB

1From 5b5c10b8a75f68c7ba25a1e7c9e4caeccb6bbbfa Mon Sep 17 00:00:00 2001
2From: Rodion Goritskov <[email protected]>
3Date: Sun, 20 Sep 2026 21:56:56 +0200
4Subject: [PATCH] box2d-add-pkgconfig.patch
5
6From: Erin Catto <[email protected]>
7
8This patch adds pkgconfig support.
9
10Source: https://github.com/erincatto/box2d/commit/dc67c40ba2ce1ad384b0c985dbc1b539cba9221b.patch
11Upstream-Status: https://github.com/erincatto/box2d/pull/1102
12---
13 src/CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++++++++++++++++
14 src/box2d.pc.in | 11 +++++++++++
15 2 files changed, 59 insertions(+)
16 create mode 100644 src/box2d.pc.in
17
18diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
19index 8c96462..b61c679 100644
20--- a/src/CMakeLists.txt
21+++ b/src/CMakeLists.txt
22@@ -222,3 +222,51 @@ install(
23 FILES "${CMAKE_CURRENT_BINARY_DIR}/box2dConfigVersion.cmake"
24 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/box2d"
25 )
26+
27+# Anchor every path to the .pc file itself so the install tree can be relocated,
28+# by cmake --install --prefix or by moving it afterwards
29+file(RELATIVE_PATH PKGCONFIG_PREFIX_REL "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
30+string(REGEX REPLACE "/$" "" PKGCONFIG_PREFIX_REL "${PKGCONFIG_PREFIX_REL}")
31+file(RELATIVE_PATH PKGCONFIG_LIBDIR_REL "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_LIBDIR}")
32+file(RELATIVE_PATH PKGCONFIG_INCLUDEDIR_REL "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
33+
34+# The file has to carry every PUBLIC define the exported target carries, or consumers
35+# compile against different headers than the library was built with. Keep in sync
36+# with the defines above.
37+set(PKGCONFIG_CFLAGS "")
38+if (BOX2D_DOUBLE_PRECISION)
39+ string(APPEND PKGCONFIG_CFLAGS " -DBOX2D_DOUBLE_PRECISION")
40+endif()
41+if (WIN32 AND BUILD_SHARED_LIBS)
42+ # base.h keys the dllimport off _WIN32, so MinGW needs this as much as MSVC
43+ string(APPEND PKGCONFIG_CFLAGS " -DBOX2D_DLL")
44+endif()
45+string(APPEND PKGCONFIG_CFLAGS "$<$<CONFIG:RELWITHDEBINFO>: -DB2_ENABLE_ASSERT>")
46+
47+set(PKGCONFIG_LIBNAME "box2d$<$<CONFIG:Debug>:${CMAKE_DEBUG_POSTFIX}>")
48+
49+# Plain pkg-config --libs skips Libs.private, and Box2D builds static by default, so
50+# public link deps belong on the main line unless we are actually building a shared lib
51+set(PKGCONFIG_LIBS "")
52+set(PKGCONFIG_LIBS_PRIVATE "")
53+if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
54+ if(BUILD_SHARED_LIBS)
55+ set(PKGCONFIG_LIBS_PRIVATE "-lm")
56+ else()
57+ set(PKGCONFIG_LIBS " -lm")
58+ endif()
59+endif()
60+
61+configure_file(box2d.pc.in box2d.pc.gen @ONLY)
62+
63+# The library name and the assert define vary by config, so finish the substitution
64+# per config instead of once at configure time
65+file(GENERATE
66+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/$<CONFIG>/box2d.pc"
67+ INPUT "${CMAKE_CURRENT_BINARY_DIR}/box2d.pc.gen"
68+)
69+
70+install(
71+ FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/$<CONFIG>/box2d.pc"
72+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
73+)
74diff --git a/src/box2d.pc.in b/src/box2d.pc.in
75new file mode 100644
76index 0000000..01a507b
77--- /dev/null
78+++ b/src/box2d.pc.in
79@@ -0,0 +1,11 @@
80+prefix=${pcfiledir}/@PKGCONFIG_PREFIX_REL@
81+exec_prefix=${prefix}
82+libdir=${prefix}/@PKGCONFIG_LIBDIR_REL@
83+includedir=${prefix}/@PKGCONFIG_INCLUDEDIR_REL@
84+
85+Name: @PROJECT_NAME@
86+Description: @PROJECT_DESCRIPTION@
87+Version: @PROJECT_VERSION@
88+Libs: -L${libdir} -l@PKGCONFIG_LIBNAME@@PKGCONFIG_LIBS@
89+Libs.private: @PKGCONFIG_LIBS_PRIVATE@
90+Cflags: -I${includedir}@PKGCONFIG_CFLAGS@
91--
922.54.0
93