Skip to content

Commit caeea5b

Browse files
Add pcl PointCloudLibrary package
Inspired from conan-io#1891
1 parent 18b58bb commit caeea5b

8 files changed

+596
-0
lines changed

recipes/pcl/all/conandata.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sources:
2+
"1.13.1":
3+
url: https://github.com/PointCloudLibrary/pcl/archive/refs/tags/pcl-1.13.1.tar.gz
4+
sha256: 8ab98a9db371d822de0859084a375a74bdc7f31c96d674147710cf4101b79621
5+
patches:
6+
"1.13.1":
7+
- patch_file: "patches/0001-test.patch"
8+
patch_description: "Update pcl CMake files to work with conan"
9+
patch_type: "conan"
10+
- patch_file: "patches/0001-KB-H020_avoid_pkgconfig_files.patch"
11+
patch_description: "Disable pkgconfig files install to follow KB-H020 rule"
12+
patch_type: "conan"

recipes/pcl/all/conanfile.py

+242
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
from conan import ConanFile
2+
from conan.errors import ConanInvalidConfiguration
3+
from conan.tools.microsoft import check_min_vs, is_msvc
4+
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir
5+
from conan.tools.build import check_min_cppstd
6+
from conan.tools.scm import Version
7+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
8+
from conan.tools.system import package_manager
9+
import os
10+
11+
12+
required_conan_version = ">=1.53.0"
13+
14+
15+
class PclConan(ConanFile):
16+
name = "pcl"
17+
description = "Point Cloud Library"
18+
license = "BSD-3-Clause"
19+
url = "https://github.com/conan-io/conan-center-index"
20+
homepage = "https://github.com/PointCloudLibrary/pcl"
21+
topics = ("computer vision", "point cloud", "pointcloud", "3d", "pcd", "ply", "stl", "ifs", "vtk")
22+
package_type = "library"
23+
settings = "os", "arch", "compiler", "build_type"
24+
options = {
25+
"shared": [True, False],
26+
"fPIC": [True, False],
27+
"with_openmp": [True, False],
28+
"with_libusb": [True, False],
29+
"with_png": [True, False],
30+
"with_qhull": [True, False],
31+
"with_vtk": [True, False],
32+
"with_cuda": [True, False],
33+
"with_pcap": [True, False],
34+
"with_opengl": [True, False],
35+
"with_tools": [True, False],
36+
"with_apps": [True, False],
37+
}
38+
default_options = {
39+
"shared": False,
40+
"fPIC": True,
41+
"with_openmp": False,
42+
"with_libusb": False,
43+
"with_png": True,
44+
"with_qhull": True,
45+
"with_vtk": False,
46+
"with_cuda": False,
47+
"with_pcap": False,
48+
"with_opengl": False,
49+
"with_tools": False,
50+
"with_apps": False,
51+
}
52+
53+
@property
54+
def _min_cppstd(self):
55+
return 17
56+
57+
# in case the project requires C++14/17/20/... the minimum compiler version should be listed
58+
@property
59+
def _compilers_minimum_version(self):
60+
return {
61+
"gcc": "7",
62+
"clang": "7",
63+
"apple-clang": "10",
64+
}
65+
66+
def export_sources(self):
67+
export_conandata_patches(self)
68+
69+
def config_options(self):
70+
if self.settings.os == "Windows":
71+
del self.options.fPIC
72+
73+
def configure(self):
74+
if self.options.shared:
75+
self.options.rm_safe("fPIC")
76+
77+
def layout(self):
78+
cmake_layout(self, src_folder="src")
79+
80+
def system_requirements(self):
81+
if self.options.with_vtk:
82+
package_manager.Apt(self).install(["libvtk-dev"])
83+
package_manager.Dnf(self).install(["vtk-devel"])
84+
if self.settings.os == "Windows":
85+
self.output.warn("On Windows VTK must be installed manually.")
86+
87+
def requirements(self):
88+
self.requires("zlib/1.2.13")
89+
self.requires("boost/1.82.0")
90+
self.requires("eigen/3.4.0", transitive_headers=True)
91+
self.requires("flann/1.9.1")
92+
if self.options.with_png:
93+
self.requires("libpng/1.6.39")
94+
if self.options.with_qhull:
95+
self.requires("qhull/8.0.1")
96+
if self.options.with_apps:
97+
self.requires("qt/6.5.0")
98+
if self.options.with_libusb:
99+
self.requires("libusb/1.0.26")
100+
if self.options.with_pcap:
101+
self.requires("libpcap/1.10.4")
102+
if self.options.with_opengl:
103+
self.requires("opengl/system")
104+
105+
def validate(self):
106+
# validate the minimum cpp standard supported. For C++ projects only
107+
if self.settings.compiler.cppstd:
108+
check_min_cppstd(self, self._min_cppstd)
109+
check_min_vs(self, 191)
110+
if not is_msvc(self):
111+
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
112+
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
113+
raise ConanInvalidConfiguration(
114+
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
115+
)
116+
# in case it does not work in another configuration, it should validated here too
117+
if is_msvc(self) and self.options.shared:
118+
raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Visual Studio and msvc.")
119+
120+
def source(self):
121+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
122+
123+
def generate(self):
124+
tc = CMakeToolchain(self)
125+
tc.variables["PCL_SHARED_LIBS"] = self.options.shared
126+
tc.variables["WITH_OPENMP"] = self.options.with_openmp
127+
tc.variables["WITH_LIBUSB"] = self.options.with_libusb
128+
tc.variables["WITH_PNG"] = self.options.with_png
129+
tc.variables["WITH_QHULL"] = self.options.with_qhull
130+
tc.variables["WITH_VTK"] = self.options.with_vtk
131+
tc.variables["WITH_CUDA"] = self.options.with_cuda
132+
tc.variables["WITH_PCAP"] = self.options.with_pcap
133+
tc.variables["WITH_OPENGL"] = self.options.with_opengl
134+
tc.variables["BUILD_tools"] = self.options.with_tools
135+
tc.variables["BUILD_apps"] = self.options.with_apps
136+
tc.variables["BUILD_examples"] = True
137+
tc.cache_variables["WITH_QT"] = self.options.with_apps
138+
tc.generate()
139+
140+
tc = CMakeDeps(self)
141+
tc.generate()
142+
143+
def _patch_sources(self):
144+
apply_conandata_patches(self)
145+
146+
def build(self):
147+
self._patch_sources()
148+
cmake = CMake(self)
149+
cmake.configure()
150+
cmake.build()
151+
152+
def package(self):
153+
copy(self, pattern="LICENSE.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
154+
cmake = CMake(self)
155+
cmake.install()
156+
157+
rmdir(self, os.path.join(self.package_folder, "share"))
158+
159+
@property
160+
def _pcl_lib_components(self):
161+
def usb():
162+
return ["libusb::libusb"] if self.options.with_libusb else []
163+
def png():
164+
return ["libpng::libpng"] if self.options.with_png else []
165+
def qhull():
166+
return ["qhull::qhull"] if self.options.with_qhull else []
167+
168+
return {
169+
"common": {"requires": ["eigen::eigen3", "boost::boost"]},
170+
"kdtree": {"requires": ["common", "flann::flann"]},
171+
"octree": {"requires": ["common"]},
172+
"search": {"requires": ["common", "kdtree", "octree", "flann::flann"]},
173+
"sample_consensus": {"requires": ["common", "search"]},
174+
"filters": {"requires": ["common", "sample_consensus", "search", "kdtree", "octree"]},
175+
"2d": {"requires": ["common", "filters"], "header_only": True},
176+
"geometry": {"requires": ["common"], "header_only": True},
177+
"io": {"requires": ["common", "octree", "zlib::zlib"] + png() + usb(), "extra_libs": ["io_ply"]},
178+
"features": {"requires": ["common", "search", "kdtree", "octree", "filters", "2d"]},
179+
"ml": {"requires": ["common"]},
180+
"segmentation": {"requires": ["common", "geometry", "search", "sample_consensus", "kdtree", "octree", "features", "filters", "ml"]},
181+
"surface": {"requires": ["common", "search", "kdtree", "octree"] + qhull()},
182+
"registration": {"requires": ["common", "octree", "kdtree", "search", "sample_consensus", "features", "filters"]},
183+
"keypoints": {"requires": ["common", "search", "kdtree", "octree", "features", "filters"]},
184+
"tracking": {"requires": ["common", "search", "kdtree", "filters", "octree"]},
185+
"recognition": {"requires": ["common", "io", "search", "kdtree", "octree", "features", "filters", "registration", "sample_consensus", "ml"]},
186+
"stereo": {"requires": ["common", "io"]}
187+
}
188+
189+
@property
190+
def _version_suffix(self):
191+
semver = Version(self.version)
192+
return "{}.{}".format(semver.major, semver.minor)
193+
194+
def _lib_name(self, lib):
195+
if self.settings.compiler == "msvc" and self.settings.build_type == "Debug":
196+
return "pcl_{}d".format(lib)
197+
return "pcl_{}".format(lib)
198+
199+
def package_info(self):
200+
self.cpp_info.names["cmake_find_package"] = "PCL"
201+
self.cpp_info.names["cmake_find_package_multi"] = "PCL"
202+
203+
self.cpp_info.set_property("cmake_file_name", "PCL")
204+
self.cpp_info.set_property("cmake_module_file_name", "PCL")
205+
self.cpp_info.set_property("cmake_target_name", "PCL::PCL")
206+
207+
def _update_components(components):
208+
for comp, values in components.items():
209+
self.cpp_info.components[comp].names["cmake_find_package"] = comp
210+
self.cpp_info.components[comp].names["cmake_find_package_multi"] = comp
211+
self.cpp_info.components[comp].set_property("cmake_file_name", comp)
212+
self.cpp_info.components[comp].set_property("cmake_module_file_name", comp)
213+
self.cpp_info.components[comp].set_property("cmake_target_name", f"PCL::{comp}")
214+
215+
self.cpp_info.components[comp].names["pkg_config"] = "pcl_{}-{}".format(comp, self._version_suffix)
216+
self.cpp_info.components[comp].set_property("pkg_config_name", "pcl_{}-{}".format(comp, self._version_suffix))
217+
218+
self.cpp_info.components[comp].includedirs = [os.path.join("include", "pcl-{}".format(self._version_suffix))]
219+
if not values.get("header_only", False):
220+
libs = [comp] + values.get("extra_libs", [])
221+
self.cpp_info.components[comp].libs = [self._lib_name(lib) for lib in libs]
222+
self.cpp_info.components[comp].requires = values["requires"]
223+
224+
_update_components(self._pcl_lib_components)
225+
226+
if not self.options.shared:
227+
if self.settings.os in ["Linux", "FreeBSD"]:
228+
self.cpp_info.components["common"].system_libs.append("pthread")
229+
if self.options.with_openmp:
230+
if self.settings.os == "Linux":
231+
if self.settings.compiler == "gcc":
232+
self.cpp_info.components["common"].sharedlinkflags.append("-fopenmp")
233+
self.cpp_info.components["common"].exelinkflags.append("-fopenmp")
234+
elif self.settings.os == "Windows":
235+
if self.settings.compiler == "msvc":
236+
self.cpp_info.components["common"].system_libs.append("delayimp")
237+
elif self.settings.compiler == "gcc":
238+
self.cpp_info.components["common"].system_libs.append("gomp")
239+
240+
if self.options.with_apps:
241+
self.cpp_info.components["apps"].libs = []
242+
self.cpp_info.components["apps"].requires = ["qt::qt"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- a/cmake/pcl_targets.cmake
2+
+++ b/cmake/pcl_targets.cmake
3+
@@ -571,9 +571,6 @@ function(PCL_MAKE_PKGCONFIG _name)
4+
else()
5+
configure_file(${PROJECT_SOURCE_DIR}/cmake/pkgconfig.cmake.in ${_pc_file} @ONLY)
6+
endif()
7+
- install(FILES ${_pc_file}
8+
- DESTINATION ${PKGCFG_INSTALL_DIR}
9+
- COMPONENT pcl_${ARGS_COMPONENT})
10+
endfunction()
11+
12+
###############################################################################

0 commit comments

Comments
 (0)