Skip to content

Commit

Permalink
glim: new recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 18, 2024
1 parent 5f85cba commit 7814b45
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 0 deletions.
9 changes: 9 additions & 0 deletions recipes/glim/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
127 changes: 127 additions & 0 deletions recipes/glim/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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])
55 changes: 55 additions & 0 deletions recipes/glim/all/patches/0001-cmake-fixes.patch
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json/include>
$<INSTALL_INTERFACE:include>
${OpenCV_INCLUDE_DIRS}
)
@@ -97,6 +97,7 @@ target_link_libraries(glim
gtsam_points::gtsam_points
OpenMP::OpenMP_CXX
spdlog::spdlog
+ nlohmann_json::nlohmann_json
$<TARGET_NAME_IF_EXISTS:Iridescence::Iridescence>
${OpenCV_LIBRARIES}
)
--
2.25.1

8 changes: 8 additions & 0 deletions recipes/glim/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(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)
26 changes: 26 additions & 0 deletions recipes/glim/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions recipes/glim/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <glim/common/imu_integration.hpp>

#include <iostream>

int main() {
glim::IMUIntegration imu_integration;
std::cout << "Number of IMU values in queue: " << imu_integration.imu_data_in_queue().size() << std::endl;
}
3 changes: 3 additions & 0 deletions recipes/glim/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.0":
folder: all

0 comments on commit 7814b45

Please sign in to comment.