From 4de26d018222c1ea3eb59842b926aec470b1a717 Mon Sep 17 00:00:00 2001 From: Jean-Marco Alameddine Date: Fri, 7 Apr 2023 12:12:59 +0200 Subject: [PATCH] (#16299) cubicinterpolation: modernize for conan 2.0 * compatability of cubic_interpolation with Conan 2.0 * missing newline * use patch from new resource * invalid use of patch * adapt structure for patch * add patch for older version of package * safe delete of fPIC * disable VS<16 * fix VS check * add suggestions by @prince-chrismc * update organization name * clarify TODO in comment * rename patch files and remove duplicate cpp file * Apply suggestions from code review --------- Co-authored-by: Chris Mc --- recipes/cubicinterpolation/all/conandata.yml | 18 ++-- recipes/cubicinterpolation/all/conanfile.py | 102 ++++++++---------- .../all/patches/patch_conanbuildinfo.diff | 24 +++++ .../all/patches/patch_conanbuildinfo.txt | 11 -- .../all/patches/rm_conan_basic_setup.diff | 15 +++ .../all/test_package/CMakeLists.txt | 5 +- .../all/test_package/conanfile.py | 19 +++- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../all/test_v1_package/conanfile.py | 17 +++ 9 files changed, 134 insertions(+), 85 deletions(-) create mode 100644 recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.diff delete mode 100644 recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.txt create mode 100644 recipes/cubicinterpolation/all/patches/rm_conan_basic_setup.diff create mode 100644 recipes/cubicinterpolation/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/cubicinterpolation/all/test_v1_package/conanfile.py diff --git a/recipes/cubicinterpolation/all/conandata.yml b/recipes/cubicinterpolation/all/conandata.yml index 21963599ee1f4..7a7f4164cb542 100644 --- a/recipes/cubicinterpolation/all/conandata.yml +++ b/recipes/cubicinterpolation/all/conandata.yml @@ -1,17 +1,21 @@ sources: "0.1.5": - url: "https://github.com/MaxSac/cubic_interpolation/archive/v0.1.5.tar.gz" + url: "https://github.com/tudo-astroparticlephysics/cubic_interpolation/archive/v0.1.5.tar.gz" sha256: "fc34de15c9dd9e651728c9e0eee5528ee9636e41a3d8aa6f41735018810afd59" "0.1.4": - url: "https://github.com/MaxSac/cubic_interpolation/archive/v0.1.4.tar.gz" + url: "https://github.com/tudo-astroparticlephysics/cubic_interpolation/archive/v0.1.4.tar.gz" sha256: "38bb8fe46b19b135bfcba79e098c5d90284f0bc02f42f86118aefcb63aed7668" "0.1.3": - url: "https://github.com/MaxSac/cubic_interpolation/archive/v0.1.3.tar.gz" + url: "https://github.com/tudo-astroparticlephysics/cubic_interpolation/archive/v0.1.3.tar.gz" sha256: "3151d99ecbbddd4e57605ff1919bdf234d08336b47d369b9dc562acff780aaf7" patches: "0.1.4": - - patch_file: "patches/patch_conanbuildinfo.txt" - base_path: "source_subfolder" + - patch_file: "patches/patch_conanbuildinfo.diff" + patch_type: "conan" + - patch_file: "patches/rm_conan_basic_setup.diff" + patch_type: "conan" "0.1.3": - - patch_file: "patches/patch_conanbuildinfo.txt" - base_path: "source_subfolder" + - patch_file: "patches/patch_conanbuildinfo.diff" + patch_type: "conan" + - patch_file: "patches/rm_conan_basic_setup.diff" + patch_type: "conan" diff --git a/recipes/cubicinterpolation/all/conanfile.py b/recipes/cubicinterpolation/all/conanfile.py index 5ab5b03d47a69..722cbaa5424a1 100644 --- a/recipes/cubicinterpolation/all/conanfile.py +++ b/recipes/cubicinterpolation/all/conanfile.py @@ -1,8 +1,12 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import get, copy, rmdir, apply_conandata_patches, export_conandata_patches +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.microsoft import is_msvc, check_min_vs import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.57.0" class CubicInterpolationConan(ConanFile): @@ -12,7 +16,7 @@ class CubicInterpolationConan(ConanFile): url = "https://github.com/conan-io/conan-center-index" description = "Leightweight interpolation library based on boost and eigen." topics = ("interpolation", "splines", "cubic", "bicubic", "boost", "eigen3") - exports_sources = ["CMakeLists.txt", "patches/**"] + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -23,91 +27,73 @@ class CubicInterpolationConan(ConanFile): "fPIC": True, } - generators = "cmake", "cmake_find_package" _cmake = None - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _is_msvc(self): - return str(self.settings.compiler) in ["Visual Studio", "msvc"] + def export_sources(self): + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": - del self.options.fPIC + self.options.rm_safe("fPIC") def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") def requirements(self): - # TODO: update boost dependency as soon as issue #11207 is fixed + # TODO: update boost dependency as soon as we deprecate conan1.x (see discussion in #11207) self.requires("boost/1.75.0") self.requires("eigen/3.3.9") - @property - def _minimum_compilers_version(self): - return { - "Visual Studio": "16", - "gcc": "5", - "clang": "5", - "apple-clang": "5.1", - } - @property def _required_boost_components(self): return ["filesystem", "math", "serialization"] def validate(self): - miss_boost_required_comp = any(getattr(self.options["boost"], "without_{}".format(boost_comp), True) for boost_comp in self._required_boost_components) - if self.options["boost"].header_only or miss_boost_required_comp: - raise ConanInvalidConfiguration("{0} requires non header-only boost with these components: {1}".format(self.name, ", ".join(self._required_boost_components))) - if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, "14") - - minimum_version = self._minimum_compilers_version.get( - str(self.settings.compiler), False - ) - if not minimum_version: - self.output.warn( - "CubicInterpolation requires C++14. Your compiler is unknown. Assuming it supports C++14." - ) - elif tools.Version(self.settings.compiler.version) < minimum_version: + miss_boost_required_comp = any(getattr(self.dependencies["boost"].options, f"without_{boost_comp}", True) for boost_comp in self._required_boost_components) + if self.dependencies["boost"].options.header_only or miss_boost_required_comp: raise ConanInvalidConfiguration( - "CubicInterpolation requires C++14, which your compiler does not support." + f"{self.ref} requires non header-only boost with these components: " + f"{', '.join(self._required_boost_components)}", ) - if self._is_msvc and self.options.shared: - raise ConanInvalidConfiguration("cubicinterpolation shared is not supported with Visual Studio") + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, "14") + + if not check_min_vs(self, 192, raise_invalid=False): + raise ConanInvalidConfiguration(f"{self.ref} currently Visual Studio < 2019 not yet supported in this recipe. Contributions are welcome") + + if is_msvc(self) and self.options.shared: + raise ConanInvalidConfiguration(f"{self.ref} shared is not supported with Visual Studio") 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_EXAMPLE"] = False - self._cmake.definitions["BUILD_DOCUMENTATION"] = False - self._cmake.configure() - return self._cmake + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["BUILD_EXAMPLE"] = False + tc.variables["BUILD_DOCUMENTATION"] = False + tc.generate() + + deps = CMakeDeps(self) + deps.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) + apply_conandata_patches(self) - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) def package_info(self): self.cpp_info.set_property("cmake_file_name", "CubicInterpolation") diff --git a/recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.diff b/recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.diff new file mode 100644 index 0000000000000..a97479b5d1290 --- /dev/null +++ b/recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.diff @@ -0,0 +1,24 @@ +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 0199a76..b7cd42c 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -11,8 +11,10 @@ add_subdirectory(CubicInterpolation) + add_subdirectory(detail) + + target_link_libraries(CubicInterpolation +- CONAN_PKG::eigen +- CONAN_PKG::boost ++ Eigen3::Eigen ++ Boost::boost ++ Boost::filesystem ++ Boost::serialization + ) + + target_include_directories(CubicInterpolation PUBLIC +@@ -46,6 +48,3 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CubicInterpolationConfig.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CubicInterpolation + ) +- +-install(FILES "${PROJECT_BINARY_DIR}/conanbuildinfo.cmake" +- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CubicInterpolation) diff --git a/recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.txt b/recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.txt deleted file mode 100644 index 614a14be9b7ed..0000000000000 --- a/recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.txt +++ /dev/null @@ -1,11 +0,0 @@ -diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt -index 0199a76..1b0a2b4 100644 ---- a/src/CMakeLists.txt -+++ b/src/CMakeLists.txt -@@ -46,6 +46,3 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CubicInterpolationConfig.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CubicInterpolation - ) -- --install(FILES "${PROJECT_BINARY_DIR}/conanbuildinfo.cmake" -- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CubicInterpolation) diff --git a/recipes/cubicinterpolation/all/patches/rm_conan_basic_setup.diff b/recipes/cubicinterpolation/all/patches/rm_conan_basic_setup.diff new file mode 100644 index 0000000000000..6bc1808f2d777 --- /dev/null +++ b/recipes/cubicinterpolation/all/patches/rm_conan_basic_setup.diff @@ -0,0 +1,15 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index db6eb04..b319d33 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,8 +9,8 @@ set(CubicInterpolation_VERSION ${CubicInterpolation_VERSION_MAJOR}.${CubicInterp + + set(CMAKE_CXX_STANDARD 14) + +-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +-conan_basic_setup(TARGETS) ++find_package(Eigen3 REQUIRED) ++find_package(Boost COMPONENTS filesystem serialization REQUIRED) + + add_subdirectory(src) + diff --git a/recipes/cubicinterpolation/all/test_package/CMakeLists.txt b/recipes/cubicinterpolation/all/test_package/CMakeLists.txt index f0da4436b7927..b98fa443a5368 100644 --- a/recipes/cubicinterpolation/all/test_package/CMakeLists.txt +++ b/recipes/cubicinterpolation/all/test_package/CMakeLists.txt @@ -1,8 +1,5 @@ cmake_minimum_required(VERSION 3.1) -project(test_package CXX) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +project(test_package LANGUAGES CXX) find_package(CubicInterpolation REQUIRED CONFIG) diff --git a/recipes/cubicinterpolation/all/test_package/conanfile.py b/recipes/cubicinterpolation/all/test_package/conanfile.py index 38f4483872d47..0a6bc68712d90 100644 --- a/recipes/cubicinterpolation/all/test_package/conanfile.py +++ b/recipes/cubicinterpolation/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -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", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): 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) + 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/cubicinterpolation/all/test_v1_package/CMakeLists.txt b/recipes/cubicinterpolation/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..7ea0378c83fe1 --- /dev/null +++ b/recipes/cubicinterpolation/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/cubicinterpolation/all/test_v1_package/conanfile.py b/recipes/cubicinterpolation/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/cubicinterpolation/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +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)