diff mbox series

package/picotool: add patch to fix sparc static build

Message ID 20240807150952.765978-1-buildroot@bubu1.eu
State Changes Requested
Headers show
Series package/picotool: add patch to fix sparc static build | expand

Commit Message

Marcus Hoffmann Aug. 7, 2024, 3:09 p.m. UTC
Fixes: http://autobuild.buildroot.net/results/20d2fc02b7ca4c19b22b5853dccd8e55a052db10/

Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu>
---
 ...lso-link-to-additional-package-confi.patch | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 package/picotool/0001-CMakeLists.txt-also-link-to-additional-package-confi.patch

Comments

Thomas Petazzoni Aug. 7, 2024, 8:05 p.m. UTC | #1
Hello Marcus,

On Wed,  7 Aug 2024 17:09:52 +0200
Marcus Hoffmann via buildroot <buildroot@buildroot.org> wrote:

> +diff --git a/CMakeLists.txt b/CMakeLists.txt
> +index ff3e787..d6e41da 100644
> +--- a/CMakeLists.txt
> ++++ b/CMakeLists.txt
> +@@ -58,7 +58,8 @@ else()
> +             pico_platform_headers
> +             pico_usb_reset_interface_headers
> +             picoboot_connection_cxx
> +-            ${LIBUSB_LIBRARIES})
> ++            ${LIBUSB_LIBRARIES}
> ++            ${PC_LIBUSB_LIBRARIES})

Thanks for working on this. Unfortunately, while this patch perhaps
works for you, it might breaks things for systems where pkg-config is
not available: you unconditionally use ${PC_LIBUSB_LIBRARIES}, which
will only have a value if pkg-config is used. Instead could you try
something like this:

diff --git a/cmake/FindLIBUSB.cmake b/cmake/FindLIBUSB.cmake
index 169f594..7ae02b3 100644
--- a/cmake/FindLIBUSB.cmake
+++ b/cmake/FindLIBUSB.cmake
@@ -17,14 +17,18 @@ else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
         # in the FIND_PATH() and FIND_LIBRARY() calls
         find_package(PkgConfig)
         pkg_check_modules(PC_LIBUSB libusb-1.0)
+	IF (${PC_LIBUSB_FOUND})
+	  SET(LIBUSB_INCLUDE_DIR ${PC_LIBUSB_INCLUDE_DIRS})
+	  SET(LIBUSB_LIBRARIES ${PC_LIBUSB_LIBRARIES})
+	ENDIF ()
+    ENDIF ()
+    IF (NOT ${PC_LIBUSB_FOUND})
+      FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
+        HINTS $ENV{LIBUSB_ROOT}/include/libusb-1.0)
+      FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb-1.0 usb-1.0 usb
+        HINTS $ENV{LIBUSB_ROOT}/VS2019/MS32/static)
+      include(FindPackageHandleStandardArgs)
+      FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR)
+      MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)
     ENDIF ()
-    FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
-            HINTS $ENV{LIBUSB_ROOT}/include/libusb-1.0
-            PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS})
-    FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb-1.0 usb-1.0 usb
-            HINTS $ENV{LIBUSB_ROOT}/VS2019/MS32/static
-            PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS})
-    include(FindPackageHandleStandardArgs)
-    FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR)
-    MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)
 endif (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)


The logic is:

- If pkg-config has found the library, assign LIBUSB_INCLUDE_DIR and
  LIBUSB_LIBRARIES to the values found by pkg-config

- If pkg-config has not found the library, proceed with find_path() and
  find_library().

Of course, we drop the hints passed to find_path() and find_library()
that were results of pkg-config... as if pkg-config has returned
meaningful results, we will no longer be calling find_path() and
find_library().

I am not 100% sure of my change (I did not even test it), but I believe
it is closer to something that has a chance of being acceptable
upstream.

Thomas
diff mbox series

Patch

diff --git a/package/picotool/0001-CMakeLists.txt-also-link-to-additional-package-confi.patch b/package/picotool/0001-CMakeLists.txt-also-link-to-additional-package-confi.patch
new file mode 100644
index 0000000000..b80de67b8a
--- /dev/null
+++ b/package/picotool/0001-CMakeLists.txt-also-link-to-additional-package-confi.patch
@@ -0,0 +1,40 @@ 
+From fc86e05ea6a2976d0e1004d20b5bf3e693621253 Mon Sep 17 00:00:00 2001
+From: Marcus Hoffmann <marcus.hoffmann@othermo.de>
+Date: Wed, 7 Aug 2024 16:49:53 +0200
+Subject: [PATCH] CMakeLists.txt: also link to additional package-config
+ libraries
+
+LibUSB might specify additional libraries to link to via package-config
+(i.e. libatomic where this isn't a builtin [1]). These are correctly
+discovered by the call to pkg_check_modules and put into the
+PC_LIBUSB_LIBRARIES variable but then never added to the actual linking
+step.
+
+Fix that by additionally adding them behind the libusb library
+discovered by the find_library call().
+
+[1] https://github.com/libusb/libusb/blob/v1.0.27/configure.ac#L184
+
+Upstream: https://github.com/raspberrypi/picotool/pull/103
+Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu>
+---
+ CMakeLists.txt | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index ff3e787..d6e41da 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -58,7 +58,8 @@ else()
+             pico_platform_headers
+             pico_usb_reset_interface_headers
+             picoboot_connection_cxx
+-            ${LIBUSB_LIBRARIES})
++            ${LIBUSB_LIBRARIES}
++            ${PC_LIBUSB_LIBRARIES})
+     # allow `make install`
+     install(TARGETS picotool RUNTIME DESTINATION bin)
+ endif()
+-- 
+2.34.1
+