From 7814b452ae9833842f863e8a1d33e7fb4c46dbcf Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 18 Jul 2024 20:13:39 +0300 Subject: [PATCH] glim: new recipe --- recipes/glim/all/conandata.yml | 9 ++ recipes/glim/all/conanfile.py | 127 ++++++++++++++++++ .../glim/all/patches/0001-cmake-fixes.patch | 55 ++++++++ recipes/glim/all/test_package/CMakeLists.txt | 8 ++ recipes/glim/all/test_package/conanfile.py | 26 ++++ .../glim/all/test_package/test_package.cpp | 8 ++ recipes/glim/config.yml | 3 + 7 files changed, 236 insertions(+) create mode 100644 recipes/glim/all/conandata.yml create mode 100644 recipes/glim/all/conanfile.py create mode 100644 recipes/glim/all/patches/0001-cmake-fixes.patch create mode 100644 recipes/glim/all/test_package/CMakeLists.txt create mode 100644 recipes/glim/all/test_package/conanfile.py create mode 100644 recipes/glim/all/test_package/test_package.cpp create mode 100644 recipes/glim/config.yml diff --git a/recipes/glim/all/conandata.yml b/recipes/glim/all/conandata.yml new file mode 100644 index 0000000000000..c9957ff83976e --- /dev/null +++ b/recipes/glim/all/conandata.yml @@ -0,0 +1,9 @@ +sources: + "1.0.0": + url: "https://github.com/koide3/glim/archive/refs/tags/v1.0.0.tar.gz" + sha256: "51861ddeb322478c101fa4953f0fca09102d493f2bb176d7d4f70bb4678c5bb8" +patches: + "1.0.0": + - patch_file: "patches/0001-cmake-fixes.patch" + patch_description: "Unvendor dependencies, misc CMake fixes" + patch_type: "conan" diff --git a/recipes/glim/all/conanfile.py b/recipes/glim/all/conanfile.py new file mode 100644 index 0000000000000..57713b6ad0cab --- /dev/null +++ b/recipes/glim/all/conanfile.py @@ -0,0 +1,127 @@ +import os + +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.files import apply_conandata_patches, export_conandata_patches, get, rmdir +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" + + +class GlimPackage(ConanFile): + name = "glim" + description = "GLIM: versatile and extensible range-based 3D localization and mapping framework" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/koide3/glim" + topics = ("localization", "mapping", "gpu", "ros", "imu", "lidar", "slam", "3d", "rgb-d") + + package_type = "shared-library" + settings = "os", "arch", "compiler", "build_type" + options = { + "march_native": [True, False], + "cuda": [True, False], + "viewer": [True, False], + } + default_options = { + "march_native": False, + "cuda": False, + "viewer": True, + } + + @property + def _min_cppstd(self): + return 17 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "9", + "clang": "10", + "apple-clang": "12", + "Visual Studio": "16", + "msvc": "192", + } + + def export_sources(self): + export_conandata_patches(self) + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("boost/1.85.0", transitive_headers=True, force=True) + self.requires("eigen/3.4.0", transitive_headers=True) + self.requires("opencv/4.9.0", transitive_headers=True, transitive_libs=True) + self.requires("gtsam/4.2", transitive_headers=True, transitive_libs=True) + self.requires("gtsam_points/1.0.0", transitive_headers=True, transitive_libs=True) + self.requires("nlohmann_json/3.11.3", transitive_headers=True) + self.requires("openmp/system") + self.requires("spdlog/1.14.1", transitive_headers=True) + if self.options.viewer: + self.requires("iridescence/cci.20240709", 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 source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["BUILD_WITH_MARCH_NATIVE"] = self.options.march_native + tc.variables["BUILD_WITH_CUDA"] = self.options.cuda + tc.variables["BUILD_WITH_VIEWER"] = self.options.viewer + tc.generate() + + deps = CMakeDeps(self) + deps.set_property("gtsam", "cmake_target_name", "GTSAM::GTSAM") + deps.generate() + + def _patch_sources(self): + apply_conandata_patches(self) + rmdir(self, os.path.join(self.source_folder, "thirdparty")) + + def build(self): + self._patch_sources() + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + # copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "glim") + self.cpp_info.set_property("cmake_target_name", "glim::glim") + + self.cpp_info.libs = [ + "glim", + "global_mapping", + "global_mapping_pose_graph", + "odometry_estimation_cpu", + "odometry_estimation_ct", + "sub_mapping", + "sub_mapping_passthrough", + ] + if self.options.viewer: + self.cpp_info.libs += [ + "interactive_viewer", + "standard_viewer", + ] + + # TODO: add CUDA support + # self.cpp_info.builddirs.append(os.path.join("lib", "cmake")) + # cmake_module = os.path.join("lib", "cmake", "conan-cuda-dependency.cmake") + # self.cpp_info.set_property("cmake_build_modules", [cmake_module]) diff --git a/recipes/glim/all/patches/0001-cmake-fixes.patch b/recipes/glim/all/patches/0001-cmake-fixes.patch new file mode 100644 index 0000000000000..a11ec4c26ce18 --- /dev/null +++ b/recipes/glim/all/patches/0001-cmake-fixes.patch @@ -0,0 +1,55 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 62baabd..d485686 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,7 +1,9 @@ +-cmake_minimum_required(VERSION 3.5) ++cmake_minimum_required(VERSION 3.15) + project(glim VERSION 0.1.0 LANGUAGES CXX) + +-add_compile_options(-std=c++17) ++if(NOT DEFINED CMAKE_CXX_STANDARD) ++ set(CMAKE_CXX_STANDARD 17) ++endif() + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake") + + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) +@@ -15,10 +17,8 @@ option(BUILD_WITH_VIEWER "Build with visualizer" ON) + option(BUILD_WITH_MARCH_NATIVE "Build with -march=native" OFF) + + if(BUILD_WITH_MARCH_NATIVE) +- add_definitions(-march=native) ++ add_compile_options(-march=native) + add_definitions(-DBUILD_WITH_MARCH_NATIVE) +- set(CMAKE_C_FLAGS "-march=native ${CMAKE_C_FLAGS}") +- set(CMAKE_CXX_FLAGS "-march=native ${CMAKE_CXX_FLAGS}") + endif() + + find_package(Boost REQUIRED serialization) +@@ -28,6 +28,7 @@ find_package(GTSAM REQUIRED) + find_package(gtsam_points REQUIRED) + find_package(OpenMP REQUIRED) + find_package(spdlog REQUIRED) ++find_package(nlohmann_json REQUIRED) + + if(BUILD_WITH_VIEWER) + find_package(Iridescence REQUIRED) +@@ -85,7 +86,6 @@ add_library(glim SHARED + ) + target_include_directories(glim PUBLIC + $ +- $ + $ + ${OpenCV_INCLUDE_DIRS} + ) +@@ -97,6 +97,7 @@ target_link_libraries(glim + gtsam_points::gtsam_points + OpenMP::OpenMP_CXX + spdlog::spdlog ++ nlohmann_json::nlohmann_json + $ + ${OpenCV_LIBRARIES} + ) +-- +2.25.1 + diff --git a/recipes/glim/all/test_package/CMakeLists.txt b/recipes/glim/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..d55fc5af894e9 --- /dev/null +++ b/recipes/glim/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(glim REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE glim::glim) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/glim/all/test_package/conanfile.py b/recipes/glim/all/test_package/conanfile.py new file mode 100644 index 0000000000000..3a91c9439218e --- /dev/null +++ b/recipes/glim/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_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "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.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/glim/all/test_package/test_package.cpp b/recipes/glim/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..ad388259e2ea6 --- /dev/null +++ b/recipes/glim/all/test_package/test_package.cpp @@ -0,0 +1,8 @@ +#include + +#include + +int main() { + glim::IMUIntegration imu_integration; + std::cout << "Number of IMU values in queue: " << imu_integration.imu_data_in_queue().size() << std::endl; +} diff --git a/recipes/glim/config.yml b/recipes/glim/config.yml new file mode 100644 index 0000000000000..40341aa3db6cd --- /dev/null +++ b/recipes/glim/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.0": + folder: all