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

small_gicp: new recipe #23458

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions recipes/small_gicp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.0":
url: "https://github.com/koide3/small_gicp/archive/refs/tags/v1.0.0.tar.gz"
sha256: "8ace22cfc79b1ea1c827d199c98f1efd01fd5a6686cda99e684ef21cb86ebbbf"
124 changes: 124 additions & 0 deletions recipes/small_gicp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, rm, rmdir, download
from conan.tools.scm import Version
import os

required_conan_version = ">=1.53.0"


class IridescenceConan(ConanFile):
name = "small_gicp"
description = "Efficient and parallelized algorithms for point cloud registration"
license = "MIT AND BSD" # BSD is from nanoflann and Sophus
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/koide3/small_gicp"
topics = ("point-cloud", "icp", "registration", "scan-matching", "pcl")

package_type = "library" # TODO: could add a header_only option as well
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_openmp": [True, False],
"with_tbb": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_openmp": True,
"with_tbb": True,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"clang": "7",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
}

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)
if self.options.with_openmp:
# '#pragma omp' is used in public headers
# Note: native MSVC OpenMP is not compatible
self.requires("llvm-openmp/18.1.8", transitive_headers=True, transitive_libs=True)
Comment on lines +64 to +66
Copy link
Member

Choose a reason for hiding this comment

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

Can we validate() this configuration out to be able to move this forward while work on mp progresses?

if self.options.with_tbb:
self.requires("onetbb/2021.12.0", transitive_headers=True, transitive_libs=True)

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def build_requirements(self):
self.tool_requires("cmake/[>=3.16 <4]")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
download(self, "https://github.com/jlblancoc/nanoflann/blob/568ae53f5fcd82d5398bb1b32144fa22028518d5/COPYING", "LICENSE.nanoflann")
download(self, "https://github.com/strasdat/Sophus/blob/593db47500ea1a2de5f0e6579c86147991509c59/LICENSE.txt", "LICENSE.sophus")

def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()

tc = CMakeToolchain(self)
tc.variables["BUILD_HELPER"] = True
tc.variables["BUILD_WITH_OPENMP"] = self.options.with_openmp
tc.variables["BUILD_WITH_TBB"] = self.options.with_tbb
tc.generate()

deps = CMakeDeps(self)
deps.generate()

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

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
# The source code contains fragments from nanoflann and Sophus
copy(self, "LICENSE.nanoflann", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "LICENSE.sophus", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "small_gicp")
self.cpp_info.set_property("cmake_target_name", "small_gicp::small_gicp")

self.cpp_info.libs = ["small_gicp"]

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
8 changes: 8 additions & 0 deletions recipes/small_gicp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(small_gicp REQUIRED CONFIG)

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


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

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

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
if self.dependencies["small_gicp"].options.with_openmp:
tc.preprocessor_definitions["WITH_OPENMP"] = ""
if self.dependencies["small_gicp"].options.with_tbb:
tc.preprocessor_definitions["WITH_TBB"] = ""
tc.generate()

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.bindir, "test_package")
self.run(bin_path, env="conanrun")
31 changes: 31 additions & 0 deletions recipes/small_gicp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <small_gicp/points/point_cloud.hpp>
#include <small_gicp/ann/kdtree.hpp>
#ifdef WITH_OPENMP
#include <small_gicp/ann/kdtree_omp.hpp>
#endif
#ifdef WITH_TBB
#include <small_gicp/ann/kdtree_tbb.hpp>
#endif

using namespace small_gicp;

int main() {
std::vector<Eigen::Vector4f> target_points = {
{1.0f, 2.0f, 3.0f, 1.0f},
{4.0f, 5.0f, 6.0f, 1.0f},
{7.0f, 8.0f, 9.0f, 1.0f},
};
auto target = std::make_shared<PointCloud>(target_points);

const int num_threads = 1;
std::make_shared<KdTree<PointCloud>>(target, KdTreeBuilderOMP(num_threads));

#ifdef WITH_OPENMP
std::make_shared<KdTree<PointCloud>>(target, KdTreeBuilderOMP());
#endif

#ifdef WITH_TBB
std::make_shared<KdTree<PointCloud>>(target, KdTreeBuilderTBB());
#endif

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