projects/guix·blob java-team · refs

91 lines · 3.4 KiB

1Taken from https://github.com/flann-lib/flann/pull/481 .
2From 910099bcf51e8e4ad48bc7adee88fd26abef982a Mon Sep 17 00:00:00 2001
3From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= <[email protected]>
4Date: Tue, 2 Nov 2021 00:13:27 +0100
5Subject: [PATCH] Fix lz4 / HDF5 missing from flann.pc `Requires:` line.
6
7lz4 is an unconditional dependency of flann (see #399),
8but until now was not correctly generated into the
9`Requires: lz4` line of `flann.pc`,
10because the `PKG_EXTERNAL_DEPS` variable used in `flann.pc.in`
11was not defined at all.
12
13This fixes build error `lz4.h: No such file or directory`
14for properly sandboxed builds, in which undeclared dependencies
15are not made available.
16
17Same thing for HDF5, but conditionally.
18
19For lz4, also remove the hardcode of `@LZ4_STATIC_LDFLAGS@`
20from `flann.pc.in`, as this is no longer necessary.
21That fixes an incorrect `-L` flag being generated in there, e.g.
22`-L/usr/lib;-llz4`. Thus fixes #480.
23---
24 CMakeLists.txt | 8 ++++++++
25 cmake/CMakeLists.txt | 9 +++++++++
26 cmake/flann.pc.in | 2 +-
27 3 files changed, 18 insertions(+), 1 deletion(-)
28
29diff --git a/CMakeLists.txt b/CMakeLists.txt
30index f79d173a..a3fe9ddd 100644
31--- a/CMakeLists.txt
32+++ b/CMakeLists.txt
33@@ -62,6 +62,9 @@ option(USE_MPI "Use MPI" OFF)
34
35 set(NVCC_COMPILER_BINDIR "" CACHE PATH "Directory where nvcc should look for C++ compiler. This is passed to nvcc through the --compiler-bindir option.")
36
37+# pkg-config dependencies to be generated into the .pc file
38+set(PKGCONFIG_EXTERNAL_DEPS_LIST "")
39+
40 if (NOT BUILD_C_BINDINGS)
41 set(BUILD_PYTHON_BINDINGS OFF)
42 set(BUILD_MATLAB_BINDINGS OFF)
43@@ -81,6 +84,7 @@ if (NOT HDF5_FOUND)
44 message(WARNING "hdf5 library not found, some tests will not be run")
45 else()
46 include_directories(${HDF5_INCLUDE_DIR})
47+ list(APPEND PKGCONFIG_EXTERNAL_DEPS_LIST "hdf5")
48 endif()
49
50 if (USE_MPI OR HDF5_IS_PARALLEL)
51@@ -150,6 +154,10 @@ endif(BUILD_CUDA_LIB)
52 find_package(PkgConfig REQUIRED)
53 pkg_check_modules(LZ4 REQUIRED liblz4)
54 include_directories(${LZ4_INCLUDE_DIRS})
55+# flann is exposing lz4 headers e.g. in `util/serialization.h`
56+# we need lz4 to appear in `Requires` (not `Requires.private`) in the
57+# `.pc` file, see https://people.freedesktop.org/~dbn/pkg-config-guide.html
58+list(APPEND PKGCONFIG_EXTERNAL_DEPS_LIST "liblz4")
59
60 #set the C/C++ include path to the "include" directory
61 include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src/cpp)
62diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
63index fb70f4cc..be6c1dc0 100644
64--- a/cmake/CMakeLists.txt
65+++ b/cmake/CMakeLists.txt
66@@ -1,4 +1,13 @@
67 set(PKG_DESC "Fast Library for Approximate Nearest Neighbors")
68+
69+# Compute `PKG_EXTERNAL_DEPS` string from `PKGCONFIG_EXTERNAL_DEPS_LIST`.
70+# Once the project has `cmake_minimum_required(VERSION 2.6)`, this
71+# can be replaced by `list(JOIN ...)`.
72+set(PKG_EXTERNAL_DEPS "")
73+foreach(_dep ${PKGCONFIG_EXTERNAL_DEPS_LIST})
74+ string(APPEND PKG_EXTERNAL_DEPS " ${_dep}")
75+endforeach()
76+
77 set(pkg_conf_file ${CMAKE_CURRENT_BINARY_DIR}/flann.pc)
78 configure_file(flann.pc.in ${pkg_conf_file} @ONLY)
79 install(FILES ${pkg_conf_file}
80diff --git a/cmake/flann.pc.in b/cmake/flann.pc.in
81index 07b8d649..82eee5e6 100644
82--- a/cmake/flann.pc.in
83+++ b/cmake/flann.pc.in
84@@ -8,6 +8,6 @@ Name: @PROJECT_NAME@
85 Description: @PKG_DESC@
86 Version: @FLANN_VERSION@
87 Requires: @PKG_EXTERNAL_DEPS@
88-Libs: -L${libdir} @LZ4_STATIC_LDFLAGS@ -lflann -lflann_cpp
89+Libs: -L${libdir} -lflann -lflann_cpp
90 Cflags: -I${includedir}
91