Skip to content

Commit

Permalink
add libnabo/1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Mar 5, 2023
1 parent cab2db2 commit 3e07156
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 0 deletions.
9 changes: 9 additions & 0 deletions recipes/libnabo/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"1.0.7":
url: "https://github.com/ethz-asl/libnabo/archive/refs/tags/1.0.7.tar.gz"
sha256: "817f43ba77668a7fab2834e78f0a9ff80e294d69c9818142084a32040547d10a"
patches:
"1.0.7":
- patch_file: "patches/1.0.7-0001-fix-cmake.patch"
patch_description: "Fix upstream CMakeLists"
patch_type: "conan"
81 changes: 81 additions & 0 deletions recipes/libnabo/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
import os

required_conan_version = ">=1.53.0"


class LibnaboConan(ConanFile):
name = "libnabo"
description = "A fast K Nearest Neighbor library for low-dimensional spaces"
license = "BSD-3-Clause"
topics = ("nearest-neighbor", "kd-tree")
homepage = "https://github.com/ethz-asl/libnabo"
url = "https://github.com/conan-io/conan-center-index"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_openmp": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_openmp": False,
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("eigen/3.4.0", transitive_headers=True)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["USE_OPEN_MP"] = self.options.with_openmp
tc.cache_variables["USE_OPEN_CL"] = False
tc.cache_variables["SHARED_LIBS"] = self.options.shared
tc.generate()
deps = CMakeDeps(self)
deps.generate()

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

def package(self):
copy(self, "copyright", src=os.path.join(self.source_folder, "debian"),
dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "libnabo")
self.cpp_info.set_property("cmake_target_name", "libnabo::nabo")
# TODO: back to global scope in conan v2
self.cpp_info.components["nabo"].libs = ["nabo"]

# TODO: to remove in conan v2
self.cpp_info.components["nabo"].names["cmake_find_package"] = "nabo"
self.cpp_info.components["nabo"].names["cmake_find_package_multi"] = "nabo"
self.cpp_info.components["nabo"].set_property("cmake_target_name", "libnabo::nabo")
self.cpp_info.components["nabo"].requires = ["eigen::eigen"]
80 changes: 80 additions & 0 deletions recipes/libnabo/all/patches/1.0.7-0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 3.15)

if (NOT CMAKE_VERSION VERSION_LESS "3.1")
cmake_policy(SET CMP0054 NEW)
@@ -7,6 +7,10 @@ endif ()
set(LIB_NAME nabo)
project("lib${LIB_NAME}")

+file(READ "nabo/nabo.h" NABO_HEADER_CONTENT)
+string(REGEX MATCH "#define NABO_VERSION \"([0-9]+\.[0-9]+\.[0-9]+)\"" _ ${NABO_HEADER_CONTENT})
+set(PROJECT_VERSION ${CMAKE_MATCH_1})
+if(0)
# Extract version from header
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(
@@ -86,6 +90,7 @@ if (CMAKE_VERSION VERSION_LESS "3.1")
else ()
set (CMAKE_CXX_STANDARD 11)
endif ()
+endif()

# openmp
set(USE_OPEN_MP TRUE CACHE BOOL "Set to FALSE to not use OpenMP")
@@ -101,15 +106,7 @@ if (USE_OPEN_MP)
endif (USE_OPEN_MP)

# eigen 2 or 3
-find_path(EIGEN_INCLUDE_DIR Eigen/Core
- /usr/local/include/eigen3
- /usr/local/include/eigen2
- /usr/local/include/eigen
- /usr/include/eigen3
- /usr/include/eigen2
- /usr/include/eigen
- /opt/local/include/eigen3
-)
+find_package(Eigen3 REQUIRED CONFIG)

# optionally, opencl
# OpenCL disabled as its code is not up-to-date with API
@@ -141,7 +138,6 @@ else (USE_OPEN_CL)
endif (USE_OPEN_CL)

# include all libs so far
-include_directories(${CMAKE_SOURCE_DIR} ${EIGEN_INCLUDE_DIR})

# main nabo lib
set(NABO_SRC
@@ -153,12 +149,13 @@ set(NABO_SRC
set(SHARED_LIBS FALSE CACHE BOOL "Set to TRUE to build shared library")
if (SHARED_LIBS)
add_library(${LIB_NAME} SHARED ${NABO_SRC})
- install(TARGETS ${LIB_NAME} LIBRARY DESTINATION lib)
+ install(TARGETS ${LIB_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin)
else (SHARED_LIBS)
add_library(${LIB_NAME} ${NABO_SRC})
- add_definitions(-fPIC)
install(TARGETS ${LIB_NAME} ARCHIVE DESTINATION lib)
endif (SHARED_LIBS)
+target_link_libraries(${LIB_NAME} PUBLIC Eigen3::Eigen)
+target_compile_features(${LIB_NAME} PUBLIC cxx_std_11)
set_target_properties(${LIB_NAME} PROPERTIES VERSION "${PROJECT_VERSION}" SOVERSION 1)

# create doc before installing
@@ -170,11 +167,7 @@ if (DOXYGEN_FOUND)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html DESTINATION ${DOC_INSTALL_TARGET})
endif (DOXYGEN_FOUND)

-enable_testing()

-add_subdirectory(examples)
-add_subdirectory(tests)
-add_subdirectory(python)

# Install catkin package.xml
install(FILES package.xml DESTINATION share/libnabo)
8 changes: 8 additions & 0 deletions recipes/libnabo/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(libnabo REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE libnabo::nabo)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
26 changes: 26 additions & 0 deletions recipes/libnabo/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
17 changes: 17 additions & 0 deletions recipes/libnabo/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <nabo/nabo.h>

#include <memory>

int main()
{
Eigen::MatrixXf M = Eigen::MatrixXf::Random(3, 100);
Eigen::VectorXf q = Eigen::VectorXf::Random(3);
auto nns = std::unique_ptr<Nabo::NNSearchF>(Nabo::NNSearchF::createKDTreeLinearHeap(M));

const int K = 5;
Eigen::VectorXi indices(K);
Eigen::VectorXf dists2(K);
nns->knn(q, indices, dists2, K);

return 0;
}
8 changes: 8 additions & 0 deletions recipes/libnabo/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/libnabo/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


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

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/libnabo/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.7":
folder: all

0 comments on commit 3e07156

Please sign in to comment.