diff --git a/recipes/libnabo/all/conandata.yml b/recipes/libnabo/all/conandata.yml new file mode 100644 index 0000000000000..86054cc4bd55a --- /dev/null +++ b/recipes/libnabo/all/conandata.yml @@ -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" diff --git a/recipes/libnabo/all/conanfile.py b/recipes/libnabo/all/conanfile.py new file mode 100644 index 0000000000000..7ea7ce19cee21 --- /dev/null +++ b/recipes/libnabo/all/conanfile.py @@ -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"] diff --git a/recipes/libnabo/all/patches/1.0.7-0001-fix-cmake.patch b/recipes/libnabo/all/patches/1.0.7-0001-fix-cmake.patch new file mode 100644 index 0000000000000..8efc965410dc9 --- /dev/null +++ b/recipes/libnabo/all/patches/1.0.7-0001-fix-cmake.patch @@ -0,0 +1,94 @@ +--- 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,14 @@ 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) ++ set_target_properties(${LIB_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) + 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 +168,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) +@@ -195,6 +189,7 @@ install(FILES package.xml DESTINATION share/libnabo) + # 1- local build # + + # Register the local build in case one doesn't use "make install" ++if(0) + export(PACKAGE libnabo) + + # Create variable with the library location +@@ -244,3 +239,4 @@ configure_file( + + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) ++endif() diff --git a/recipes/libnabo/all/test_package/CMakeLists.txt b/recipes/libnabo/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..6398a814018da --- /dev/null +++ b/recipes/libnabo/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libnabo/all/test_package/conanfile.py b/recipes/libnabo/all/test_package/conanfile.py new file mode 100644 index 0000000000000..0a6bc68712d90 --- /dev/null +++ b/recipes/libnabo/all/test_package/conanfile.py @@ -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") diff --git a/recipes/libnabo/all/test_package/test_package.cpp b/recipes/libnabo/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..7f61223412edc --- /dev/null +++ b/recipes/libnabo/all/test_package/test_package.cpp @@ -0,0 +1,17 @@ +#include + +#include + +int main() +{ + Eigen::MatrixXf M = Eigen::MatrixXf::Random(3, 100); + Eigen::VectorXf q = Eigen::VectorXf::Random(3); + auto nns = std::unique_ptr(Nabo::NNSearchF::createKDTreeLinearHeap(M)); + + const int K = 5; + Eigen::VectorXi indices(K); + Eigen::VectorXf dists2(K); + nns->knn(q, indices, dists2, K); + + return 0; +} diff --git a/recipes/libnabo/all/test_v1_package/CMakeLists.txt b/recipes/libnabo/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/libnabo/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/libnabo/all/test_v1_package/conanfile.py b/recipes/libnabo/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/libnabo/all/test_v1_package/conanfile.py @@ -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) diff --git a/recipes/libnabo/config.yml b/recipes/libnabo/config.yml new file mode 100644 index 0000000000000..377623d3a93f7 --- /dev/null +++ b/recipes/libnabo/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.7": + folder: all