diff mbox series

libgit2: remove library paths from installed .cmake

Message ID 20260723193744.3592838-1-ross.burton@arm.com
State New
Headers show
Series libgit2: remove library paths from installed .cmake | expand

Commit Message

Ross Burton July 23, 2026, 7:37 p.m. UTC
The libgit2 cmake rules generate a .cmake file that tells people linking
to libgit2 how to link.  This includes the complete path to each of the
libraries that libgit2 links, such as /path/to/sysroot/usr/lib/libssl.so.

The build paths were previously removed with a quick sed, but this breaks
builds where those target paths exist on the build host as they get used
verbatim.

However, all of this linkage is redundant as the library directly links
to these libraries.  Mark the linkage as private, so the references do
not appear in the .cmake files.

[ YOCTO #16373 ]

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 ...m-libraries-are-private-link-librari.patch | 42 +++++++++++++++++++
 meta/recipes-support/libgit2/libgit2_1.9.4.bb |  8 ++--
 2 files changed, 45 insertions(+), 5 deletions(-)
 create mode 100644 meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch

Comments

Jörg Sommer July 23, 2026, 8:03 p.m. UTC | #1
Ross Burton via lists.openembedded.org schrieb am Do 23. Jul, 20:37 (+0100):
> The libgit2 cmake rules generate a .cmake file that tells people linking
> to libgit2 how to link.  This includes the complete path to each of the
> libraries that libgit2 links, such as /path/to/sysroot/usr/lib/libssl.so.
> 
> The build paths were previously removed with a quick sed, but this breaks
> builds where those target paths exist on the build host as they get used
> verbatim.
> 
> However, all of this linkage is redundant as the library directly links
> to these libraries.  Mark the linkage as private, so the references do
> not appear in the .cmake files.
> 
> [ YOCTO #16373 ]
> 
> Signed-off-by: Ross Burton <ross.burton@arm.com>
> ---
>  ...m-libraries-are-private-link-librari.patch | 42 +++++++++++++++++++
>  meta/recipes-support/libgit2/libgit2_1.9.4.bb |  8 ++--
>  2 files changed, 45 insertions(+), 5 deletions(-)
>  create mode 100644 meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch
> 
> diff --git a/meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch b/meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch
> new file mode 100644
> index 00000000000..267770ae6fe
> --- /dev/null
> +++ b/meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch
> @@ -0,0 +1,42 @@
> +From 5670d3eed82f0d64766158809bf3d0c7c631b0ea Mon Sep 17 00:00:00 2001
> +From: Ross Burton <ross.burton@arm.com>
> +Date: Thu, 23 Jul 2026 17:35:23 +0100
> +Subject: [PATCH] cmake: mark system libraries are private link libraries
> +
> +When generating libgit2Targets.cmake, mark the system libraries that
> +libgit2.so links to as private, as the don't not need to be seen by

I think this should be “as they do not need”

> +applications that link to libgit2.
> +

Jörg
diff mbox series

Patch

diff --git a/meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch b/meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch
new file mode 100644
index 00000000000..267770ae6fe
--- /dev/null
+++ b/meta/recipes-support/libgit2/files/0001-cmake-mark-system-libraries-are-private-link-librari.patch
@@ -0,0 +1,42 @@ 
+From 5670d3eed82f0d64766158809bf3d0c7c631b0ea Mon Sep 17 00:00:00 2001
+From: Ross Burton <ross.burton@arm.com>
+Date: Thu, 23 Jul 2026 17:35:23 +0100
+Subject: [PATCH] cmake: mark system libraries are private link libraries
+
+When generating libgit2Targets.cmake, mark the system libraries that
+libgit2.so links to as private, as the don't not need to be seen by
+applications that link to libgit2.
+
+This stops the generated file from containing absolute paths to the
+libraries, which both leaks build information and means the build output
+is not relocatable:
+
+set_target_properties(libgit2::libgit2package PROPERTIES
+  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
+  INTERFACE_LINK_LIBRARIES "/PATH/TO/SYSROOT/usr/lib/libssl.so;/PATH/TO/SYSROOT/usr/lib/libcrypto.so;/PATH/TO/SYSROOT/usr/lib/libpcre2-8.so;/PATH/TO/SYSROOT/usr/lib/libz.so;rt"
+)
+
+Making the linkage private removes the INTERFACE_LINK_LIBRARIES line,
+and applications linking to libgit2 still succeed.
+
+Upstream-Status: Submitted [https://github.com/libgit2/libgit2/pull/7324]
+Signed-off-by: Ross Burton <ross.burton@arm.com>
+---
+ src/libgit2/CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/libgit2/CMakeLists.txt b/src/libgit2/CMakeLists.txt
+index 8045ddef9..fafdb09ec 100644
+--- a/src/libgit2/CMakeLists.txt
++++ b/src/libgit2/CMakeLists.txt
+@@ -65,7 +65,7 @@ if (NOT BUILD_SHARED_LIBS AND XCODE_VERSION)
+ endif()
+ 
+ add_library(libgit2package ${SRC_RC} ${LIBGIT2_OBJECTS})
+-target_link_libraries(libgit2package ${LIBGIT2_SYSTEM_LIBS})
++target_link_libraries(libgit2package PRIVATE ${LIBGIT2_SYSTEM_LIBS})
+ target_include_directories(libgit2package SYSTEM PRIVATE ${LIBGIT2_INCLUDES})
+ target_include_directories(libgit2package INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+ 
+-- 
+2.43.0
diff --git a/meta/recipes-support/libgit2/libgit2_1.9.4.bb b/meta/recipes-support/libgit2/libgit2_1.9.4.bb
index 10999f972ed..7310dda66dd 100644
--- a/meta/recipes-support/libgit2/libgit2_1.9.4.bb
+++ b/meta/recipes-support/libgit2/libgit2_1.9.4.bb
@@ -5,7 +5,9 @@  LIC_FILES_CHKSUM = "file://COPYING;md5=8eacfdc17c8f4d219e131a073973b97d"
 
 DEPENDS = "curl openssl zlib libssh2 libgcrypt libpcre2"
 
-SRC_URI = "git://github.com/libgit2/libgit2.git;branch=maint/v1.9;protocol=https;tag=v${PV}"
+SRC_URI = "git://github.com/libgit2/libgit2.git;branch=maint/v1.9;protocol=https;tag=v${PV} \
+           file://0001-cmake-mark-system-libraries-are-private-link-librari.patch"
+
 SRCREV = "f7164261c9bc0a7e0ebf767c584e5192810a8b24"
 
 inherit cmake
@@ -17,7 +19,3 @@  EXTRA_OECMAKE = "\
 "
 
 BBCLASSEXTEND = "native"
-
-do_install:append() {
-    sed -i -e 's,${RECIPE_SYSROOT},,g' ${D}${libdir}/cmake/libgit2/libgit2Targets.cmake
-}