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

libelas: new recipe #23795

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions recipes/libelas/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Adapted from the original CMakeLists.txt
# mirror: https://github.com/kou1okada/libelas/blob/master/CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(libelas LANGUAGES CXX)

if(USE_SSE3)
if(MSVC)
add_compile_options(/arch:SSE3)
else()
add_compile_options(-msse3)
endif()
endif()

find_package(OpenMP REQUIRED)

add_library(elas
descriptor.cpp
elas.cpp
filter.cpp
matrix.cpp
triangle.cpp
)

target_link_libraries(elas PRIVATE OpenMP::OpenMP_CXX)

install(TARGETS elas
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(FILES elas.h DESTINATION include)
13 changes: 13 additions & 0 deletions recipes/libelas/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
"cci.20150630":
sources:
url: "https://www.cvlibs.net/downloads/libelas_omp.zip"
sha256: "636db6e10a053c84d3b1de3baa8224e0ded6caf4bae27021a5293ead37894ad3"
license:
url: "https://raw.githubusercontent.com/kou1okada/libelas/master/README.TXT"
sha256: "627924f4cb0fe790de303fe721233d227a6d0c1734ed39fa4641923dcb9c5b8f"
patches:
"cci.20150630":
- patch_file: "patches/001-fix-cast.patch"
patch_type: "portability"
patch_description: "Add a missing explicit cast from int to float"
83 changes: 83 additions & 0 deletions recipes/libelas/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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, CMakeToolchain, cmake_layout, CMakeDeps
from conan.tools.files import copy, get, rm, download, load, save, export_conandata_patches, apply_conandata_patches

required_conan_version = ">=1.53.0"


class LibelasConan(ConanFile):
name = "libelas"
description = "LIBELAS is a C++ library for computing disparity maps from rectified graylevel stereo pairs"
license = "GPL-3.0-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.cvlibs.net/software/libelas/"
topics = ("computer-vision", "stereo-matching", "disparity", "depth")

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

def export_sources(self):
export_conandata_patches(self)
copy(self, "CMakeLists.txt", 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")

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

def requirements(self):
self.requires("llvm-openmp/17.0.6")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, 98)
if self.settings.arch not in ["x86", "x86_64"]:
raise ConanInvalidConfiguration("Only x86 and x86_64 architectures are supported")

def source(self):
get(self, **self.conan_data["sources"][self.version]["sources"], strip_root=True)
download(self, **self.conan_data["sources"][self.version]["license"], filename="README.TXT")

def generate(self):
tc = CMakeToolchain(self)
tc.variables["USE_SSE3"] = self.settings.arch in ["x86", "x86_64"]
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def _read_license(self):
content = load(self, os.path.join(self.source_folder, "README.TXT"))
return "\n".join(content.splitlines()[:46])

def package(self):
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), self._read_license())
cmake = CMake(self)
cmake.install()
rm(self, "*.pdb", self.package_folder, recursive=True)

def package_info(self):
self.cpp_info.libs = ["elas"]
13 changes: 13 additions & 0 deletions recipes/libelas/all/patches/001-fix-cast.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Fix
error: non-constant-expression cannot be narrowed from type 'int32_t' (aka 'int') to 'float' in initializer list [-Wc++11-narrowing]
--- elas.cpp
+++ elas.cpp
@@ -874,7 +874,7 @@
tri_u[1] = p_support[c2].u-p_support[c2].d;
tri_u[2] = p_support[c3].u-p_support[c3].d;
}
- float tri_v[3] = {p_support[c1].v,p_support[c2].v,p_support[c3].v};
+ float tri_v[3] = {static_cast<float>(p_support[c1].v), static_cast<float>(p_support[c2].v), static_cast<float>(p_support[c3].v)};

for (uint32_t j=0; j<3; j++) {
for (uint32_t k=0; k<j; k++) {
8 changes: 8 additions & 0 deletions recipes/libelas/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(libelas REQUIRED CONFIG)

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

int main() {
Elas::parameters param;
Elas elas(param);
}
3 changes: 3 additions & 0 deletions recipes/libelas/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20150630":
folder: all
Loading