Skip to content
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

Merged
merged 19 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions recipes/cubicinterpolation/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ sources:
patches:
"0.1.4":
- patch_file: "patches/patch_conanbuildinfo.txt"
base_path: "source_subfolder"
patch_type: "conan"
- patch_file: "patches/patch_conan_basic_setup.txt"
Copy link
Contributor

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 🤩

patch_type: "conan"
"0.1.3":
- patch_file: "patches/patch_conanbuildinfo.txt"
base_path: "source_subfolder"
patch_type: "conan"
- patch_file: "patches/patch_conan_basic_setup.txt"
patch_type: "conan"
98 changes: 47 additions & 51 deletions recipes/cubicinterpolation/all/conanfile.py
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
Expand All @@ -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],
Expand All @@ -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":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_min_vs with raise_invalid=False has only been available since 1.57.0 (see #12880).

Should I just replace the block with a simple check_min_vs(self, 192)? Otherwise I would have to change the required_conan_version to >=1.57.0.

Copy link
Contributor

Choose a reason for hiding this comment

The 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")
Expand Down
15 changes: 15 additions & 0 deletions recipes/cubicinterpolation/all/patches/patch_conan_basic_setup.txt
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)

17 changes: 15 additions & 2 deletions recipes/cubicinterpolation/all/patches/patch_conanbuildinfo.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0199a76..1b0a2b4 100644
index 0199a76..b7cd42c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -46,6 +46,3 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
@@ -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
)
Expand Down
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")
11 changes: 11 additions & 0 deletions recipes/cubicinterpolation/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.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)
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)
22 changes: 22 additions & 0 deletions recipes/cubicinterpolation/all/test_v1_package/test_package.cpp
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;
}