forked from neka-nat/cupoch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconanfile.py
290 lines (254 loc) · 10.8 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import sys
from pathlib import Path
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, rm
required_conan_version = ">=1.53.0"
MODULE_DEPS = {
"camera": [],
"collision": ["geometry"],
"geometry": ["camera", "knn"],
"imageproc": ["geometry"],
"integration": ["camera", "geometry"],
"io": ["geometry"],
"kinematics": ["collision", "io"],
"kinfu": ["camera", "geometry", "integration", "registration"],
"knn": [],
"odometry": ["camera", "geometry"],
"planning": ["collision", "geometry"],
"registration": ["geometry", "knn"],
"visualization": ["camera", "geometry", "io"],
}
MODULES = sorted(MODULE_DEPS)
class CupochConan(ConanFile):
name = "cupoch"
version = "0.2.10.0"
package_type = "library"
license = "MIT"
author = "[email protected]"
url = "https://github.com/neka-nat/cupoch"
description = "Rapid 3D data processing for robotics using CUDA."
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"cuda_architectures": ["native", "all", "all-major", "ANY"],
"use_rmm": [True, False],
}
options.update({module: [True, False] for module in MODULES})
default_options = {
"shared": False,
"fPIC": True,
"cuda_architectures": "native",
"use_rmm": True,
}
default_options.update({module: True for module in MODULES})
options_description = {
"shared": "Build shared libraries, static otherwise.",
"fPIC": "Enable position-independent code.",
"cuda_architectures": (
"Sets the CUDA architectures to generate device code for via CMAKE_CUDA_ARCHITECTURES. "
),
"use_rmm": "Use RAPIDS Memory Manager for memory management.",
}
exports = ["third_party/conan-recipes/*"]
exports_sources = [
"cmake/*",
"include/*",
"src/cupoch/*",
"src/tests/*",
"src/CMakeLists.txt",
"scripts/*",
"third_party/*",
"CMakeLists.txt",
"LICENSE",
]
@property
def _enabled_modules(self):
# The list of requested modules together with their dependencies
def add_deps(modules):
for dep in modules:
if dep not in mods:
mods.add(dep)
add_deps(MODULE_DEPS[dep])
if not hasattr(self, "_enabled_modules_cache"):
mods = set()
add_deps([mod for mod in MODULES if self.options.get_safe(mod, False)])
self._enabled_modules_cache = sorted(mods)
return self._enabled_modules_cache
@property
def _with_unit_tests(self):
# Unit tests are not built or run by default.
# Add '-c tools.build:skip_test=false' to command line args to enable.
return not self.conf.get("tools.build:skip_test", default=True, check_type=bool)
def _export_local_recipes(self):
self.output.info("Exporting recipes for dependencies that are not yet available in ConanCenter")
recipes_root = Path(self.recipe_folder) / "third_party" / "conan-recipes"
for pkg_dir in recipes_root.iterdir():
if pkg_dir.is_dir():
conan = sys.argv[0]
self.run(f"{conan} export {pkg_dir} --user cupoch")
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
del self.options.use_rmm
def configure(self):
if self.options.shared:
del self.options.fPIC
self.options["thrust"].device_system = "cuda"
self.options["stdgpu"].backend = "cuda"
def package_id(self):
for module in self._enabled_modules:
setattr(self.info.options, module, True)
def layout(self):
cmake_layout(self)
def requirements(self):
self._export_local_recipes()
# Used by all modules via cupoch_utility
self.requires("eigen/3.4.0-20230718@cupoch", transitive_headers=True, transitive_libs=True)
self.requires("spdlog/1.13.0", transitive_headers=True, transitive_libs=True, force=True)
self.requires("thrust/2.2.0@cupoch", transitive_headers=True, transitive_libs=True, force=True)
self.requires("libcudacxx/2.2.0@cupoch", override=True)
self.requires("cub/2.2.0@cupoch", override=True)
self.requires("stdgpu/cci.20240211@cupoch", transitive_headers=True, transitive_libs=True)
self.requires("dlpack/0.8")
self.requires("jsoncpp/1.9.5")
self.requires("fmt/10.2.1", override=True)
if self.options.get_safe("use_rmm"):
self.requires("rmm/23.10.00", transitive_headers=True, transitive_libs=True)
modules = self._enabled_modules
self.output.info("Enabled modules:", modules)
if "imageproc" in modules:
self.requires("libsgm/3.0.0@cupoch", transitive_headers=True, transitive_libs=True)
if "io" in modules:
self.requires("libjpeg-turbo/3.0.2")
self.requires("libpng/1.6.42")
self.requires("rply/1.1.4")
self.requires("tinyobjloader/2.0.0-rc10")
self.requires("liblzf/3.6")
if "kinematics" in modules:
self.requires("urdfdom/4.0.0")
if "visualization" in modules:
self.requires("glew/2.2.0")
self.requires("glfw/3.3.8")
self.requires("imgui/1.90.4-docking")
def build_requirements(self):
# For native/all/all-major CUDA architectures support
self.tool_requires("cmake/[>=3.24]")
self.test_requires("gtest/1.14.0")
def _copy_imgui_backends(self):
# The imgui backends are not built by default and need to be copied to the source tree
backends_dir = Path(self.dependencies["imgui"].package_folder) / "res" / "bindings"
output_dir = self.source_path.joinpath(
"src", "cupoch", "visualization", "visualizer", "imgui", "backends"
)
for backend_file in [
"imgui_impl_glfw.h",
"imgui_impl_glfw.cpp",
"imgui_impl_opengl3.h",
"imgui_impl_opengl3_loader.h",
"imgui_impl_opengl3.cpp",
]:
copy(self, backend_file, backends_dir, output_dir)
def generate(self):
VirtualBuildEnv(self).generate()
tc = CMakeToolchain(self)
# Do not set CXX, C flags from Conan to avoid adding -stdlib=libstdc++
tc.blocks.remove("cmake_flags_init")
tc.cache_variables["BUILD_UNIT_TESTS"] = self._with_unit_tests
tc.cache_variables["BUILD_EXAMPLES"] = False
tc.cache_variables["BUILD_PYTHON_MODULE"] = False
tc.cache_variables["USE_RMM"] = self.options.get_safe("use_rmm", False)
tc.cache_variables["CMAKE_CUDA_ARCHITECTURES"] = self.options.cuda_architectures
for module in MODULES:
tc.cache_variables[f"BUILD_cupoch_{module}"] = module in self._enabled_modules
tc.generate()
deps = CMakeDeps(self)
# Make find_package() fail if any required components are missing
deps.check_components_exist = True
deps.generate()
if "visualization" in self._enabled_modules:
self._copy_imgui_backends()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
if self._with_unit_tests:
cmake.test()
def package(self):
cmake = CMake(self)
cmake.install()
for cmake_module in ["cupoch_cuda_flags.cmake", "cuda_architecture_macros.cmake"]:
copy(self, cmake_module,
dst=self.package_path / "lib" / "cmake",
src=self.source_path / "cmake")
copy(self, "LICENSE",
dst=self.package_path / "licenses",
src=self.source_path)
rm(self, "*.pdb", self.package_path, recursive=True)
def _module_reqs(self, component):
reqs = {
"utility": [
"eigen::eigen",
"spdlog::spdlog",
"thrust::thrust",
"stdgpu::stdgpu",
"dlpack::dlpack",
"jsoncpp::jsoncpp",
],
"imageproc": [
"libsgm::libsgm",
],
"io": [
"libjpeg-turbo::libjpeg-turbo",
"libpng::libpng",
"rply::rply",
"tinyobjloader::tinyobjloader",
"liblzf::liblzf",
],
"kinematics": [
"urdfdom::urdfdom",
],
"visualization": [
"glew::glew",
"glfw::glfw",
"imgui::imgui",
],
}
return reqs.get(component, [])
def package_info(self):
for module in self._enabled_modules + ["utility"]:
component = self.cpp_info.components[module]
component.libs += [f"cupoch_{module}"]
component.defines.append(f"CUPOCH_{module.upper()}_ENABLED")
component.requires = MODULE_DEPS.get(module, [])
component.requires += self._module_reqs(module)
if module != "utility":
component.requires.append("utility")
self.cpp_info.components["cupoch"].requires.append(module)
if "knn" in self._enabled_modules:
self.cpp_info.components["flann_cuda"].libs = ["flann_cuda_s"]
self.cpp_info.components["flann_cuda"].defines = ["FLANN_USE_CUDA"]
self.cpp_info.components["knn"].requires.append("flann_cuda")
if self.options.get_safe("use_rmm"):
self.cpp_info.components["utility"].requires.append("rmm::rmm")
self.cpp_info.components["utility"].defines.append("USE_RMM")
if "flann_cuda" in self.cpp_info.components:
self.cpp_info.components["flann_cuda"].requires.append("rmm::rmm")
self.cpp_info.components["flann_cuda"].defines.append("USE_RMM")
# Propagate necessary build flags
utility = self.cpp_info.components["utility"]
utility.defines.append("_USE_MATH_DEFINES")
if self.settings.os == "Windows":
utility.cxxflags += ["/EHsc", "/Zc:__cplusplus", "/bigobj"]
utility.defines.append("_ENABLE_EXTENDED_ALIGNED_STORAGE")
utility.defines.append("_CRT_SECURE_NO_DEPRECATE")
utility.defines.append("_CRT_NONSTDC_NO_DEPRECATE")
utility.defines.append("_SCL_SECURE_NO_WARNINGS")
utility.defines.append("THRUST_CPP11_REQUIRED_NO_ERROR")
utility.defines.append("NOMINMAX")
# Export CUDA dependencies and flags
cmake_dir = Path("lib", "cmake")
self.cpp_info.builddirs.append(cmake_dir)
self.cpp_info.set_property("cmake_build_modules", [cmake_dir / "cupoch_cuda_flags.cmake"])