Skip to content

Commit

Permalink
Add pcl PointCloudLibrary package
Browse files Browse the repository at this point in the history
Inspired from #1891
  • Loading branch information
EstebanDugueperoux2 committed Jul 7, 2023
1 parent 18b58bb commit 01797f9
Show file tree
Hide file tree
Showing 7 changed files with 598 additions and 0 deletions.
9 changes: 9 additions & 0 deletions recipes/pcl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"1.13.1":
url: https://github.com/PointCloudLibrary/pcl/archive/refs/tags/pcl-1.13.1.tar.gz
sha256: 8ab98a9db371d822de0859084a375a74bdc7f31c96d674147710cf4101b79621
patches:
"1.13.1":
- patch_file: "patches/0001-flann-target-cmake.patch"
patch_description: "Use flann::flann instead of FLANN::FLANN target generated by CMakeDeps"
patch_type: "conan"
224 changes: 224 additions & 0 deletions recipes/pcl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
import os


required_conan_version = ">=1.53.0"


class PclConan(ConanFile):
name = "pcl"
description = "Point Cloud Library"
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/PointCloudLibrary/pcl"
topics = ("computer-vision", "point-cloud", "pcl", "pointcloud")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_openmp": [True, False],
"with_libusb": [True, False],
"with_png": [True, False],
"with_qhull": [True, False],
"with_cuda": [True, False],
"with_pcap": [True, False],
"with_opengl": [True, False],
"with_tools": [True, False],
"with_apps": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_openmp": False,
"with_libusb": False,
"with_png": True,
"with_qhull": True,
"with_cuda": False,
"with_pcap": False,
"with_opengl": False,
"with_tools": False,
"with_apps": False,
}

@property
def _min_cppstd(self):
return 17

# in case the project requires C++14/17/20/... the minimum compiler version should be listed
@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"clang": "7",
"apple-clang": "10",
}

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("boost/1.82.0")
self.requires("eigen/3.3.9")
self.requires("flann/1.9.2")
if self.options.with_png:
self.requires("libpng/1.6.39")
if self.options.with_qhull:
self.requires("qhull/8.0.1")
if self.options.with_apps:
self.requires("qt/6.5.0")
if self.options.with_libusb:
self.requires("libusb/1.0.26")

def validate(self):
# validate the minimum cpp standard supported. For C++ projects only
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
check_min_vs(self, 191)
if not is_msvc(self):
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."
)
# in case it does not work in another configuration, it should validated here too
if is_msvc(self) and self.options.shared:
raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["PCL_SHARED_LIBS"] = self.options.shared
tc.variables["WITH_OPENMP"] = self.options.with_openmp
tc.variables["WITH_LIBUSB"] = self.options.with_libusb
tc.variables["WITH_PNG"] = self.options.with_png
tc.variables["WITH_QHULL"] = self.options.with_qhull
tc.variables["WITH_CUDA"] = self.options.with_cuda
tc.variables["WITH_PCAP"] = self.options.with_pcap
tc.variables["WITH_OPENGL"] = self.options.with_opengl
tc.variables["BUILD_TOOLS"] = self.options.with_tools
tc.variables["BUILD_APPS"] = self.options.with_apps
tc.cache_variables["WITH_QT"] = self.options.with_apps
tc.cache_variables["WITH_VTK"] = False
tc.generate()

tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
apply_conandata_patches(self)

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

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

@property
def _pcl_lib_components(self):
def png():
return ["libpng::libpng"] if self.options.with_png else []
def qhull():
return ["qhull::qhull"] if self.options.with_qhull else []

return {
"common": {"requires": ["eigen::eigen3", "boost::boost"]},
"kdtree": {"requires": ["common", "flann::flann"]},
"octree": {"requires": ["common"]},
"search": {"requires": ["common", "kdtree", "octree", "flann::flann"]},
"sample_consensus": {"requires": ["common", "search"]},
"filters": {"requires": ["common", "sample_consensus", "search", "kdtree", "octree"]},
"2d": {"requires": ["common", "filters"], "header_only": True},
"geometry": {"requires": ["common"], "header_only": True},
"io": {"requires": ["common", "octree"] + png(), "extra_libs": ["io_ply"]},
"features": {"requires": ["common", "search", "kdtree", "octree", "filters", "2d"]},
"ml": {"requires": ["common"]},
"segmentation": {"requires": ["common", "geometry", "search", "sample_consensus", "kdtree", "octree", "features", "filters", "ml"]},
"surface": {"requires": ["common", "search", "kdtree", "octree"] + qhull()},
"registration": {"requires": ["common", "octree", "kdtree", "search", "sample_consensus", "features", "filters"]},
"keypoints": {"requires": ["common", "search", "kdtree", "octree", "features", "filters"]},
"tracking": {"requires": ["common", "search", "kdtree", "filters", "octree"]},
"recognition": {"requires": ["common", "io", "search", "kdtree", "octree", "features", "filters", "registration", "sample_consensus", "ml"]},
"stereo": {"requires": ["common", "io"]}
}

@property
def _version_suffix(self):
semver = Version(self.version)
return "{}.{}".format(semver.major, semver.minor)

def _lib_name(self, lib):
if self.settings.compiler == "msvc" and self.settings.build_type == "Debug":
return "pcl_{}d".format(lib)
return "pcl_{}".format(lib)

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

self.cpp_info.set_property("cmake_file_name", "PCL")
self.cpp_info.set_property("cmake_module_file_name", "PCL")
self.cpp_info.set_property("cmake_target_name", "PCL::PCL")

def _update_components(components):
for comp, values in components.items():
self.cpp_info.components[comp].names["cmake_find_package"] = comp
self.cpp_info.components[comp].names["cmake_find_package_multi"] = comp
self.cpp_info.components[comp].set_property("cmake_file_name", comp)
self.cpp_info.components[comp].set_property("cmake_module_file_name", comp)
self.cpp_info.components[comp].set_property("cmake_target_name", f"PCL::{comp}")

self.cpp_info.components[comp].names["pkg_config"] = "pcl_{}-{}".format(comp, self._version_suffix)
self.cpp_info.components[comp].set_property("pkg_config_name", "pcl_{}-{}".format(comp, self._version_suffix))

self.cpp_info.components[comp].includedirs = [os.path.join("include", "pcl-{}".format(self._version_suffix))]
if not values.get("header_only", False):
libs = [comp] + values.get("extra_libs", [])
self.cpp_info.components[comp].libs = [self._lib_name(lib) for lib in libs]
self.cpp_info.components[comp].requires = values["requires"]

_update_components(self._pcl_lib_components)

if not self.options.shared:
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["common"].system_libs.append("pthread")
if self.options.with_openmp:
if self.settings.os == "Linux":
if self.settings.compiler == "gcc":
self.cpp_info.components["common"].sharedlinkflags.append("-fopenmp")
self.cpp_info.components["common"].exelinkflags.append("-fopenmp")
elif self.settings.os == "Windows":
if self.settings.compiler == "msvc":
self.cpp_info.components["common"].system_libs.append("delayimp")
elif self.settings.compiler == "gcc":
self.cpp_info.components["common"].system_libs.append("gomp")

if self.options.with_apps:
self.cpp_info.components["apps"].libs = []
self.cpp_info.components["apps"].requires = ["qt::qt"]

Loading

0 comments on commit 01797f9

Please sign in to comment.