(#7408) Add opengv recipe

* Add opengv recipe

* Let conan handle fPIC / shared

* Add option to build python bindings

* Try to fix M1 builds

* Fix syntax

* use tools.collect_libs() since the library name changes on Windows

* Raise if windows+release

* Disable Windows builds all together.

* Create a _patch_sources() function that handles all the patching.

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Disable shared builds with gcc5 since CCI errors out due to exessive RAM usage

* Fix typo

* Disable shared builds on gcc since they error out on CCI

Co-authored-by: Uilian Ries <uilianries@gmail.com>
This commit is contained in:
Eric Riff
2021-10-11 16:02:36 -03:00
committed by GitHub
parent 360bb17555
commit 98de1a2f79
7 changed files with 219 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1.2)
project(cmake_wrapper)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_subdirectory(source_subfolder)

View File

@@ -0,0 +1,4 @@
sources:
"cci.20200806":
url: "https://github.com/laurentkneip/opengv/archive/91f4b19c73450833a40e463ad3648aae80b3a7f3.tar.gz"
sha256: "b03f61ff597a6c16a32b8939c3e49e9f240ae7b4da3358f1430e9743e093d596"

View File

@@ -0,0 +1,148 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import textwrap
required_conan_version = ">=1.33.0"
class opengvConan(ConanFile):
name = "opengv"
description = "A collection of computer vision methods for solving geometric vision problems"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/laurentkneip/opengv"
license = "BSD-3-Clause"
topics = ("computer", "vision", "geometric", "pose", "triangulation", "point-cloud")
exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_python_bindings": [True, False]
}
default_options = {
"shared": False,
"fPIC": False,
"with_python_bindings": False
}
_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")
@property
def _module_file_rel_path(self):
return os.path.join(self._module_subfolder,
"conan-official-{}-targets.cmake".format(self.name))
@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)
def validate(self):
# Disable windows builds since they error out.
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("Windows builds are not supported by this recipe.")
#FIXME disable this one CCI has more RAM available
if (self.settings.compiler == "gcc" and self.options.shared):
raise ConanInvalidConfiguration("Shared builds not supported with gcc since CCI errors out due to excessive memory usage.")
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
del self.options.fPIC
def requirements(self):
self.requires("eigen/3.4.0")
if self.options.with_python_bindings:
self.requires("pybind11/2.7.1")
def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_PYTHON"] = self.options.with_python_bindings
if self.settings.os == "Macos" and self.settings.arch == "armv8":
self._cmake.definitions["CMAKE_SYSTEM_PROCESSOR"] = "aarch64"
self._cmake.configure()
return self._cmake
def _patch_sources(self):
# Use conan's Eigen
old = """\
find_package(Eigen REQUIRED)
set(ADDITIONAL_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIR}/unsupported)"""
new = """\
find_package(Eigen3 REQUIRED)
set(ADDITIONAL_INCLUDE_DIRS ${Eigen3_INCLUDE_DIRS} ${Eigen3_INCLUDE_DIR}/unsupported)"""
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
textwrap.dedent(old),
textwrap.dedent(new)
)
# Use conan's pybind11
tools.replace_in_file(os.path.join(self._source_subfolder, "python", "CMakeLists.txt"),
"add_subdirectory(pybind11)",
"find_package(pybind11 REQUIRED)"
)
# Let conan handle fPIC / shared
old = """\
IF(MSVC)
set(BUILD_SHARED_LIBS OFF)"""
new = """\
IF(1)
#set(BUILD_SHARED_LIBS OFF)"""
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
textwrap.dedent(old),
textwrap.dedent(new)
)
def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"opengv": "opengv::opengv"}
)
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.builddirs.append(self._module_subfolder)
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
if self.options.with_python_bindings:
self.env_info.PYTHONPATH = os.path.join(self.package_folder, "lib", "python3", "dist-packages")

View File

@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package(opengv REQUIRED)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} opengv)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

View File

@@ -0,0 +1,16 @@
import os
from conans import ConanFile, CMake, tools
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

View File

@@ -0,0 +1,30 @@
#include <opengv/math/roots.hpp>
#include <vector>
#include <iostream>
int main() {
std::vector<double> poly {1.0, -2.0, -5.0, 6.0};
std::vector<double> computed_roots = opengv::math::o3_roots(poly);
std::vector<double> expected_roots {-2.0, 3.0, 1.0};
std::cout << "Computed roots: ";
for (auto i = computed_roots.begin(); i != computed_roots.end(); ++i)
std::cout << *i << ' ';
std::cout << std::endl;
std::cout << "Expected roots: ";
for (auto i = expected_roots.begin(); i != expected_roots.end(); ++i)
std::cout << *i << ' ';
std::cout << std::endl;
if (computed_roots != expected_roots) {
std::cout << "The calculated roots do not match the expected ones" << std::endl;
return 1;
}
std::cout << "Success" << std::endl;
return 0;
}

View File

@@ -0,0 +1,3 @@
versions:
"cci.20200806":
folder: all