sci-libs/flann: Use system-lz4 and fix underlinking
authorAndreas Sturmlechner <asturm@gentoo.org>
Sat, 23 May 2020 09:38:04 +0000 (11:38 +0200)
committerAndreas Sturmlechner <asturm@gentoo.org>
Sat, 23 May 2020 10:52:50 +0000 (12:52 +0200)
Closes: https://bugs.gentoo.org/681898
Package-Manager: Portage-2.3.99, Repoman-2.3.22
Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
sci-libs/flann/files/flann-1.9.1-system-lz4.patch [new file with mode: 0644]
sci-libs/flann/flann-1.9.1-r3.ebuild [new file with mode: 0644]

diff --git a/sci-libs/flann/files/flann-1.9.1-system-lz4.patch b/sci-libs/flann/files/flann-1.9.1-system-lz4.patch
new file mode 100644 (file)
index 0000000..dcc9fed
--- /dev/null
@@ -0,0 +1,125 @@
+From: Jochen Sprickerhof <git@jochen.sprickerhof.de>
+Date: Sun, 14 Oct 2018 00:25:05 +0200
+Subject: Use system version of liblz4
+
+Also make sure that flann_cpp is linked against LZ4.
+---
+ CMakeLists.txt                     | 3 +++
+ cmake/flann.pc.in                  | 2 +-
+ examples/CMakeLists.txt            | 3 +++
+ src/cpp/CMakeLists.txt             | 8 ++++++--
+ src/cpp/flann/util/serialization.h | 4 ++--
+ 5 files changed, 15 insertions(+), 5 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index a01fb7a..995e54e 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -142,6 +142,9 @@ if (BUILD_CUDA_LIB)
+     endif(CUDA_FOUND)
+ endif(BUILD_CUDA_LIB)
++find_package(PkgConfig REQUIRED)
++pkg_check_modules(LZ4 REQUIRED liblz4)
++
+ #set the C/C++ include path to the "include" directory
+ include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src/cpp)
+diff --git a/cmake/flann.pc.in b/cmake/flann.pc.in
+index 82eee5e..07b8d64 100644
+--- a/cmake/flann.pc.in
++++ b/cmake/flann.pc.in
+@@ -8,6 +8,6 @@ Name: @PROJECT_NAME@
+ Description: @PKG_DESC@
+ Version: @FLANN_VERSION@
+ Requires: @PKG_EXTERNAL_DEPS@
+-Libs: -L${libdir} -lflann -lflann_cpp
++Libs: -L${libdir} @LZ4_STATIC_LDFLAGS@ -lflann -lflann_cpp
+ Cflags: -I${includedir}
+diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
+index e9fef04..2b2bb9d 100644
+--- a/examples/CMakeLists.txt
++++ b/examples/CMakeLists.txt
+@@ -3,6 +3,7 @@ add_custom_target(examples ALL)
+ if (BUILD_C_BINDINGS)
+     add_executable(flann_example_c flann_example.c)
++    target_link_libraries(flann_example_c -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+     target_link_libraries(flann_example_c flann)
+     set_target_properties(flann_example_c PROPERTIES COMPILE_FLAGS -std=c99)
+@@ -14,6 +15,7 @@ if (HDF5_FOUND)
+     include_directories(${HDF5_INCLUDE_DIRS})
+     add_executable(flann_example_cpp flann_example.cpp)
++    target_link_libraries(flann_example_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+     target_link_libraries(flann_example_cpp ${HDF5_LIBRARIES} flann_cpp)
+     if (HDF5_IS_PARALLEL)
+         target_link_libraries(flann_example_cpp ${MPI_LIBRARIES})
+@@ -25,6 +27,7 @@ if (HDF5_FOUND)
+     if (USE_MPI AND HDF5_IS_PARALLEL)
+         add_executable(flann_example_mpi flann_example_mpi.cpp)
++        target_link_libraries(flann_example_mpi -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+         target_link_libraries(flann_example_mpi flann_cpp ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${Boost_LIBRARIES})
+         add_dependencies(examples flann_example_mpi)
+diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
+index b453b27..5c4f693 100644
+--- a/src/cpp/CMakeLists.txt
++++ b/src/cpp/CMakeLists.txt
+@@ -4,11 +4,12 @@ add_definitions(-D_FLANN_VERSION=${FLANN_VERSION})
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flann/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/flann/config.h)
+-file(GLOB_RECURSE C_SOURCES flann.cpp lz4.c lz4hc.c)
+-file(GLOB_RECURSE CPP_SOURCES flann_cpp.cpp lz4.c lz4hc.c)
++file(GLOB_RECURSE C_SOURCES flann.cpp)
++file(GLOB_RECURSE CPP_SOURCES flann_cpp.cpp)
+ file(GLOB_RECURSE CU_SOURCES *.cu)
+ add_library(flann_cpp_s STATIC ${CPP_SOURCES})
++target_link_libraries(flann_cpp_s ${LZ4_LIBRARIES})
+ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
+     set_target_properties(flann_cpp_s PROPERTIES COMPILE_FLAGS -fPIC)
+ endif()
+@@ -42,6 +43,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
+     endif()
+ else()
+     add_library(flann_cpp SHARED ${CPP_SOURCES})
++    target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+     if (BUILD_CUDA_LIB)
+               cuda_add_library(flann_cuda SHARED ${CPP_SOURCES})
+         set_property(TARGET flann_cpp PROPERTY COMPILE_DEFINITIONS FLANN_USE_CUDA)
+@@ -77,6 +79,7 @@ endif()
+ if (BUILD_C_BINDINGS)
+     add_library(flann_s STATIC ${C_SOURCES})
++    target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+     if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
+         set_target_properties(flann_s PROPERTIES COMPILE_FLAGS -fPIC)
+     endif()
+@@ -88,6 +91,7 @@ if (BUILD_C_BINDINGS)
+         target_link_libraries(flann -Wl,-whole-archive flann_s -Wl,-no-whole-archive)
+     else()
+         add_library(flann SHARED ${C_SOURCES})
++        target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
+         if(MINGW AND OPENMP_FOUND)
+           target_link_libraries(flann gomp)
+diff --git a/src/cpp/flann/util/serialization.h b/src/cpp/flann/util/serialization.h
+index d731021..cdc2e5e 100644
+--- a/src/cpp/flann/util/serialization.h
++++ b/src/cpp/flann/util/serialization.h
+@@ -6,8 +6,8 @@
+ #include <cstdlib>
+ #include <cstring>
+ #include <stdio.h>
+-#include "flann/ext/lz4.h"
+-#include "flann/ext/lz4hc.h"
++#include <lz4.h>
++#include <lz4hc.h>
+ namespace flann
diff --git a/sci-libs/flann/flann-1.9.1-r3.ebuild b/sci-libs/flann/flann-1.9.1-r3.ebuild
new file mode 100644 (file)
index 0000000..b34a544
--- /dev/null
@@ -0,0 +1,94 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit cmake cuda flag-o-matic toolchain-funcs
+
+DESCRIPTION="Fast approximate nearest neighbor searches in high dimensional spaces"
+HOMEPAGE="https://www.cs.ubc.ca/research/flann/"
+SRC_URI="https://github.com/mariusmuja/${PN}/archive/${PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="amd64 ~arm arm64 ~ppc x86 ~amd64-linux ~x86-linux"
+IUSE="cuda doc examples mpi octave openmp"
+
+BDEPEND="
+       app-arch/unzip
+       doc? ( dev-tex/latex2html )
+"
+DEPEND="
+       app-arch/lz4:=
+       cuda? ( >=dev-util/nvidia-cuda-toolkit-5.5 )
+       mpi? (
+               dev-libs/boost:=[mpi]
+               sci-libs/hdf5[mpi]
+       )
+       !mpi? ( !sci-libs/hdf5[mpi] )
+       octave? ( >=sci-mathematics/octave-3.6.4-r1 )
+"
+RDEPEND="${DEPEND}"
+# TODO:
+# readd dependencies for test suite,
+# requires multiple ruby dependencies
+
+PATCHES=(
+       "${FILESDIR}"/${P}-cmake-3.11{,-1}.patch # bug 678030
+       "${FILESDIR}"/${P}-cuda-9.patch
+       "${FILESDIR}"/${P}-system-lz4.patch # bug 681898
+)
+
+pkg_pretend() {
+       [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
+}
+
+pkg_setup() {
+       [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
+}
+
+src_prepare() {
+       # bug #302621
+       use mpi && export CXX=mpicxx
+       # produce pure octave files
+       # octave gentoo installation for .m files respected
+       sed -i \
+               -e 's/--mex//' \
+               -e 's/\.mex/\.oct/' \
+               -e '/FILES/s/${MEX_FILE}//' \
+               -e 's:share/flann/octave:share/octave/site/m:' \
+               -e "/CUSTOM_TARGET/a\INSTALL(FILES \${MEX_FILE} DESTINATION libexec/octave/site/oct/${CHOST})" \
+               src/matlab/CMakeLists.txt || die
+       use cuda && cuda_src_prepare
+
+       cmake_src_prepare
+}
+
+src_configure() {
+       append-cxxflags -std=c++11
+
+       # python bindings are split off into dev-python/pyflann
+       local mycmakeargs=(
+               -DBUILD_C_BINDINGS=ON
+               -DBUILD_PYTHON_BINDINGS=OFF
+               -DPYTHON_EXECUTABLE=
+               -DBUILD_CUDA_LIB=$(usex cuda)
+               -DBUILD_EXAMPLES=$(usex examples)
+               -DBUILD_DOC=$(usex doc)
+               -DBUILD_TESTS=OFF
+               -DBUILD_MATLAB_BINDINGS=$(usex octave)
+               -DUSE_MPI=$(usex mpi)
+               -DUSE_OPENMP=$(usex openmp)
+       )
+       use cuda && mycmakeargs+=(
+               -DCUDA_NVCC_FLAGS="${NVCCFLAGS} --linker-options \"-arsch\""
+       )
+       use doc && mycmakeargs+=( -DDOCDIR=share/doc/${PF} )
+
+       cmake_src_configure
+}
+
+src_install() {
+       cmake_src_install
+       find "${D}" -name 'lib*.a' -delete || die
+}