Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stella-cv-fbow: new recipe #23889

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/stella-cv-fbow/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"cci.20240508":
url: "https://github.com/stella-cv/FBoW/archive/c6e3c29e3332a0b0834021797e2aa4e8eb66a3c1.zip"
sha256: "23d866d86eaca6a85da8fe3e542b94324d5f6be4b37691cf82cd74a6cfd838bd"
127 changes: 127 additions & 0 deletions recipes/stella-cv-fbow/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.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rm, rmdir, replace_in_file

required_conan_version = ">=1.53.0"


class StellaCvFbowConan(ConanFile):
name = "stella-cv-fbow"
description = "FBoW (Fast Bag of Words) is an extremely optimized version of the DBoW2/DBoW3 libraries."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/stella-cv/FBoW"
topics = ("bag-of-words", "computer-vision", "visual-slam", "dbow")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"fast_math": [True, False],
"avx": [True, False],
"mmx": [True, False],
"sse": [True, False],
"sse2": [True, False],
"sse3": [True, False],
"sse4": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"fast_math": True,
"avx": True,
"mmx": True,
"sse": True,
"sse2": True,
"sse3": True,
"sse4": True,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.arch not in ["x86", "x86_64"] or self.settings.compiler not in ["gcc", "clang", "apple-clang"]:
del self.options.avx
del self.options.mmx
del self.options.sse
del self.options.sse2
del self.options.sse3
del self.options.sse4

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

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

def requirements(self):
# https://github.com/stella-cv/FBoW/blob/master/include/fbow/vocabulary.h#L35
self.requires("opencv/4.9.0", transitive_headers=True, transitive_libs=True)
self.requires("llvm-openmp/17.0.6")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, 11)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["USE_FAST_MATH"] = self.options.fast_math
tc.variables["USE_AVX"] = self.options.get_safe("avx", False)
tc.variables["USE_MMX"] = self.options.get_safe("mmx", False)
tc.variables["USE_SSE"] = self.options.get_safe("sse", False)
tc.variables["USE_SSE2"] = self.options.get_safe("sse2", False)
tc.variables["USE_SSE3"] = self.options.get_safe("sse3", False)
tc.variables["USE_SSE4"] = self.options.get_safe("sse4", False)
tc.variables["BUILD_UTILS"] = False
tc.variables["BUILD_TESTS"] = False
tc.variables["USE_CONTRIB"] = self.dependencies["opencv"].options.xfeatures2d
tc.generate()

tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
# Let Conan set the C++ standard
if self.settings.compiler.cppstd:
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, "share"))
rm(self, "*.pdb", self.package_folder, recursive=True)

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "fbow")
self.cpp_info.set_property("cmake_target_name", "fbow::fbow")
# unofficial
self.cpp_info.set_property("pkg_config_name", "fbow")

self.cpp_info.libs = ["fbow"]
self.cpp_info.requires = [
"opencv::opencv_core",
"opencv::opencv_features2d",
"opencv::opencv_highgui",
"llvm-openmp::llvm-openmp",
]
if self.dependencies["opencv"].options.xfeatures2d:
self.cpp_info.requires.append("opencv::opencv_xfeatures2d")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])
8 changes: 8 additions & 0 deletions recipes/stella-cv-fbow/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(fbow REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE fbow::fbow)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
26 changes: 26 additions & 0 deletions recipes/stella-cv-fbow/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")
10 changes: 10 additions & 0 deletions recipes/stella-cv-fbow/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <fbow/fbow.h>
#include <fbow/cpu.h>
#include <iostream>

int main() {
auto features = fbow::cpu();
features.detect_host();
std::cout << "CPU Vendor String: " << fbow::cpu::get_vendor_string() << '\n';
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
std::cout << "64-bit = " << features.OS_x64 << '\n';
}
3 changes: 3 additions & 0 deletions recipes/stella-cv-fbow/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20240508":
folder: all
Loading