From 5da45664aa31c575ee92c0f20bf5bb54f12f0f9f Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:48:25 +0200 Subject: [PATCH] (#12210) sophus: conan v2 support * conan v2 support * explicit cpp_info.requires due to https://github.com/conan-io/conan/issues/11789 fixed by https://github.com/conan-io/conan/pull/11790 * use self.info.clear() instead of self.info.header_only() --- recipes/sophus/all/CMakeLists.txt | 7 --- recipes/sophus/all/conanfile.py | 49 ++++++++++++------- .../sophus/all/test_cmakedeps/CMakeLists.txt | 8 --- .../sophus/all/test_cmakedeps/conanfile.py | 26 ---------- .../all/test_cmakedeps/test_package.cpp | 16 ------ .../sophus/all/test_package/CMakeLists.txt | 9 ++-- recipes/sophus/all/test_package/conanfile.py | 20 +++++--- .../sophus/all/test_v1_package/CMakeLists.txt | 11 +++++ .../sophus/all/test_v1_package/conanfile.py | 18 +++++++ 9 files changed, 76 insertions(+), 88 deletions(-) delete mode 100644 recipes/sophus/all/CMakeLists.txt delete mode 100644 recipes/sophus/all/test_cmakedeps/CMakeLists.txt delete mode 100644 recipes/sophus/all/test_cmakedeps/conanfile.py delete mode 100644 recipes/sophus/all/test_cmakedeps/test_package.cpp create mode 100644 recipes/sophus/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/sophus/all/test_v1_package/conanfile.py diff --git a/recipes/sophus/all/CMakeLists.txt b/recipes/sophus/all/CMakeLists.txt deleted file mode 100644 index 1848ca5a77c35..0000000000000 --- a/recipes/sophus/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 2.8.12) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory("source_subfolder") diff --git a/recipes/sophus/all/conanfile.py b/recipes/sophus/all/conanfile.py index bade804dee72a..de0219b9e8d9a 100644 --- a/recipes/sophus/all/conanfile.py +++ b/recipes/sophus/all/conanfile.py @@ -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" @@ -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" diff --git a/recipes/sophus/all/test_cmakedeps/CMakeLists.txt b/recipes/sophus/all/test_cmakedeps/CMakeLists.txt deleted file mode 100644 index 15b1d4f2772d3..0000000000000 --- a/recipes/sophus/all/test_cmakedeps/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_package) - -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) diff --git a/recipes/sophus/all/test_cmakedeps/conanfile.py b/recipes/sophus/all/test_cmakedeps/conanfile.py deleted file mode 100644 index d0714cec38218..0000000000000 --- a/recipes/sophus/all/test_cmakedeps/conanfile.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -from conans import ConanFile, tools -from conan.tools.cmake import CMake, CMakeToolchain -from conan.tools.layout import cmake_layout - -required_conan_version = ">=1.43.0" - -class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "CMakeDeps" - - def generate(self): - tc = CMakeToolchain(self) - tc.generate() - - 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): - self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), run_environment=True) diff --git a/recipes/sophus/all/test_cmakedeps/test_package.cpp b/recipes/sophus/all/test_cmakedeps/test_package.cpp deleted file mode 100644 index 02ad5bc7e962a..0000000000000 --- a/recipes/sophus/all/test_cmakedeps/test_package.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#define _USE_MATH_DEFINES -#include -#include - -int main() { - Sophus::Matrix4d random_se3 = Sophus::SE3d::exp(Sophus::Vector6d::Random()).matrix(); - std::cout << "Random SE(3) matrix:\n" << random_se3 << std::endl; - -#ifdef SOPHUS_FMT_PRINT - SOPHUS_FMT_PRINT("Sophus fmt check: {}, {}. (If works should be: 20.0, true)", 20.0, true); -#endif - - std::cout << "Sophus uses EIGEN_VERSION: " << EIGEN_WORLD_VERSION << "." << EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION << std::endl; - - return 0; -} diff --git a/recipes/sophus/all/test_package/CMakeLists.txt b/recipes/sophus/all/test_package/CMakeLists.txt index 3d19ec30eb254..6fd2e8f57ae50 100644 --- a/recipes/sophus/all/test_package/CMakeLists.txt +++ b/recipes/sophus/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/sophus/all/test_package/conanfile.py b/recipes/sophus/all/test_package/conanfile.py index 7e2dfe859bb27..d120a992c06a6 100644 --- a/recipes/sophus/all/test_package/conanfile.py +++ b/recipes/sophus/all/test_package/conanfile.py @@ -1,10 +1,18 @@ -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) @@ -12,6 +20,6 @@ def build(self): 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") diff --git a/recipes/sophus/all/test_v1_package/CMakeLists.txt b/recipes/sophus/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..8a25f45a5a90a --- /dev/null +++ b/recipes/sophus/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/sophus/all/test_v1_package/conanfile.py b/recipes/sophus/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..75c0cd81d2d2f --- /dev/null +++ b/recipes/sophus/all/test_v1_package/conanfile.py @@ -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)