Skip to content

Commit

Permalink
(conan-io#16299) cubicinterpolation: modernize for conan 2.0
Browse files Browse the repository at this point in the history
* 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 <prince.chrismc@gmail.com>
  • Loading branch information
2 people authored and MartinDelille committed Apr 12, 2023
1 parent f8e79ca commit 687d7f2
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 85 deletions.
18 changes: 11 additions & 7 deletions recipes/cubicinterpolation/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
102 changes: 44 additions & 58 deletions recipes/cubicinterpolation/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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],
Expand All @@ -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")
Expand Down
24 changes: 24 additions & 0 deletions recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.diff
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 0 additions & 11 deletions recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.txt

This file was deleted.

15 changes: 15 additions & 0 deletions recipes/cubicinterpolation/all/patches/rm_conan_basic_setup.diff
Original file line number Diff line number Diff line change
@@ -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)

5 changes: 1 addition & 4 deletions recipes/cubicinterpolation/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
19 changes: 14 additions & 5 deletions recipes/cubicinterpolation/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
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)
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)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/cubicinterpolation/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
17 changes: 17 additions & 0 deletions recipes/cubicinterpolation/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 687d7f2

Please sign in to comment.