Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FLANN 1.9.1 #897

Merged
merged 9 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions recipes/flann/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/flann/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.9.1":
sha256: b23b5f4e71139faa3bcb39e6bbcc76967fbaf308c4ee9d4f5bfbeceaa76cc5d3
url: https://github.com/mariusmuja/flann/archive/1.9.1.tar.gz
118 changes: 118 additions & 0 deletions recipes/flann/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import glob
import os

from conans import ConanFile, CMake, tools


class LibFlannConan(ConanFile):
name = "flann"
description = "Fast Library for Approximate Nearest Neighbors"
topics = "conan", "flann"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.cs.ubc.ca/research/flann/"
license = "BSD-3-Clause"
exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_hdf5": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_hdf5": False
}

_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
_cmake = None

def config_options(self):
if self.settings.compiler == "Visual Studio":
del self.options.fPIC

def requirements(self):
if self.options.with_hdf5:
self.requires("hdf5/1.10.6")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

# Workaround issue with empty sources for a CMake target
flann_cpp_dir = os.path.join(self._source_subfolder, "src", "cpp")
with open(os.path.join(flann_cpp_dir, "empty.cpp"), "w") as fd:
Morwenn marked this conversation as resolved.
Show resolved Hide resolved
fd.write("\n") # touch

tools.replace_in_file(
os.path.join(flann_cpp_dir, "CMakeLists.txt"),
'add_library(flann_cpp SHARED "")',
'add_library(flann_cpp SHARED empty.cpp)'
)
tools.replace_in_file(
os.path.join(flann_cpp_dir, "CMakeLists.txt"),
'add_library(flann SHARED "")',
'add_library(flann SHARED empty.cpp)'
)

def _configure_cmake(self):
if self._cmake is not None:
return self._cmake
self._cmake = CMake(self)

# Only build the C++ libraries
self._cmake.definitions["BUILD_DOC"] = "OFF"
Morwenn marked this conversation as resolved.
Show resolved Hide resolved
self._cmake.definitions["BUILD_EXAMPLES"] = "OFF"
self._cmake.definitions["BUILD_TESTS"] = "OFF"
self._cmake.definitions["BUILD_C_BINDINGS"] = "OFF"
self._cmake.definitions["BUILD_MATLAB_BINDINGS"] = "OFF"
self._cmake.definitions["BUILD_PYTHON_BINDINGS"] = "OFF"

# Workaround issue with flann_cpp
if self.settings.os == "Windows" and self.options.shared:
self._cmake.definitions["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True

self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()

self.copy("COPYING", src=self._source_subfolder, dst="licenses")

# Remove pkg-config files
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
# Remove MS runtime files (KB-H021)
for file_to_remove in ["concrt140.dll", "msvcp140.dll", "vcruntime140.dll"]:
path = os.path.join(self.package_folder, "bin", file_to_remove)
if os.path.isfile(path):
os.remove(path)

# Remove static/dynamic libraries depending on the build mode
if self.options.shared:
for file_to_remove in glob.glob(os.path.join(self.package_folder, "lib", "flann_cpp_s*")):
os.remove(file_to_remove)
else:
if self.settings.os != "Linux":
tools.rmdir(os.path.join(self.package_folder, "bin"))
else:
for file_to_remove in glob.glob(os.path.join(self.package_folder, "lib", "*.so*")):
os.remove(file_to_remove)

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "FLANN"
self.cpp_info.names["cmake_find_package_multi"] = "FLANN"

if self.options.shared:
self.cpp_info.libs = ["flann_cpp"]
else:
self.cpp_info.libs = ["flann_cpp_s"]
9 changes: 9 additions & 0 deletions recipes/flann/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 2.8.11)

project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${CONAN_LIBS})
17 changes: 17 additions & 0 deletions recipes/flann/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os.path

from conans import ConanFile, CMake


class FlannTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
7 changes: 7 additions & 0 deletions recipes/flann/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <flann/flann.hpp>

int main()
{
flann::Matrix<float> dataset;
flann::Matrix<float> query;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These use default constructors of templated classes.
So no code from the packaged library is called and executed.
Maybe the examples at https://github.com/mariusmuja/flann/tree/master/examples are useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They load datasets, which seemed like something you don't always want to ship with your packages because it's an additional 10Mo. Now if it isn't a problem I'm definitely adding that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10MiB is a bit too much, I'm afraid.
What could be done is skip the load, or create a dummy dataset in the same format as the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to come up with something when I find some time, maybe tomorrow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each folder can consume only 256KB IIRC

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the point is just to verify example compiles and links correctly.
so, an actual example isn't needed. it should be enough to just call some API function (e.g. flann_get_distance_type, or any other you prefer). you may also call the function that will fail, it's okay (it just shouldn't crash or hang at least).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently only the C bindings allow to test whether linking works easily since flann_cpp.cpp only includes flann.hpp. Therefore I had the recipe build the C bindings along with the rest, I guess that it's pretty harmless to have them too.

}
3 changes: 3 additions & 0 deletions recipes/flann/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.9.1":
folder: all