Skip to content

Commit

Permalink
(#12210) sophus: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* explicit cpp_info.requires

due to conan-io/conan#11789
fixed by conan-io/conan#11790

* use self.info.clear() instead of self.info.header_only()
  • Loading branch information
SpaceIm authored Aug 24, 2022
1 parent 3f703bc commit 5da4566
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 88 deletions.
7 changes: 0 additions & 7 deletions recipes/sophus/all/CMakeLists.txt

This file was deleted.

49 changes: 30 additions & 19 deletions recipes/sophus/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from conans import ConanFile, tools
from conans.tools import Version
from conan import ConanFile
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.50.0"


class SophusConan(ConanFile):
name = "sophus"
description = "C++ implementation of Lie Groups using Eigen."
topics = ("conan", "eigen", "numerical", "math")
topics = ("eigen", "numerical", "math")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://strasdat.github.io/Sophus/"
license = "MIT"
Expand All @@ -21,35 +24,43 @@ class SophusConan(ConanFile):
"with_fmt": True,
}

@property
def _source_subfolder(self):
return "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name.capitalize() + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def requirements(self):
self.requires("eigen/3.4.0")
if self.options.with_fmt and Version(self.version) >= Version("22.04.1"):
self.requires("fmt/8.1.1")

def package(self):
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*.hpp", src=os.path.join(self._source_subfolder, "sophus"), dst=os.path.join("include", "sophus"), keep_path=False)

def package_id(self):
self.info.header_only()
self.info.clear()

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

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

def package(self):
copy(self, "LICENSE.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "*.hpp", src=os.path.join(self.source_folder, "sophus"),
dst=os.path.join(self.package_folder, "include", "sophus"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Sophus")
self.cpp_info.set_property("cmake_target_name", "Sophus::Sophus")
self.cpp_info.set_property("pkg_config_name", "sophus")

self.cpp_info.bindirs = []
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
if not self.options.with_fmt:
self.cpp_info.defines.append("SOPHUS_USE_BASIC_LOGGING=1")

# TODO: remove this block if required_conan_version changed to 1.51.1 or higher
# (see https://github.com/conan-io/conan/pull/11790)
self.cpp_info.requires = ["eigen::eigen"]
if self.options.with_fmt and Version(self.version) >= Version("22.04.1"):
self.cpp_info.requires.append("fmt::fmt")

# TODO: to remove in conan v2 once cmake_find_package* generator removed
self.cpp_info.names["cmake_find_package"] = "Sophus"
self.cpp_info.names["cmake_find_package_multi"] = "Sophus"
8 changes: 0 additions & 8 deletions recipes/sophus/all/test_cmakedeps/CMakeLists.txt

This file was deleted.

26 changes: 0 additions & 26 deletions recipes/sophus/all/test_cmakedeps/conanfile.py

This file was deleted.

16 changes: 0 additions & 16 deletions recipes/sophus/all/test_cmakedeps/test_package.cpp

This file was deleted.

9 changes: 3 additions & 6 deletions recipes/sophus/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(Sophus REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
target_link_libraries(${PROJECT_NAME} Sophus::Sophus)
target_link_libraries(${PROJECT_NAME} PRIVATE Sophus::Sophus)
20 changes: 14 additions & 6 deletions recipes/sophus/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

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 not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/sophus/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(Sophus REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
target_link_libraries(${PROJECT_NAME} PRIVATE Sophus::Sophus)
18 changes: 18 additions & 0 deletions recipes/sophus/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pylint: skip-file
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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)

0 comments on commit 5da4566

Please sign in to comment.