-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cubicinterpolation: modernize for conan 2.0 #16299
Changes from 14 commits
e8ff226
0475bbe
bb074ed
cdb23df
1186db1
3d6b63d
6b52939
5fdb7ad
91981f5
ee8e041
7cc4948
a6f7b40
10c1f3b
5633e5e
ede44c0
51f4f56
5bcdbca
fda45b2
a548b73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
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, patch, apply_conandata_patches, export_conandata_patches | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.scm import Version | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import os | ||
|
||
required_conan_version = ">=1.43.0" | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -12,7 +16,6 @@ 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/**"] | ||
settings = "os", "arch", "compiler", "build_type" | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
options = { | ||
"shared": [True, False], | ||
|
@@ -23,91 +26,84 @@ 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): | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return str(self.settings.compiler) in ["Visual Studio", "msvc"] | ||
|
||
def export_sources(self): | ||
#self.copy("CMakeLists.txt") | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export_conandata_patches(self) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
try: | ||
del self.options.fPIC | ||
except Exception: | ||
pass | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def configure(self): | ||
if self.options.shared: | ||
del self.options.fPIC | ||
try: | ||
del self.options.fPIC | ||
except Exception: | ||
pass | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def requirements(self): | ||
# TODO: update boost dependency as soon as issue #11207 is fixed | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.settings.compiler.get_safe("cppstd"): | ||
check_min_cppstd(self, "14") | ||
|
||
if str(self.settings.compiler) == "Visual Studio" and Version(self.settings.compiler.version) < "16": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is raise = False would be better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should I just replace the block with a simple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ConanCenter recipes are always the latest (minus a version) Consumers are expected to be on 1.59 (sooner the later it will become 2.0) so it's absolutely allowed to increase the min version :) |
||
raise ConanInvalidConfiguration("Visual Studio < 2019 not yet supported in this recipe") | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if self._is_msvc and self.options.shared: | ||
raise ConanInvalidConfiguration("cubicinterpolation shared is not supported with Visual Studio") | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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") | ||
|
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) | ||
|
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") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(CubicInterpolation REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} CubicInterpolation::CubicInterpolation) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) |
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "CubicInterpolation/Axis.h" | ||
#include "CubicInterpolation/CubicSplines.h" | ||
#include "CubicInterpolation/Interpolant.h" | ||
|
||
double func(double x) { return x * x + x; } | ||
|
||
int main(int argc, char* argv[]) | ||
prince-chrismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
|
||
auto def = cubic_splines::CubicSplines<double>::Definition(); | ||
def.f = func; | ||
def.axis = std::make_unique<cubic_splines::LinAxis<double>>( | ||
-2.f, 2.f, (size_t)10); | ||
|
||
auto inter | ||
= cubic_splines::Interpolant<cubic_splines::CubicSplines<double>>( | ||
std::move(def), "", ""); | ||
|
||
auto res = inter.evaluate(1.2345f); | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind renaming this (and the old patch) to a
.diff
this way github will apply formating and it will be easier to read 🙏patches/rm_conan_basic_setup.diff
would be amazing 🤩