Skip to content

Commit

Permalink
stella_vslam: new recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed May 6, 2024
1 parent 8997195 commit 9a6bf75
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 2 deletions.
4 changes: 2 additions & 2 deletions recipes/assimp/5.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def _compilers_minimum_version(self):
}

def export_sources(self):
export_conandata_patches(self)
copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))
export_conandata_patches(self)`

Check failure on line 126 in recipes/assimp/5.x/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

invalid syntax (<unknown>, line 126)
copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))`

def config_options(self):
if self.settings.os == "Windows":
Expand Down
7 changes: 7 additions & 0 deletions recipes/stella_vslam/all/conan_deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
find_package(tinycolormap REQUIRED CONFIG)
find_package(nlohmann_json REQUIRED CONFIG)

link_libraries(
tinycolormap::tinycolormap
nlohmann_json::nlohmann_json
)
19 changes: 19 additions & 0 deletions recipes/stella_vslam/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sources:
"0.5.0":
stella_vslam:
url: "https://github.com/stella-cv/stella_vslam/archive/refs/tags/0.5.0.tar.gz"
sha256: "0382df7663d738b2b73f12c193f499faacf68ed497c8e828f1bf880b1ed1ea71"
iridescence_viewer:
url: "https://github.com/stella-cv/iridescence_viewer/archive/c451852585f7df147eb8c7c1f29a24e5557d4251.zip"
sha256: "b4906781cf1ac2b9a1c98672c63761c07b6acbf027e2af0ef41808279a61e663"
pangolin_viewer:
url: "https://github.com/stella-cv/pangolin_viewer/archive/1e0233534055ea3c184dbf6f8b254a0c6c25cee4.zip"
sha256: "eea013614ef82cfa3df019501908e986a8aca6fe923cda5ca3012c78324a536f"
socket_viewer:
url: "https://github.com/stella-cv/socket_viewer/archive/e1e14eec215f5022c84185781ba8d81de22a6f40.zip"
sha256: "0325d1ab801e65f4e10791f9aa81d5ad5d9ce0f10246b03f7074f159199c7f09"
patches:
"0.5.0":
- patch_file: "patches/001-cmake-conan.patch"
patch_description: "Add support for Conan dependencies, unvendor dependencies"
patch_type: "conan"
185 changes: 185 additions & 0 deletions recipes/stella_vslam/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd, valid_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class StellaVslamConan(ConanFile):
name = "stella_vslam"
description = "stella_vslam is a monocular, stereo, and RGBD visual SLAM system."
license = "BSD-2-Clause AND BSD-3-Clause AND MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/project/package"
topics = ("visual-slam", "computer-vision")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_gtsam": [True, False],
"build_iridescence_viewer": [True, False],
"build_pangolin_viewer": [True, False],
"build_socket_viewer": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"build_iridescence_viewer": False,
"build_pangolin_viewer": False,
"build_socket_viewer": False,
"with_gtsam": True,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "16",
"msvc": "192",
"gcc": "8",
"clang": "7",
"apple-clang": "12",
}

def export_sources(self):
export_conandata_patches(self)
copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

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")
self.options["g2o"].build_sba_types = True
self.options["g2o"].build_sim3_types = True
self.options["g2o"].with_csparse = True

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("eigen/3.4.0", transitive_headers=True, transitive_libs=True)
self.requires("g2o/20230806", transitive_headers=True, transitive_libs=True)
self.requires("llvm-openmp/17.0.6")
self.requires("nlohmann_json/3.11.3", transitive_headers=True, transitive_libs=True)
self.requires("opencv/4.9.0", transitive_headers=True, transitive_libs=True)
self.requires("spdlog/1.14.1", transitive_headers=True, transitive_libs=True)
self.requires("sqlite3/3.45.3", transitive_headers=True, transitive_libs=True)
self.requires("stella-cv-fbow/cci.20240107", transitive_headers=True, transitive_libs=True)
self.requires("tinycolormap/cci.20230223", transitive_headers=True, transitive_libs=True)
self.requires("yaml-cpp/0.8.0", transitive_headers=True, transitive_libs=True)
if self.options.with_gtsam:
self.requires("gtsam/4.2", transitive_headers=True, transitive_libs=True)

# TODO: add support for viewers
if self.options.build_iridescence_viewer:
self.requires("iridescence/cci.20240407")
if self.options.build_pangolin_viewer:
self.requires("pangolin/0.9.1")
if self.options.build_socket_viewer:
self.requires("protobuf/3.21.12")
# TODO: add socket.io-client-cpp to CCI
self.requires("socket.io-client-cpp/3.1.0")

def validate(self):
if self.settings.compiler.get_safe("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."
)

if self.options.build_iridescence_viewer:
raise ConanInvalidConfiguration("build_iridescence_viewer option is not yet implemented")
if self.options.build_pangolin_viewer:
raise ConanInvalidConfiguration("build_pangolin_viewer option is not yet implemented")
if self.options.build_socket_viewer:
raise ConanInvalidConfiguration("build_socket_viewer option is not yet implemented")

g2o = self.dependencies["g2o"].options
if not (g2o.build_sba_types and g2o.build_sim3_types and g2o.with_csparse):
raise ConanInvalidConfiguration(
"g2o must be built with g2o/*:build_sba_types=True, "
"g2o/*:build_sim3_types=True and g2o/*:with_csparse options=True"
)

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

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["CMAKE_PROJECT_stella_vslam_INCLUDE"] = "conan_deps.cmake"
tc.variables["USE_ARUCO"] = self.dependencies["opencv"].options.aruco
tc.variables["USE_GTSAM"] = self.options.with_gtsam
if not valid_min_cppstd(self, self._min_cppstd):
tc.variables["CMAKE_CXX_STANDARD"] = self._min_cppstd
# The project unnecessarily tries to find and link SuiteSparse as a transitive dep for g2o
tc.variables["CMAKE_DISABLE_FIND_PACKAGE_SuiteSparse"] = True
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
apply_conandata_patches(self)
rmdir(self, os.path.join(self.source_folder, "3rd"))
# Latest g2o requires C++17 or newer. Let Conan set the C++ standard.
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"set(CMAKE_CXX_STANDARD 11)", "")

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"))
rm(self, "*.pdb", self.package_folder, recursive=True)

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "stella_vslam")
self.cpp_info.set_property("cmake_target_name", "stella_vslam::stella_vslam")

self.cpp_info.libs = ["stella_vslam"]

self.cpp_info.requires = [
"eigen::eigen",
"g2o::g2o",
"llvm-openmp::llvm-openmp",
"nlohmann_json::nlohmann_json",
"opencv::opencv_calib3d",
"opencv::opencv_core",
"opencv::opencv_features2d",
"opencv::opencv_imgproc",
"opencv::opencv_objdetect",
"spdlog::spdlog",
"sqlite3::sqlite3",
"stella-cv-fbow::stella-cv-fbow",
"tinycolormap::tinycolormap",
"yaml-cpp::yaml-cpp",
]
if self.options.with_gtsam:
self.cpp_info.requires.append("gtsam::libgtsam")
if self.dependencies["opencv"].options.aruco:
self.cpp_info.requires.append("opencv::opencv_aruco")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])
45 changes: 45 additions & 0 deletions recipes/stella_vslam/all/patches/001-cmake-conan.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--- src/stella_vslam/CMakeLists.txt
+++ src/stella_vslam/CMakeLists.txt
@@ -25,10 +25,8 @@

# gtsam
set(USE_GTSAM OFF CACHE BOOL "Enable gtsam")
-unset(GTSAM_INCLUDE_DIRS CACHE)
-find_path(GTSAM_INCLUDE_DIRS NAMES gtsam
- PATHS /usr/local/include/)
-if(USE_GTSAM AND GTSAM_INCLUDE_DIRS)
+if(USE_GTSAM)
+ find_package(GTSAM REQUIRED CONFIG)
message(STATUS "gtsam: enabled (Found in ${GTSAM_INCLUDE_DIRS})")
else()
set(USE_GTSAM OFF)
@@ -125,12 +123,12 @@
endif()

if(BOW_FRAMEWORK MATCHES "DBoW2")
- set(BoW_LIBRARY ${DBoW2_LIBS})
+ set(BoW_LIBRARY ${DBoW2_LIBRARIES})
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_DBOW2)
message(STATUS "BoW framework: ${BOW_FRAMEWORK} (found in ${DBoW2_INCLUDE_DIRS})")
elseif(BOW_FRAMEWORK MATCHES "FBoW")
if(fbow_FOUND)
- set(BoW_LIBRARY ${fbow_LIBS})
+ set(BoW_LIBRARY ${fbow_LIBRARIES})
message(STATUS "BoW framework: ${BOW_FRAMEWORK} (found in ${fbow_INCLUDE_DIRS})")
else()
target_include_directories(${PROJECT_NAME}
@@ -226,14 +224,6 @@
install(FILES ${HEADERS}
DESTINATION ${STELLA_VSLAM_INCLUDE_INSTALL_DIR})

-# Install 3rd party headers
-install(FILES ${json_INCLUDE_DIR}/nlohmann/json.hpp ${json_INCLUDE_DIR}/nlohmann/json_fwd.hpp
- DESTINATION ${STELLA_VSLAM_INCLUDE_INSTALL_DIR}/3rd/json/include/nlohmann)
-if(NOT spdlog_FOUND)
- install(DIRECTORY ${spdlog_INCLUDE_DIR}
- DESTINATION ${STELLA_VSLAM_INCLUDE_INSTALL_DIR}/3rd/spdlog)
-endif()
-
# ----- Append subdirectory -----

add_subdirectory(camera)
8 changes: 8 additions & 0 deletions recipes/stella_vslam/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(stella_vslam REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE stella_vslam::stella_vslam)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
26 changes: 26 additions & 0 deletions recipes/stella_vslam/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 requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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")
7 changes: 7 additions & 0 deletions recipes/stella_vslam/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stella_vslam/util/converter.h>

using namespace stella_vslam;

int main() {
util::converter::to_rot_mat(97.37 * M_PI / 180 * Vec3_t{9.0, -8.5, 1.1}.normalized());
}
3 changes: 3 additions & 0 deletions recipes/stella_vslam/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.5.0":
folder: all

0 comments on commit 9a6bf75

Please sign in to comment.